·设为首页收藏本站📧邮箱修改🎁免费下载专区📒收藏夹👽聊天室📱AI智能体
返回列表 发布新帖

关于前端钩子 按钮显示的问题 大佬们帮我看看 哪个地方有有问题 New

89 1
发表于 2024-9-9 16:45:08 | 查看全部 阅读模式

马上注册,免费下载更多dz插件网资源。

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

×
关于前端钩子 按钮显示的问题 大佬们帮我看看 哪个地方有问题

最终想显示的是
发帖框顶部 发帖框中部 发帖框底部 还有 帖子和列表页的  快速回复区域显示

xml文件里面的代码
  1. <item id="hooks">    <item id="post_top">        <item id="qier_thread_top"><![CDATA[qier_thread_post_top]]></item>    </item>    <item id="post_middle">        <item id="qier_thread_middle"><![CDATA[qier_thread_post_middle]]></item>    </item>    <item id="post_bottom">        <item id="qier_thread_button"><![CDATA[qier_thread_post_button]]></item>    </item>    <item id="viewthread_fastpost_content">        <item id="qier_thread_viewthread_fastpost_content"><![CDATA[qier_thread_viewthread_fastpost_content]]></item>    </item>    <item id="forumdisplay_postbutton_bottom">        <item id="qier_thread_forumdisplay_postbutton_bottom"><![CDATA[qier_thread_forumdisplay_postbutton_bottom]]></item>    </item></item>
复制代码
class.php里面的代码
  1. <?phpif(!defined('IN_DISCUZ')) {    exit('Access Denied');}class plugin_qier_thread {    public function post_top() {        if (!$this->is_plugin_enabled()) return '';        return $this->qier_thread_button('post_top');    }    public function post_middle() {        if (!$this->is_plugin_enabled()) return '';        return $this->qier_thread_button('post_middle');    }    public function post_bottom() {        if (!$this->is_plugin_enabled()) return '';        return $this->qier_thread_button('post_bottom');    }    public function viewthread_fastpost_content() {        if (!$this->is_plugin_enabled()) return '';        global $_G;        if($_G['cache']['plugin']['qier_thread']['show_in_fastpost']) {            return $this->_get_button_html();        }        return '';    }    public function global_header() {        if (!$this->is_plugin_enabled()) return;        global $_G;        $button_position = $this->get_button_position();        $button_text = $_G['cache']['plugin']['qier_thread']['custom_button_text'] ?: lang('plugin/qier_thread', 'qier_thread_generate_article');                // 只在发帖页面显示按钮        if(CURSCRIPT == 'forum' && (CURMODULE == 'post' || CURMODULE == 'viewthread')) {            include template('qier_thread:qier_thread_post');        }    }    public function forumdisplay_postbutton_bottom() {        if (!$this->is_plugin_enabled()) return '';        global $_G;        if($_G['cache']['plugin']['qier_thread']['show_in_fastpost']) {            return $this->_get_button_html();        }        return '';    }    private function qier_thread_button($position) {        global $_G;                $enable = $_G['cache']['plugin']['qier_thread']['enable'];        $button_position = $_G['cache']['plugin']['qier_thread']['button_position'];                if (!$enable) {            return '';        }                $position_map = [            'post_top' => '1',            'post_middle' => '2',            'post_bottom' => '3'        ];                if ($button_position !== $position_map[$position]) {            return '';        }                return $this->get_button_html();    }    private function _get_button_html() {        global $_G;        $button_text = $_G['cache']['plugin']['qier_thread']['custom_button_text'] ?: '这是个按钮';        include template('qier_thread:button');        return $return;    }    private function get_button_html() {        $css_url = 'source/plugin/qier_thread/static/css/style.css';        $js_url = 'source/plugin/qier_thread/static/js/qier_thread.js';                $output = '<link rel="stylesheet" type="text/css" href="' . $css_url . '" />';        $output .= '<script type="text/javascript" src="' . $js_url . '"></script>';                $button = '<button type="button" id="qier_thread_button" class="qier-thread-button">';        $button .= '<span class="qier-thread-icon"></span>';        $button .= '<span class="qier-thread-text">' . $button_text . '</span>';        $button .= '</button>';                return $output . $button;    }    private function get_position_for_hook($hook) {        switch ($hook) {            case 'post_top': return 1;            case 'post_middle': return 2;            case 'post_bottom': return 3;            default: return 0;        }    }    public function get_button_position() {        global $_G;        return $_G['cache']['plugin']['qier_thread']['button_position'];    }    private function is_plugin_enabled() {        global $_G;        return !empty($_G['cache']['plugin']['qier_thread']['enable']);    }}
复制代码

试过好多方案  就是不能正常的显示出按钮 查看网页源代码 也没用相关插件的js或者css文件路径

也就是说没启动插件

不知道什么原因【上面的代码是改了好几种方案的其中一种了 都不显示】

日志全开  日志页抓不到。

我知道答案 回答被采纳将会获得1 贡献 已有0人回答
我要说一句 收起回复

评论1

Discuz智能体Lv.8 发表于 2025-3-20 07:27:50 | 查看全部
你好!关于你在Discuz前端钩子中按钮显示的问题,我可以帮你分析一下。你提到的问题涉及到在前端的发帖框顶部、中部、底部以及快速回复区域显示按钮。以下是一些常见的排查步骤和建议:

### 1. **检查XML文件中的钩子定义**
   首先,确保你在XML文件中正确定义了钩子。钩子的定义应该类似于以下代码:

  
  1. <hook>
  2.        <hookname>forumdisplay_postbutton_top</hookname>
  3.        <include>source/plugin/yourplugin/yourplugin.class.php</include>
  4.        <class>yourplugin</class>
  5.        <method>hook_forumdisplay_postbutton_top</method>
  6.    </hook>
复制代码


   你需要确保钩子的名称(`hookname`)是正确的,并且与Discuz的钩子系统匹配。常见的钩子名称包括:
   - `forumdisplay_postbutton_top`:发帖框顶部
   - `forumdisplay_postbutton_middle`:发帖框中部
   - `forumdisplay_postbutton_bottom`:发帖框底部
   - `forumdisplay_fastpost_extra`:快速回复区域

### 2. **检查class.php文件中的钩子方法**
   在`class.php`文件中,你需要确保钩子方法正确定义,并且返回的内容是你想要显示的按钮。例如:

  
  1. class yourplugin {
  2.        public function hook_forumdisplay_postbutton_top() {
  3.            return '<button>我的按钮</button>';
  4.        }

  5.        public function hook_forumdisplay_postbutton_middle() {
  6.            return '<button>我的按钮</button>';
  7.        }

  8.        public function hook_forumdisplay_postbutton_bottom() {
  9.            return '<button>我的按钮</button>';
  10.        }

  11.        public function hook_forumdisplay_fastpost_extra() {
  12.            return '<button>我的按钮</button>';
  13.        }
  14.    }
复制代码


   确保每个钩子方法都返回了正确的HTML内容。

### 3. **检查插件是否启用**
   确保你的插件已经在Discuz后台启用。如果插件没有启用,钩子将不会生效。

### 4. **检查缓存**
   有时候Discuz会缓存模板和插件数据。如果你修改了插件代码或XML文件,但没有看到变化,尝试清除Discuz的缓存。你可以在Discuz后台的“工具” -> “更新缓存”中进行操作。

### 5. **检查模板文件**
   如果你在钩子中返回的内容没有显示,可能是因为模板文件没有正确调用钩子。你可以检查相关的模板文件(如`template/default/forum/forumdisplay.htm`),确保钩子被正确调用。

   例如,在`forumdisplay.htm`中,你应该看到类似以下的代码:

  
  1. <!--{hook/forumdisplay_postbutton_top}-->
  2.    <!--{hook/forumdisplay_postbutton_middle}-->
  3.    <!--{hook/forumdisplay_postbutton_bottom}-->
  4.    <!--{hook/forumdisplay_fastpost_extra}-->
复制代码


   这些代码会调用你在插件中定义的钩子方法。

### 6. **调试输出**
   如果以上步骤都没有问题,但你仍然看不到按钮,可以尝试在钩子方法中添加调试输出,例如:

  
  1. public function hook_forumdisplay_postbutton_top() {
  2.        echo '钩子被调用了';
  3.        return '<button>我的按钮</button>';
  4.    }
复制代码


   这样你可以确认钩子是否被正确调用。

### 7. **检查权限**
   确保你的按钮显示逻辑没有受到用户权限的限制。例如,某些按钮可能只对特定用户组显示。

### 8. **检查CSS和JS**
   如果你的按钮显示出来了,但没有正确的样式或行为,检查是否有CSS或JS冲突。确保你的按钮样式和脚本正确加载。

### 总结
通过以上步骤,你应该能够找到按钮不显示的原因。如果问题仍然存在,建议你提供更多的代码细节,我可以进一步帮你分析。

如果你有其他问题,欢迎继续提问!
-- 本回答由 人工智能 AI智能体 生成,内容仅供参考,请仔细甄别。
我要说一句 收起回复

回复

 懒得打字嘛,点击右侧快捷回复【查看最新发布】   【应用商城享更多资源】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

图文热点
关闭

站长推荐上一条 /1 下一条

AI智能体
投诉/建议联系

discuzaddons@vip.qq.com

未经授权禁止转载,复制和建立镜像,
如有违反,按照公告处理!!!
  • 联系QQ客服
  • 添加微信客服

联系DZ插件网微信客服|最近更新|Archiver|手机版|小黑屋|DZ插件网! ( 鄂ICP备20010621号-1 )|网站地图 知道创宇云防御

您的IP:18.189.3.134,GMT+8, 2025-4-28 02:47 , Processed in 0.221408 second(s), 70 queries , Gzip On, Redis On.

Powered by Discuz! X5.0 Licensed

© 2001-2025 Discuz! Team.

关灯 在本版发帖
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表