前一节 主要学习了Joomla1.5模块开发的基本原理,这一节简单改变了一些代码编写命名等
基本功能:
1、后台指定Discuz!的版块ID,显示该ID下的帖子
2、设定帖子显示条数
3、设定Discuz!表前缀
待加功能:
1、Discuz!路径填写,及帖子地址链接
2、帖子排序选择功能(计划为最新发表主题、最多回复主题两种)
3、设置是否显示帖子的主题分类(非版块名称,Discuz!帖子的主题分类)
4、设置是否显示帖子发表时间
5、设置是否显示帖子回复数
存在问题:
1、如果后台分类ID输入的值在Discuz!表中的版块分类ID不存在,未给出提示!目前判断为无值输入
/******************分割线********************/
1、创建文件 /modules/mod_jk_dz_post/mod_dz_jk_dz_post.xml:
<?xml version="1.0" encoding="utf-8"?>
<install type="module" version="1.5.0">
<name>Jk Discuz! Post</name>
<author>Joomla178, vanshion</author>
<creationDate>2011-01-01</creationDate>
<copyright>All rights reserved by Joomla178 2010.</copyright>
<license>GPL 2.0</license>
<authorEmail>shion.van#gmail.com</authorEmail>
<authorUrl>www.Joomla178.com</authorUrl>
<version>1.0.0</version>
<description>Provides a listing of Discuz post</description>
<!-- 需要安装的模块相关文件列表 -->
<files>
<!-- 模块控制文件 -->
<filename module="mod_jk_dz_post">mod_jk_dz_post.php</filename>
<filename>index.html</filename>
<filename>helper.php</filename>
<filename>tmpl/default.php</filename>
<filename>tmpl/index.html</filename>
</files>
<languages>
<!-- 模块包含的语言文件 -->
<language tag="en-GB">en-GB.mod_jk_dz_post.ini</language>
<language tag="zh-CN">zh-CN.mod_jk_dz_post.ini</language>
</languages>
<params>
<param name="moduleclass_sfx" type="text" default="" label="Module Class Suffix" description="PARAMMODULECLASSSUFFIX" />
<param name="@spacer" type="spacer" default="" label="" description="" />
<param name="dz_category" type="text" default="" label="LABEL DISCUZ CATEGORY ID" description="DESC DISCUZ CATEGORY ID" />
<param name="dz_count" type="text" default="5" label="LABEL DISCUZ POST COUNT" description="DESC DISCUZ POST COUNT" />
<param name="dz_tableprefix" type="text" default="cdb_" label="LABEL DISCUZ TABLE PREFIX" description="DESC DISCUZ TABLE PREFIX" />
<param name="@spacer" type="spacer" default="" label="" description="" />
</params>
<params group="advanced">
<param name="cache" type="list" default="1" label="CACHING" description="SELECT WHETHER TO CACHE THE CONTENT OF THIS MODULE">
<option value="1">USE GLOBAL</option>
<option value="0">NO CACHING</option>
</param>
<param name="cache_time" type="text" default="30" label="CACHE TIME" description="THE TIME BEFORE THE MODULE IS RECACHED" />
</params>
</install>
上述代码主要设定了一个后台传入参数:Discuz主题显示条数。
2、创建文件 /modules/mod_jk_dz_post/mod_jk_dz_post.php:
*这次编写将由后台传入的值放到了helper.php中,便于代码查找编写
<?php
/**
* @version $Id: mod_jk_dz_post.php 492 2011-01-08 13:54:46Z vanshion $
* @package joomla
* @author Joomla178 http://www.Joomla178.com
* @copyright Copyright (c) 2010 - 2011 Joomla178. All rights reserved.
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
*/
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
require_once(dirname(__FILE__).DS.'helper.php');
$list = ModJkDzPostHelper::getList($params);
require(JModuleHelper::getLayoutPath('mod_jk_dz_post'));
?>
3、创建文件 /modules/mod_jk_dz_post/helper.php:
<?php
/**
* @version $Id: helper.php 492 2011-01-08 13:54:46Z vanshion $
* @package joomla
* @author Joomla178 http://www.Joomla178.com
* @copyright Copyright (c) 2010 - 2011 Joomla178. All rights reserved.
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
*/
defined('_JEXEC') or die('Direct Access to this location is not allowed.');
class ModJkDzPostHelper
{
function getList(&$params)
{
global $mainframe;
$db = &JFactory::getDBO();
$dz_count = intval ( $params->get ( 'dz_count', 5 ) );//限定帖子数
$dz_tableprefix = $params->get( 'dz_tableprefix', "cdb_" );//表前缀
$dz_category = trim($params->get( 'dz_category'));//DZ版块分类
$dz_post_table = $dz_tableprefix . "threads";//关联表_threads
$fids = null;
if ( !$dz_category ) {//如果后台类别无输入值
$query = 'SELECT `subject` FROM '. $dz_post_table .' ORDER BY `dateline` DESC LIMIT 0, '.$dz_count .' ';
$db->setQuery($query);
$list = ($list = $db->loadObjectList())?$list:array();
return $list;}
else{//如果后台类别有输入值
if( $dz_category > 0){//输入值大于0
$fids = $dz_category;
$query = 'SELECT `subject` FROM '. $dz_post_table .' WHERE `fid` = '.$fids.' ORDER BY `dateline` DESC LIMIT 0, '.$dz_count .' ';
$db->setQuery($query);
$list = ($list = $db->loadObjectList())?$list:array();
return $list;
}
else{//输入值为0或者负数
$query = 'SELECT `subject` FROM '. $dz_post_table .' ORDER BY `dateline` DESC LIMIT 0, '.$dz_count .' ';
$db->setQuery($query);
$list = ($list = $db->loadObjectList())?$list:array();
return $list;
}
}
} //结束获取主题
} //end ModDzLatestPostHelper
?>
4、创建文件 /modules/mod_jk_dz_post/tmpl/default.php:
<?php defined('_JEXEC') or die('Restricted access'); // no direct access ?>
<?php echo JText::_('DISCUZ POST'); ?>
<ul>
<?php foreach ($list as $row) { ?>
<li>
<?php echo $row->subject; ?>
</li>
<?php } ?>
</ul>
5、创建文件 /modules/mod_jk_dz_post/index.html:
创建文件 /modules/mod_jk_dz_post/tmpl/index.html:
<html><body bgcolor="#FFFFFF"></body></html>
6、创建英文标准包 /modules/mod_jk_dz_post/en-GB.mod_dz_latest_post.ini:
6、创建中文标准包 /modules/mod_jk_dz_post/zh-CN.mod_dz_latest_post.ini:
语言包见下面打包文件
7、切记以上所有文件均以utf-8编码保存!最后打包文件为zip格式,便于后续开发,在此打包为
网站调整,暂时无法下载,将发布beta版