vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 4 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=242)
-   -   [HOW TO - vB4] Create a New Tab in the navbar (with template) (https://vborg.vbsupport.ru/showthread.php?t=228313)

gabrielt 01-21-2010 09:22 PM

Hello,

Adapted this to create a link to my main website:

Plugin "Main Website Button", on process_template_complete:

Code:

$template_hook['navtab_middle'] .= vB_Template::create('Link to Main Website')->render();
Template "Link to Main Website":

Code:

<vb:if condition="$vboptions['selectednavtab'] == 'mainwebsite'">
<li class="selected">
<a class="navtab" href="{vb:raw vboptions.homeurl}">{vb:raw vboptions.hometitle}</a>
<ul class="floatcontainer">
<li><a href="#">#</a></li>
</ul>
</li>
<vb:else />
<li><a class="navtab" href="{vb:raw vboptions.homeurl}">{vb:raw vboptions.hometitle}</a></li>
</vb:if>

Enjoy!

nsilva 01-27-2010 06:28 PM

How come when I click on the nav tab, it shows the Forum tab as selected and not the tab I created?

Lynne 01-27-2010 06:44 PM

Quote:

Originally Posted by nsilva (Post 1968227)
How come when I click on the nav tab, it shows the Forum tab as selected and not the tab I created?

Because you didn't make the condition a valid condition for your tab.

Chickenpotpie 03-10-2010 07:03 AM

Good article. It worked well. question. if I need to add more tabs do I need to make new templates and hooks?

-CP

Sarcoth 03-19-2010 04:57 PM

In case anyone is curious and you know how to create a permission group, here is how you can use that group to determine who can see the tab.

FIRST:
At the top of the plugin, add a variable for your permission group array:
PHP Code:

$accessgroups explode(','$vbulletin->options['permission_group_name']); 

SECOND:
At the bottom of the plugin, find the following line:
PHP Code:

$template_hook['navtab_end'] .= vB_Template::create('template_navbar')->render(); 

Change it to:
PHP Code:

$templater vB_Template::create('template_navbar');
    
$templater->register('accessgroups'$accessgroups);
$template_hook['navtab_end'] .= $templater->render(); 

THIRD:
Open your template and add a line to the top and the bottom.
HTML Code:

<vb:if condition="is_member_of($bbuserinfo, $accessgroups)">
HTML Code:

</vb:if>
NOTE: I know you could just edit the current if condition with an AND, but I think that will just confuse some people.

Theda 03-21-2010 05:29 AM

I kind of modified this to try and use it with articles as "pages" with the tabs linked to articles.. (and it works, the tabs show as on).... but the HOME button is on too. Is there a way to set the home button to unselected?

Code:

$tabselected = '';
$tablinks = '';
if ($_GET ['r'] == '180-Roster')
{
    $vbulletin->options['selectednavtab']='Roster';
    $tabselected = ' class="selected"';
}
$template_hook['navtab_start'] .= '<li'.$tabselected.'><a class="navtab" href="content.php?r=180-Roster">ROSTER</a>'.$tablinks.'</li>' ;


Sarcoth 03-24-2010 12:47 PM

I finally figured out a way to add all my variables from my custom page to the navbar. I went about it in a sneaky way.

I first added the following code to my showroster.php file which allowed me to add all the registered variables I wanted to use:

PHP Code:

$accessgroups explode(','$vbulletin->options['showroster_access_groups']);
$navbarloc $vbulletin->options['showroster_navbar_loc'];

switch (
$navbarloc) {
    case 
'1':
        
$nbloc 'navtab_start'; break;
    case 
'2':
        
$nbloc 'navtab_middle'; break;
    case 
'3':
        
$nbloc 'navtab_end'; break;
}

if (
THIS_SCRIPT == 'showroster') {
    
$vbulletin->options['selectednavtab'] = 'showroster'
}

$templater vB_Template::create('showroster_navbar');
    
$templater->register('sorturl'$sorturl);
    
$templater->register('accessgroups'$accessgroups);
    
$templater->register('columns'$columns);
    
$templater->register('sortgroupfield'$sortgroupfield);
    
$templater->register('oppositesort'$oppositesort);
$template_hook[$nbloc] .= $templater->render(); 

Since that was a close repeat to the code in my plugin, I ended up having one Roster button when on another tab and two when viewing the roster. I tried to remove the plugin, but that then caused the button to be missing when on another page; although it was there when on the roster. It makes sense after the fact. So, after some thought, I changed my plugin to the following:

PHP Code:

if (THIS_SCRIPT != 'showroster') {
$accessgroups explode(','$vbulletin->options['showroster_access_groups']);
$navbarloc $vbulletin->options['showroster_navbar_loc'];
$navbarorder $vbulletin->options['showroster_navbar_order']; 

switch (
$navbarloc) {
    case 
'1':
        
$nbloc 'navtab_start'; break;
    case 
'2':
        
$nbloc 'navtab_middle'; break;
    case 
'3':
        
$nbloc 'navtab_end'; break;
}

$templater vB_Template::create('showroster_navbar');
    
$templater->register('accessgroups'$accessgroups);
$template_hook[$nbloc] .= $templater->render();


That allowed me to use the plugin code when not on the roster page. When on the roster page, this code doesn't work, but the code from my showroster.php does. I then set up my showroster_navbar template to include the variables from my .php file and they work very well.

HTML Code:

<vb:if condition="is_member_of($bbuserinfo, $accessgroups)">
<vb:if condition="$vboptions['selectednavtab'] == 'showroster'">
<li class="selected">
        <a class="navtab" href="showroster.php{vb:raw session.sessionurl_q}">Roster</a>
        <ul class="floatcontainer">
                <li><a href="showroster.php{vb:raw session.sessionurl_q}">Default Sort</a></li>
                <li class="popupmenu">
                        <a href="javascript://" class="popupctrl">Sorting Options</a>
                        <ul class="popupbody popuphover">
                                <vb:if condition="$show[field1st]"><li><a href="{vb:raw sorturl}&amp;order=<vb:if condition="$sortgroupfield == $columns[column1]">{vb:raw oppositesort}<vb:else />{vb:raw columns.sorts1}</vb:if>&amp;sortgroupfield={vb:raw columns.column1}">{vb:raw columns.title1}</a></li></vb:if>
                                <vb:if condition="$show[field2nd]"><li><a href="{vb:raw sorturl}&amp;order=<vb:if condition="$sortgroupfield == $columns[column2]">{vb:raw oppositesort}<vb:else />{vb:raw columns.sorts2}</vb:if>&amp;sortgroupfield={vb:raw columns.column2}">{vb:raw columns.title2}</a></li></vb:if>
                                <vb:if condition="$show[field3rd]"><li><a href="{vb:raw sorturl}&amp;order=<vb:if condition="$sortgroupfield == $columns[column3]">{vb:raw oppositesort}<vb:else />{vb:raw columns.sorts3}</vb:if>&amp;sortgroupfield={vb:raw columns.column3}">{vb:raw columns.title3}</a></li></vb:if>
                                <vb:if condition="$show[field4th]"><li><a href="{vb:raw sorturl}&amp;order=<vb:if condition="$sortgroupfield == $columns[column4]">{vb:raw oppositesort}<vb:else />{vb:raw columns.sorts4}</vb:if>&amp;sortgroupfield={vb:raw columns.column4}">{vb:raw columns.title4}</a></li></vb:if>
                                <vb:if condition="$show[field5th]"><li><a href="{vb:raw sorturl}&amp;order=<vb:if condition="$sortgroupfield == $columns[column5]">{vb:raw oppositesort}<vb:else />{vb:raw columns.sorts5}</vb:if>&amp;sortgroupfield={vb:raw columns.column5}">{vb:raw columns.title5}</a></li></vb:if>
                                <vb:if condition="$show[field6th]"><li><a href="{vb:raw sorturl}&amp;order=<vb:if condition="$sortgroupfield == $columns[column6]">{vb:raw oppositesort}<vb:else />{vb:raw columns.sorts6}</vb:if>&amp;sortgroupfield={vb:raw columns.column6}">{vb:raw columns.title6}</a></li></vb:if>
                                <vb:if condition="$show[field7th]"><li><a href="{vb:raw sorturl}&amp;order=<vb:if condition="$sortgroupfield == $columns[column7]">{vb:raw oppositesort}<vb:else />{vb:raw columns.sorts7}</vb:if>&amp;sortgroupfield={vb:raw columns.column7}">{vb:raw columns.title7}</a></li></vb:if>
                                <vb:if condition="$show[field8th]"><li><a href="{vb:raw sorturl}&amp;order=<vb:if condition="$sortgroupfield == $columns[column8]">{vb:raw oppositesort}<vb:else />{vb:raw columns.sorts8}</vb:if>&amp;sortgroupfield={vb:raw columns.column8}">{vb:raw columns.title8}</a></li></vb:if>
                                <vb:if condition="$show[datejoinedcol]"><li><a href="{vb:raw sorturl}&amp;order=<vb:if condition="$sortgroupfield == 'joindate'">{vb:raw oppositesort}<vb:else />{vb:raw columns.sortsdj}</vb:if>&amp;sortgroupfield=joindate">{vb:rawphrase join_date}</a></li></vb:if>
                                <vb:if condition="$show[lastactivecol]"><li><a href="{vb:raw sorturl}&amp;order=<vb:if condition="$sortgroupfield == 'lastactive'">{vb:raw oppositesort}<vb:else />{vb:raw columns.sortsla}</vb:if>&amp;sortgroupfield=lastactive">{vb:rawphrase last_activity}</a></li></vb:if>
                        </ul>
                </li>
        </ul>
</li>
<vb:else />
<li><a class="navtab" href="showroster.php{vb:raw session.sessionurl_q}">Roster</a></li>
</vb:if>
</vb:if>

I'm not saying this is the best way, far from it. I would much rather have had a way to pull the data from my .php to the plugin and then use it in the template that way, but this works for now. I'll gladly accept a better way if someone can tell me. I'm sure I'm added more code than I need.

shooptek 03-25-2010 03:03 PM

Okay I am struggling with this. I want to add a button on my navbar that links to a specific forum, and when a user is viewing that forum for the tab on the navbar to be highlighted.

So this is the information that I used:

template name: bb_navbar_events

template code:
HTML Code:

<vb:if condition="$vboptions['selectednavtab'] == 'navbarevents'">
<li class="selected">
    <a class="navtab" href="forumdisplay.php?8-Events{vb:raw session.sessionurl_q}">{vb:rawphrase navbar_events}</a>
<ul class="floatcontainer">
<li><a href="#">#</a></li>
</ul>
</li>
<vb:else />
<li><a class="navtab" href="forumdisplay.php?8-Events{vb:raw session.sessionurl_q}">{vb:rawphrase navbar_events}</a></li>
</vb:if>


plugin code:
PHP Code:

if (THIS_SCRIPT == 'xxx')  // also defined('navbarevents') possible
{
//set selected tab
    
$vbulletin->options['selectednavtab'] = 'navbarevents';
}
// add the "subtemplate" to the navbartemplate
$template_hook['navtab_middle'] .= vB_Template::create('bb_navbar_events')->render(); 


Should this arrangement be working properly?

I want the Events tab to be highlighted when it is on that page, but the Forum tab remains highlighted.

Any suggestions?

Jaxel 04-05-2010 06:26 PM

How do you do PERMISSIONS with this? I use the following code for permissions in my mods, and it works fine...

Code:

if (!($permissions['medialibperms'] & $vbulletin->bf_ugp_medialibperms['cansubm']))
{
        print_no_permission();
}


I am trying to use this code in my plugin, but the permission ALWAYS fails...
Code:

if (THIS_SCRIPT == 'media')
{
        $vbulletin->options['selectednavtab'] = 'media';

        $categories = $vbulletin->db->query_read("SELECT * FROM " . TABLE_PREFIX . "media_category");
        $submitperm = $permissions['medialibperms'] & $vbulletin->bf_ugp_medialibperms['cansubm'];

        while ($category = $vbulletin->db->fetch_array($categories))
        {
                $templater = vB_Template::create('media_NAVTAB_cat');
                $templater->register('categoryID', $category['categoryID']);
                $templater->register('catName', $category['catName']);
                $categorybits .= $templater->render();

                $templater = vB_Template::create('media_NAVTAB_sub');
                $templater->register('categoryID', $category['categoryID']);
                $templater->register('catName', $category['catName']);
                $submitbits .= $templater->render();
        }
}

$templater = vB_Template::create('media_NAVTAB');
$templater->register('categorybits', $categorybits);
$templater->register('submitbits', $submitbits);
$templater->register('submitperm', $submitperm);
$template_hook['navtab_middle'] .= $templater->render();

No matter what, $submitperm is always false...

unknown22 09-16-2010 07:57 PM

Where do I add these I know to create a new plugin?


All times are GMT. The time now is 03:17 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01439 seconds
  • Memory Usage 1,831KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_code_printable
  • (4)bbcode_html_printable
  • (6)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete