vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   How to use "if" condition? (https://vborg.vbsupport.ru/showthread.php?t=320754)

Jennifer2010 11-10-2015 04:58 PM

How to use "if" condition?
 
I have a plugin that inserts PHP code on all pages to check a user's IP address. What I want to do exclude it from checking administrator's IPs.

The plugin looks like this:
HTML Code:

        <dependencies />
        <codes />
        <templates />
        <plugins>
                <plugin active="1" executionorder="1">
                        <title>BlockScript vBulletin Integration</title>
                        <hookname>init_startup</hookname>
                        <phpcode><![CDATA[if (file_exists(CWD.'/blockscript/detector.php')) {
        include_once(CWD.'/blockscript/detector.php');
} elseif (file_exists(CWD.'/../blockscript/detector.php')) {
        include_once(CWD.'/../blockscript/detector.php');
} else {
        include_once(CWD.'/../../blockscript/detector.php');
}]]>
</phpcode>
                </plugin>
        </plugins>
        <phrases />
        <options />
        <helptopics />
        <cronentries />
        <faqentries />
</product>

And the if condition I'd like to use is this:
<vb:if condition="is_member_of($bbuserinfo, 1,2,3,4,8,17,19,20,26,15,22,16,14,18,21)">

But if I insert that in the xml file when adding the product/plugin it gives me a mysql error and doesn't work.

Any ideas?

Thank you!
-Jennifer

MarkFL 11-10-2015 05:00 PM

Wrap the plugin code with:

PHP Code:

if (is_member_of($vbulletin->userinfo, array(1,2,3,4,8,17,19,20,26,15,22,16,14,18,21)))
{
    
existing code here



Dragonsys 11-10-2015 05:55 PM

<vb:if> is for use in templates. Are you needing the IF statement in a template or in php code?

If using it in the php plugin, use it as MarkFL stated above.

Jennifer2010 11-10-2015 06:13 PM

Quote:

Originally Posted by MarkFL (Post 2558543)
Wrap the plugin code with:

PHP Code:

if (is_member_of($vbulletin->userinfo, array(1,2,3,4,8,17,19,20,26,15,22,16,14,18,21)))
{
    
existing code here



Thanks for the response!

I've tried a few times but can't seem to know exactly where I'm supposed to wrap the code. I keep breaking something.

This is the entire XML file...


HTML Code:

<?xml version="1.0" encoding="ISO-8859-1"?>
<product productid="blockscript" active="1">
        <title>BlockScript vBulletin Integration</title>
        <description>BlockScript vBulletin Integration</description>
        <version>1.0</version>
        <url>http://www.blockscript.com/</url>
        <versioncheckurl />
        <dependencies />
        <codes />
        <templates />
        <plugins>
                <plugin active="1" executionorder="1">
                        <title>BlockScript vBulletin Integration</title>
                        <hookname>init_startup</hookname>
                        <phpcode><![CDATA[if (file_exists(CWD.'/blockscript/detector.php')) {
        include_once(CWD.'/blockscript/detector.php');
} elseif (file_exists(CWD.'/../blockscript/detector.php')) {
        include_once(CWD.'/../blockscript/detector.php');
} else {
        include_once(CWD.'/../../blockscript/detector.php');
}]]>
</phpcode>
                </plugin>
        </plugins>
        <phrases />
        <options />
        <helptopics />
        <cronentries />
        <faqentries />
</product>


MarkFL 11-10-2015 06:21 PM

Change it to read:

HTML Code:

<?xml version="1.0" encoding="ISO-8859-1"?>
<product productid="blockscript" active="1">
        <title>BlockScript vBulletin Integration</title>
        <description>BlockScript vBulletin Integration</description>
        <version>1.0</version>
        <url>http://www.blockscript.com/</url>
        <versioncheckurl />
        <dependencies />
        <codes />
        <templates />
        <plugins>
                <plugin active="1" executionorder="1">
                        <title>BlockScript vBulletin Integration</title>
                        <hookname>init_startup</hookname>
                        <phpcode><![CDATA[if (is_member_of($vbulletin->userinfo, array(1,2,3,4,8,17,19,20,26,15,22,16,14,18,21)))
{
        if (file_exists(CWD.'/blockscript/detector.php')) {
                include_once(CWD.'/blockscript/detector.php');
        } elseif (file_exists(CWD.'/../blockscript/detector.php')) {
                include_once(CWD.'/../blockscript/detector.php');
        } else {
                include_once(CWD.'/../../blockscript/detector.php');
        }
}]]></phpcode>
                </plugin>
        </plugins>
        <phrases />
        <options />
        <helptopics />
        <cronentries />
        <faqentries />
</product>


Jennifer2010 11-10-2015 06:48 PM

Quote:

Originally Posted by MarkFL (Post 2558546)
Change it to read:

HTML Code:

<?xml version="1.0" encoding="ISO-8859-1"?>
<product productid="blockscript" active="1">
        <title>BlockScript vBulletin Integration</title>
        <description>BlockScript vBulletin Integration</description>
        <version>1.0</version>
        <url>http://www.blockscript.com/</url>
        <versioncheckurl />
        <dependencies />
        <codes />
        <templates />
        <plugins>
                <plugin active="1" executionorder="1">
                        <title>BlockScript vBulletin Integration</title>
                        <hookname>init_startup</hookname>
                        <phpcode><![CDATA[if (is_member_of($vbulletin->userinfo, array(1,2,3,4,8,17,19,20,26,15,22,16,14,18,21)))
{
        if (file_exists(CWD.'/blockscript/detector.php')) {
                include_once(CWD.'/blockscript/detector.php');
        } elseif (file_exists(CWD.'/../blockscript/detector.php')) {
                include_once(CWD.'/../blockscript/detector.php');
        } else {
                include_once(CWD.'/../../blockscript/detector.php');
        }
}]]></phpcode>
                </plugin>
        </plugins>
        <phrases />
        <options />
        <helptopics />
        <cronentries />
        <faqentries />
</product>


That worked perfect. Thank you thank you thank you!

--------------- Added [DATE]1447265522[/DATE] at [TIME]1447265522[/TIME] ---------------

I just realized today that the code isn't working :(

It doensn't return any errors but the code isn't executing for any of the usergroups in the array. If anyone has any ideas I'd greatly appreciate it.

Thank you!

Dragonsys 11-12-2015 04:48 PM

Quote:

Originally Posted by Jennifer2010 (Post 2558547)
I just realized today that the code isn't working :(

It doensn't return any errors but the code isn't executing for any of the usergroups in the array. If anyone has any ideas I'd greatly appreciate it.

Thank you!

Try setting the include file a var:
Code:

if (file_exists($CWD.'/blockscript/detector.php')) {
        $bs_detector_path = $CWD.'/blockscript/';
}

Then add this to the bottom of your PHP Code:
Code:

ob_start();
  include($bs_detector_path.'detector.php');
  $includedphp = ob_get_contents();
ob_end_clean();

Use the global_start hook, instead of init_startup

Unless you are using an external (to VB) file, $CWD should be the root VB folder, so you should not need to check it several times.

Jennifer2010 11-13-2015 07:19 PM

Quote:

Originally Posted by Dragonsys (Post 2558639)
Try setting the include file a var:
Code:

if (file_exists($CWD.'/blockscript/detector.php')) {
        $bs_detector_path = $CWD.'/blockscript/';
}

Then add this to the bottom of your PHP Code:
Code:

ob_start();
  include($bs_detector_path.'detector.php');
  $includedphp = ob_get_contents();
ob_end_clean();

Use the global_start hook, instead of init_startup

Unless you are using an external (to VB) file, $CWD should be the root VB folder, so you should not need to check it several times.

Thank you for the response! I'm a little confused, but is this what the code should end up looking as?

HTML Code:

<?xml version="1.0" encoding="ISO-8859-1"?>
<product productid="blockscript" active="1">
        <title>BlockScript vBulletin Integration</title>
        <description>BlockScript vBulletin Integration</description>
        <version>1.0</version>
        <url>http://www.blockscript.com/</url>
        <versioncheckurl />
        <dependencies />
        <codes />
        <templates />
        <plugins>
                <plugin active="1" executionorder="1">
                        <title>BlockScript vBulletin Integration</title>
                        <hookname>init_startup</hookname>
                        <phpcode><![CDATA[if (is_member_of($vbulletin->userinfo, array(1,2,3,4,8,17,19,20,26,15,22,16,14,18,21)))
{
        if (file_exists($CWD.'/blockscript/detector.php')) {
        $bs_detector_path = $CWD.'/blockscript/';
}
        if (file_exists(CWD.'/blockscript/detector.php')) {
                include_once(CWD.'/blockscript/detector.php');
        } elseif (file_exists(CWD.'/../blockscript/detector.php')) {
                include_once(CWD.'/../blockscript/detector.php');
        } else {
                include_once(CWD.'/../../blockscript/detector.php');
        }
        ob_start();
  include($bs_detector_path.'detector.php');
  $includedphp = ob_get_contents();
ob_end_clean();
}]]> </phpcode>
                </plugin>
        </plugins>
        <phrases />
        <options />
        <helptopics />
        <cronentries />
        <faqentries />
</product>


Dragonsys 11-13-2015 07:50 PM

Quote:

Originally Posted by Jennifer2010 (Post 2558753)
Thank you for the response! I'm a little confused, but is this what the code should end up looking as?

Something like this:
Code:

<?xml version="1.0" encoding="ISO-8859-1"?>
<product productid="blockscript" active="1">
        <title>BlockScript vBulletin Integration</title>
        <description>BlockScript vBulletin Integration</description>
        <version>1.0</version>
        <url>http://www.blockscript.com/</url>
        <versioncheckurl />
        <dependencies />
        <codes />
        <templates />
        <plugins>
                <plugin active="1" executionorder="1">
                        <title>BlockScript vBulletin Integration</title>
                        <hookname>global_start</hookname>
                        <phpcode><![CDATA[if (is_member_of($vbulletin->userinfo, array(1,2,3,4,8,17,19,20,26,15,22,16,14,18,21)))
{
        if (file_exists($CWD.'/blockscript/detector.php')) {
                $bs_detector_path = $CWD.'/blockscript/';
                ob_start();
                        include($bs_detector_path.'detector.php');
                        $includedphp = ob_get_contents();
                ob_end_clean();
        }
        elseif (file_exists(CWD.'/../blockscript/detector.php')) {
                $bs_detector_path = $CWD.'/../blockscript/';
                ob_start();
                        include($bs_detector_path.'detector.php');
                        $includedphp = ob_get_contents();
                ob_end_clean();
        }
        elseif {
                $bs_detector_path = CWD.'/../../blockscript/';
                ob_start();
                        include($bs_detector_path.'detector.php');
                        $includedphp = ob_get_contents();
                ob_end_clean();
        }
        else {
                $includedphp = "<!-- File Not Found -->";
        }
vB_Template::preRegister('FORUMHOME',array('includedphp' => $includedphp));
}]]> </phpcode>
                </plugin>
        </plugins>
        <phrases />
        <options />
        <helptopics />
        <cronentries />
        <faqentries />
</product>

if blockscript/detector.php is inside the VB path, then you should be able to use this (without all the different folder searches):
Code:

<?xml version="1.0" encoding="ISO-8859-1"?>
<product productid="blockscript" active="1">
        <title>BlockScript vBulletin Integration</title>
        <description>BlockScript vBulletin Integration</description>
        <version>1.0</version>
        <url>http://www.blockscript.com/</url>
        <versioncheckurl />
        <dependencies />
        <codes />
        <templates />
        <plugins>
                <plugin active="1" executionorder="1">
                        <title>BlockScript vBulletin Integration</title>
                        <hookname>global_start</hookname>
                        <phpcode><![CDATA[if (is_member_of($vbulletin->userinfo, array(1,2,3,4,8,17,19,20,26,15,22,16,14,18,21)))
{
        if (file_exists($CWD.'/blockscript/detector.php')) {
                $bs_detector_path = $CWD.'/blockscript/';
                ob_start();
                        include($bs_detector_path.'detector.php');
                        $includedphp = ob_get_contents();
                ob_end_clean();
        }
        else {
                $includedphp = "<!-- File Not Found -->";
        }
vB_Template::preRegister('FORUMHOME',array('includedphp' => $includedphp));
}]]> </phpcode>
                </plugin>
        </plugins>
        <phrases />
        <options />
        <helptopics />
        <cronentries />
        <faqentries />
</product>

Then you need to register the variable, change FORUMHOME (in the above code) to the template which you plan on including this in.

Then in the template, where you want the included file to appear you put this:
Code:

{vb:raw includedphp}
All of this may need some tweaking to work perfectly, but hopefully it will get you started in the right direction

Jennifer2010 11-13-2015 09:51 PM

Thanks for the response.

Just to say: The original template I provided was working/already in use. The only thing that seemed to stop it from working altogether was the inclusion of the:
HTML Code:

if (is_member_of($vbulletin->userinfo, array(1,2,3,4,8,17,19,20,26,15,22,16,14,18,21)))
So by itself the plugin already inserted itself into all of the templates. Is it possible to keep how it was (without having to include anything manually inside of the template files) and still only trigger it on a per usergroup basis?

Thank you!


All times are GMT. The time now is 04:30 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.01373 seconds
  • Memory Usage 1,830KB
  • 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
  • (7)bbcode_code_printable
  • (6)bbcode_html_printable
  • (2)bbcode_php_printable
  • (5)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

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

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