[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)); 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! |
This is excellent, it works great on the forum and blog pages but it won't load on the home page for me. Any advice?
|
Helped someone else with the same problem. Globalstart isn't a hook on the home page.
I can't currently give you documentation, but if you use init_start it should work. For optimization reasons though I do not suggest that. I can offer more after the weekend is over if needed. Thanks. |
Hi,
Thanks for the tips. How would I use this idea to replicate a php 'echo file_get_contents' instead of a 'require_once'? Cheers, Phil |
I'm not 100% sure. I haven't done that yet.
Stupid question, but have you tried swapping the two? |
Yep, this works thanks...
Code:
// Textpattern External Output: body-social |
Quote:
$php_include = file_get_contents('...'); would also work;) |
I tried this, but it made my forum crash miserably. I had to restore a database backup in order for it to work again.
Quote:
|
When I create the plugin and I activate it, I get a blank page in my forum. This is the code I'm using in the plugin:
PHP Code:
Code:
{vb:raw kbar} |
Can please somebody help me out?
|
Looks OK to me, have you made the plugin hook 'global_start'?
Maybe try a full server path for kbar.php? |
Yes, I'm using global_start. Using a full server path I can get the forum to work (previously I was getting a blank forum page).. but nothing is being included. And yes, I'm sure the file is where it is supposed to be.
This is strange.. please help me! :) |
And that's the problem;)
There is no global_start hook anymore;) Use global_bootstrap_init_start |
Quote:
|
PHP Code:
|
Ah OK thanks, I'll change all occurrences of 'global_start' to 'global_bootstrap_init_start' to futureproof the hooks.
|
I was having problems both with the hook and the PHP code of the plugin. This is the correct code:
PHP Code:
|
i am having the same issue, did you ever find a solution to this problem Centrix ? or anybody else who could help ?
Quote:
|
Quote:
ob_start(); include('/home/mydomain/public_html/php/includes/ineverypost.inc.php'); $includedineverypost = ob_get_contents(); ob_end_clean(); vB_Template::preRegister('postbit_display_complete ',array('includedineverypost' => $includedineverypost)); in vb 3.8.6, this was hooked to 'postbit_display_complete' Now with VB4, there is no template for post_display_complete.... I tried "postbit" it did notwork. I tried other postbit related templates, this still did not work. any help ?? |
The included page shows up but it's showing on every page. I used the parse_template hook. Do I need to include anything else to only show one a specific page?
|
Quote:
any generous person wants to share his knowledge ? --------------- Added 11 Dec 2010 at 03:23 --------------- would any kind person help with this ? |
postbit_display_complete is a php code hook... not a template... the template is named postbit and it's the same in VB3 and VB4.
|
Nice idea i will give this a try ..........
|
Hi everybody,
sorry in advance for me maybe talking rubbish, but I am completely new to developing plugin code for vbulletin. I am quite experienced in coding PHP, though. Boofo pointed me in the right direction (thanks for that), but, however, I am still facing the following problem: I want to extend the list of online users (online.php) by another column. Information within that column is not extracted from the database but fetched from a third party. This has to be done for each user that shows up in the list of online users - but I have no idea which hook I may use. At the moment, my plugin works pretty fine - but it is a bad mixture of source code hacking and template modifications. If any future upgrade replaces online.php, all my changes are gone. I added a very few lines of code in online.php (v4.1.0 PL2) starting from line 414, which basically adds another value to the $userinfo array which (as if this variable is registered) can be accessed from the whoisonlinebit template, where the output is generated from the additional value. As mentioned before - so far, everything works fine but I truly hate source code modifications as they are gone after an update. Therefore, it would be great to know if there is another way of executing code (maybe in an external file) for each line in the result set. If I interpret the PHP source in online.php correctly, anything that should be executed for each user name should go inside the while loop on line 393. The instructions above explain how to use external files with hooks but I just can't figure out which hook to use in that case... Is there a way to execute PHP code from templates without having a hook? As I said, I am completely new to this stuff, please help... |
There's a hook at the very end of the while loop:
PHP Code:
|
Indeed, I have found that hook and I thought it would be what I was looking for, but obviously this hook only affects spiders/guests, according to the comment on line 449:
PHP Code:
|
Probably not... although it's of no use when releasing a mod to others you can add your own hooks to the code anywhere you want- so if it's just for you adding a 1 line hook and keeping the bulk of the code in a plugin will make life easier than keeping all edits in the files.
|
Thanks for replying to fast! Well, that of course would be possible and still, this is probably the best idea. I still could add instructions on how to create the custom hook in my install guide. However, I consider this hook a bug... I just can't believe it makes any sense in that position. But as mentioned before, I am quite new to this plugin system, probably I just do not understand enough...
But am I right that there is no way to achieve what I want without modifying the original vb source code? |
Quote:
However if you're fetching data from an external source could you not just "run the loop" a second time and collect the data needed per user id, and put the data in an array who's keys are the userid's themselves so it's say $mydata[1] for userid 1, $mydata[200] for user 200, etc... then call it in the template where needed (after pre-registering it of course.) |
PHP Code:
global bootstrap init start, is the hook I am using. I had some bugs in the code when I first included it, and it showed up as I worked the bugs out, and the code ran clean, it made it through the hook. Thats great. I clicked on the tab, that is linked to the template I added it to, and it just wont display Ideas anybody? RG |
o.k. I got that to work, now how to get scripts that call the same page to work?
|
woooooooooooooooooooooow
very nice thanx thanx man gooood job :) exelent |
How can I php file in my Sidebar include?
help :( |
This is a nice tutorial you have, I have read many, but this one is very clear and simple. But from all the tutorials I've tried, I can never get this to work. I want to have a php file output into the postbit_legacy template. So I made a plugin following this tutorial, using this:
Hook Location: global_start Title: Testing Execution Order: 5 And the PHP Code: PHP Code:
PHP Code:
PHP Code:
Note: Where the "****" are, just for posting the code here, I put those in to censor where the files are, just to be safe. I really do have the correct paths in the files uploaded to the site. |
Well global_start hook location is now obsolete as of 4.0.3+ and 4.1. You should probably use the global_bootstrap_init_start hook instead if you are using a recent version. Also using $php_include as your variable might be causing problems so rename it to something unique. Your plugin code should probably be more like this
Code:
and of course the call in the postbit_legacy template {vb:raw creds} The parse error in your code is due to your missing the ";" at the end of your statement Quote:
|
Thanks for the help. I tried all of that, and now every page in the forum is completely blank when I turn the plugin on. If I turn it off the forums are back. Is there any reason for this?
|
I still don't understand why you guys just don't use the require_once to include the file in the php hook right before the code you want to use it with. You are taking the long way around doing it this way. Unless you need the included file for every page, it makes no sense to put it in the global hook.
|
What version of vbulletin are you using?
If you type in the script location directly from your browser, does it work? If not, then its a problem with your script. Also, your php.ini might be set to disallow http php include calls, if you so need to enable it, or use the path call instead Code:
ob_start(); Quote:
|
I'm using version 4.1.0. I tried changing my creds.php file to just simply echo "Test", and I still just get a plain white page on the forums. If I open the php file in my browser it correctly says Test. Should I change the hook location? Is there a better location for postbit_legacy? And I have copy pasted that code exactly in, and replaced the URL. What could be going wrong here? Thanks
Edit: I have noticed something else that is interesting. If I remove the {vb:raw creds} from the postbit_legacy template, there is still a blank page. If the plugin is on, theres a blank page, even if its not being called from the template. Hope this helps. |
The plugin is fairly straight forward, as long as you have a valid script that you are calling and your plugin code is valid, you should be good to go.
you might have a php.ini config issue going on. Create a new file in your forum root, call it test.php Insert this <?php include ("/server/path/to/your/test.php"); ?> <?php include ("http://www.yoursite.com/forum/test.php"); ?> /insert this Then open the test.php in your browser If they BOTH work, you should have your echoed text inserted twice. If only ONE works, or you get a php error, you have a php.ini config issue to work out. |
All times are GMT. The time now is 02:31 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 | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|