请选择 进入手机版 | 继续访问电脑版
查看: 625|回复: 4

[求助] 插件钩子没有生效

[复制链接]

1

主题

4

帖子

9

积分

Newbie

Rank: 1

贡献
0 点
金币
5 个
发表于 2022-1-12 12:28:01 | 显示全部楼层 |阅读模式
  1. <p class="p1" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(0, 80, 50);"><span class="s1" style="color: rgb(127, 0, 85);">class </span>plugin_test<span class="s2" style="color: rgb(0, 0, 0);"> {</span></p><p class="p2" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; min-height: 15px; color: rgb(0, 0, 0);">
  2. </p><p class="p3" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(85, 127, 95);"><span class="s2" style="color: rgb(0, 0, 0);"><span class="Apple-tab-span" style="white-space: pre;">        </span></span>/*</p><p class="p3" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(85, 127, 95);"><span class="Apple-tab-span" style="white-space: pre;">        </span> * 贴内用户信息标记,返回值为标记显示内容</p><p class="p3" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(85, 127, 95);"><span class="Apple-tab-span" style="white-space: pre;">        </span> * "界面 ? 界面设置 ? 帖内用户信息" 用户信息模板中的标记</p><p class="p3" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(85, 127, 95);"><span class="Apple-tab-span" style="white-space: pre;">        </span> * 文档: http://open.discuz.net/?ac=document&page=plugin_hook (搜索"profile_node")</p><p class="p3" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(85, 127, 95);"><span class="Apple-tab-span" style="white-space: pre;">        </span> */</p><p class="p4" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(0, 0, 0);"><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="s1" style="color: rgb(127, 0, 85);">function</span> profile_node(<span class="s3" style="text-decoration-line: underline;">$post</span>, <span class="s3" style="text-decoration-line: underline;">$start</span>, <span class="s3" style="text-decoration-line: underline;">$end</span>) {</p><p class="p4" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(0, 0, 0);"><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="Apple-tab-span" style="white-space: pre;">        </span><span class="s1" style="color: rgb(127, 0, 85);">return </span><span class="s3" style="text-decoration-line: underline;">$start</span>.<span class="s4" style="color: rgb(0, 0, 192);">'我是插件'</span>.<span class="s3" style="text-decoration-line: underline;">$end</span>;</p><p class="p4" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(0, 0, 0);"><span class="Apple-tab-span" style="white-space: pre;">        </span>}</p><p class="p2" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; min-height: 15px; color: rgb(0, 0, 0);"><span class="Apple-tab-span" style="white-space: pre;">        </span></p><p class="p4" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(0, 0, 0);"><span class="Apple-converted-space">    </span><span class="s5" style="color: rgb(34, 128, 76);">public </span><span class="s1" style="color: rgb(127, 0, 85);">function</span> global_test()</p><p class="p4" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(0, 0, 0);"><span class="Apple-converted-space">    </span>{</p><p class="p4" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(0, 0, 0);"><span class="Apple-converted-space">        </span><span class="s1" style="color: rgb(127, 0, 85);">global </span>$_G;</p><p class="p2" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; min-height: 15px; color: rgb(0, 0, 0);">
  3. </p><p class="p4" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(0, 0, 0);"><span class="Apple-converted-space">        </span><span class="s1" style="color: rgb(127, 0, 85);">if</span>(isset(<span class="s1" style="color: rgb(127, 0, 85);">$_GET</span>[<span class="s4" style="color: rgb(0, 0, 192);">'mod'</span>], <span class="s1" style="color: rgb(127, 0, 85);">$_GET</span>[<span class="s4" style="color: rgb(0, 0, 192);">'ac'</span>]) && <span class="s1" style="color: rgb(127, 0, 85);">$_GET</span>[<span class="s4" style="color: rgb(0, 0, 192);">'mod'</span>] == <span class="s4" style="color: rgb(0, 0, 192);">'spacecp' </span>&& <span class="s1" style="color: rgb(127, 0, 85);">$_GET</span>[<span class="s4" style="color: rgb(0, 0, 192);">'ac'</span>] == <span class="s4" style="color: rgb(0, 0, 192);">'avatar'</span>){</p><p class="p2" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; min-height: 15px; color: rgb(0, 0, 0);"><span class="Apple-converted-space">            </span></p><p class="p3" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(85, 127, 95);"><span class="s2" style="color: rgb(0, 0, 0);">           </span>// die('ok1');</p><p class="p2" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; min-height: 15px; color: rgb(0, 0, 0);"><span class="Apple-converted-space">            </span></p><p class="p4" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(0, 0, 0);"><span class="Apple-converted-space">        </span>}</p><p class="p2" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; min-height: 15px; color: rgb(0, 0, 0);">
  4. </p><p class="p2" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; min-height: 15px; color: rgb(0, 0, 0);">
  5. </p><p class="p4" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(0, 0, 0);"><span class="Apple-converted-space">    </span>}</p><p class="p2" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; min-height: 15px; color: rgb(0, 0, 0);">
  6. </p><p class="p4" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(0, 0, 0);">}</p><p class="p2" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; min-height: 15px; color: rgb(0, 0, 0);">
  7. </p><p class="p1" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(0, 80, 50);"><span class="s1" style="color: rgb(127, 0, 85);">class </span>plugin_test_home<span class="s2" style="color: rgb(0, 0, 0);"> </span><span class="s1" style="color: rgb(127, 0, 85);">extends </span>plugin_test<span class="s2" style="color: rgb(0, 0, 0);">{</span></p><p class="p2" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; min-height: 15px; color: rgb(0, 0, 0);"><span class="Apple-converted-space">    </span></p><p class="p4" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(0, 0, 0);"><span class="Apple-converted-space">    </span><span class="s1" style="color: rgb(127, 0, 85);">function</span> spacecp_testxx()</p><p class="p4" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(0, 0, 0);"><span class="Apple-converted-space">    </span>{</p><p class="p4" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(0, 0, 0);"><span class="Apple-converted-space">        </span>die(<span class="s4" style="color: rgb(0, 0, 192);">'ok2'</span>);</p><p class="p5" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(127, 0, 85);"><span class="s2" style="color: rgb(0, 0, 0);">        </span>return false<span class="s2" style="color: rgb(0, 0, 0);">;</span></p><p class="p4" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(0, 0, 0);"><span class="Apple-converted-space">    </span>}</p><p class="p4" style="font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Monaco; color: rgb(0, 0, 0);">}</p>
复制代码

根据教程https://open.dismall.com/?ac=document&page=plugin_hook
  1. function CURMODULE_USERDEFINE[_output]()
复制代码


当访问
/home.php?mod=spacecp&ac=avatar时,这个 spacecp_testxx() 为什么没有被调用(global_test能被正常调用)?
我知道答案 回答被采纳将会获得5 金币 已有4人回答
回复

使用道具 举报

1

主题

4

帖子

9

积分

Newbie

Rank: 1

贡献
0 点
金币
5 个
 楼主| 发表于 2022-1-13 09:42:01 | 显示全部楼层
科站网 发表于 2022-1-12 17:42
https://open.dismall.com/?ac=document&page=plugin_hook脚本嵌入点demo里写的
  1. 函数名并不限于以上列表,您可以自定义,只要符合以下规则,函数就会在适当的地方被调用。

  2. function CURMODULE_USERDEFINE[_output]()
复制代码

是要用这种嵌入点
但是这里说的是不全面的,如果CURSCRIPT是home
那么嵌入点函数的写法应该是
  1. function CURMODULE_AC_USERDEFINE[_output]() //AC为对应请求URL的ac参数值
复制代码
回复 支持 反对

使用道具 举报

1

主题

4

帖子

9

积分

Newbie

Rank: 1

贡献
0 点
金币
5 个
 楼主| 发表于 2022-1-12 12:30:44 | 显示全部楼层
  1. class plugin_test {

  2.         /*
  3.          * 贴内用户信息标记,返回值为标记显示内容
  4.          * "界面 ? 界面设置 ? 帖内用户信息" 用户信息模板中的标记
  5.          * 文档: http://open.discuz.net/?ac=document&page=plugin_hook (搜索"profile_node")
  6.          */
  7.         function profile_node($post, $start, $end) {
  8.                 return $start.'我是插件'.$end;
  9.         }
  10.        
  11.     public function global_test()
  12.     {
  13.         global $_G;

  14.         if(isset($_GET['mod'], $_GET['ac']) && $_GET['mod'] == 'spacecp' && $_GET['ac'] == 'avatar'){
  15.             
  16.            // die('ok1');
  17.             
  18.         }


  19.     }

  20. }

  21. class plugin_test_home extends plugin_test{
  22.    
  23.     function spacecp_testxx()
  24.     {
  25.         die('ok2');
  26.         return false;
  27.     }
  28. }
复制代码


上面乱码里,没权限编辑,代码在这里
回复 支持 反对

使用道具 举报

1

主题

4

帖子

9

积分

Newbie

Rank: 1

贡献
0 点
金币
5 个
 楼主| 发表于 2022-1-12 16:14:10 | 显示全部楼层
呃,知道了,home脚本的脚本嵌入点与其他页面不一样,跟后面的ac参数也有关。。。。文档没有标明,坑了。。。
回复 支持 反对

使用道具 举报

19

主题

799

帖子

1145

积分

开发者

Discuz! 运维

Rank: 6Rank: 6Rank: 6

贡献
2 点
金币
161 个
QQ
发表于 2022-1-12 17:42:15 | 显示全部楼层
https://open.dismall.com/?ac=document&page=plugin_hook脚本嵌入点demo里写的
  1. //脚本嵌入点类
  2. class plugin_identifier_CURSCRIPT extends plugin_identifier {

  3.         function HookId_1() {
  4.                 ......
  5.                 return ...;
  6.         }

  7.         function HookId_2() {
  8.                 ......
  9.                 return ...;
  10.         }

  11.         ......

  12. }
复制代码
回复 支持 反对

使用道具 举报

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

本版积分规则

扫一扫添加有偿QQ
扫一扫添加微信客服