Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 4 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
vB4.2 Navigation Manager - how to discussion
AusPhotography's Avatar
AusPhotography
Join Date: Nov 2007
Posts: 521

 

Hobart & Adelaide .au
Show Printable Version Email this Page Subscription
AusPhotography AusPhotography is offline 05-18-2012, 10:00 PM

I have vB 4.2.0 BETA 1 running in my test system.

Products that use templates/hooks to integrate with the navbar will need the following changes to work with the Navigation Manager.

Please post code snips and hints in this thread, we are all on a learning curve.

1. Remove old style navigation hooks/templates etc.

2. Create a new <navigation> section in the product XML file
(You can create the navigation in the navigation manager, linked to a product then export the product file as a skeleton)

3. Set any conditionals in a hook or in your main code
Eg. $show['apmgtug'] = true; is set for one of the menu items in my example
My example relies on $show['member'] = true; as well.
Leave the <show> tag empty for 'public' tabs/links

4. If you have multiple scripts, leave <scripts> blank and set $root at the new hooks set_navigation_tab_fallaback or set_navigation_tab_vbview

Code:
if (<some condition>) $root= '<name of tab>';
I hope that helps you get a quick leg up for this change.

I would probably have a new vB4.2 code base because of the differences, you could have the same code base with some sort of version check.

In the end the new navigation integration is better and easier.

Here are sample <navigation> from one of my own plugins...

Code:
	<navigation>
		<tab name="aptab_competition" date="1337135420" username="APcompetition" version="3.0.0">
			<active>1</active>
			<show>member</show>
			<scripts>apcompetition</scripts>
			<displayorder>30</displayorder>
			<url><![CDATA[apcompetition.php{session.sessionurl_q}]]></url>
		</tab>
		<link name="aplink_enter" date="1337135420" username="APcompetition" version="3.0.0">
			<active>1</active>
			<show>member</show>
			<parent>aptab_competition</parent>
			<displayorder>20</displayorder>
			<url><![CDATA[apcompetition.php{session.sessionurl_q}]]></url>
		</link>
		<link name="aplink_search" date="1337135420" username="APcompetition" version="3.0.0">
			<active>1</active>
			<show>member</show>
			<parent>aptab_competition</parent>
			<displayorder>40</displayorder>
			<url><![CDATA[apcompetition.php?{vb:raw session.sessionurl}do=search&apmycomps=1]]></url>
		</link>
		<link name="aplink_performance" date="1337135420" username="APcompetition" version="3.0.0">
			<active>1</active>
			<show>member</show>
			<parent>aptab_competition</parent>
			<displayorder>60</displayorder>
			<url><![CDATA[apcompetition.php?{vb:raw session.sessionurl}do=performance]]></url>
		</link>
		<link name="aplink_fame" date="1337135420" username="APcompetition" version="3.0.0">
			<active>1</active>
			<show>apmgtug</show>
			<parent>aptab_competition</parent>
			<displayorder>80</displayorder>
			<url><![CDATA[apcompetition.php?{vb:raw session.sessionurl}do=finalvotereport]]></url>
		</link>
	</navigation>
Sample phrases the give the text of the navigation items.
Code:
		<phrasetype name="GLOBAL" fieldname="global">
			<phrase name="vb_navigation_tab_aptab_competition_text" date="1336964077" username="APcompetition" version="3.0.0"><![CDATA[Competitions]]></phrase>
			<phrase name="vb_navigation_link_aplink_enter_text" date="1336964077" username="APcompetition" version="3.0.0"><![CDATA[Enter a Competition]]></phrase>
			<phrase name="vb_navigation_link_aplink_search_text" date="1336964077" username="APcompetition" version="3.0.0"><![CDATA[Search Competitions]]></phrase>
			<phrase name="vb_navigation_link_aplink_performance_text" date="1336964077" username="APcompetition" version="3.0.0"><![CDATA[My Performance]]></phrase>
			<phrase name="vb_navigation_link_aplink_fame_text" date="1336964077" username="APcompetition" version="3.0.0"><![CDATA[Hall of Fame]]></phrase>
		</phrasetype>
--------------- Added [DATE]1337391078[/DATE] at [TIME]1337391078[/TIME] ---------------

Pull down menu's can also be coded.
Have a look at the vB source for examples.
Specifically "./install/vbulletin-navigation.xml"
Reply With Quote
  #2  
Old 05-19-2012, 10:01 AM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

FYI, the navtab_end template hook in 4.2.0 still works the same as it did in 4.1.12.

It's the navbar that gives headaches.

You can add to the navbar with a DB routine too.

EDIT: But this does totally screw up dynamically built navbar links. On first glance it looks like a phrase needs to be created for each navbar link. If that's the case, the maintenance DB routines for a dynamically created link will be interesting.
Reply With Quote
  #3  
Old 05-19-2012, 12:34 PM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

FYI, the 'show' check can use multiple variables, so if you want a link to only appear if $show['cond1'] and $show['cond2'] are set, you add them both, separated by a dot

<show>cond1.cond2</show>

Custom $show variables can be created pretty much in any hook, as the navigation is almost the last thing built, but two common ones added for the purpose are load_show_variables & load_forum_show_variables.
Reply With Quote
3 благодарности(ей) от:
AusPhotography, nhawk, Sunka
  #4  
Old 05-19-2012, 03:34 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
But this does totally screw up dynamically built navbar links
IMHO, there should be no dynamically created links as this defeats the purpose of the navigation manager, which is to allow the administrator full control over the menu structure.

May I ask why you would need dynamically created links?
Reply With Quote
4 благодарности(ей) от:
AusPhotography, ragtek, scoles15, soniceffect
  #5  
Old 05-19-2012, 04:04 PM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Andreas View Post
IMHO, there should be no dynamically created links as this defeats the purpose of the navigation manager, which is to allow the administrator full control over the menu structure.

May I ask why you would need dynamically created links?
Posted on vB.com..

'user' in this case means the administrator.

ie: A mod uses a portion of the information entered by the user for the navbar link, say the 'title' portion of the user entry. In order to create the navbar link in the community menu, that 'title' must be also be saved in the phrase table of vB. And then the additional navbar link must be created in the navigation table. Along with that a $show variable must be created in a plugin if the member has permission to view that link.

Now because different 'titles' can have different permissions, there has to be a different $show for each menu item.

That seems like a lot to go through for something that use to take a one line piece of code to throw the menu selection in the community menu in earlier versions.
Reply With Quote
  #6  
Old 05-19-2012, 04:32 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by nhawk View Post
A mod uses a portion of the information entered by the user for the navbar link, say the 'title' portion of the user entry. In order to create the navbar link in the community menu, that 'title' must be also be saved in the phrase table of vB.
Can you give a concreate example of an Add-on so it is easier to understand what exactly you are talking abount?
As far as I understand you intentions by now is that the Add-on allows the administrator to set the title for a link in the Community Menu on the Forum tab?
This can easily be achived by just using the Navigation Manager to rename the link.


Quote:
And then the additional navbar link must be created in the navigation table.
If it is a "static" link - yes, it should be added to the navigation table upon Add-on installation.
(Which will happen automatically if you have already added that link on your developement system, assigned in to the Add-on and exported the XML).


Quote:
Along with that a $show variable must be created in a plugin if the member has permission to view that link.

Now because different 'titles' can have different permissions, there has to be a different $show for each menu item.
Yes, you have to check the permissions and set a flag wether to show the link or not.
But again this is not different from how it worked in vB 4.1


Quote:
That seems like a lot to go through for something that use to take a one line piece of code to throw the menu selection in the community menu in earlier versions.
Not really, in fact it does require less work in my mind:

In vB 4.1 you had to
  • Add a template for the link
  • Add the phrase for the link
  • Create a setting to let the user select where the link should appear (eg. template hook)
  • Write code to check the setting, the user permissions and to render the template for the selected template hook
... and still the administrator might have wanted to have the link appear on a completely different location

In vB 4.2
  • Add the link in Navigation Manager
  • Write a Plug-in to check permissions and set the $show-Flag
Reply With Quote
  #7  
Old 05-19-2012, 04:39 PM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Andreas View Post
Can you give a concreate example of an Add-on so it is easier to understand what exactly you are talking abount?
Sure.. it's my Advanced Application Forms..

Here's a snippet of the code to add an application type to the community menu...
Code:
while($application = $vbulletin->db->fetch_array($applications))
{
	if ($vbulletin->options['advapp_inmenu'] && $vbulletin->userinfo['posts'] >= intval($application['postcount']) && is_member_of($vbulletin->userinfo, explode(',', $application['usergroup'])) && $application['community'] && $application['active'])
	{
		$template_hook['navbar_community_menu_end'] .= '<li><a href="application-forms.php?appid=' . $application['appid'] . '" title="' . $application['description'] . '">' . $application['type'] . '</a></li>';
	}
}
Don't get me wrong. I can create the menu in the database when the application is created. It just seems like more work to me.

This reminds me of the addition of the <vb:each> in templates...
Nobody is going to tell me that reading a database, parse the data to build an array, sending that array to the template and parsing it a second time is faster than bulding/formating the array and sending it in all one lump piece of data to the template. It's just not possible. Two parses take double the time. But that's a different topic.
Reply With Quote
  #8  
Old 05-19-2012, 05:17 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by nhawk View Post
Here's a snippet of the code to add an application type to the community menu...
Code:
while($application = $vbulletin->db->fetch_array($applications))
{
	if ($vbulletin->options['advapp_inmenu'] && $vbulletin->userinfo['posts'] >= intval($application['postcount']) && is_member_of($vbulletin->userinfo, explode(',', $application['usergroup'])) && $application['community'] && $application['active'])
	{
		$template_hook['navbar_community_menu_end'] .= '<li><a href="application-forms.php?appid=' . $application['appid'] . '" title="' . $application['description'] . '">' . $application['type'] . '</a></li>';
	}
}
Thanks, that's what I expected

The idea behind Navigation Manager is to give the Administrator full control over the menu structure - if you are creating links dynamically at runtime (which is still possible) you are IMHO somewhat defeating that goal.

Quote:
This reminds me of the addition of the <vb:each> in templates...
Nobody is going to tell me that reading a database, parse the data to build an array, sending that array to the template and parsing it a second time is faster than bulding/formating the array and sending it in all one lump piece of data to the template.
<vb:each> is a lot faster then doing a ton of vB_Template::create() ... render() calls in a loop

Here is a little benchmark:
PHP Code:
require('./global.php');
require(
DIR '/includes/adminfunctions_template.php');

$vbulletin->templatecache['text_bit'] = compile_template('{vb:raw text}');
$vbulletin->templatecache['text'] = compile_template('{vb:raw textbits}');
$vbulletin->templatecache['text_foreach'] = compile_template('<vb:each from="textbits" value="text">{vb:raw text}</vb:each>');

// Benchmarking bit templates
$start microtime(true);
$textbits ='';
for (
$i 1$i 10000$i++)
{
    
$templater vB_Template::create('text_bit');
    
$templater->register('text''This is Text #' $i);
    
$textbits .= $templater->render();
}
$templater vB_Template::create('text');
$templater->register('textbits'$textbits);
$result1 trim($templater->render());
$end microtime(true);
header('Content-type: text/plain');
echo(
'Time taken for 10.000 Bit Templates: ' . ($end-$start) . "\n");

// Benachmarking <vb:each>
$start microtime(true);
$textbits = array();
for (
$i 1$i 10000$i++)
{
    
$textbits[] = 'This is Text #' $i;
}
$templater vB_Template::create('text_foreach');
$templater->register('textbits'$textbits);
$result2 trim($templater->render());
$end microtime(true);
echo(
'Time taken for 10.000 Array-Elements with <vb:each>: ' . ($end-$start) . "\n");

if (
$result1 == $result2)
{
    echo(
'Success - Both methods yielded the same result data');
}
else
{
    echo(
'Huh? Smth. went wrong, the results are not identical');
    echo(
"\n\n----\n$result1\n----\n$result2");

Reply With Quote
  #9  
Old 05-19-2012, 06:13 PM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just in case you dont bother running that benchmark, here is the result on my local test environment

Time taken for 10.000 Bit Templates: 1.2209470272064
Time taken for 10.000 Array-Elements with <vb:each>: 0.010501146316528 (over 100x faster)
Success - Both methods yielded the same result data

and on my remote test server ;

Time taken for 10.000 Bit Templates: 1.3666188716888
Time taken for 10.000 Array-Elements with <vb:each>: 0.01978611946106 (over 70x faster)
Success - Both methods yielded the same result data
Reply With Quote
  #10  
Old 05-19-2012, 07:04 PM
nhawk nhawk is offline
 
Join Date: Jan 2011
Posts: 1,604
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've already given in to the idea of having to create the menu additions in the database and have the update for that particular mod ready to be released. And those menu selections were always under the admin's control to begin with. Now they can just move them around a little more.

The bechmark isn't exactly what I was talking about. In the case of rendering bits templates I agree it's much faster.

But I see people using it something like this...

Code:
in PHP..
While $whatever...
{
      $whatever_each_array[] = xpartofdata;
}
$templater->register('whatever'. $whatever_each_array);

In template..
<ul>
<vb:each whatever_each>
	<li>{vb:raw whatever_array_part}</li>
</vb:each>
</ul>
When bulding the array as a static value and displaying it as a single value is much faster..
Code:
In PHP...
While $whatever....
{
	$static .=  '<li>' . $whatever_array_part . '</li>' . "\r\n";
}
templater->register('static', $static);

in template...
<ul>
{vb:raw static}
</ul>
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:30 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05141 seconds
  • Memory Usage 2,368KB
  • Queries Executed 24 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (7)bbcode_code
  • (1)bbcode_php
  • (9)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (10)post_thanks_box
  • (11)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete