Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 4 Articles

Reply
 
Thread Tools
[vBulletin 4] Simple way of including an external PHP file
Crimm's Avatar
Crimm
Join Date: Feb 2007
Posts: 170

 

Show Printable Version Email this Page Subscription
Crimm Crimm is offline 05-12-2010, 10:00 PM

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!
Reply With Quote
  #72  
Old 12-23-2011, 09:09 AM
absofts's Avatar
absofts absofts is offline
 
Join Date: Oct 2011
Location: Pakistan
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I include a file but its showing me this error

Quote:
Fatal error: Call to a member function query_read_slave() on a non-object in /home/content/i/c/o/icompany/html/forum/verified.php on line 4
--------------- Added [DATE]1324635016[/DATE] at [TIME]1324635016[/TIME] ---------------

My file code is

PHP Code:
<?php
require_once('includes/class_paid_subscription.php');

$susers $db->query_read_slave("
    SELECT *
    FROM " 
TABLE_PREFIX "subscriptionlog
    WHERE status = 1
    AND userid = " 
$vbulletin->userinfo['userid']
);
$isPremium $db->num_rows($susers);
if (
$isPremium != 0){
    
$st '1';
}else{
    
$st '0';
}
    echo 
$st;

?>
Reply With Quote
  #73  
Old 12-23-2011, 06:13 PM
iwpg iwpg is offline
 
Join Date: May 2008
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I''m not sure where query_read_slave is loaded. Did you try loading the hook in global_start?
Reply With Quote
  #74  
Old 12-23-2011, 06:17 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You should be using $vbulletin->db... to access queries, data, and the like... try this code:

PHP Code:
<?php
global $vbulletin;

require_once(
'includes/class_paid_subscription.php');

$susers $vbulletin->db->query_read_slave("
    SELECT *
    FROM " 
TABLE_PREFIX "subscriptionlog
    WHERE status = 1
    AND userid = " 
$vbulletin->userinfo['userid']
);
$isPremium $vbulletin->db->num_rows($susers);
if (
$isPremium != 0){
    
$st '1';
}else{
    
$st '0';
}
    echo 
$st;

?>
Reply With Quote
  #75  
Old 03-18-2012, 09:30 PM
iiFragyyHD iiFragyyHD is offline
 
Join Date: Oct 2011
Posts: 4
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Can I add 2 plugins like this?

--------------- Added [DATE]1332106295[/DATE] at [TIME]1332106295[/TIME] ---------------

Nevermind, got it. All you have to do is change bot $php_include variables and the array name to the same thing.
Reply With Quote
  #76  
Old 03-21-2012, 02:05 AM
zero477 zero477 is offline
 
Join Date: Jan 2012
Posts: 59
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks it works perfectly, they should update or make more clear the vBulletin manual...

--------------- Added [DATE]1332297428[/DATE] at [TIME]1332297428[/TIME] ---------------

Hello Crimm,

Thanks very much for your post about including PHP files ... It was much more clear than in the manual.

I followed your instructions and everything works fine for the forum, but in the CMS the PHP file is not included.

I tried to fix it by adding:

PHP Code:
 ob_start();
  require_once(
'plugins/rightsidebar.php');
  
$php_include ob_get_contents();
ob_end_clean();
vB_Template::preRegister('footer',array('php_include' => $php_include)); 
To global_start of the CMS. But it still does not work... Can you help me?
Reply With Quote
  #77  
Old 06-26-2012, 03:18 PM
zero477 zero477 is offline
 
Join Date: Jan 2012
Posts: 59
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello,

If would like to use many PHP files on URL can we do something like:

PHP Code:
ob_start();
  require_once(
'LOCATION OF EXTERNAL FILE');
  
$php_include ob_get_contents();

  require_once(
'LOCATION OF EXTERNAL OF SECOND FILE');
  
$php_include_SECOND_FILE ob_get_contents();

ob_end_clean();
vB_Template::preRegister('TEMPLATE YOU ARE USING',array('php_include' => $php_include));
vB_Template::preRegister('TEMPLATE YOU ARE USING FOR SECOND FILE',array('php_include' => $$php_include_SECOND_FILE)); 

??????????
Reply With Quote
  #78  
Old 06-26-2012, 05:21 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You should be able to do this (use ob_get_clean() instead of ob_get_contents()):

Code:
ob_start();
  require_once('LOCATION OF EXTERNAL FILE');
  $php_include = ob_get_clean();

  require_once('LOCATION OF EXTERNAL OF SECOND FILE');
  $php_include_SECOND_FILE = ob_get_clean();

ob_end_clean();
vB_Template::preRegister('TEMPLATE YOU ARE USING',array('php_include' => $php_include));
vB_Template::preRegister('TEMPLATE YOU ARE USING FOR SECOND FILE',array('php_include' => $$php_include_SECOND_FILE));

I think if you want you could also put a preRegister call after each call to ob_get_clean() so you wouldn't need a bunch of different variables.
Reply With Quote
  #79  
Old 06-29-2012, 07:54 PM
RivaCom RivaCom is offline
 
Join Date: Aug 2005
Posts: 48
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've tried the following code. But whenever you click a user thread, no matter what thread you click, it always brings us to the same thread.

Code:
ob_start();
   require_once('/home/ihatejob/revenantgaming.com/forum/modules/slidermodule.php');
$php_include = ob_get_clean();

ob_end_clean();
vB_Template::preRegister('adv_portal',array('php_include' => $php_include));
any help?
Reply With Quote
  #80  
Old 06-29-2012, 08:11 PM
zero477 zero477 is offline
 
Join Date: Jan 2012
Posts: 59
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello guys,

I finally achieved it!! I did a small tutorial about making External PHP files that can be used as Widgets in vBulletin CMS.

I do not know if I can post links here ... but here is the tutorial ... I think someone might find it useful in the future.

http://www.hyperlinkbuilding.org/con...idget-Tutorial

Greetings,
Eddie

--------------- Added [DATE]1341004474[/DATE] at [TIME]1341004474[/TIME] ---------------

I have to say something else ... Thanks a lot for trying helping me!! I will help others whenever I can.
Reply With Quote
  #81  
Old 07-23-2012, 12:58 PM
hqlman's Avatar
hqlman hqlman is offline
 
Join Date: Aug 2008
Posts: 96
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am helping a friend out to try and display his wordpress header above his vb forums header, im using the code below in the plugin and calling it in the header template:

Code:
ob_start();
  require_once('http://al-hussain.co.uk/wp-
content/themes/Karma/header.php');
  $php_include = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('Test',array('php_include' => $php_include));
but get the following errors:

Code:
Warning: require_once() [function.require-once]: http:// wrapper is disabled in the server configuration by allow_url_include=0 in [path]/includes/class_bootstrap.php(106) : eval()'d code on line 3

Warning: require_once(http://al-hussain.co.uk/wp- content/themes/Karma/header.php) [function.require-once]: failed to open stream: no suitable wrapper could be found in [path]/includes/class_bootstrap.php(106) : eval()'d code on line 3

Fatal error: require_once() [function.require]: Failed opening required 'http://al-hussain.co.uk/wp- content/themes/Karma/header.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/alhussai/public_html/forum/includes/class_bootstrap.php(106) : eval()'d code on line 3
Im running Wordpress 3.4.1 and vb 4.1.12, any ideas how to solve this?
Reply With Quote
Reply

Thread Tools

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


All times are GMT. The time now is 09:35 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
  • Page Generation 0.05578 seconds
  • Memory Usage 2,343KB
  • Queries Executed 26 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (7)bbcode_code
  • (4)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (7)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete