Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
3.9k views
in Plugins by

For the new plugin (q2a-best-users-per-month) I was not able yet to add a subnavigation (a "tab" for a plugin page) by using a layer.php.

This is what is needed:

q2a subnavigation

I registered a layer.php with my plugin and tried (without success):

<?php

class qa_html_theme_layer extends qa_html_theme_base
{

    function doctype() {
        //if($this->template == 'users' && (qa_get_logged_in_handle() === $this->_user_handle() || qa_opt('user_act_list_show'))) {
        if($this->template == 'users' || $this->template == 'bestusers' ) {
            if(!isset($this->content['navigation']['sub'])) {
                $this->content['navigation']['sub'] = array(
                    'profile' => array(
                        'url' => qa_path_html('user/'.$this->_user_handle(), null, qa_opt('site_url')),
                        'label' => $this->_user_handle(),
                        'selected' => !qa_get('tab')?true:false
                    ),
                    'history' => array(
                        'url' => qa_path_html('user/'.$this->_user_handle(), array('tab'=>'history'), qa_opt('site_url')),
                        'label' => qa_opt('user_act_list_tab'),
                        'selected' => qa_get('tab')=='history'?true:false
                    ),
                );
            }
            else {
                $this->content['navigation']['sub']['users$'] = array(
                    'url' => qa_path_html('users'),
                    'label' => qa_lang_html('main/highest_users'),
                    'selected' => qa_get('tab')=='users$'?true:false
                );
                $this->content['navigation']['sub']['bestusers'] = array(
                    'url' => "http://www.gute-mathe-fragen.de/bestusers",// qa_path_html('users'),
                    'label' => "Monatsbeste",
                    'selected' => qa_get('tab')=='bestusers'?true:false
                );
            }
        }
        qa_html_theme_base::doctype();
    }

    
    // grab the handle of the profile you're looking at
    function _user_handle()
    {
        $handle = preg_replace( '#^user/([^/]+)#', "$1", $this->request );
        return $handle;
    }

}

 

This did not change anything.

 

For now, I hacked the qa-include/qa-app-format.php with:

around line 1055:

        } else {
            return array(
                // show submenu best users and monthly best
                'users$' => array(
                    'url' => qa_path_html('users'),
                    'label' => qa_lang_html('main/highest_users'),
                ),
    
                // eetv: added link to monthly users
                'users/bestusers' => array(
                    'label' => "Monatsbeste",
                    'url' => "http://www.gute-mathe-fragen.de/bestusers",
                ),
                // end
            );

        }

 

2 Answers

+1 vote
by

here is the code from pool plugin:qa-poll-layer.php: line 168

I think it is the code which over rides the sub nav function:


        function nav_list($navigation, $class, $level=null)
        {
            if($class == 'nav-sub' && in_array($this->template, array('plugin','questions')) && qa_opt('poll_enable') && qa_opt('poll_enable_subnav')) {
                $navigation['polls'] = array(
                      'label' => qa_lang('polls/page_title'),
                      'url' => qa_path_html('polls'),
                );
                if($this->request == 'polls') {
                    unset($navigation['special']);
                    $newnav = qa_qs_sub_navigation(null,null);
                    $navigation = array_merge($newnav, $navigation);
                    unset($navigation['recent']['selected']);
                    $navigation['polls']['selected'] = true;
                }
            }
            if(count($navigation) > 1 || $class != 'nav-sub') qa_html_theme_base::nav_list($navigation, $class, $level=null);
        }


 

by
thanks towhid, that helped me!

Now I have:

    function nav_list($navigation, $class, $level=null)
    {
        if($class == 'nav-sub') {
            // all users (default list)
            $navigation['users'] = array(
                  'label' => qa_lang_html('main/highest_users'),
                  'url' => qa_path_html('users'),
            );
           
            $navigation['bestusers'] = array(
                  'label' => qa_lang_html('qa_best_users_lang/subnav_title'),
                  'url' => qa_path_html('bestusers'),
            );
            if($this->request == 'bestusers') {
                $navigation['bestusers']['selected'] = true;
            }
        }
        if(count($navigation) > 1 || $class != 'nav-sub') qa_html_theme_base::nav_list($navigation, $class, $level=null);
    }

However, the default *qa-app-format.php* is not showing the subnavigation on page /users. Due to line 1052:

        } else
            return null;

Do you know if it is possible to overwrite function *qa_users_sub_navigation* with the plugin?
by
I could display the subnav by adding function doctype() to the layer:

function doctype(){
        global $qa_request;
        if($qa_request == 'bestusers') {
            $this->content['navigation']['sub'] = array('special'=>1);
        }
    }

However, this is not 100% correct as my theme gets distorted...
Maybe due to "array('special'=>1);" -> is this telling q2a that it should insert a subnavigation?
by
qa_html_theme_base::doctype(); was missing, check my answer :)
0 votes
by

Alright, after a while I found out that I have to call: qa_html_theme_base::doctype();

This is how I got the subnavigation to show up, layer-file.php:

<?php

class qa_html_theme_layer extends qa_html_theme_base
{

    function doctype(){
    
        qa_html_theme_base::doctype();

        global $qa_request;
        if($qa_request == 'bestusers' || $qa_request == 'users' ) {
            $this->content['navigation']['sub'] = array(
                // show subnavigation: best users and monthly best
                'users$' => array(
                    'url' => qa_path_html('users'),
                    'label' => qa_lang_html('main/highest_users'),
                ),
                // link to monthly users
                'users/bestusers' => array(
                    'label' => qa_lang_html('qa_best_users_lang/subnav_title'),
                    'url' => qa_path_html('bestusers'),
                ),
            );
        }
    }

}

 

 

...