View Full Version : Using vbulletin IF conditionals in a module
helltonic
09-30-2009, 12:08 AM
Hello, I had a menu strip that shows different options to different usergroups.
For instance:<if condition="is_member_of($vbulletin->userinfo, 21, 13)">
<li><a href="/forums/forumdisplay.php?f=7"><font color="gold">Forum 21</font></a></li>
<li><a href="/forums/forumdisplay.php?f=8"><font color="lime">Forum 13</font></a></li>
</if>
This was originally written in the Header area of Common Templates, which is in Style Manager.
Since I have two skins, I had to keep updating this menu strip in both skins whenever it needed to be changed. So i figured I could put the menu strip in a separate PHP file and create a Module (in the Plugins & Products System section). That way I would only have to edit it once.
So in the Header of each skin's Common Templates, I replaced the menu strip with the variable $hgNavStrip and then I created a module defining it:ob_start();
include('/home/mydomain/public_html/navstrip/navstrip.php');
$hgNavStrip = ob_get_contents();
ob_end_clean();
Well, the menu strip shows up, but all the vB conditionals are ignored. It's like it doesn't know the user's state anymore.
I think I am perhaps not using the right Hook Location or Execution Order. I am currently using a Hook Location of: global_start and an Execution Order of 5. Most of the other Hook Locations I have tried don't show the menu strip at all, but parse_template and init_startup also work, but similarly they ignore the vB conditionals.
If someone could please let me know how to resolve my issue I would be most appreciative.
Lynne
09-30-2009, 03:39 AM
If you are going to go it in a php file, you need to write the conditions in php. For instance:
if (is_member_of($vbulletin->userinfo, 21, 13)) {
stuff
}
helltonic
09-30-2009, 05:20 AM
Thank you. I didn't know I could do that. It works perfect
However, what about links like this? They still don't work.<a href="/forums/$vboptions[forumhome].php$session[sessionurl_q]">link</a>
<a href="/forums/search.php?$session[sessionurl]do=getnew">link</a>
<a href="/forums/memberlist.php$session[sessionurl_q]">link</a>
<a href="/forums/search.php$session[sessionurl_q]">link</a>
--------------- Added 1254323020 at 1254323020 ---------------
Could it be something like this? (with concatenation dots (.) in the URL?) I do not understand what the $session[] array does in the middle of the link.
<?php echo('<a href="/forums/'.$vbulletin->options['forumhome'].'.php'.$vbulletin->session->vars['sessionurl_q'].'">link</a>') ?>
Sorry, but I am not at my normal PC right now. Please let me know if I am on the right track. Thank you
Lynne
09-30-2009, 03:00 PM
Yes, you are on the right track. :)
helltonic
10-01-2009, 02:13 AM
Hey thanks for helping me. I got most of those working. Here is what I did:
<?php /* Forum index */
$href = '/forums/'.$vbulletin->options['forumhome'].'.php'.$vbulletin->session->vars['sessionurl_q'];
$innerHtml = ' Forums <img src="http://files.bortweb.com/hg/web/navstrip2/downarrow.png" border="0" /> ';
echo('<a href="'.$href.'">'.$innerHtml.'</a>');
?>
<?php /* Get new posts */
$href = '/forums/search.php?'.$vbulletin->session->vars['sessionurl'].'do=getnew';
$innerHtml = ' New Posts ';
echo('<a href="'.$href.'">'.$innerHtml.'</a>');
?>
<?php /* Forum member */
$href = '/forums/memberlist.php'.$vbulletin->session->vars['sessionurl_q'];
$innerHtml = ' Members <img src="http://files.bortweb.com/hg/web/navstrip2/downarrow.png" border="0" /> ';
echo('<a href="'.$href.'">'.$innerHtml.'</a>');
?>
I do still have one more question. The Search button is not registering to be a js dropdown. I think because I do not know the correct vB implementation of the $show[] array. Could you please help me with that? Here is what I have so far:
<?php /* Search button or dropdown */
$href = '/forums/search.php'.$vbulletin->session->vars['sessionurl_q'];
$innerHtml = ' Search ';
echo('<a id="navbar_search" href="'.$href.'">'.$innerHtml.'</a>');
if($show['quicksearch'])
{
echo('<script type="text/javascript">vbmenu_register("navbar_search", 1);</script>');
}
?>
Thank you
Lynne
10-01-2009, 02:34 AM
If you are expecting a dropdown, you have more code you need to add to the navbar. Do a search on "dropdown" or "navbar" in "articles" "titles only" and you should find an article on how to add dropdowns to the navbar.
helltonic
10-01-2009, 02:59 AM
Dear Lynne,
This dropdown works fine when it is in Style Manager; it doesn't need any more code. I just need to translate it properly from the following code block into PHP so I can take it out of Style Manager and put it in the PHP module.
This works:
<a id="navbar_search" href="/forums/search.php$session[sessionurl_q]"> Search </a><if condition="$show['quicksearch']"><script type="text/javascript"> vbmenu_register("navbar_search", 1); </script></if>
I believe the main reason why it is not working when I turn it into PHP is because I don't know what the PHP version is for the $show[] array. This is what I was trying to do in the last code block of my previous post. There is a $show[] array, but I am not sure it is correct b/c it does not contain 'quicksearch' as a member. Here is what it contains:
Array ( [search_engine] => [old_explorer] => [left_column] => 1 [center_column] => 1 [right_column] => 1 [editor_css] => [xfire] => )
Thanks!
Lynne
10-01-2009, 03:02 PM
$show is a variable vbulletin uses to determine whether something should be shown. All the permissions for the forum and the user are looked at and then it is determined if something should be 'shown' for that user. If it should, it is set to true. If not, the default is false. If the code needed to determine if $show['whatever'] is not present to set that variable to true, it will stay at false. If you don't care about that variable, then just don't use it.
helltonic
10-01-2009, 03:31 PM
hmm that's weird why $show[] would include 'quicksearch' for me normally, but now when I moved it to a PHP module it only includes the things I pasted above.
I thought perhaps I was not looking at the right $show[] (maybe there is a $show[] in the $vbulletin class instance like $vbulletin->show[] ?)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.