PDA

View Full Version : vB4.2 Navigation Manager - how to discussion


AusPhotography
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

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...

<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.

<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 1337391078 at 1337391078 ---------------

Pull down menu's can also be coded.
Have a look at the vB source for examples.
Specifically "./install/vbulletin-navigation.xml"

nhawk
05-19-2012, 10:01 AM
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.

Paul M
05-19-2012, 12:34 PM
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.

Andreas
05-19-2012, 03:34 PM
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?

nhawk
05-19-2012, 04:04 PM
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.

Andreas
05-19-2012, 04:32 PM
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.



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).


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



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

nhawk
05-19-2012, 04:39 PM
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 (https://vborg.vbsupport.ru/showthread.php?t=263944&highlight=application+forms)..

Here's a snippet of the code to add an application type to the community menu...
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. ;)

Andreas
05-19-2012, 05:17 PM
Here's a snippet of the code to add an application type to the community menu...
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.


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:

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");
}

Paul M
05-19-2012, 06:13 PM
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

nhawk
05-19-2012, 07:04 PM
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...


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..
In PHP...
While $whatever....
{
$static .= '<li>' . $whatever_array_part . '</li>' . "\r\n";
}
templater->register('static', $static);

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

Andreas
05-19-2012, 07:44 PM
But I see people using it something like this...


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>

Although that is a bit slower than hardcoding the HTML, this is the way it should be done as it separates the presentation from the business logic.

If the designer want's to do smth. complletely different from <ul> he can do that by simply modifying the template - with the list entries being generated in PHP he can't

kh99
05-19-2012, 09:25 PM
<vb:each> is a lot faster then doing a ton of vB_Template::create() ... render() calls in a loop :)

I'm curious, do you know why that is? Is it the time needed to create the objects?

AusPhotography
05-20-2012, 06:14 AM
I'm curious, do you know why that is? Is it the time needed to create the objects?

The render uses 'eval' 'nuff said

Kym

AusPhotography
05-20-2012, 06:45 AM
This is very handy... https://vborg.vbsupport.ru/showthread.php?t=283123 (Thanks Andreas)

Also Scott's post on vb.com https://www.vbulletin.com/forum/showthread.php/401289-vBulletin-4-2-Feedback-amp-Discussion?p=2295256#post2295256

nhawk
05-20-2012, 10:22 AM
Although that is a bit slower than hardcoding the HTML, this is the way it should be done as it separates the presentation from the business logic.

If the designer want's to do smth. complletely different from <ul> he can do that by simply modifying the template - with the list entries being generated in PHP he can't

Even though I'm not a big fan of anything that increases processing time, I see your point. :)

And a note for any other coders that might want to add menus via DB addition rather than at installation.. Be sure you run build_language() after adding the navigation and phrase info. If you don't, your phrase won't appear in the menus.

EDIT: Another note.. The information that's the original topic of this thread gets added to the install XML when you export it. So, you just need to create the navigation links and export a new XML for the mod.

kh99
05-20-2012, 12:03 PM
The render uses 'eval' 'nuff said

Kym

OK, but I ran this modified version of the benchmark:


require('./global.php');
require(DIR . '/includes/adminfunctions_template.php');

$vbulletin->options['addtemplatename'] = 0;

$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();
$text = 'This is Text #' . $i;
eval($vbulletin->templatecache['text_bit']);
$textbits .= $final_rendered;
}
$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");
}


and I got these results:

Time taken for 10.000 Bit Templates: 0.072948932647705
Time taken for 10.000 Array-Elements with <vb:each>: 0.011199951171875
Success - Both methods yielded the same result data


vs. these for the original version:

Time taken for 10.000 Bit Templates: 1.542927980423
Time taken for 10.000 Array-Elements with <vb:each>: 0.011492967605591
Success - Both methods yielded the same result data


That's 6.5 times slower vs 134 times slower, and seems to indicate that eval() isn't the main offender.

Andreas
05-20-2012, 12:12 PM
It's basically the overhead required for variable registration and object creation that makes rending templates in a loop pretty slow.

kh99
05-20-2012, 12:41 PM
Yeah, I played around more and found that my times dropped from 1.5 to 0.7 just by not calling register_globals().

BirdOPrey5
05-20-2012, 01:41 PM
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).


But if it's not a static link? I'm supposed to tell user's to do it themselves now because vBulletin thinks they want more control over their navbar? Respectfully, most user's do not want total control, they want things done for them.

I've come up with this code, it's not efficient but it works, I will work on efficiency-

nhawk I know you mentioned making a database change but I prefer to avoid db edits if possible.

This example adds a link to Quick Links
No phrase needed.

On navigation_tab_complete hook:


//Quick Links Add in 4.2.0 Start
foreach ($tabdata AS $key => &$thistab)
{
if (is_array($thistab['children']))
{
foreach ($thistab['children'] AS &$ttab)
{
if ($ttab['name'] == 'vbmenu_qlinks')
{
$nl['root'] = $key;
$nl['type'] = 'link';
$nl['url'] = 'myfile.php';
$nl['title'] = 'Link Title';
$nl['name'] = 'custom_name_here';
$nl['children'] = 0;
$ttab['children'][] = $nl;
}
}
}
}
//Quick Links Add 4.2.0 END


Mind you that needs to be run for each new link which itself will likely be some kind of loop.

Andreas
05-20-2012, 02:06 PM
But if it's not a static link?
That is a problem :)

I do not know the exact ideas behind Navigation Manager , but I think it simply wasn't designed with dynamic links in mind as vBulletin itself (except vBulletin CMS) does not do that.

As I see it, there are currently three alternatives (of which none is realldy ideal):

Programatically create/update/delete links in navigation manager based on the Add-on data
Pro: Full control over the links
Con: Rather complicated management for the Add-on, might requires extensive changes to the logic
Don't create any links and leave it up to the user
Pro: Full control, no additional work the for Add-on author
Con: A lot of work for the Administrator
Create links at runtime
Pro: Fairly easy to do
Con: Zero control over placement in Navigation Manager, code can be a little bit inefficient


IMHO the best solution would be if the Navigation Manager would offer "Dynamic Content" items which would just act as placeholders in ACP and are only being filled with content on the frontend when needed.
This would be easy to implement and maintain for Add-ons and would still give the Administrator the power to control placement, etc.

http://tracker.vbulletin.com/browse/VBIV-15123

nhawk
05-20-2012, 03:19 PM
But if it's not a static link? I'm supposed to tell user's to do it themselves now because vBulletin thinks they want more control over their navbar? Respectfully, most user's do not want total control, they want things done for them.

I've come up with this code, it's not efficient but it works, I will work on efficiency-

nhawk I know you mentioned making a database change but I prefer to avoid db edits if possible.

This example adds a link to Quick Links
No phrase needed.

On navigation_tab_complete hook:


//Quick Links Add in 4.2.0 Start
foreach ($tabdata AS $key => &$thistab)
{
if (is_array($thistab['children']))
{
foreach ($thistab['children'] AS &$ttab)
{
if ($ttab['name'] == 'vbmenu_qlinks')
{
$nl['root'] = $key;
$nl['type'] = 'link';
$nl['url'] = 'myfile.php';
$nl['title'] = 'Link Title';
$nl['name'] = 'custom_name_here';
$nl['children'] = 0;
$ttab['children'][] = $nl;
}
}
}
}
//Quick Links Add 4.2.0 END


Mind you that needs to be run for each new link which itself will likely be some kind of loop.
I thought of doing it that way, an actually had it done that way. But then there's no control by the admin as to where it goes (as pointed out by Andreas) and I changed to the DB write.

The advantage of doing it in the DB is the admin can move it around to any menu once it's created. After working with it a bit, I found management really isn't difficult. It's only a couple of DB writes at application type creation (in my mod) and then I'm done with it. No need to parse out a special template or anything else in vB 4.2.

And the nice thing is that when the product is uninstalled, the navigation and phrase info gets deleted like it should.

Andreas
05-20-2012, 03:56 PM
The advantage of doing it in the DB is the admin can move it around to any menu once it's created. After working with it a bit, I found management really isn't difficult. It's only a couple of DB writes at application type creation (in my mod) and then I'm done with it. No need to parse out a special template or anything else in vB 4.2.

And the nice thing is that when the product is uninstalled, the navigation and phrase info gets deleted like it should.

Keep in mind that links created this way will be deleted when your Add-on is upgraded:
http://tracker.vbulletin.com/browse/VBIV-14959

To avoid this you would have to do some trickery in your installation code.

If anyone feels that this issue is important, please vote for it :)

BirdOPrey5
05-20-2012, 07:13 PM
Keep in mind that links created this way will be deleted when your Add-on is upgraded:
http://tracker.vbulletin.com/browse/VBIV-14959

To avoid this you would have to do some trickery in your installation code.

If anyone feels that this issue is important, please vote for it :)

Voted... But I do think it's working logically now, consistent with plugins and templates. Seems like nav elements should have a special setting though.

Andreas
05-20-2012, 09:03 PM
Consistent with Plug-ins, yes - but not consistent with how it worked in previous vBulletin versions:

In previous versions Add-ons usually added their links into the Navbar by rendering their own templates on a certain template Hook.

If the Administrator modified those templates (eg. if he added another link), an upgrade of the Add-on would not overwrite this modification - the link would still be there after an upgrade.

Most items (Settings, Cron-Jobs, FAQ, Admin-Help, etc.) do have a volatile flag to handle "custom items" on upgrades, and this is what is missing here.

Badshah93
05-20-2012, 09:05 PM
But if it's not a static link? I'm supposed to tell user's to do it themselves now because vBulletin thinks they want more control over their navbar? Respectfully, most user's do not want total control, they want things done for them.

I've come up with this code, it's not efficient but it works, I will work on efficiency-

nhawk I know you mentioned making a database change but I prefer to avoid db edits if possible.

This example adds a link to Quick Links
No phrase needed.

On navigation_tab_complete hook:


//Quick Links Add in 4.2.0 Start
foreach ($tabdata AS $key => &$thistab)
{
if (is_array($thistab['children']))
{
foreach ($thistab['children'] AS &$ttab)
{
if ($ttab['name'] == 'vbmenu_qlinks')
{
$nl['root'] = $key;
$nl['type'] = 'link';
$nl['url'] = 'myfile.php';
$nl['title'] = 'Link Title';
$nl['name'] = 'custom_name_here';
$nl['children'] = 0;
$ttab['children'][] = $nl;
}
}
}
}
//Quick Links Add 4.2.0 END


Mind you that needs to be run for each new link which itself will likely be some kind of loop.

does 'name' key exist in tabdata[children] array, because when i print_r the tabdata array i did not find a word called "name" anywhere.

Well i liked vb 4.2.0 navigation manager and specially for my new mod. Yes i still have to create one plugin which i was doing in earlier version also but i won't have to create new template for it to use vb:each function.

i am creating a new mod which has one tab and under which there are 5 menu by default. (which i will create it through navigation manager)
there are 3 menu who's links are not fixed, it changes for each usergroup, so i will be creating array of links for those menus which i was for doing in earlier version also.

i don't know how others are going to place their dynamic links inside menu, but i will be doing this way

Plugin Hook: set_navigation_tab_main


if (THIS_SCRIPT == 'myscript')
{

$rootid = $roots['mytabname'];
$x = build_navigation_list(true, $rootid, false); // building mytabname list only

// An Array with menu name = $key and value = links array
(ex: array([menu1] => array([0]=> array('title' => 'google', 'url' => 'google.com')
[1]=> array('title' => 'vbulletin', 'url' => 'vbulletin.com')) [menu2] => (link array for menu2))

foreach ($array AS $menuname => $linkarray)
{

$menuchild = $x["$rootid"]["links"]["$menuname"]["navid"];

$tabs["$rootid"][children]["$menuchild"][children] = array_merge($tabs["$rootid"][children]["$menuchild"][children], $linkarray);

}

}


Benefits of this method:

1) admin can add new menu inside "mytabname" easily through navigation manager
2) admin can add new links inside any menu. (even those menu which have dynamic links)
3) admin can change displayorder, title of any menu.
4) admin can change title of any links through navigation. (for dynamic links through phrase manager)
5) it hardly effects overall performance. (.1 extra second)

nhawk
05-21-2012, 11:07 AM
Keep in mind that links created this way will be deleted when your Add-on is upgraded:
http://tracker.vbulletin.com/browse/VBIV-14959

To avoid this you would have to do some trickery in your installation code.

If anyone feels that this issue is important, please vote for it :)

Voted.

But a workaround for that is to create another product that only contains navigation items. Then the navigation items don't get overwritten if the main product is updated.

Andreas
05-21-2012, 11:29 AM
Yep, that would work but doesn't seem that user friendly ;)

Another workaround would be to do some installation code trickery to add already existing items to the XML data.

nhawk
05-21-2012, 12:05 PM
Yep, that would work but doesn't seem that user friendly ;)

Another workaround would be to do some installation code trickery to add already existing items to the XML data.

I agree it's not that user friendly, but it seemed to be the most fool-proof way of doing it.

The funny thing is (if I'm reading that bug report right) if an admin adds 10 or 20 navigation tabs/menu selections to a stock vB installation using the vBulletin product as the parent, and then updates vB, all of those changes will be lost with the upgrade.

That's a bug to me! The admin will have to re-insert the changes he made each time he upgrades vB.

So that's not an improvement request.

AusPhotography
05-23-2012, 06:52 AM
This is Paul M's blog on how to use the Navigation Manager

https://www.vbulletin.com/forum/entry.php/2513-4-2-Products-amp-Navigation

Kym

Paul M
05-23-2012, 08:42 AM
The funny thing is (if I'm reading that bug report right) if an admin adds 10 or 20 navigation tabs/menu selections to a stock vB installation using the vBulletin product as the parent, and then updates vB, all of those changes will be lost with the upgrade.
They will not, the upgrade process does not remove any tabs/menus/links belonging to the core 'vbulletin' product.

nhawk
05-23-2012, 01:19 PM
They will not, the upgrade process does not remove any tabs/menus/links belonging to the core 'vbulletin' product.

Hmm... but it will for other products? Odd that's not considered a bug.

But, I'm not the one who classifies these things. :D

Paul M
05-23-2012, 02:15 PM
Not odd at all - the core isnt an add-on, other products are.

Paul M
05-23-2012, 05:48 PM
A few points involving 4.2.1

Dont use the navbar_after_links or navbar_after_sublinks template hooks.
They were supposed to have been removed, and will probably go in 4.2.1.

These two hooks are likely to disappear as well - collapse_navigation_state, expand_navigation_state

The reason they existed was because the bit definitions for the state field were not defined in the vb bitfield file (long story), so the hooks were there to cope with any custom ones. However, another change due in 4.2.1 is to convert the state field to use bitfields defined in the vb bitfield file, so it will not be necessary to use any hooks to add to them.

Also, 4.2.1 should see all the Nav Man functions moved out of functions.php into their own file, making it easier to find, update or replace them in the future.

Boofo
05-23-2012, 05:54 PM
A few points involving 4.2.1

Dont use the navbar_after_links or navbar_after_sublinks template hooks.
They were supposed to have been removed, and will probably go in 4.2.1.

These two hooks are likely to disappear as well - collapse_navigation_state, expand_navigation_state

The reason they existed was because the bit definitions for the state field were not defined in the vb bitfield file (long story), so the hooks were there to cope with any custom ones. However, another change due in 4.2.1 is to convert the state field to use bitfields defined in the vb bitfield file, so it will not be necessary to use any hooks to add to them.

Also, 4.2.1 should see all the Nav Man functions moved out of functions.php into their own file, making it easier to find, update or replace them in the future.


What hooks do we use then if we want to add our own sublinb menu? I have one that uses the vb:each to get the post days for searching and I can't use the navigation manager to add that sub-menu.

BirdOPrey5
05-23-2012, 05:57 PM
For those who may be looking on just how to change the default page off of the Activity Stream and back to the CMS or Forum check out this thread: https://www.vbulletin.com/forum/showthread.php/401680-Resetting-the-Default-Tab-in-4-2-0

odln018
05-23-2012, 06:06 PM
I'm wanting to create a tab called "Special Access", with sub-links that will go to my library, jukebox, etc. There is not any base page to associate it with. It's just a tab with the sublinks. How the heck do I do this?

Lynne indicated I " will require a plugin to define that tab as active.:

Could someone please assist with this?

BirdOPrey5
05-23-2012, 06:44 PM
If there's no page what page will show when someone clicks on it?

odln018
05-23-2012, 07:00 PM
That's just where I'm messed up, I don't know what kind of page I can make or place there.

Something tells me I'm not going to be able to do this.

Paul M
05-23-2012, 07:05 PM
Its perfectly possible to have a tab with no target url defined, so its just to present a set of links.

However, bear in mind that no link will mean the system redirects you to your site default, so you may want to direct it (the tab) to something like forum.php.

nhawk
05-23-2012, 07:10 PM
If there's no page what page will show when someone clicks on it?

I've enabled the bug report forms for registered users on my site. Go there and click on the navtab. You'll get a dropdown menu. I think that's what he's talking about.

Its perfectly possible to have a tab with no target url defined, so its just to present a set of links.

If a dropdown menu with links is what you're talking about.. Please do tell how?

I've tried everything I can think of with the navigation manager with no success.

BirdOPrey5
05-23-2012, 07:15 PM
I see... This mod (https://vborg.vbsupport.ru/showthread.php?t=283123) says it allows for drop down menus from Navtabs.

That is not a default feature in the new Navigation Manager.

Paul M
05-23-2012, 07:16 PM
If a dropdown menu with links is what you're talking about.. Please do tell how?
I didnt say anything about a drop down menu, there is no such option as that.

nhawk
05-23-2012, 07:19 PM
I see... This mod (https://vborg.vbsupport.ru/showthread.php?t=283123) says it allows for drop down menus from Navtabs.

That is not a default feature in the new Navigation Manager.

Yeah, I saw that a couple of days ago. I was hoping that maybe some of that got incorporated in the new system.

But, for now creating a tab using the old navtab_end hook and template still works for those type of tabs.

odln018
05-23-2012, 07:42 PM
Its perfectly possible to have a tab with no target url defined, so its just to present a set of links.

However, bear in mind that no link will mean the system redirects you to your site default, so you may want to direct it (the tab) to something like forum.php.

OK, here is what I'd like to do (see attachment)

I added forum.php to a Special Access tab, but it still highlights the forum tab.

BirdOPrey5
05-23-2012, 07:45 PM
OK, here is what I'd like to do (see attachment)

I added forum.php to a Special Access tab, but it still highlights the forum tab.

:)

In Navigation Manager after you add the Tab "Paid Mods" you go to the drop down menu for "Paid Mods" and choose "Add Link" from the menu.

Each one of those options (Free Mods, Styles, etc...) is a Link I added via "Add Link."

Paul M
05-23-2012, 08:49 PM
I added forum.php to a Special Access tab, but it still highlights the forum tab.
You will need to turn on the append tabid option for that tab.

Boofo
05-23-2012, 08:57 PM
You will need to turn on the append tabid option for that tab.

Or add to Tab Script(s) setting. That was all I have to do to get the tab to highlight.

vbresults
05-23-2012, 10:45 PM
I wonder if I won't need https://vborg.vbsupport.ru/showthread.php?t=271740 anymore :O

Boofo
05-23-2012, 10:53 PM
Nope, with Andreas' add-on you can now do drop-down links with tabs.

AusPhotography
05-24-2012, 12:49 AM
What hooks do we use then if we want to add our own sublinb menu? I have one that uses the vb:each to get the post days for searching and I can't use the navigation manager to add that sub-menu.

Please see:
https://vborg.vbsupport.ru/showthread.php?t=283146
and
https://www.vbulletin.com/forum/showthread.php/401680-Resetting-the-Default-Tab-in-4-2-0

The way I'm ding it is via a <navigation> section of my product files and only setting $show variables to control their display.

Boofo
05-24-2012, 11:44 AM
Please see:
https://vborg.vbsupport.ru/showthread.php?t=283146
and
https://www.vbulletin.com/forum/showthread.php/401680-Resetting-the-Default-Tab-in-4-2-0

The way I'm doing it is via a <navigation> section of my product files and only setting $show variables to control their display.

The Navigation Manager won't accept variables, though, and that is the issue I am having. I have a Search Posts sub-link menu that uses a setting to get the days.

7,14,30,120,180

etc...

I then use vb:each in the template to have it build the menu with the days links:

Posts for Last 7 Days
Posts for Last 14 Days
Posts for Last 30 Days
Posts for Last 120 Days
Posts for Last 180 Days

etc...

You can't do that in the Navigation Manager so I need to be able to add that sub-link where the New Posts link (below the navtabs) is now. Without the template hooks, I'm screwed.

nhawk
05-24-2012, 02:01 PM
The Navigation Manager won't accept variables, though, and that is the issue I am having. I have a Search Posts sub-link menu that uses a setting to get the days.

7,14,30,120,180

etc...

I then use vb:each in the template to have it build the menu with the days links:

Posts for Last 7 Days
Posts for Last 14 Days
Posts for Last 30 Days
Posts for Last 120 Days
Posts for Last 180 Days

etc...

You can't do that in the Navigation Manager so I need to be able to add that sub-link where the New Posts link (below the navtabs) is now. Without the template hooks, I'm screwed.

Like this?

http://snogssite.com/tempdown/likethis.jpg

1) Add a menu to the forum tab.
2) Add links to the menu.

In the example shown I didn't disable the original New Posts link.. you might want to do that too. :D

You can do this manually, in the install file for your mod, in a php file, in a plugin using the database, or I'm pretty sure dynamically in a plugin.

I'm using the database method for items that don't change frequently. The best place I've found for something that comes from a settings page is to use the admin_options_processing hook and add/modify the navigation items in the database.

Boofo
05-24-2012, 04:36 PM
Yes, it is looks that but I use vb:each to get each link from the settings. I don't add them one by one. This is what I use in the template (wrapped in a vb:each) to get it to make the menu:

<li><a href="search.php?{vb:raw session.sessionurl}do=getdaily&amp;contenttype=vBForum _Post&amp;days={vb:raw postdays}">{vb:rawphrase boofo_posts_from_last_x_days, {vb:raw postdays}}</a></li>

nhawk
05-24-2012, 05:34 PM
Yes, it is looks that but I use vb:each to get each link from the settings. I don't add them one by one. This is what I use in the template (wrapped in a vb:each) to get it to make the menu:

<li><a href="search.php?{vb:raw session.sessionurl}do=getdaily&amp;contenttype=vBForum _Post&amp;days={vb:raw postdays}">{vb:rawphrase boofo_posts_from_last_x_days, {vb:raw postdays}}</a></li>

Since the settings are where the number of days are contained, get the template out of your head. It's not needed anymore. :)

Put the links in the navigation table and the phrases for those links in the phrase table via the admin_options_processing hook once and you're done.

The only time they would need to be updated is if the settings change and then you just update them via the same hook.

Badshah93
05-24-2012, 05:45 PM
The Navigation Manager won't accept variables, though, and that is the issue I am having. I have a Search Posts sub-link menu that uses a setting to get the days.

7,14,30,120,180

etc...

I then use vb:each in the template to have it build the menu with the days links:

Posts for Last 7 Days
Posts for Last 14 Days
Posts for Last 30 Days
Posts for Last 120 Days
Posts for Last 180 Days

etc...

You can't do that in the Navigation Manager so I need to be able to add that sub-link where the New Posts link (below the navtabs) is now. Without the template hooks, I'm screwed.

Try This Method

Hook: navigation_tab_complete

if ($root == 'vbtab_forum')
{
$days = array(7,14,30,120,180);

$tabforumid = $roots['vbtab_forum'];
$children = array();
foreach ($days AS $day)
{
$children[] = array('title' => 'Post For Last ' .
$day . ' Days', 'url' => 'search.php?do=process&searchdate=' . $day, 'type' => 'link', 'root' => $tabforumid);
}

$tabdata["$tabforumid"][children][] = array(
'root' => $tabforumid,
'type' => 'menu',
'title' => 'New Posts',
'children' => $children
);

}

Boofo
05-24-2012, 06:00 PM
Yes, that worked., although it throws it as the end of the links instead of at the beginning where it needs to be. Plus I has more items in the menu too, but this is close.

nhawk
05-24-2012, 06:05 PM
I'm really curious why people are so resistant to putting their navigation items in the database. It's easy to do and it only needs to be done once (or any time there's a change in the settings). And then the menu is handled by vB without the use of a plugin.

Badshah93
05-24-2012, 06:07 PM
Yes, that worked., although it throws it as the end of the links instead of at the beginning where it needs to be. Plus I has more items in the menu too, but this is close.

use array_slice, array_merge to adjust position

Boofo
05-24-2012, 06:09 PM
I'm really curious why people are so resistant to putting their navigation items in the database. It's easy to do and it only needs to be done once (or any time there's a change in the settings). And then the menu is handled by vB without the use of a plugin.

Because why make unnecessary queries when you don't have to?

nhawk
05-24-2012, 06:11 PM
Because why make unnecessary queries when you don't have to?

The only query you're making is when you add to the database when you save settings. The rest is already done by vB.

Boofo
05-24-2012, 06:12 PM
I misunderstood what you meant then. My bad.

I had an options setting for the days in the mod.

nhawk
05-24-2012, 06:18 PM
I misunderstood what you meant then. My bad.

I had an options setting for the days in the mod.

Ah, it's a member option then. Not one set in the ACP.

That's a different animal then. ;)

Paul M
05-24-2012, 06:28 PM
Not really, you just change

$days = array(7,14,30,120,180);

To pick up the settings from where-ever they are stored.



BTW, I would use ;

$tabdata[$tabforumid]['children'][] = array(

There isnt any reason to enclose $tabforumid in quotes, but children should be.

nhawk
05-24-2012, 06:32 PM
I understand the array can be from anywhere. But, I'm trying to avoid the use of a plugin in most cases. Creating the links in the DB eliminates the plugin and allows vB to handle the menu system.

But I can see where using a plugin to create the menu would be needed at times. Heck, I'm the one that first questioned the dynamic creation of menus in this thread. :D

Boofo
05-24-2012, 06:33 PM
Ah, it's a member option then. Not one set in the ACP.

That's a different animal then. ;)

No, it was an admin cp option.

--------------- Added 1337888754 at 1337888754 ---------------

I'm getting W3C Validation errors like crazy now:

syntax of attribute value does not conform to declared value

<li id=""><a href="search.php?do=process&amp;searchdate=90">Post For ?

The value of an attribute contained something that is not allowed by the specified syntax for that type of attribute. For instance, the ?selected? attribute must be either minimized as ?selected? or spelled out in full as ?selected="selected"?; the variant ?selected=""? is not allowed.

--------------- Added 1337896261 at 1337896261 ---------------

How do you get this to display in more than the forum tab when doing it via a plugun?

--------------- Added 1337896906 at 1337896906 ---------------

use array_slice, array_merge to adjust position

I tried it with $roots, but it seems that isn't the right way.

AusPhotography
05-25-2012, 11:18 PM
If you need to modify the Tab name on the fly...
Eg: Our photo competition system shows the number of competitions open for you to enter.

@hook: parse_templates (just convenient for me)
$vbphrase['vb_navigation_tab_YOURTABNAME_text'] = "New text";

Easy!

--------------- Added 1337991781 at 1337991781 ---------------

OP updated with correct hook name set_navigation_tab_fallaback

--------------- Added 1337992087 at 1337992087 ---------------

Using $root example here...

https://vborg.vbsupport.ru/showpost.php?p=2332895&postcount=409

--------------- Added 1337993314 at 1337993314 ---------------

Also: More doco needed ... https://www.vbulletin.com/forum/showthread.php/401899-More-Navigation-Manager-Doco-Blogs-needed?p=2297796#post2297796

Easy5s.net
05-26-2012, 03:10 AM
Pls help me:
https://vborg.vbsupport.ru/showthread.php?t=283451

Paul M
05-26-2012, 10:11 AM
No one is going to just write code for you (well, unless maybe you pay them).

Boofo
05-26-2012, 01:12 PM
If you need to modify the Tab name on the fly...
Eg: Our photo competition system shows the number of competitions open for you to enter.

@hook: parse_templates (just convenient for me)
$vbphrase['vb_navigation_tab_YOURTABNAME_text'] = "New text";

Easy!

Why nor just edit the phrase?

--------------- Added 1338041603 at 1338041603 ---------------

No one is going to just write code for you (well, unless maybe you pay them).

Exsactly! As a lot of us are still leaning the new system, too. ;)

AusPhotography
05-26-2012, 10:05 PM
Why nor just edit the phrase?

Because it's dynamic!

We have a Competitions tab which shows Competitions (C,V) where C = competitions open to enter and V = competitions open for voting.
C and V set set per user based on their competition system status.

Boofo
05-26-2012, 10:19 PM
Okay!

Christos Teriakis
05-27-2012, 07:12 AM
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.

If you don't mind, can you help me on how to convert a condition like:

<vb:if condition="$vbulletin->userinfo['permissions']['classifieds'] & $vbulletin->bf_ugp['classifieds']['moderate']">

to work as $show. I know that there are variables/condiltions like: $show['member'], but I was always using the above style.

Thank you
Chris

Boofo
05-27-2012, 07:32 AM
Maybe something like this?

if (condition="$vbulletin->userinfo['permissions']['classifieds'] & $vbulletin->bf_ugp['classifieds']['moderate']") $show['classifieds'] = true;

Christos Teriakis
05-27-2012, 07:36 AM
Maybe something like this?

if (condition="$vbulletin->userinfo['permissions']['classifieds'] & $vbulletin->bf_ugp['classifieds']['moderate']") $show['classifieds'] = true;

Thank you. I'll try it. I suppose that I can add multiple conditions and end them like $show['classifieds_post'] = true, or $show['classifieds_moderate'] = true etc.

Thanks again
Chris

Boofo
05-27-2012, 08:34 AM
Sure you can. As another example, here is one I use in the load_show_variables hook:

if ($vbulletin->products['adv_product_management4'] == 1)
{
$show['modtools_apm'] = true;
$show['modtools_pm'] = false;
}
else
{
$show['modtools_apm'] = false;
$show['modtools_pm'] = true;
}


If APM is installed it will use that link. If not, it default to the vb product manager.

I also use the show variables in the navigation_tab_complete, but you have to globalize it in that hook, as well as $vbphrase if you use that there, too.

Lionel
05-29-2012, 03:33 AM
I found it to be much easier to use old system but at navtab_start and navtab_end.
then at navigation_tab_complete I empty $tabid for THIS_SCRIPT. This way I can keep all my dynamic navigations.

nhawk
05-29-2012, 10:25 AM
A word about using the built in Navigation Manager...

If you use it as built in vB 4.2.0, add navtabs, menus or links and then delete them, the phrases used by those items are left behind in the phrase table.

Evidently it was designed to leave unused data in the database...

http://tracker.vbulletin.com/browse/VBIV-15177

Unfortunately, for some reason I don't have the option to petition to reopen that bug.

Altari
05-29-2012, 02:20 PM
Hello,

I try to add 3 links in the Quick Links menu, but that doesn't work : Sometimes nothing is shown, sometime only the last link is shown... i don't really why, maybe someone could help me ?

Here is the code i'm using (tried to do it from Paul's blog) in build_navigation_array hook

if ($show['member'])
{
$userid = vB::$vbulletin->userinfo['userid'];
if (vB::$vbulletin->options['rescue_lienannoncesonoff'] == 1)
{
$lien_mesannonces = array(
'name' => 'rescue_commu_annonces',
'navtype' => 'link',
'url' => '{options.toppath}member.php?u='.$userid.'&tab=afficher_annonces',
'active' => 1,
'productid' => 'rescue',
'text' => 'Mes annonces',
);
$result['vbtab_forum']['links']['vbmenu_qlinks']['links']['rescue_commu_annonces'] = $lien_mesannonces;
}

$lien_messujets = array(
'name' => 'rescue_messujets',
'navtype' => 'link',
'url' => '{options.toppath}search.php?do=finduser&userid='.$userid.'&starteronly=1&contenttype=vBForum_Thread',
'active' => 1,
'productid' => 'rescue',
'text' => 'Mes sujets',
);
$result['vbtab_forum']['links']['vbmenu_qlinks']['links']['rescue_messujets'] = $lien_messujets;

$lien_mesmessages = array(
'name' => 'rescue_mesmessages',
'navtype' => 'link',
'url' => '{options.toppath}search.php?do=finduser&userid='.$userid.'&starteronly=1&contenttype=vBForum_Post&showposts=1',
'active' => 1,
'productid' => 'rescue',
'text' => 'Mes messages',
);
$result['vbtab_forum']['links']['vbmenu_qlinks']['links']['rescue_mesmessages'] = $lien_mesmessages;
unset($userid);
}

Boofo
05-29-2012, 02:56 PM
You need to add this at the very top:

global $show;


And try the navigation_tab_complete hook instead.

Altari
05-29-2012, 04:16 PM
You need to add this at the very top:

global $show;


And try the navigation_tab_complete hook instead.

Hello,

Thank you for your help,
But this doesn't work better : I added the global show and change template hook, but nothing happen. I use VBOptimise(?), but i flushed the cache, cleared system cache etc... Nothing works like that :(

Anyway, i'm just trying to add this to start, and it doesn't work :
global $show;
if ($show['member'] == TRUE)
{
$lien_messujets = array(
'name' => 'rescue_messujets',
'navtype' => 'link',
'url' => '{options.toppath}search.php?do=finduser&userid='.$userid.'&starteronly=1&contenttype=vBForum_Thread',
'active' => 1,
'productid' => 'rescue',
'text' => 'Mes sujets',
);
$result['vbtab_forum']['links']['vbmenu_qlinks']['links']['rescue_messujets'] = $lien_messujets;
}

TheLastSuperman
05-29-2012, 04:44 PM
Very good discussion and imo the first post and info that follows by everyone else makes this worthy of being a Article! I moved this thread here to the articles forum, there is a 7 day redirect link in programming discussions and normally I don't do redirects but just in case some look there first in the next few days ;).

Boofo
05-29-2012, 04:48 PM
Try commenting out the $result line at the bottom. I don't know if that will work in that hook.

Altari
05-29-2012, 05:36 PM
Try commenting out the $result line at the bottom. I don't know if that will work in that hook.

I don't really know what did u expect but of course this code with $result = commented, do nothing :
global $show;
if ($show['member'] == TRUE)
{
$userid = vB::$vbulletin->userinfo['userid'];
$lien_messujets = array(
'name' => 'rescue_messujets',
'navtype' => 'link',
'url' => '{options.toppath}search.php?do=finduser&userid='.$userid.'&starteronly=1&contenttype=vBForum_Thread',
'active' => 1,
'productid' => 'rescue',
'text' => 'Mes sujets',
);
//$result['vbtab_forum']['links']['vbmenu_qlinks']['links']['rescue_messujets'] = $lien_messujets;
unset($userid);
}

(tested in build_navigation_array and navigation_tab_complete, with and without the comment)

Badshah93
05-29-2012, 05:48 PM
Hello,

Thank you for your help,
But this doesn't work better : I added the global show and change template hook, but nothing happen. I use VBOptimise(?), but i flushed the cache, cleared system cache etc... Nothing works like that :(

Anyway, i'm just trying to add this to start, and it doesn't work :
global $show;
if ($show['member'] == TRUE)
{
$lien_messujets = array(
'name' => 'rescue_messujets',
'navtype' => 'link',
'url' => '{options.toppath}search.php?do=finduser&userid='.$userid.'&starteronly=1&contenttype=vBForum_Thread',
'active' => 1,
'productid' => 'rescue',
'text' => 'Mes sujets',
);
$result['vbtab_forum']['links']['vbmenu_qlinks']['links']['rescue_messujets'] = $lien_messujets;
}

Try This Code

Hook: build_navigation_array
Code:

if (vB::$vbulletin->userinfo['userid'])
{
$lien_messujets = array(
'name' => 'rescue_messuje',
'navtype' => 'link',
'url' => '{options.toppath}search.php?do=finduser&userid='.$userid.'&starteronly=1&contenttype=vBForum_Thread',
'active' => 1,
'text' => 'Message',
'productid' => 'vbulletin',
);

$result['vbtab_forum']['links']['vbmenu_qlinks']['links']['rescue_messuje'] = $lien_messujets;
}

You can replace vbulletin with your product id but make sure that product is enabled otherwise link will not be shown.

nhawk
05-29-2012, 06:36 PM
A while back I commented about using the database method for adding things to the navigation menu and nobody has shown how to do that.

So, here's my method broken out and heavily commented so it's easy to understand....

// ########## CREATE NEW NAVIGATION ITEMS ##########
require_once(DIR . '/includes/adminfunctions_language.php');

$username = $vbulletin->userinfo['username'];
$dateline = TIMENOW;

$product = 'yourproductname'; // <<<< CHANGE TO YOUR PRODUCT NAME
$version = '1.0.0'; // <<<< CHANGE TO YOUR PRODUCT VERSION
$name = 'yourmenu_name'; // <<<< CHANGE TO WHAT YOU WANT TO NAME YOUR MENU
$varname = 'vb_navigation_menu_' . $name . '_text'; // <<<< VALID CHOICES:
// FOR MENUS: vb_navigation_menu_' . $name . '_text'
// FOR TABS: vb_navigation_tab_' . $name . '_text'
// FOR LINKS: vb_navigation_link_' . $name . '_text'

$text = 'Text to Display'; // <<<< CHANGE TO THE TEXT YOU WANT DISPLAYED IN THE MENU
$type = 'menu'; // <<<< CHANGE TO link OR tab TO CREATE OTHER TYPES
$url = ''; // <<<< URL IS USED FOR LINK OR TAB TYPES
$fieldname = 'global'; // <<<< PHRASE GROUP NAME
$active = 1; // <<<< 1 = SHOWN, 0 = HIDDEN
$usetabid = 0; // <<<< 1 = APPEND TABID TO LINK, 0 = DON'T APPEND TAB ID
$edited = 0; // <<<< SHOULD BE 0 IF NEW, 1 IF EDITED
$protected = 1; // <<<< 1 = PROTECT FROM DELETE, 0 = ALLOW DELETE
$order = 20; // <<<< DISPLAY ORDER
$parent = 'vbtab_forum'; // <<<< PARENT CAN BE A tab IF A MENU, A tab OR A menu IF A LINK
$permission = 'searchbuttons'; // <<<< CAN BE A VB PERMISSION OR A $SHOW['xyz'] VALUE
$scripts = ''; // <<<< SCRIPT FOR WHICH A TAB WILL BE DISPLAYED AS ACTIVE TAB
$language = '-1'; // <<<< DEFAULT = -1 OTHERWISE LANGUAGE ID NUMBER

$vbulletin->db->query_write("
REPLACE INTO " . TABLE_PREFIX . "navigation (name, productid, navtype, fieldname, state, displayorder, parent, scripts, showperm, url, version, username, dateline)
VALUES('" . $name . "',
'" . $product . "',
'" . $type ."',
'" . ($active ? NAV_ACTIVE : 0) . "' | '" . ($edited ? NAV_EDITED : 0) . "' | '" . ($protected ? NAV_PROTECTED : 0) . "' | '" . ($usetabid ? NAV_USETABID : 0) . "',
'" . $order . "',
'" . $parent . "',
'" . $scripts . "',
'" . $permission . "',
'" . $url . "',
'" . $version . "',
'" . $username . "',
'" . $dateline . "')
");

$vbulletin->db->query_write("
REPLACE INTO " . TABLE_PREFIX . "phrase (varname,languageid,fieldname,text,product,usernam e,dateline,version)
VALUES('" . $varname . "',
'" . $language . "',
'" . $fieldname . "',
'" . $text . "',
'" . $product . "',
'" . $username . "',
'" . $dateline . "',
'" . $version . "')
");

build_language(); // <<<< IMPORTANT - NEW ITEMS WON'T DISPLAY WITHOUT THIS

Boofo
05-29-2012, 06:47 PM
What hook do they run it in?

Altari
05-29-2012, 06:54 PM
Try This Code
...

Hello,

Thank you for your help.
You code works, but only for one link. When i want to add more than 1 link, only the last is displayed.
Tested with this code :
if (vB::$vbulletin->userinfo['userid'])
{
$userid = vB::$vbulletin->userinfo['userid'];
$lien_messujets = array(
'name' => 'rescue_messujets',
'navtype' => 'link',
'url' => '{options.toppath}search.php?do=finduser&userid='.$userid.'&starteronly=1&contenttype=vBForum_Thread',
'active' => 1,
'text' => 'Mes sujets',
'productid' => 'vbulletin',
);
$lien_mesmessages = array(
'name' => 'rescue_mesmessages',
'navtype' => 'link',
'url' => '{options.toppath}search.php?do=finduser&userid='.$userid.'&starteronly=1&contenttype=vBForum_Post&showposts=1',
'active' => 1,
'productid' => 'vbulletin',
'text' => 'Mes messages',
);
$lien_mesannonces = array(
'name' => 'rescue_commu_annonces',
'navtype' => 'link',
'url' => '{options.toppath}member.php?u='.$userid.'&tab=afficher_annonces',
'active' => 1,
'productid' => 'vbulletin',
'text' => 'Mes annonces',
);

$result['vbtab_forum']['links']['vbmenu_qlinks']['links']['rescue_messujets'] = $lien_messujets;
$result['vbtab_forum']['links']['vbmenu_qlinks']['links']['rescue_commu_annonces'] = $lien_mesannonces;
$result['vbtab_forum']['links']['vbmenu_qlinks']['links']['rescue_mesmessages'] = $lien_mesmessages;
unset($userid);
}

nhawk
05-29-2012, 06:57 PM
What hook do they run it in?

It can be run anywhere, in PHP code, or any other hook they want.

I use it in both PHP code for dynamic menus added by an admin from inside a mod and in the admin_options_processing_build hook for adding menus defined by the settings group for a mod.

If you use it in the admin_options_processing_build hook, add a !$settings['dummyvar'] condition at the beginning of the code and set $settings['dummyvar'] to 1 at the end of the code so it only runs once when the settings are updated.

Of course the variables would have to be gotten from the $settings['xyz'] values from the mod settings and/or some hard coded into the plugin.

EDIT: The advantage to using the database for menu items is there aren't any plugins required once the menu is created. vB itself will generate them for you at the proper time. That should be a BIG HINT for the discussion above and below this post that's revolving around a plugin to create a menu that on the surface appears to be a fixed menu that can accept variables (ie: {userinfo.userid} ). Create it once in settings or some other method and forget about it until it needs to change. Which I don't see that happening very often.

{options.toppath}search.php?do=finduser&amp;userid={us erinfo.userid}&amp;starteronly=1&amp;contenttype=vBForum_T hread;)

I do not suggest the database method for navigation items where the displayed text for the navigation item changes frequently (the name of the item ie: Forum or What's New) or where the link is not a fixed link with variables.

Badshah93
05-29-2012, 07:05 PM
Hello,

Thank you for your help.
You code works, but only for one link. When i want to add more than 1 link, only the last is displayed.

Try this code

if (vB::$vbulletin->userinfo['userid'])
{
$userid = vB::$vbulletin->userinfo['userid'];
$lien_messujets = array(
'name' => 'rescue_messujets',
'navtype' => 'link',
'url' => '{options.toppath}search.php?do=finduser&userid='.$userid.'&starteronly=1&contenttype=vBForum_Thread',
'active' => 1,
'text' => 'Mes sujets',
'productid' => 'vbulletin',
'navid' => 1
);
$lien_mesmessages = array(
'name' => 'rescue_mesmessages',
'navtype' => 'link',
'url' => '{options.toppath}search.php?do=finduser&userid='.$userid.'&starteronly=1&contenttype=vBForum_Post&showposts=1',
'active' => 1,
'productid' => 'vbulletin',
'text' => 'Mes messages',
'navid' => 2
);
$lien_mesannonces = array(
'name' => 'rescue_commu_annonces',
'navtype' => 'link',
'url' => '{options.toppath}member.php?u='.$userid.'&tab=afficher_annonces',
'active' => 1,
'productid' => 'vbulletin',
'text' => 'Mes annonces',
'navid' => 3
);

$result['vbtab_forum']['links']['vbmenu_qlinks']['links']['rescue_messujets'] = $lien_messujets;
$result['vbtab_forum']['links']['vbmenu_qlinks']['links']['rescue_commu_annonces'] = $lien_mesannonces;
$result['vbtab_forum']['links']['vbmenu_qlinks']['links']['rescue_mesmessages'] = $lien_mesmessages;
unset($userid);
}

compare it with your code, you will know why it was not working earlier.

Altari
05-29-2012, 07:42 PM
...

Awww that works perfectly, thank you !
For guys who read : Add an id...

Andreas
05-29-2012, 09:22 PM
Awww that works perfectly, thank you !
For guys who read : Add an id...
... a unique ID or you will run into problems sooner or later ;)

Badshah93
05-30-2012, 03:51 AM
... a unique ID or you will run into problems sooner or later ;)

chances are very less, because all the links inside menu generated through navigation manager has id in range of (20 - 50 +), so one can use any id between 1-20 for links inside menu. (per menu).

A higher number will be much better (ex: 1001)

OR

Get the last navid of link in menu.

$lastnavid = array_pop(array_keys($result['vbtab_forum']['links']['vbmenu_qlinks']['links']));
$lastnavid = $result['vbtab_forum']['links']['vbmenu_qlinks']['links'][$lastnavid]['navid'];


So, last code which i gave to one of the user will be like this

if (vB::$vbulletin->userinfo['userid'])
{
$userid = vB::$vbulletin->userinfo['userid'];
$lastnavid = array_pop(array_keys($result['vbtab_forum']['links']['vbmenu_qlinks']['links']));
$lastnavid = $result['vbtab_forum']['links']['vbmenu_qlinks']['links'][$lastnavid]['navid'];

$lien_messujets = array(
'name' => 'rescue_messujets',
'navtype' => 'link',
'url' => '{options.toppath}search.php?do=finduser&userid='.$userid.'&starteronly=1&contenttype=vBForum_Thread',
'active' => 1,
'text' => 'Mes sujets',
'productid' => 'vbulletin',
'navid' => $lastnavid++
);
$lien_mesmessages = array(
'name' => 'rescue_mesmessages',
'navtype' => 'link',
'url' => '{options.toppath}search.php?do=finduser&userid='.$userid.'&starteronly=1&contenttype=vBForum_Post&showposts=1',
'active' => 1,
'productid' => 'vbulletin',
'text' => 'Mes messages',
'navid' => $lastnavid++
);
$lien_mesannonces = array(
'name' => 'rescue_commu_annonces',
'navtype' => 'link',
'url' => '{options.toppath}member.php?u='.$userid.'&tab=afficher_annonces',
'active' => 1,
'productid' => 'vbulletin',
'text' => 'Mes annonces',
'navid' => $lastnavid++
);

$result['vbtab_forum']['links']['vbmenu_qlinks']['links']['rescue_messujets'] = $lien_messujets;
$result['vbtab_forum']['links']['vbmenu_qlinks']['links']['rescue_commu_annonces'] = $lien_mesannonces;
$result['vbtab_forum']['links']['vbmenu_qlinks']['links']['rescue_mesmessages'] = $lien_mesmessages;
unset($userid);
}

Omegatron
05-30-2012, 06:09 PM
What I need to know is how to use the $vbulletin options in a url in the navigation manager

Paul M
05-30-2012, 09:14 PM
{options.optionname}

AusPhotography
05-30-2012, 10:31 PM
{options.optionname}

Can we have a Article outlining what objects are available ?
I know of...

{options.__}
{session.__}
{userinfo.__}

What else is available?
Can we have custom objects?

Thanks!

Kym

Edit: Found the answer in the code.
See: function process_navigation_linkvars($url) in ./includes/functions.php :D
Anything in $GLOBALS or in $vbulletin->object where object is options, userinfo etc.

Merenguista
05-31-2012, 10:47 AM
1- I want add a new Tab, what shoup i put in Tab Script(s) ?

2- I want add a menu and link only for Users Awaiting Moderation, what shoud i put in Show Permission Name ?

AusPhotography
06-01-2012, 03:00 AM
We use Photopost vBgallery and it runs in a different root path to the forum...
eg: ./forurm vs ./gallery
As a result any relative paths in the Tabs fail when in the Gallery unless you do some edits in the Navigation Manager.

I've built an interim product file for vBgallery 3.01 that has support for the new vB4.2.0 navigation. (I can't post it due to (c) reasons).

Chuck @ Photopost has my code and will release an update for vBgallery (soon-ish I hope)

nhawk
06-01-2012, 08:20 AM
1- I want add a new Tab, what shoup i put in Tab Script(s) ?

The name of the php script that makes the tab the active tab. The script must supply it's name with this code...

define('THIS_SCRIPT', 'thenameofthescript');

2- I want add a menu and link only for Users Awaiting Moderation, what shoud i put in Show Permission Name ?

I don't think there's a standard $show variable for that usergroup so you would need to create a custom one in a plugin. Call it something like... uamod ...and put that in the Show Permission Name. The create a plugin with this code...

if(is_member_of($vbulletin->userinfo,3))
{
$show['uamod'] = true;
}

That code can be used in either the 'parse_templates' or the 'process_templates_complete' hook.

cjwinternet
07-06-2012, 08:39 PM
<removed>

KGodel
07-21-2012, 01:12 AM
Hey guys. I am having an issue with some Show Permissions. I have successfully gotten some working, creating the hook for each special usergroup, however when I add them together, so say I want usergroups X, Y, and Z to see a link, each having a separate $show variable in the hook I have created, when I combine them such as "showx.showy.showz" this seems to make the link appear only if a user is in ALL groups. Is there a character I am supposed to use aside from the dot to create an "or" combination versus and "and" combination? Thanks!

Paul M
07-21-2012, 11:32 AM
Joining them with a dot in the permissions box means all of them must be true.
There isnt any way to do an OR within the box, you would need to do it a hook and assign the result to another show variable.

nasko
08-21-2012, 06:32 AM
Can someone, pleace, tell mi how to make these steps because I'm new in Vbulletin and I had installed some Mod but the NavBar totaly screwed up...
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

Robbed
10-08-2012, 07:59 PM
Quick question, my navigation works for all plugins installed but one.

I doubt it will be updated so any help would be appreciated. This application sits outside of the forum path and the navigation menu doesn't show up.

Any code I can add to templates or the php file so it shows the navbar menu then i can disable the navbar plugin for this application.

Thanks

Nelson58
01-17-2014, 04:33 PM
I am using Navigation Manager with an enhancement from DBTech
https://vborg.vbsupport.ru/showthread.php?t=274972

I want to change the appearance (background and text) of just one or two tabs to make them stand out.
(hover and non hover)

How can I do this please?

ozzy47
01-17-2014, 05:02 PM
Answered in the other thread you started.

Elenna
01-31-2014, 07:43 PM
I have created a tab via the Nav Manager that links directly to an article.

That link works just fine; however, when I click on the "regular" Articles tab (the standard one, that links to content.php), my users that are not logged in get an Access Denied message.

I have checked and the Not Logged In usergroup has read access to CMS.

Any ideas?

Elenna
02-02-2014, 04:24 AM
I re-did my site and the problem, above, is fixed.

Now I have another question. :)

I am using the Navication manager in 4.2.2 and adding in some Tab sub-menus. My Tabs that have a drop-down menu attached are 1px taller than the ones that do not have sub-menus. :( I see where I can edit the tab template, but I'm not sure what to change.

Edit: Another possibility is that the Tab with the drop-down menu is looking at the stylevar or CSS height of the "selected" tab, because they both appear to be 1px larger along the bottom.

I am attaching a screenshot of what I mean.

ozzy47
02-02-2014, 10:16 AM
That is a issue that is related to your custom style, you would need to ask the skin designer what the issue is.

Elenna
02-02-2014, 02:36 PM
Thanks! It looks like we set the navtab border color to the same as the background, so it disappeared.

It looks like the "issue" is that the Tab with the drop-down isn't getting the border applied to it, even with the default style.

friendlymela
07-21-2015, 03:48 PM
how can i add fb group link in navigation ?

BirdOPrey5
07-22-2015, 07:48 PM
In Admin CP go to Settings -> Navigation Manager.

If you want a new tab click the Add Tab button at the bottom.

If you want to make it a sub-menu option of an existing tab go to the drop down menu for that tab and choose the "Add Link" option.

In either case on the next screen paste in the URL of the Facebook Group.

Set any other settings you want.

Save Changes.