The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
[vBulletin 4] Simple way of including an external PHP file
There are other articles out there on variables, templates, etc on vBulletin 4. This is a simple example of including an external PHP files like you used to be able to do here: http://www.vbulletin.com/forum/showt...P-or-HTML-File Thanks to this Blog post by David IB http://www.vbulletin.com/forum/entry...s-to-templates and this article by cellarius https://vborg.vbsupport.ru/showthread.php?t=228078 I have figured out it's only a simple extra step. Step 1: Create a new plugin
Step 2: You will have to figure out these two entries for yourself: LOCATION OF EXTERNAL FILE & Hook Location To give you an example of what you should use is that if you want to display your external PHP file on your Forum's Home. Then replace these two with these values: Hook Location with forumhome_start TEMPLATE YOU ARE USING with FORUMHOME Keep in mind that global_start will still be acceptable, but it's extra loading time where it's not needed. Therefore choosing the optimum hook location is better for your performance overall. Step 3: Visit the Style Manager -> TEMPLATE YOU ARE USING and place the variable in your style where you want it. You will have to use the new format. Code:
{vb:raw php_include} Notes, If you want to: Include this PHP file in multiple templates then preRegister it for the multiple templates: Code:
vB_Template::preRegister('TEMPLATE YOU ARE USING',array('php_include' => $php_include)); vB_Template::preRegister('TEMPLATE YOU ARE USING 2',array('php_include' => $php_include)); I'm still learning as I go with vb4, but if I learn some more notes to add... I'll drop by here. I hope that helps some one out there! |
#62
|
||||
|
||||
What I'm not understanding is why you would make several different php files when you could do the same with a single plugin or really even just template conditionals?
Can you give an example of the HTML code you want displayed from a php file? |
#63
|
||||
|
||||
OK, I'm doing it this way because I'm not a PHP guru... I'm doing it in a way I can understand.
So what I've done now is in the 'manage ads' area of the ACP, i've enabled a 'last post only' ad-spot. While testing, it shows only to admins (once it goes live, i'll change this to show only to guests instead). The content of this ad-code is: Code:
<style type="text/css"> <!-- #adspot { width: 358px; height: 268px; border: none; } --> </style> <table style="text-align: left; width: 100%;" border="0" cellpadding="4" cellspacing="4"> <tbody> <tr align="center"> <td style="vertical-align: middle; text-align: center;"> <!-- GAMETAP // UNDER 'PLAY ARCADE GAMES HERE' FORUM--> <vb:if condition="$GLOBALS['forumid'] == 63 OR $GLOBALS['forumid'] == 54 OR $GLOBALS['forumid'] == 56"> <iframe src="/ads/gaming/rotate.php" frameborder="0" align="center" name="adspot" id="adspot" marginheight="0"><p>Your browser does not support iframes.</p></iframe> </vb:if> <!-- CHRISTIAN STORE random sizes // UNDER 'Religion & spirituality' FORUM--> <vb:if condition="$GLOBALS['forumid'] == 3"> <iframe src="/ads/religion/rotate.php" frameborder="0" align="center" name="adspot" id="adspot" marginheight="0"><p>Your browser does not support iframes.</p></iframe> </vb:if> <!-- MUSIC STORE random sizes // UNDER 'music' FORUM--> <vb:if condition="$GLOBALS['forumid'] == 52"> <iframe src="/ads/music/rotate.php" frameborder="0" align="center" name="adspot" id="adspot" marginheight="0"><p>Your browser does not support iframes.</p></iframe> </vb:if> <!-- SPORTS STORE random sizes // UNDER 'sports' FORUM--> <vb:if condition="$GLOBALS['forumid'] == 55"> <iframe src="/ads/sports/rotate.php" frameborder="0" align="center" name="adspot" id="adspot" marginheight="0"><p>Your browser does not support iframes.</p></iframe> </vb:if> </td> </tr> <tr align="center"> <td style="vertical-align: top;"><small><small><span style="font-weight: bold;">Please <a href="/register.php" target="_parent">register</a> or sign in to remove these advertisements.</span></small></small><br> </td> </tr> </tbody> </table> I'm sure I could somehow move the /rotate.php file into the parent directory and have it refer to different sub-directories according to what forumID is being viewed... I have no doubt that can be done. But - I don't know how to. So I'm trying to keep things simple for myself. |
#64
|
||||
|
||||
Yeah I honestly can't see it getting any better than an IFRAME as you have it without making life A LOT for difficult.
In the unlikely event someone has a browser that doesn't allow IFRAMEs is there some static content you can put between the <IFRAME> and </IFRAME> tags besides "your browser does not support iframes" ? Maybe pick one of the codes you'll be randomizing so it's better than nothing? |
#65
|
||||
|
||||
Just wanted to add, as I said previously, I'm not guru where coding is concerned... However, after a quick flick through the vbmanual, I've managed to condense my code using <vb:else if xyz /> statements and an additional <vb:else />. This means, now, it will check to see if viewer is in forum x,y,z and show appropriate php files - otherwise (if not in the above mentioned forums) it will show a google-adsense post instead.
WIN! |
#66
|
|||
|
|||
I am planning on getting my entire site converted to take adbantage VB 4. I have more than 50,000 pages, so basically, I cannot use the global_start hook, since I would have hundreds of files / scripts loading on every page. This would not be good...
I thought about using global_start with one product (php master file), and then using conditionals within the script to decide which file to load. But decided to wait until I get some advice on this. One thing I did notice: If you have a php file loaded with global_start, every VB page may or may not use those variables. For example, I created a PHP script that looked for the last 5 forum posts, used a variable called $threadid. It happens to be that $threadid is also used within VB. So the last threadid that was called within my custom script forced VB to use that variable! All links on the forum loaded my own script's variable $threadid. Is this normal behavior? I did change my variable name to something unique, but I'm getting a little paranoid about this, because I may have more than this variable that is also used by VB. This is what I plan... Any feedback would be great. Product Example: ob_start(); include('Masterfile.php'); $masterfile = ob_get_contents(); ob_end_clean(); vB_Template:reRegister('customfiletemplate',arra y('loadexternalscripts' => $masterfile)); ---------------------------------- Masterfile.php Example: PHP Code:
Template: {vb: raw loadexternalscripts} The files would then be loaded like customfilepage.php?file=aboutus and Mod-rewrite would do the trick with bringing basic filenames to the request. |
#67
|
||||
|
||||
I'm pretty sure I've heard the global_start hook isn't called on CMS pages anyway. They were going to remove that hook but kept it to keep compatibility with older mods, but didn't add it to the "new" parts of VB4.
I really can't image trying to work on 50,000 pages... good luck with that. But using the same variable names is a concern. Not only should you avoid the variable names used by vBulletin but also names other people have used in mods you have installed. When I make a mod I'll usually call my variables $bop_post or $bop_thread for example to know I'm not changing data used elsewhere. |
#68
|
|||
|
|||
Thanks for the info Joe, do you think the method that I plan would work? This way, only one hook is created and loaded, waiting for $_GET instructions to fire off scripts.
|
#69
|
||||
|
||||
I'm really not understanding what you are really doing... surely you don't plan to write a php elseif statement with 50,000 options...
|
#70
|
|||
|
|||
I am using VB to include 1 PHP file that is open to requests. These requests load the appropriate files if that's the page being requested. So, this allows a hook to be placed in global_start without actually loading a script and consuming enormous amounts of system resources. The 50,000+ pages are generated from about 10 scripts/programs.
In other words, I am using this script as a hook on global_start with a custom template that has the vb raw variable. This is my PHP code (Master.php). Seems to work very well so far. PHP Code:
PHP Code:
Code:
RewriteRule ^C/([^/]+).php$ /FN/M.php?csl=$1 [QSA,L] Mod-Rewrite generates About-Us.php and you're done. |
#71
|
|||
|
|||
Thank you so freakin much!
The file get contents worked! |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|