vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 4 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=242)
-   -   [vBulletin 4] Simple way of including an external PHP file (https://vborg.vbsupport.ru/showthread.php?t=242454)

Crimm 05-12-2010 10:00 PM

[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
  • 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:

    Code:

    ob_start();
      require_once('LOCATION OF EXTERNAL FILE');
      $php_include = ob_get_contents();
    ob_end_clean();
    vB_Template::preRegister('TEMPLATE YOU ARE USING',array('php_include' => $php_include));


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}
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:

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));

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!

frostyx 05-27-2010 06:07 PM

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?

Crimm 05-28-2010 09:18 AM

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.

philwareham 07-06-2010 04:36 PM

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

Crimm 07-09-2010 05:00 PM

I'm not 100% sure. I haven't done that yet.

Stupid question, but have you tried swapping the two?

philwareham 07-12-2010 03:31 PM

Yep, this works thanks...
Code:

// Textpattern External Output: body-social
ob_start();
    echo file_get_contents('http://mydomain/?rah_external_output=body-social');
    $php_include = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('footer',array('txp_body_social' => $php_include));

Cool, this will make vBulletin really easy to integrate with my CMS templates. Great stuff.

ragtek 07-12-2010 05:45 PM

Quote:

Originally Posted by philwareham (Post 2068121)
Yep, this works thanks...
Code:

// Textpattern External Output: body-social
ob_start();
    echo file_get_contents('http://mydomain/?rah_external_output=body-social');
    $php_include = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('footer',array('txp_body_social' => $php_include));

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;)

Centrix 07-14-2010 01:30 PM

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:

Originally Posted by Crimm (Post 2036621)
Code:

ob_start();
  require_once('LOCATION OF EXTERNAL FILE');
  $php_include = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('TEMPLATE YOU ARE USING',array('php_include' => $php_include));

[/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.

Triky 07-15-2010 01:47 PM

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:

ob_start();
  require_once(
'../includes/kbar.php');
  
$kbar ob_get_contents();
ob_end_clean();
vB_Template::preRegister('header',array('php_include' => $php_include)); 

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

Code:

{vb:raw kbar}
Why? Can you please help me?

Triky 07-20-2010 11:48 AM

Can please somebody help me out?


All times are GMT. The time now is 09:00 AM.

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.01441 seconds
  • Memory Usage 1,748KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (7)bbcode_code_printable
  • (1)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete