[Помогите] Проблема с хуком "Создать тему на главной странице"

Тема в разделе "IP. Board 3.3", создана пользователем ursus102, 6 сен 2012.

  1. ursus102

    ursus102

    Регистрация:
    7 авг 2012
    Сообщения:
    13
    Симпатии:
    2
    Приветствую.
    Есть хук, который создает кнопку на главной странице форума, при нажатии на которую можно выбрать в каком разделе создать тему. Очень удобно, не нужно лазить по всему форуму.
    Хук рабочий, я проверял. Но дело в том, что у меня стоит IP.Content 2.3.2. Причем нюанс - он стоит ГЛАВНОЙ страницей, а не форум. Из-за этого хук не устанавливается, вернее устанавливается, но не работает.
    Я головой понимаю, что нужно менять код хука, но, к сожалению, сам я сделать это не могу.
    Буду благодарен за помощь. Надеюсь, что изъяснил все понятно.
    В initdata.php менял 'forums' на 'ccs' для того, чтобы IP.Content стал главной. Думается, что и в хуке нужно пояснить где что и как. Но я возился, так и не смог.
    Ниже привожу код хука.
    Код:
      <?xml version="1.0" encoding="utf-8" ?>
    - <hookexport>
    - <hookdata>
    - <config>
      <hook_name>New Topic Button on Board Index</hook_name>
      <hook_desc>Shows a button for starting a new topic on the Board Index</hook_desc>
      <hook_author>Michael McCune</hook_author>
      <hook_email>[email protected]</hook_email>
      <hook_website>http://invisionfocus.com/</hook_website>
      <hook_update_check>http://invisionfocus.com/resource_updates.php?resource=newTopicButtonBoardIndex</hook_update_check>
    - <hook_requirements>
    - <![CDATA[ a:3:{s:21:"required_applications";a:1:{s:4:"core";a:3:{s:8:"app_name";s:6:"System";s:11:"min_version";i:30001;s:11:"max_version";i:0;}}s:20:"hook_php_version_min";s:0:"";s:20:"hook_php_version_max";s:0:"";}
      ]]>
      </hook_requirements>
      <hook_version_human>1.0.1</hook_version_human>
      <hook_version_long>10001</hook_version_long>
    - <hook_extra_data>
    - <![CDATA[ a:6:{s:7:"display";a:4:{s:8:"language";s:102:"From forums_public_boards: hookNewTopic_no_forums, hookNewTopic_select_forum, hookNewTopic_start_topic";s:9:"templates";s:68:"From skin_boards: hookNewTopicBoardIndex, hookNewTopicBoardIndexList";s:8:"settings";s:47:"Setting groups: New Topic Button on Board Index";s:3:"css";s:21:"CSS Files:  ipb_ntbbi";}s:9:"templates";a:1:{s:11:"skin_boards";a:2:{s:22:"hookNewTopicBoardIndex";s:22:"hookNewTopicBoardIndex";s:26:"hookNewTopicBoardIndexList";s:26:"hookNewTopicBoardIndexList";}}s:8:"database";a:0:{}s:8:"language";a:1:{s:20:"forums_public_boards";a:3:{s:0:"";s:22:"hookNewTopic_no_forums";i:1;s:25:"hookNewTopic_select_forum";i:2;s:24:"hookNewTopic_start_topic";}}s:13:"settingGroups";a:1:{s:0:"";s:24:"newTopicButtonBoardIndex";}s:3:"css";a:1:{s:0:"";s:9:"ipb_ntbbi";}}
      ]]>
      </hook_extra_data>
      <hook_key>newTopicButtonBoardIndex</hook_key>
      <hook_global_caches />
      </config>
      </hookdata>
    - <hookfiles>
    - <file>
      <hook_file_real>newTopicButtonBoardIndex.php</hook_file_real>
      <hook_type>templateHooks</hook_type>
      <hook_classname>newTopicButtonBoardIndex</hook_classname>
    - <hook_data>
    - <![CDATA[ a:8:{s:12:"dataLocation";s:0:"";s:14:"libApplication";s:0:"";s:15:"classToOverload";s:0:"";s:9:"skinGroup";s:11:"skin_global";s:12:"skinFunction";s:14:"globalTemplate";s:4:"type";s:2:"if";s:2:"id";s:11:"showhomeurl";s:8:"position";s:11:"pre.startif";}
      ]]>
      </hook_data>
    - <hooks_source>
    - <![CDATA[
    <?php
     
    class newTopicButtonBoardIndex
    {
        protected $registry;
       
        public function __construct()
        {
            /* Make registry objects */
            $this->registry = ipsRegistry::instance();
        }
       
        public function getOutput()
        {
            /* Simply return the button */
            return $this->registry->output->getTemplate('boards')->hookNewTopicBoardIndex();
        }
    }
     
      ]]>
      </hooks_source>
      </file>
    - <file>
      <hook_file_real>newTopicButtonBoardIndexAjax.php</hook_file_real>
      <hook_type>commandHooks</hook_type>
      <hook_classname>newTopicButtonBoardIndexAjax</hook_classname>
    - <hook_data>
    - <![CDATA[ a:8:{s:12:"dataLocation";s:0:"";s:14:"libApplication";s:0:"";s:15:"classToOverload";s:25:"public_forums_ajax_forums";s:9:"skinGroup";N;s:12:"skinFunction";N;s:4:"type";N;s:2:"id";N;s:8:"position";N;}
      ]]>
      </hook_data>
    - <hooks_source>
    - <![CDATA[
    <?php
     
    class newTopicButtonBoardIndexAjax extends (~extends~)
    {
        private $cnt = 0;
       
        public function doExecute( ipsRegistry $registry )
        {
            if ( $this->request['do'] == 'fetchNewTopicForums' )
            {
                /* Language */
                $this->lang->loadLanguageFile( array( 'public_boards' ), 'forums' );
               
                /* Get our list of forums */
                $links = array();
                $depth = 0;
               
                /* Loop over categories */
                if ( is_array( $this->registry->class_forums->forum_cache['root'] ) && count( $this->registry->class_forums->forum_cache['root'] ) )
                {
                    foreach ( $this->registry->class_forums->forum_cache['root'] as $forum_data )
                    {
                        /* Add to our array */
                        $links[] = array( 'important' => true, 'depth' => $depth, 'title' => $forum_data['name'], 'url' => '#' );
                       
                        /* Loop over forums */
                        if ( isset( $this->registry->class_forums->forum_cache[ $forum_data['id'] ] ) && is_array( $this->registry->class_forums->forum_cache[ $forum_data['id'] ] ) )
                        {
                            $depth++;
                           
                            foreach ( $this->registry->class_forums->forum_cache[ $forum_data['id'] ] as $forum_data )
                            {
                                /* Can we start a topic here? */
                                if ( !$forum_data['redirect_on'] && $this->registry->class_forums->canStartTopic( $forum_data['id'] ) )
                                {
                                    $this->cnt++;
                                    $links[] = array( 'depth' => $depth, 'title' => $forum_data['name'], 'url' => $this->registry->output->buildSEOUrl( 'app=forums&amp;module=post&amp;section=post&amp;do=new_post&amp;f=' . $forum_data['id'], 'public' ) );
                                }
                               
                                $links = $this->_getDataRecursively( $forum_data['id'], $links, $depth );
                            }
                           
                            $depth--;
                        }
                    }
                }
               
                /* If we got no postable forums, give an error */
                if ( !$this->cnt )
                {
                    $this->returnJsonArray( array( 'error' => $this->lang->words['hookNewTopic_no_forums'] ) );
                }
                else
                {
                    /* Return the list */
                    $this->returnJsonArray( array( 'html' => $this->registry->output->getTemplate('boards')->hookNewTopicBoardIndexList( $links ) ) );
                }
            }
           
            /* Return */
            return parent::doExecute( $registry );
        }
       
        private function _getDataRecursively( $root_id, $links=array(), $depth=0 )
        {
            /* Loop over forums */
            if ( isset( $this->registry->class_forums->forum_cache[ $root_id ] ) && is_array( $this->registry->class_forums->forum_cache[ $root_id ] ) )
            {
                $depth++;
               
                foreach ( $this->registry->class_forums->forum_cache[ $root_id ] as $forum_data )
                {
                    /* Can we start a topic here? */
                    if ( !$forum_data['redirect_on'] && $this->registry->class_forums->canStartTopic( $forum_data['id'] ) )
                    {
                        $this->cnt++;
                        $links[] = array( 'depth' => $depth, 'title' => $forum_data['name'], 'url' => $this->registry->output->buildSEOUrl( 'app=forums&amp;module=post&amp;section=post&amp;do=new_post&amp;f=' . $forum_data['id'], 'public' ) );
                    }
                   
                    $links = $this->_getDataRecursively( $forum_data['id'], $links, $depth );
                }
            }
           
            /* Return */
            return $links;
        }
    }
     
      ]]>
      </hooks_source>
      </file>
      </hookfiles>
    - <hookextras_settings>
    - <setting>
      <conf_is_title>1</conf_is_title>
      <conf_title_title>New Topic Button on Board Index</conf_title_title>
      <conf_title_desc>Settings for the New Topic Button on Board Index hook</conf_title_desc>
      <conf_title_noshow>0</conf_title_noshow>
      <conf_title_keyword>newTopicButtonBoardIndex</conf_title_keyword>
      <conf_title_app>forums</conf_title_app>
      <conf_title_tab>Hooks</conf_title_tab>
      </setting>
    - <setting>
      <conf_id>1070</conf_id>
      <conf_title>Groups that can see the button</conf_title>
      <conf_description>Select which group(s) you want to be able to see and use the New Topic button</conf_description>
      <conf_group>117</conf_group>
      <conf_type>multi</conf_type>
      <conf_key>ntbbi_groups</conf_key>
      <conf_value />
      <conf_default />
      <conf_extra>#show_groups#</conf_extra>
    - <conf_evalphp>
    - <![CDATA[
    if ( $save == 1 )
    {
        if ( is_array( $_POST['ntbbi_groups'] ) )
        {
            $_POST['ntbbi_groups'] = implode( ",", $_POST['ntbbi_groups'] );
        }
        else
        {
            $_POST['ntbbi_groups'] = "";
        }
       
        $key = 'ntbbi_groups';
    }
    if ( $show == 1 )
    {
        $key='ntbbi_groups[]';
    }
     
      ]]>
      </conf_evalphp>
      <conf_protected>1</conf_protected>
      <conf_position>1</conf_position>
      <conf_start_group />
      <conf_add_cache>1</conf_add_cache>
      <conf_keywords />
      <conf_title_keyword>newTopicButtonBoardIndex</conf_title_keyword>
      <conf_is_title>0</conf_is_title>
      </setting>
      </hookextras_settings>
    - <hookextras_language>
    - <language>
      <word_app>forums</word_app>
      <word_pack>public_boards</word_pack>
      <word_key>hookNewTopic_no_forums</word_key>
      <word_default>Sorry, you do not have access to post a new topic in any forums</word_default>
      </language>
    - <language>
      <word_app>forums</word_app>
      <word_pack>public_boards</word_pack>
      <word_key>hookNewTopic_select_forum</word_key>
      <word_default>Select a forum:</word_default>
      </language>
    - <language>
      <word_app>forums</word_app>
      <word_pack>public_boards</word_pack>
      <word_key>hookNewTopic_start_topic</word_key>
      <word_default>Start New Topic</word_default>
      </language>
      </hookextras_language>
      <hookextras_modules />
      <hookextras_help />
    - <hookextras_templates>
    - <templates>
      <template_group>skin_boards</template_group>
    - <template_content>
    - <![CDATA[
    <if test="showButton:|:IPSMember::isInGroup( $this->memberData, explode( ',', $this->settings['ntbbi_groups'] ) ) && IPS_APP_COMPONENT == 'forums' && ipsRegistry::$current_module == 'forums' && ipsRegistry::$current_section == 'boards'">
        <li class="right">
            <a href="#" id="new_topic_index" title="{$this->lang->words['hookNewTopic_start_topic']}">{$this->lang->words['hookNewTopic_start_topic']}</a>
        </li>
        <script type="text/javascript">
            document.observe("dom:loaded", function()
            {
                $('new_topic_index').observe('click', function(e)
                {
                    if ( !$('new_topic_index_menucontent') )
                    {
                        var url = ipb.vars['base_url'] + 'app=forums&module=ajax&section=forums&do=fetchNewTopicForums';
                       
                        new Ajax.Request
                        (
                            url,
                            {
                                method: 'post',
                                evalJSON: 'force',
                                parameters: {
                                    secure_key: ipb.vars['secure_hash']
                                },
                                onSuccess: function(t)
                                {
                                    if ( t.responseJSON['error'] )
                                    {
                                        alert( t.responseJSON['error'] );
                                    }
                                    else
                                    {
                                        $('new_topic_index').addClassName('ipbmenu');
                                        $('ipboard_body').insert( t.responseJSON['html'] );
                                       
                                        var _newMenu = new ipb.Menu( $('new_topic_index'), $('new_topic_index_menucontent') );
                                        _newMenu.doOpen();
                                    }
                                }
                            }
                        );
                    }
                });
            });
        </script>
    </if>
     
      ]]>
      </template_content>
      <template_name>hookNewTopicBoardIndex</template_name>
      <template_data />
      <template_updated>1328378304</template_updated>
      <template_removable>0</template_removable>
      <template_added_to>0</template_added_to>
      <template_user_added>0</template_user_added>
      <template_user_edited>0</template_user_edited>
      <template_master_key>root</template_master_key>
      </templates>
    - <templates>
      <template_group>skin_boards</template_group>
    - <template_content>
    - <![CDATA[
    <div id="new_topic_index_menucontent">
        <h3 class="header bar">{$this->lang->words['hookNewTopic_select_forum']}</h3>
        <div>
            <ul class="ipbmenu_content boxShadow">
                <foreach loop="$links as $t">
                    <li><a href="{$t['url']}"<if test="isCategory:|:$t['important']"> style="font-weight: bold;"</if>><if test="depth:|:!empty($t['depth'])">{parse expression="str_repeat( '&nbsp;&nbsp;&nbsp;&nbsp;', $t['depth'])"}</if>{$t['title']}</a></li>
                </foreach>
            </ul>
        </div>
    </div>
     
      ]]>
      </template_content>
      <template_name>hookNewTopicBoardIndexList</template_name>
      <template_data>$links=array()</template_data>
      <template_updated>1328378713</template_updated>
      <template_removable>0</template_removable>
      <template_added_to>0</template_added_to>
      <template_user_added>0</template_user_added>
      <template_user_edited>0</template_user_edited>
      <template_master_key>root</template_master_key>
      </templates>
      </hookextras_templates>
    - <hookextras_css>
    - <css>
      <css_updated>1328378701</css_updated>
      <css_group>ipb_ntbbi</css_group>
      <css_content>div#new_topic_index_menucontent { margin-top: 1px; } div#new_topic_index_menucontent div { max-height: 500px; overflow: auto; } div#new_topic_index_menucontent ul.ipbmenu_content li { white-space: nowrap; } div#new_topic_index_menucontent ul.ipbmenu_content li a { padding-right: 24px; }</css_content>
      <css_position>0</css_position>
      <css_added_to>0</css_added_to>
      <css_app>forums</css_app>
      <css_app_hide>1</css_app_hide>
    - <css_attributes>
    - <![CDATA[ title="Main" media="screen"
      ]]>
      </css_attributes>
      <css_modules>forums</css_modules>
      <css_removed>0</css_removed>
      <css_master_key>root</css_master_key>
      </css>
      </hookextras_css>
      <hookextras_tasks />
      <hookextras_database_create />
      <hookextras_database_alter />
      <hookextras_database_update />
      <hookextras_database_insert />
      </hookexport>