找回密码
 注册账号

QQ登录

只需一步,快速开始

《泰拉瑞亚下载-1.4.2.3版》 泰拉瑞亚服务器 - MOD模组下载

入驻泰拉战网 新手指引 - 升级 - 师徒

泰拉瑞亚合成表 泰拉卡牌 - 泰拉江湖 - 泰拉刺客

联系泰拉开发组👈进入 积分市场 - 房产交易 - 水晶获取

查看: 2648|回复: 0

Discuz runhooks函数 运行钩子

[复制链接]

431

主题

77

回帖

8

广播

论坛版主

积分
214
泰拉
0
水晶
10
铜钥匙
0
银钥匙
0
金钥匙
0

【江湖新秀】【宝剑回鞘】【泰拉达人】【奥运选手】

发表于 2020-10-27 14:57:18 | 显示全部楼层 |阅读模式
本帖最后由 mickeyort 于 2020-10-27 15:03 编辑
  1. /**
  2. * 运行钩子
  3. */

  4. function runhooks($scriptextra = '') {
  5.         if(!defined('HOOKTYPE')) {
  6.                 define('HOOKTYPE', !defined('IN_MOBILE') ? 'hookscript' : 'hookscriptmobile');
  7.         }
  8.         if(defined('CURMODULE')) {
  9.                 global $_G;
  10.                 if($_G['setting']['plugins']['func'][HOOKTYPE]['common']) {
  11.                         hookscript('common', 'global', 'funcs', array(), 'common');
  12.                 }
  13.                 hookscript(CURMODULE, $_G['basescript'], 'funcs', array(), '', $scriptextra);
  14.         }
  15. }
复制代码



  1. /**
  2. * 执行插件脚本
  3. */
  4. function hookscript($script, $hscript, $type = 'funcs', $param = array(), $func = '', $scriptextra = '') {
  5.         global $_G;
  6.         static $pluginclasses;
  7.         if($hscript == 'home') {
  8.                 if($script == 'space') {
  9.                         $scriptextra = !$scriptextra ? $_GET['do'] : $scriptextra;
  10.                         $script = 'space'.(!empty($scriptextra) ? '_'.$scriptextra : '');
  11.                 } elseif($script == 'spacecp') {
  12.                         $scriptextra = !$scriptextra ? $_GET['ac'] : $scriptextra;
  13.                         $script .= !empty($scriptextra) ? '_'.$scriptextra : '';
  14.                 }
  15.         }
  16.         if(!isset($_G['setting'][HOOKTYPE][$hscript][$script][$type])) {
  17.                 return;
  18.         }
  19.         if(!isset($_G['cache']['plugin'])) {
  20.                 loadcache('plugin');
  21.         }
  22.         foreach((array)$_G['setting'][HOOKTYPE][$hscript][$script]['module'] as $identifier => $include) {
  23.                 if($_G['pluginrunlist'] && !in_array($identifier, $_G['pluginrunlist'])) {
  24.                         continue;
  25.                 }
  26.                 $hooksadminid[$identifier] = !$_G['setting'][HOOKTYPE][$hscript][$script]['adminid'][$identifier] || ($_G['setting'][HOOKTYPE][$hscript][$script]['adminid'][$identifier] && $_G['adminid'] > 0 && $_G['setting']['hookscript'][$hscript][$script]['adminid'][$identifier] >= $_G['adminid']);
  27.                 if($hooksadminid[$identifier]) {
  28.                         @include_once DISCUZ_ROOT.'./source/plugin/'.$include.'.class.php';
  29.                 }
  30.         }
  31.         if(@is_array($_G['setting'][HOOKTYPE][$hscript][$script][$type])) {
  32.                 $_G['inhookscript'] = true;
  33.                 $funcs = !$func ? $_G['setting'][HOOKTYPE][$hscript][$script][$type] : array($func => $_G['setting'][HOOKTYPE][$hscript][$script][$type][$func]);
  34.                 foreach($funcs as $hookkey => $hookfuncs) {
  35.                         foreach($hookfuncs as $hookfunc) {
  36.                                 if($hooksadminid[$hookfunc[0]]) {
  37.                                         $classkey = (HOOKTYPE != 'hookscriptmobile' ? '' : 'mobile').'plugin_'.($hookfunc[0].($hscript != 'global' ? '_'.$hscript : ''));
  38.                                         if(!class_exists($classkey, false)) {
  39.                                                 continue;
  40.                                         }
  41.                                         if(!isset($pluginclasses[$classkey])) {
  42.                                                 $pluginclasses[$classkey] = new $classkey;
  43.                                         }
  44.                                         if(!method_exists($pluginclasses[$classkey], $hookfunc[1])) {
  45.                                                 continue;
  46.                                         }
  47.                                         $return = call_user_func(array($pluginclasses[$classkey], $hookfunc[1]), $param);

  48.                                         if(substr($hookkey, -7) == '_extend' && !empty($_G['setting']['pluginhooks'][$hookkey])) {
  49.                                                 continue;
  50.                                         }

  51.                                         if(is_array($return)) {
  52.                                                 if(!isset($_G['setting']['pluginhooks'][$hookkey]) || is_array($_G['setting']['pluginhooks'][$hookkey])) {
  53.                                                         foreach($return as $k => $v) {
  54.                                                                 $_G['setting']['pluginhooks'][$hookkey][$k] .= $v;
  55.                                                         }
  56.                                                 } else {
  57.                                                         foreach($return as $k => $v) {
  58.                                                                 $_G['setting']['pluginhooks'][$hookkey][$k] = $v;
  59.                                                         }
  60.                                                 }
  61.                                         } else {
  62.                                                 if(!is_array($_G['setting']['pluginhooks'][$hookkey])) {
  63.                                                         $_G['setting']['pluginhooks'][$hookkey] .= $return;
  64.                                                 } else {
  65.                                                         foreach($_G['setting']['pluginhooks'][$hookkey] as $k => $v) {
  66.                                                                 $_G['setting']['pluginhooks'][$hookkey][$k] .= $return;
  67.                                                         }
  68.                                                 }
  69.                                         }
  70.                                 }
  71.                         }
  72.                 }
  73.         }
  74.         $_G['inhookscript'] = false;
  75. }
复制代码


  1. function hookscriptoutput($tplfile) {
  2.         global $_G;
  3.         if(!empty($_G['hookscriptoutput'])) {
  4.                 return;
  5.         }
  6.         hookscript('global', 'global');
  7.         $_G['hookscriptoutput'] = true;
  8.         if(defined('CURMODULE')) {
  9.                 $param = array('template' => $tplfile, 'message' => $_G['hookscriptmessage'], 'values' => $_G['hookscriptvalues']);
  10.                 hookscript(CURMODULE, $_G['basescript'], 'outputfuncs', $param);
  11.         }
  12. }
复制代码

[发帖际遇]: mickeyort 在网吧通宵,花了 18 泰拉. 幸运榜 / 衰神榜
您需要登录后才可以回帖 登录 | 注册账号

本版积分规则

QQ|友链申请|Archiver|手机版|小黑屋|游芯沙盒 ( 陕ICP备11006283号-1 )

GMT+8, 2024-5-3 05:53 , Processed in 0.114145 second(s), 41 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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