找回密码
 立即注册
搜索
查看: 1730|回复: 0

【discuz 插件教程】插件嵌入点与插件模板

[复制链接]

581

主题

110

回帖

4066

积分

管理员

积分
4066

众神之神

发表于 2014-11-4 23:01:36 | 显示全部楼层 |阅读模式
在线手册:http://faq.comsenz.com/library/plug/plugin/plugin_pre.htm
嵌入点类型
1、页面嵌入点(作用:修改页面显示)
2、信息提示嵌入点(作用:修改showmessage())
3、广告嵌入点(作用:处理广告位数据)
4、功能嵌入点(作用:处理主题,帖子,头像等)

页面嵌入点的三种类型
1、全局页面嵌入点(运行位置:公共模板页面,如头部,尾部)
2、普通页面嵌入点(运行位置:普通模块模板页面)
3、输出前置页面嵌入点(运行位置:模块与模板间(模块输出之后,页面载入之前),处理数据)
页面嵌入点类的命名规则
全局页面嵌入点类(必须)
class plugin_插件标识符{}
如:plugin_thi_kf{}
普通嵌入点类
class plugin_插件标识符_入口文件名 extends 全局页面嵌入点类{} 必须继承全局页面嵌入点类
如:class plugin_thi_kf_forum extends plugin_thi_kf{}
如:forum.php?mod=viewthread&tid=1 中的forum就是入口文件名
页面嵌入点方法命名规则
全局页面嵌入点方法
function global_任意(){}
输出前置页面嵌入点方法
function 模块名_任意_output(){}
普通页面嵌入点方法
function 模块名_任意(){}
如:forum.php?mod=viewthread&tid=1(viewthread就是模块名 mod后面跟着的就是模块名)
全局嵌入点方法写在全局嵌入点类中
普通嵌入点方法写在普通嵌入点类中
普通嵌入点类要继承全局嵌入点类
例子:
  1. <?php
  2. /*全局嵌入点类(公共嵌入点类) class plugin_插件标识符{}*/
  3. class plugin_thi_kf{
  4.         /*全局嵌入点方法 function global_任意(){}*/
  5.         function global_cpnav_extral1() {
  6.                 return 'hellow discuz';
  7.         }
  8. }

  9. /*普通嵌入点类(脚本嵌入点类) class plugin_插件标识符_入口文件名 extends 全局页面嵌入点类{}*/
  10. class plugin_thi_kf_forum extends plugin_thi_kf {
  11.         /*普通嵌入点方法 function 模块名_任意(){}*/
  12.         function index_status_extra() {
  13.                 return 'wellcome to php4';
  14.         }
  15.         /*输出前置页面嵌入点方法 function 模块名_任意_output(){}*/
  16.         function index_thirteen_output() {
  17.                 global $_G;
  18.                 $_G['member']['username'] = 'hehe';
  19.         }
  20. }
  21. ?>
复制代码
页面嵌入点的两种返回值类型
字符串类型
示例:[string global_login_extra]
作用:普通数据显示

数据类型:列表数据显示
示例:[array forumdisplay_thread_subject/0] (0 是数组的键名)
作用:列表数据显示

例子:
  1. function forumdisplay_thread_subject() {
  2.         return array(
  3.         0 => '第一个主题',
  4.         1 => '第二个主题',
  5.         )
  6. }
复制代码

插件模板的定义规则
用法:
include template(插件标识符:模板目录名称/模板名称)
示例:include template ('thi_kf:forum/thirteen');
对应
插件目录/thi_kf/template/forum/thirteen.htm
例子(插件文件中):
  1. <?php
  2. /*全局嵌入点类 class plugin_插件标识符{}*/
  3. class plugin_thi_kf{
  4.         /*全局嵌入点方法 function global_任意(){}*/
  5.         function global_cpnav_extral1() {
  6.                 /*include template(插件标识符:模板目录名称/模板名称)*/
  7.                 include template('thi_kf:forum/thiteen')
  8.         }
  9. }

  10. /*普通嵌入点类 class plugin_插件标识符_入口文件名 extends 全局页面嵌入点类{}*/
  11. class plugin_thi_kf_forum extends plugin_thi_kf {
  12.         /*普通嵌入点方法 function 模块名_任意(){}*/
  13.         function index_status_extra() {
  14.                 return 'wellcome to php4';
  15.         }
  16.         /*输出前置页面嵌入点方法 function 模块名_任意_output(){}*/
  17.         function index_thirteen_output() {
  18.                 global $_G;
  19.                 $_G['member']['username'] = 'hehe';
  20.         }
  21. }
  22. ?>
复制代码
block 标签的应用
作用:将显示的内容,存储到指定变量中
示例:
<!--block 变量名-->
任意的html内容
<!--/block-->
然后在模板文件中写:
  1. <!--{block str}-->
  2. <span>欢迎来到php4中文网,请记住我们的网址为:www.php4.cn</span>
  3. <!--{/block}-->
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|十三博客 ( 鲁ICP备2023000528号 )

GMT+8, 2026-6-1 16:16 , Processed in 0.052380 second(s), 24 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表