Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 11-10-2015, 04:58 PM
Jennifer2010 Jennifer2010 is offline
 
Join Date: Mar 2011
Posts: 94
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
Reply With Quote
  #2  
Old 11-10-2015, 05:00 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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

Reply With Quote
2 благодарности(ей) от:
RichieBoy67, TheLastSuperman
  #3  
Old 11-10-2015, 05:55 PM
Dragonsys's Avatar
Dragonsys Dragonsys is offline
 
Join Date: Jan 2008
Location: DFW, Texas
Posts: 743
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

<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.
Reply With Quote
2 благодарности(ей) от:
MarkFL, TheLastSuperman
  #4  
Old 11-10-2015, 06:13 PM
Jennifer2010 Jennifer2010 is offline
 
Join Date: Mar 2011
Posts: 94
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MarkFL View Post
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>
Reply With Quote
  #5  
Old 11-10-2015, 06:21 PM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>
Reply With Quote
3 благодарности(ей) от:
Dragonsys, Lynne, TheLastSuperman
  #6  
Old 11-10-2015, 06:48 PM
Jennifer2010 Jennifer2010 is offline
 
Join Date: Mar 2011
Posts: 94
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MarkFL View Post
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!
Reply With Quote
2 благодарности(ей) от:
MarkFL, TheLastSuperman
  #7  
Old 11-12-2015, 04:48 PM
Dragonsys's Avatar
Dragonsys Dragonsys is offline
 
Join Date: Jan 2008
Location: DFW, Texas
Posts: 743
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Jennifer2010 View Post
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.
Reply With Quote
  #8  
Old 11-13-2015, 07:19 PM
Jennifer2010 Jennifer2010 is offline
 
Join Date: Mar 2011
Posts: 94
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Dragonsys View Post
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>
Reply With Quote
  #9  
Old 11-13-2015, 07:50 PM
Dragonsys's Avatar
Dragonsys Dragonsys is offline
 
Join Date: Jan 2008
Location: DFW, Texas
Posts: 743
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Jennifer2010 View Post
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
Reply With Quote
Благодарность от:
MarkFL
  #10  
Old 11-13-2015, 09:51 PM
Jennifer2010 Jennifer2010 is offline
 
Join Date: Mar 2011
Posts: 94
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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!
Reply With Quote
Reply


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

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

Forum Jump


All times are GMT. The time now is 09:24 PM.


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

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete