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

I get requests from users who don't find their answers and questions listed.

I thought it would be great to have 2 extra tabs, when they click on "My Account" which shows only My Details and My Favorites.

Would it be possible to add the 2 tabs "My Questions" and "My Answers"?

 

I tried to add this to the plugin, but does not work, I do sth wrong here I guess:

$this->content['navigation']['sub']['useractivity'] = array(
    'url' => qa_path_html('user-activity/answers/'.$this->_user_handle(), array('tab'=>'useractivity'), qa_opt('site_url')),
    'label' => qa_opt('user_act_list_tab'),
    'selected' => qa_get('tab')=='useractivity'?true:false
);

 

Thanks.

by
I didn't try the code but I think you should add array to $this->content['navigation']['useractivity']['subnav']
by
Hi QA-Themes, thanks for bringing this issue up again. I posted my solution in the answer below. :)

1 Answer

0 votes
by

This is how I solved it finally, new code of qa-uact-layer.php:

<?php
/*
    Question2Answer User Activity Plus plugin, v1.0
    License: http://www.gnu.org/licenses/gpl.html
*/

class qa_html_theme_layer extends qa_html_theme_base
{
    /* override to add tabs */
    function doctype(){
    
        qa_html_theme_base::doctype();

        $handle_raw = $this->user_handle();
        $activePage = '';
        if(!isset($handle_raw)) {
            // e.g. yourdomain.com/user-activity/answers/username
            $parts = explode('/', $this->request);
            if($parts[0]=='user-activity') {
                $activePage = $parts[1];
                $handle_raw = isset($parts[2]) ? $parts[2] : null;
            }
        }
        
        // add main sub navigation (2 items), only if on UA-page
        if($this->template == 'plugin' && isset($handle_raw)) {
            $this->content['navigation']['sub'] = array(
                'profile' => array(
                    'url' => qa_path_html('user/'.$handle_raw, null, qa_opt('site_url')),
                    'label' => $handle_raw,
                    'selected' => false
                ),
                'history' => array(
                    'url' => qa_path_html('user/'.$handle_raw, array('tab'=>'history'), qa_opt('site_url')),
                    'label' => qa_opt('user_act_list_tab'),
                    'selected' => false
                ),
            );
        }
        
        // adds subnavigation to user pages
        if( $this->template === 'user' || ($this->template == 'plugin' && isset($handle_raw)) ) {
            // add tab element for all questions
            $this->content['navigation']['sub']['allQuestions'] = array(
                'label' => qa_lang_html('useractivity/all_questions'),
                'url' => qa_path('user-activity/questions/'.$handle_raw),
                'selected' => $activePage=='questions'?true:false
            );
            // add tab element for all questions
            $this->content['navigation']['sub']['allAnswers'] = array(
                'label' => qa_lang_html('useractivity/all_answers'),
                'url' => qa_path('user-activity/answers/'.$handle_raw),
                'selected' => $activePage=='answers'?true:false
            );
            // add tab element for all comments
            $this->content['navigation']['sub']['allComments'] = array(
                'label' => qa_lang_html('useractivity/all_comments'),
                'url' => qa_path('user-activity/comments/'.$handle_raw),
                'selected' => $activePage=='comments'?true:false
            );
        }
    }

    // grab the handle of the profile you're looking at
    private function user_handle()
    {
        preg_match( '#user/([^/]+)#', $this->request, $matches );
        return empty($matches[1]) ? null : $matches[1];
    }

    // grab the handle of the profile you're looking at
    private function user_handle2()
    {
        // preg_match( '#user-activity/([^/]+)#', $this->request, $matches );
        // return empty($matches[2]) ? null : $matches[2];
        // e.g. http://www.gute-mathe-fragen.de/user/echteinfachtv
        $parts = explode('/', parse_url($this->request));
        return $parts[2];
    }

}

 

Note that from 1.6.2 you have the answers / questions tab in each user profile together with the list. However, comments listing is still missing.

And: The user activity plugin shows the text of each answer and each comment (first 150 chars), what I really like.

...