vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Using vbulletin IF conditionals in a module (https://vborg.vbsupport.ru/showthread.php?t=224240)

helltonic 09-30-2009 12:08 AM

Using vbulletin IF conditionals in a module
 
Hello, I had a menu strip that shows different options to different usergroups.

For instance:
PHP Code:

<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:
PHP Code:

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:
PHP Code:

if (is_member_of($vbulletin->userinfo2113)) {
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.
PHP Code:

<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 [DATE]1254323020[/DATE] at [TIME]1254323020[/TIME] ---------------

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 Code:


<?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 Code:

<?php /* Forum index */
    
$href '/forums/'.$vbulletin->options['forumhome'].'.php'.$vbulletin->session->vars['sessionurl_q'];
    
$innerHtml '&nbsp; Forums <img src="http://files.bortweb.com/hg/web/navstrip2/downarrow.png" border="0" />&nbsp;';
    echo(
'<a href="'.$href.'">'.$innerHtml.'</a>');
?>

<?php /* Get new posts */
    
$href '/forums/search.php?'.$vbulletin->session->vars['sessionurl'].'do=getnew';
    
$innerHtml '&nbsp; New Posts &nbsp;';
    echo(
'<a href="'.$href.'">'.$innerHtml.'</a>');
?>

<?php /* Forum member */
    
$href '/forums/memberlist.php'.$vbulletin->session->vars['sessionurl_q'];
    
$innerHtml '&nbsp; Members <img src="http://files.bortweb.com/hg/web/navstrip2/downarrow.png" border="0" />&nbsp;';
    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 Code:

<?php /* Search button or dropdown */
    
$href '/forums/search.php'.$vbulletin->session->vars['sessionurl_q'];
    
$innerHtml '&nbsp; Search &nbsp;';
    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:
HTML Code:

<a id="navbar_search" href="/forums/search.php$session[sessionurl_q]">&nbsp; Search &nbsp;</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:

Code:

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[] ?)


All times are GMT. The time now is 04:05 PM.

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

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01660 seconds
  • Memory Usage 1,764KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_html_printable
  • (7)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

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

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