View Single Post
  #1  
Old 12-31-2009, 03:24 PM
saajjj saajjj is offline
 
Join Date: Nov 2009
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Including output of PHP file in custom template? [closed]

Hi Guys,
I've read plenty of threads on how to insert PHP code in a custom vBulletin page. However, I'm trying to insert the output of a PHP file inside a custom template. This custom template is itself inside the header template.

What I've got right now is a custom template which creates a place-holder inside the header.
The header template just has the following added:
Code:
{vb:raw showCustomTemplate}
This place-holder needs to be populated with the output of a PHP file. Within my custom template I have some styling information and the statement:
Code:
{vb:raw myPHPFileOutput}
The question, I suppose is, how do I connect myPHPFileOutput to read whatever myPHPFile.php outputs? AFAIK, a template can't execute php code, otherwise I could've simply done an 'include' there.

Any help appreciated.

Edit: Let's assume the php file is:
<?php
echo("hello world");
?>

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

I've added a new plugin which helps me somewhat but not entirely:

Code:
ob_start();
include 'myPHPFile.php';
$include_contents = ob_get_contents();
ob_end_flush();

vB_Template::preRegister('myCustomTemplate',array('php_file_output' => $include_contents));
The above does work but I see 'hello world' in two places.
1. Inside the header place-holder, which is correct
2. Right at the top of the page, which is wrong.

I have a feeling this isn't the correct approach.

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

I've changed the new plugin code from ob_end_flush() to ob_end_clean().

This has got rid of the output appearing right at the top of the page (#2) however, I've got these strange characters before the output of my php file. The place-holder in the header now reads:
hello world

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

Right so those strange characters represent the Byte Order Mark (BOM). I got rid of those by converting my php file to save without the BOM. I really don't see why this should solve the problem since I'm only including what's being output by the PHP file; nevertheless, it does work.

It seems all my problems are solved. Consider this thread closed
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01173 seconds
  • Memory Usage 1,769KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (3)bbcode_code
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.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_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete