Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 4 Articles
FAQ Community Calendar Today's Posts Search

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
  #42  
Old 02-02-2011, 03:22 AM
MMODisneyForums MMODisneyForums is offline
 
Join Date: Jan 2011
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #43  
Old 02-02-2011, 07:06 PM
risestar risestar is offline
 
Join Date: Oct 2001
Posts: 31
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #44  
Old 02-02-2011, 07:57 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 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
Reply With Quote
  #45  
Old 02-04-2011, 04:25 AM
MMODisneyForums MMODisneyForums is offline
 
Join Date: Jan 2011
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you guys so much for all the help, everything is working like a charm now!
Reply With Quote
  #46  
Old 02-08-2011, 07:46 PM
Schoelle Schoelle is offline
 
Join Date: Feb 2011
Location: Germany
Posts: 72
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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));
It works als long as i only activate 1 of those 4 plugins.
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
Reply With Quote
  #47  
Old 02-14-2011, 08:37 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Where are you wanting the info to show up at? Every page?
Reply With Quote
  #48  
Old 02-14-2011, 01:24 PM
Schoelle Schoelle is offline
 
Join Date: Feb 2011
Location: Germany
Posts: 72
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
require_once('./script.php'); 
This end up in showing the created list above the forum header!


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.
Reply With Quote
  #49  
Old 02-14-2011, 03:34 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #50  
Old 02-15-2011, 02:43 PM
Schoelle Schoelle is offline
 
Join Date: Feb 2011
Location: Germany
Posts: 72
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
<?php
require_once('script.php');
myfunction();
?>
Now let's include this not in the simple script but in a vbulletin page!

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
Reply With Quote
  #51  
Old 03-01-2011, 03:59 PM
cric2k cric2k is offline
 
Join Date: Jan 2010
Posts: 40
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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));
My problem is that $PageTitle = $GLOBALS.foruminfo.title_clean; doesn't populate in this place, I need to populate it in the template 'headinclude' any ideas?

--------------- 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.
Reply With Quote
Reply


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 10:25 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.04527 seconds
  • Memory Usage 2,338KB
  • 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
  • (6)bbcode_code
  • (2)bbcode_php
  • (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