Discuz - 新插件核心开发说明文档

本开发文档仅提供给开发新插件内核的开发者使用

Discuz! 新插件核心开发说明文档

新增插件模块说明

“页面嵌入”类型

页面嵌入类型脚本格式

<?php

class plugin_identifier {

function HookId_1() {
......
return ...;
}

function HookId_2() {
......
return ...;
}

......

}

?>

identifier

插件的唯一标识符,在插件设置中设置。

HookId

可用函数名以及被调用的脚本请看参照以下列表。这些函数将在 Discuz! 执行到 common.inc.php 的时候调用。如果要在模板输出前调用,需在函数名结尾加上“_output”。全局调用的函数(“global_”开头的)在模板输出前调用。
如:viewthread_imicons() 在 common.inc.php 时调用,viewthread_imicons_output() 在模板输出前调用。

预定义嵌入点列表

函数名/嵌入点名/HookId 对应脚本 返回值类型
index_header index.php string
index_top index.php string
index_middle index.php string
index_bottom index.php string
forumdisplay_top forumdisplay.php string
forumdisplay_middle forumdisplay.php string
forumdisplay_thread forumdisplay.php array
forumdisplay_bottom forumdisplay.php string
memcp_side memcp.php string
profile_baseinfo_top profile.php string
profile_baseinfo_bottom profile.php string
profile_extrainfo profile.php string
profile_side_top profile.php string
profile_side_bottom profile.php string
viewthread_top viewthread.php string
viewthread_fastpost_side viewthread.php string
viewthread_fastpost_content viewthread.php string
viewthread_profileside viewthread.php array
viewthread_imicons viewthread.php array
viewthread_sidetop viewthread.php array
viewthread_sidebottom viewthread.php array
viewthread_postheader viewthread.php array
viewthread_posttop viewthread.php array
viewthread_postbottom viewthread.php array
viewthread_postfooter viewthread.php array
viewthread_endline viewthread.php array
viewthread_middle viewthread.php string
viewthread_bottom viewthread.php string
global_header 全局 string
global_footer 全局 string
global_footerlink 全局 string

以上预定义的嵌入点会在页面预置好的位置输出函数返回的内容。函数返回值类型如果是 array 且是空值的,必须输出一个空数组,如:

return array();

函数名并不限于以上列表,您可以自定义,只要符合以下规则,函数就会在适当的地方被调用。

function CURSCRIPT_USERDEFINE[_output]()

CURSCRIPT 指明了此函数是哪个脚本执行,USERDEFINE 可自定义,如果函数名以“_output”结尾则会在模板输出前调用,否则会在 common.inc.php 的时候调用。

如:attachment_test() 函数会在下载附件的时候执行。

“_output”结尾的函数的第一个参数为数组,含义为 array('template' => 要输出的模板名, 'message' => showmessage 的文字)

如:以下函数将在登录的时候输出调试文字

function logging_test_output($a) {
print_r($a);
print_r($_POST);
}

plugin_identifier 类中的其它函数为了便于阅读建议以“_”开头,如:

<?php

class plugin_sample {

function _updatecache() {
......
return ...;
}

function viewthread_posttop() {
......
return ...;
}

......

}

?>
特殊主题

特殊主题类型脚本格式

<?php

class threadplugin_identifier {

var $name = 'XX主题'; //主题类型名称
var $iconfile = 'icon.gif';//images/icons/ 目录下新增的主题类型图片文件名
var $buttontext = '发布xx主题';//发帖时按钮文字

function newthread($fid) {
return ...;
}

function newthread_submit($fid) {

}

function newthread_submit_end($fid) {

}

function editpost() {
return ...;
}

function editpost_submit() {

}

function editpost_submit_end() {

}

function newreply_submit_end() {

}

function viewthread() {
return ...;
}
}

?>

此类型用于自创一个特殊主题。

函数名 含义
newthread 发主题时页面新增的表单项目,通过 return 返回即可输出到发帖页面中
newthread_submit 主题发布后的数据判断
newthread_submit_end 主题发布后的数据处理
editpost 编辑主题时页面新增的表单项目,通过 return 返回即可输出到编辑主题页面中
editpost_submit 主题编辑后的数据判断
editpost_submit_end 主题编辑后的数据处理
newreply_submit_end 回帖后的数据处理
viewthread 查看主题时页面新增的内容,通过 return 返回即可输出到主题首贴页面中

Hooks 模块调试说明

写好 Hooks 后更新下论坛缓存(主要是插件部分的缓存),只要你做的插件是处于开启状态,那么你写的 Hooks 模块就已经生效了。如果你的方法不增加和删除的话无需反复更新缓存,更新缓存只是让论坛系统记录下有哪些 Hooks 方法需要调用。

如果要查看页面嵌入类型的嵌入点的具体位置可以在 common.inc.php 结尾包含 _hooks.php 文件即可

include './_hooks.php';

安装、卸载

插件作者可以设计 2 个脚本文件用户插件的安装和卸载,文件名任意。脚本中可用 runquery() 函数执行 SQL 语句,表名可以直接写“cdb_”

在导出的 XML 文件结尾加上安装、卸载脚本的文件名即可

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

安装程序中可随意设计页面的跳转,只要在插件安装结束时候输出添加以下代码即可。

$finish = TRUE;

授权协议、插件介绍

插件在安装的时候您可以自定义授权信息文本,文本支持 Discuz 代码,站长同意后才能安装插件。如果插件存在后台管理界面或者变量配置,那么插件介绍文本会显示在插件后台页面中。

在导出的 XML 文件结尾加上以

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值