discuz hook使用
公共hook global_footer
模板显示形式: $_G['setting']['pluginhooks']['global_footer']
追踪
runhooks();
↓
if($_G['setting']['plugins'][HOOKTYPE.'_common']) { hookscript('common', 'global', 'funcs', array(), 'common'); }
↓
插件类中相对应的方法
//plugin_qqconnect == plugin_qqconnect_common
class plugin_qqconnect extends plugin_qqconnect_base { var $allow = false; function plugin_qqconnect() { $this->init(); } function common() { $this->common_base(); } function global_footer() { if(!$this->allow) { return; } global $_G; if(!$_G['cookie']['client_token'] || !empty($_G['inshowmessage']) || empty($_G['cookie']['connect_js_name'])) { return; } if($_G['cookie']['connect_js_name'] == 'user_bind') { require_once libfile('function/connect'); $params = array('openid' => $_G['cookie']['connect_uin']); return connect_user_bind_js($params); }elseif($_G['cookie']['connect_js_name'] == 'feed_resend') { require_once libfile('function/connect'); return connect_feed_resend_js(); } } }
模块动作 hook
模板显示形式: $_G['setting']['pluginhooks']['logging_method']
追踪
runhooks();
↓
hookscript(CURMODULE, $_G['basescript']);// 如CURMODULE :logging $_G['basescript']: member
↓
插件类中相对应的方法
class plugin_qqconnect_member extends plugin_qqconnect { function logging_method() {// CURMODULE... if(!$this->allow) { return; } return tpl_login_bar(); }
}
手动添加一个公共的hook
在专题中添加一个hook
<!--{hook/global_topic_show}-->
在插件类common类(即没有basescript类)中添加方法 global_topic_show(begin with global_...)
如:
class plugin_rotate_award extends plugin_rotate_award_base { var $allow = false; function plugin_rotate_award() { $this->init(); } function common() { $this->common_base(); } //抽奖转盘 function global_rotate_reward() { global $_G; if (!$this->allow) { return; } $extrastr = ''; if (!$_G['pluginrotateaward']['loadedjquery']) { $extrastr = '<script type="text/javascript" src="source/plugin/rotate_award/template/jquery-1.7.2.min.js"></script><script type="text/javascript">jQuery.noConflict();</script>'; } return $extrastr. tpl_rotate_reward(); } }