discuz制作插件备忘录

第一步,设计新插件,保存后

discuz制作插件备忘录 - qidizi - qidizi 的博客

第二步,修改模块增加一个class类型,对于文件夹名,可以保持默认(跟id相同),保存.

discuz制作插件备忘录 - qidizi - qidizi 的博客

第三步,在./source/plugin目录下建立跟上面的目录名相同的目录.然后把xml导出到那个目录中.

第四步,在本插件目录中创建随便.class.php文件,内容如下;作用见代码中说明也可以到官方的帮助中看一下.但是官方的说明有一个点我看得不太明白.不得已直接瞧代码才明白.

 

<?php
if(!defined('IN_DISCUZ')) {
    exit('Access Denied');
}
/*class名由plugin_id名组成*/
class plugin_recommend_article {

/*初始化*/
    function plugin_recommend_article(){
        global $_G;
        //$this->pluginPath = $_G['siteurl']. 'source/plugin/recommend_article/';
    }  

    /*
     * add by qidizi
     * 输出推荐下拉

    * 内部使用公用方法,建议增加_线
     */
    function _recommendSelect($vars = array()){
        global $_G;
        if (empty($_G['uid']) || empty($vars) ) return;//未登录
        
        $res = DB::query("SELECT p_a_id, name FROM ".DB::table('chrd_common_recommend_area'));

//注意这里为了代码独立出来,方便升级,把所有的功能代码都放到这个目录来了,所以js也放这里了.

//然后使用php输出js代码方式.也可以使用上面的 //$this->pluginPath来输出一个xxx.js

 

       $sel = "
        <script type=\"text/javascript\" src=\"plugin.php?id=recommend_article:ajaxrecommed&action=loadJs\"></script>
        <select οnchange=\"ajaxRecommend({pid:this.value, type:{$vars['type']}, aid:{$vars['aid']}, path:'{$vars['path']}' });\">
        <option value=0>请选择推荐位置</option>";
        
        while ($tmp = DB::fetch($res)){
            $sel .="<option value=\"{$tmp['p_a_id']}\">{$tmp['name']}</option>";
        }
        
        $sel .="</select>";
        return array('select'=>$sel);
    }
}

/* 子类,由 plugin_id名_需要出现的对象脚本名 组成

* 脚本对象在discuz的根目录下,

* 有home.php,即home

* 有forum.php即forum

*反正你看到 地址上是http://chrd.q/discuz/forum.php,想出现在这个页面就得写一个plugin_id名_forum子类;

*/

 

class plugin_recommend_article_forum extends plugin_recommend_article {
    /*在帖子内容页输出推荐下拉

* 方法名字组成,define('CURMODULE', $mod)定义的$mod,表示在那个模块中可以出现,配合类名中forum,就能达到某个限定_自定名字_output这个位置还有其它定义,需要看官方说明

*

*/
    function viewthread_showSelect_output(){
        global $_G;
        $vars = array('type'=>1, 'aid'=>$_G['tid'], 'path'=>$_G['fid']);        
        return $this->_recommendSelect($vars);
    }   
}

/* plugin_是固定需要的,recommend_article是插件id,home是根目录下home.php的名字*/
class plugin_recommend_article_home extends plugin_recommend_article {
    
    /*在日志内容页输出推荐下拉
     * 要在home模块内出现,必须加上do的类型,http://chrd.q/discuz/home.php?mod=space&uid=1&do=blog&id=1
     * 所以需要space_showSelect_output 写成 space_blog_showSelect_output

*我就是因为只看官方说明.发现这个东东怎么总是出不来,

*在function_core.php中的hookscript中有一句说明了它在这个时候改了规则....


    if($hscript == 'home') {
        if($script != 'spacecp') {
            $script = 'space_'.(!empty($_G['gp_do']) ? $_G['gp_do'] : (!empty($_GET['do']) ? $_GET['do'] : ''));
        } else {
            $script .= !empty($_G['gp_ac']) ? '_'.$_G['gp_ac'] : (!empty($_GET['ac']) ? '_'.$_GET['ac'] : '');
        }
    }  

 

  */
    function space_blog_showSelect_output(){//array('type'=>2, 'id'=>$blog[blogid], 'path'=>''
        global $_G;
        $vars = array('type'=>2, 'aid'=>$_G['gp_id'], 'path'=>'');        
        return $this->_recommendSelect($vars);
    }
}

 

 

插件数据生成是在./function/cache/cache_setting.php中的get_cachedata_setting_plugin($method = '')生成的.

放在模板中的hook代码只是在对应的位置输出对应的$_G数组中的数据而已;

 

在模板中的home/space_blog_view.html某处显示space_blog_showSelect_output输出的内容,这样写

<!--{hook/space_blog_showSelect 'select'}-->

效果

discuz制作插件备忘录 - qidizi - qidizi 的博客

 

 

如果安装时候需要用到install或是uninstall.php文件,需要手动向xml中增加(xml中有很item,注意item放的树序),关于这个xml的解释,看后台的admin中的plugin的脚本代码.


        <item id="installfile"><![CDATA[install.php]]></item>
        <item id="uninstallfile"><![CDATA[uninstall.php]]></item>
    </item>
</root>

 

安装脚本install.php可以这样写,uninstall差不多意思了.

<?php

if(!defined('IN_DISCUZ')) {
    exit('Access Denied');
}

$dir = $_G['gp_dir'];//获取本插件的目录名

if (empty($_G['gp_installing'])){//第一次,进入本文件时,先进行提示,忘记写取消按钮了.第二次,即按下确定安装再进行安装
    echo '<div class="infobox"><h4 class="infotitle2">安装前提示</h4>'
        .'<div style="text-align:left;line-height:25px;">'
        ."
        安装前说明:<br />
        重新安装将会把旧的推荐信息数据库的表全部删除,所以.以前的信息将会丢失.请慎重操作.
        "
        .'</div><br /><br /><center>'
        .'<button οnclick="location.href=\''.ADMINSCRIPT.'?action=plugins&operation=plugininstall&dir='.$dir.'&installtype=&installing=1\'">'
        .'知道了,开始安装</button></center></div>';
    exit;//注意别直接就安装了.退出先
}


$sid = 1;//服务器id
$tabPre = $_G['config']['db'][$sid]['tablepre'];//获取配置中的表前缀

$sql = <<<EOF

--
-- 表的结构 `{$tabPre}chrd_common_recommend_area`
--

DROP TABLE IF EXISTS `{$tabPre}chrd_common_recommend_area`;
CREATE TABLE IF NOT EXISTS `{$tabPre}chrd_common_recommend_area` (
  `p_a_id` int(4) NOT NULL COMMENT '页序号+位置序号数字组合',
  `name` varchar(250) NOT NULL COMMENT '位置名称',
  PRIMARY KEY (`p_a_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='文章推荐位置表';

-- --------------------------------------------------------

--
-- 表的结构 `{$tabPre}chrd_common_recommend_article`
--

DROP TABLE IF EXISTS `{$tabPre}chrd_common_recommend_article`;
CREATE TABLE IF NOT EXISTS `{$tabPre}chrd_common_recommend_article` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `uid` int(11) NOT NULL COMMENT '首个推荐用户id',
  `users` int(11) NOT NULL DEFAULT '0' COMMENT '推荐总数',
  `type` int(11) NOT NULL COMMENT '文章类别(1帖子2日志)',
  `path` varchar(250) NOT NULL COMMENT '文章分类路径,用.分隔',
  `aid` int(11) NOT NULL COMMENT '文章id',
  `p_a_id` int(11) NOT NULL COMMENT '推荐位置id',
  `yes` int(11) NOT NULL DEFAULT '0' COMMENT '同意人数',
  `no` int(11) NOT NULL DEFAULT '0' COMMENT '不同意人数',
  `pass` int(1) NOT NULL DEFAULT '0' COMMENT '通过审核',
  `time` int(11) NOT NULL COMMENT '推荐时间',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COMMENT='推荐文章表' AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- 表的结构 `{$tabPre}chrd_common_recommend_grade_log`
--

DROP TABLE IF EXISTS `{$tabPre}chrd_common_recommend_grade_log`;
CREATE TABLE IF NOT EXISTS `{$tabPre}chrd_common_recommend_grade_log` (
  `rid` int(11) NOT NULL COMMENT '推荐id',
  `uid` int(11) NOT NULL COMMENT '用户id',
  `time` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='推荐文章审核记录';

-- --------------------------------------------------------

--
-- 表的结构 `{$tabPre}chrd_common_recommend_log`
--

DROP TABLE IF EXISTS `{$tabPre}chrd_common_recommend_log`;
CREATE TABLE IF NOT EXISTS `{$tabPre}chrd_common_recommend_log` (
  `rid` int(11) NOT NULL COMMENT '推荐id',
  `uid` int(11) NOT NULL COMMENT '推荐用户',
  `time` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='推荐记录';


EOF;

runquery($sql);//执行sql语句

$finish = TRUE;//安装完成了,必须出现这个变量.

 

-------

安装后需要启用才能在模板中显示.

 

-------------

使用<script type=\"text/javascript\" src=\"plugin.php?id=recommend_article:ajaxrecommed&action=loadJs\"></script>调用本目录中的php代码编写.

文件名为 随便.inc.php

 

ajaxrecommed.inc.php

 

内容就简单的

 

<?php

if(!defined('IN_DISCUZ')) {
    exit('Access Denied');
}

switch($_G['gp_action']) {
    case 'loadJs':

 

就可以了.

 

插件简介 估数游戏1.上传插件包 upload 目录下的所有文件到论坛根目录下 2.运行下列SQL语句:(如6.1版论坛时已曾安装过开口中插件,升级数据语可忽略,只须从新覆盖文件与源码修改)DROP TABLE IF EXISTS cdb_mouth; CREATE TABLE cdb_mouth (   id int(4) NOT NULL auto_increment,   state tinyint(1) NOT NULL default '0',   lastid mediumint(8) NOT NULL default '0',   lastupper mediumint(1) unsigned NOT NULL default '0',   lastlower mediumint(1) unsigned NOT NULL default '0',   number mediumint(1) unsigned NOT NULL default '0',   chance mediumint(1) unsigned NOT NULL default '0',   timer int(10) NOT NULL default '0',   rantype tinyint(1) NOT NULL default '0',   authorid mediumint(8) NOT NULL default '0',   pointid mediumint(8) NOT NULL default '0',   comment varchar(40) NOT NULL default '',   data text NOT NULL,   PRIMARY KEY  (id) ) TYPE=MyISAM AUTO_INCREMENT=1;DROP TABLE IF EXISTS cdb_mouth_members; CREATE TABLE cdb_mouth_members (   uid mediumint(8) NOT NULL default '0',   mouthtime int(10) NOT NULL default '0',   profit int(10) NOT NULL default '0',   ktimes smallint(8) NOT NULL default '0',   ptimes smallint(8) NOT NULL default '0',   ltimes smallint(8) NOT NULL default '0',   style tinyint(1) NOT NULL default '0',   PRIMARY KEY  (uid) ) TYPE=MyISAM;3.在后台导入插件配置信息 discuz_plugin_mouth. 4..打开 include/cache.func.php 查找'medals'        => array('medals')下面加:'mouth'        => array('mouth'),查找               case 'medals':                       $table = 'medals';                       $cols = 'medalid, name, image';                       $conditions = "WHERE available='1'";                     break;下面加:                              case 'mouth':                                                $table = "mouth mo LEFT JOIN {$tablepre}members m ON m.uid=mo.pointid LEFT JOIN {$tablepre}members mm ON mm.uid=mo.authorid LEFT JOIN {$tablepre}members mmm ON mmm.uid=mo.lastid";                                                $cols = "mo.*, m.username AS pointname, mm.username AS authorname, mmm.username AS lastname";                            
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值