bug八阿哥 发表于 2024-9-8 00:35:24

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

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

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

xml文件里面的代码

[*]<item id=&quot;hooks&quot;>
[*]    <item id=&quot;post_top&quot;>
[*]      <item id=&quot;qier_thread_top&quot;><!]></item>
[*]    </item>
[*]    <item id=&quot;post_middle&quot;>
[*]      <item id=&quot;qier_thread_middle&quot;><!]></item>
[*]    </item>
[*]    <item id=&quot;post_bottom&quot;>
[*]      <item id=&quot;qier_thread_button&quot;><!]></item>
[*]    </item>
[*]    <item id=&quot;viewthread_fastpost_content&quot;>
[*]      <item id=&quot;qier_thread_viewthread_fastpost_content&quot;><!]></item>
[*]    </item>
[*]    <item id=&quot;forumdisplay_postbutton_bottom&quot;>
[*]      <item id=&quot;qier_thread_forumdisplay_postbutton_bottom&quot;><!]></item>
[*]    </item></item>
class.php里面的代码

[*]<?php
[*]if(!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=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;' . $css_url . '&quot; />';
[*]      $output .= '<script type=&quot;text/javascript&quot; src=&quot;' . $js_url . '&quot;></script>';
[*]      
[*]      $button = '<button type=&quot;button&quot; id=&quot;qier_thread_button&quot; class=&quot;qier-thread-button&quot;>';
[*]      $button .= '<span class=&quot;qier-thread-icon&quot;></span>';
[*]      $button .= '<span class=&quot;qier-thread-text&quot;>' . $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文件路径

也就是说没启动插件

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

日志全开日志页抓不到。


来源:https://www.dismall.com/thread-23445-1-1.html
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
页: [1]
查看完整版本: 关于前端钩子 按钮显示的问题 大佬们帮我看看 哪个地方有有问题