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! |
#42
|
|||
|
|||
Ok, I tried that out. The first one did indeed echo, but the second one didn't. So this means I need to go into the php.ini config file and change something? I can't seem to find this php.ini. Should I be looking somewhere?
Edit: It works now! Before in my plugin I was putting the entire path in (http://www.yoursite.com/forum/test.php). So I just changed it to "../forum/test.php" and it works! So it must be a problem with the php.ini. I looked around and it sounds like it is a real huge pain to mess with. Unless it is simple, I will just remember to not put the full path in. |
#43
|
|||
|
|||
Yes, theres a setting in php.ini to allow scripts to be passed over http
I'm not sure exactly where it is, but I had to do the same before some of my scripts would run properly on my server You need to set php to include through HTTP , ie: allowing remote files to be included Some info is available here. http://www.php.net/manual/en/features.remote-files.php |
#44
|
||||
|
||||
You can't include a php file using it's remote (http) address EVER. It will never work that way. PHP files are executed when viewed by http, the code is never shown or known to the browser. You can include using full or relative paths on your server, examples:
Code:
/includes/myfile.php or /home/yoursite/public_html/forums/includes/myfile.php |
#45
|
|||
|
|||
Thank you guys so much for all the help, everything is working like a charm now!
|
#46
|
|||
|
|||
Ok i need your help please!
I have created four pages according to this How-To: https://vborg.vbsupport.ru/showthread.php?t=228112 I have also 4 external php scripts that i want to include. I have created 4 templates and 4 plugins. I have change the php_include to php_include_1 to php_include_4 and also changed this accordingly in the templates. Code:
ob_start(); require_once('../vbtest/test_1.php'); $php_include_1 = ob_get_contents(); ob_end_clean(); vB_Template::preRegister('template_1',array('php_include_1' => $php_include_1)); As soon as i activate 2,3 or 4 plugins i get this: Warnung: require_once(../vbtest/test_1.php) [function.require-once]: failed to open stream: No such file or directory in [path]/includes/class_bootstrap.php(122) : eval()'d code (Zeile 7) Fatal error: require_once() [function.require]: Failed opening required '../vbtest/test_1.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/b/b0000009/weball/vbtest/includes/class_bootstrap.php(122) : eval()'d code on line 7 The file which is mentioned as missing here is there and it is producing output as long as i only activate 1 of the modules! I guess it maybe is because of the hook i've chosen? As i was not sure which one, and most of the ones i expected to be the right ones did not work at all i've chosen 'global_bootstrap_init_complete' Any ideas? Which would be the correct hook? Thanks for any help, regards, Matthias |
#47
|
||||
|
||||
Where are you wanting the info to show up at? Every page?
|
#48
|
|||
|
|||
Ok, i'll explain what i want to achieve, and hopefully you guys can help me.
I'm very new to vBulletin and my knowledge of php is also not 'the' best I have a php script that is creating a linklist from files within a directory. At the end of the script i have an echo statement to display the list. What i want is to have this showing up inside a vbulletin page. The only thing i have achieved so far is including this script in the new page i have created according to this: https://vborg.vbsupport.ru/showthread.php?t=228112 I have put PHP Code:
So what i want to achive is: Including the output of several php scripts in several vbulletin pages. www.mysite.com/script1.php > www.mysite.com/page1.php www.mysite.com/script2.php > www.mysite.com/page2.php and so forth. |
#49
|
||||
|
||||
Of course you will see the created list if you use echo in the file. You need to use the function from the file to show the listing formatted to whatever template you set up for it.
|
#50
|
|||
|
|||
Ok, lack of vbulletin knowledge + only very basic php knowledge = fail
I have now changed my script.php file so that the output is now a function. When i include the script.php in a simple php script like this it works. So no problem in the script. PHP Code:
I have a page.php file and a matching template. These i have created after reading this tutorial: https://vborg.vbsupport.ru/showthread.php?t=228112 In the page.php file i include script.php after global.php require_once('./global.php'); require_once('./script.php'); What i still don't understand is where i now have to put "myfunction();" to show the output in a vbulletin page. In the template? In a plugin? Thanks for your help! Really appreciated! Schoelle |
#51
|
|||
|
|||
I'm using this and it works, only I want to pass a variable (GLOBALS.foruminfo.title_clean) from my template to my PHP script.
I am attempting to pass the current Forum title and with my own PHP generate CSS to have a specific image for that forum in the background. My Plugin code: Code:
ob_start(); $stringPath = "/var/www/vhosts/***/httpdocs/includes/getForumImage.php"; $PageTitle = $GLOBALS.foruminfo.title_clean; require_once($stringPath); $php_include = ob_get_contents(); ob_end_clean(); vB_Template::preRegister('headinclude',array('php_include' => $php_include)); --------------- Added [DATE]1299018239[/DATE] at [TIME]1299018239[/TIME] --------------- figured it out, didnt have to use the global variable - just used foruminfo[title_clean] which worked instead. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|