Register Members List Search Today's Posts Mark Forums Read

Reply
 
Article Options
[vBulletin 4] Simple way of including an external PHP file
Crimm
Join Date: Feb 2007
Posts: 170

by Crimm Crimm is offline 13 May 2010
Rating: (3 votes - 5.00 average)

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 http://www.vbulletin.org/forum/showthread.php?t=228078

I have figured out it's only a simple extra step.

Step 1: Create a new plugin
  • Hook Location: What area of the forums you want this variable to appear. Don't know where? Use global_start
  • Title: Give it a title
  • Execution order: Your choice
  • Plugin PHP Code:


    Block Disabled:      (Update License Status)  
    Suspended or Unlicensed Members Cannot View Code.


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.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

That's it - Pretty simple; see?

Notes, If you want to:

Include this PHP file in multiple templates then preRegister it for the multiple templates:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Thanks to David IB again.

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!
Views: 53783
Reply With Quote
Comments
  #2  
Old 27 May 2010, 19:07
frostyx frostyx is offline
 
Join Date: Mar 2010
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?
Reply With Quote
  #3  
Old 28 May 2010, 10:18
Crimm's Avatar
Crimm Crimm is offline
 
Join Date: Feb 2007
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.
__________________
- Trying to get back into this vB developer thing, bear with me -
Catch me on Twitter: @crimmFTW
Reply With Quote
  #4  
Old 06 Jul 2010, 17:36
philwareham philwareham is offline
 
Join Date: Jun 2010
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
Reply With Quote
  #5  
Old 09 Jul 2010, 18:00
Crimm's Avatar
Crimm Crimm is offline
 
Join Date: Feb 2007
I'm not 100% sure. I haven't done that yet.

Stupid question, but have you tried swapping the two?
__________________
- Trying to get back into this vB developer thing, bear with me -
Catch me on Twitter: @crimmFTW
Reply With Quote
  #6  
Old 12 Jul 2010, 16:31
philwareham philwareham is offline
 
Join Date: Jun 2010
Smile

Yep, this works thanks...

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Cool, this will make vBulletin really easy to integrate with my CMS templates. Great stuff.
Reply With Quote
  #7  
Old 12 Jul 2010, 18:45
ragtek's Avatar
ragtek ragtek is offline
 
Join Date: Mar 2006
Location: austria, croatia
Originally Posted by philwareham View Post
Yep, this works thanks...

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Cool, this will make vBulletin really easy to integrate with my CMS templates. Great stuff.
You don't need the output buffer!
$php_include = file_get_contents('...'); would also work
__________________
my addons: http://ragtek.github.com
Reply With Quote
  #8  
Old 14 Jul 2010, 14:30
Centrix Centrix is offline
 
Join Date: Sep 2005
I tried this, but it made my forum crash miserably. I had to restore a database backup in order for it to work again.

Originally Posted by Crimm View Post
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

[/LIST]
Step 2: You will have to figure out these two entries for yourself: LOCATION OF EXTERNAL FILE & Hook Location
I made a custom template and I dont know which hook location to use for this...? if I use global start my site and forum (site is linked to the forums) is just the contents of the php file im trying to include.

Last edited by Centrix; 14 Jul 2010 at 14:40.
Reply With Quote
  #9  
Old 15 Jul 2010, 14:47
Triky's Avatar
Triky Triky is offline
 
Join Date: Mar 2007
Location: [Italy]
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:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

And this is what I'm using on the template header:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Why? Can you please help me?
__________________
I'm italian, I am learning english.. so, please, if you see any errors in my grammar or spelling, let me know via PM. Danke!
Reply With Quote
  #10  
Old 20 Jul 2010, 12:48
Triky's Avatar
Triky Triky is offline
 
Join Date: Mar 2007
Location: [Italy]
Can please somebody help me out?
__________________
I'm italian, I am learning english.. so, please, if you see any errors in my grammar or spelling, let me know via PM. Danke!
Reply With Quote
  #11  
Old 20 Jul 2010, 12:55
philwareham philwareham is offline
 
Join Date: Jun 2010
Looks OK to me, have you made the plugin hook 'global_start'?

Maybe try a full server path for kbar.php?
Reply With Quote
  #12  
Old 21 Jul 2010, 00:21
Triky's Avatar
Triky Triky is offline
 
Join Date: Mar 2007
Location: [Italy]
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!
__________________
I'm italian, I am learning english.. so, please, if you see any errors in my grammar or spelling, let me know via PM. Danke!
Reply With Quote
  #13  
Old 21 Jul 2010, 05:18
ragtek's Avatar
ragtek ragtek is offline
 
Join Date: Mar 2006
Location: austria, croatia
And that's the problem

There is no global_start hook anymore

Use global_bootstrap_init_start
__________________
my addons: http://ragtek.github.com
Reply With Quote
  #14  
Old 21 Jul 2010, 08:19
philwareham philwareham is offline
 
Join Date: Jun 2010
Question

Originally Posted by ragtek View Post
There is no global_start hook anymore
Huh? I'm using it fine on my v4.0.5 install for hooks in the header and footer templates. Confused.
Reply With Quote
  #15  
Old 21 Jul 2010, 08:47
ragtek's Avatar
ragtek ragtek is offline
 
Join Date: Mar 2006
Location: austria, croatia

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

__________________
my addons: http://ragtek.github.com
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Article Options

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


New To Site? Need Help?

All times are GMT. The time now is 01:49.

Layout Options | Width: Wide Color: