Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 11-15-2009, 10:05 PM
Silver89 Silver89 is offline
 
Join Date: Nov 2009
Posts: 19
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Include php page

I'm trying to include a php file with the following code as documented on the vBulletin pages, my plugin is setup as:

PHP Code:
ob_start();
  include(
'/header.php');
  
$globalHeader ob_get_contents();
ob_end_clean(); 
I then write - $globalHeader - in the header file where I want this include to appear? I have it setup with the host location of global_start but at the moment it just shows $globalHeader on screen and I'm not sure what's wrong?

Many Thanks
Reply With Quote
  #2  
Old 11-15-2009, 10:22 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

nvm
Reply With Quote
  #3  
Old 11-16-2009, 03:53 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The way variables are used in templates has changed in vBulletin 4. You must register any variables before using them and address them like so: {vb:raw globalHeader}
PHP Code:
$preRegister['globalHeader'] = $globalHeader;
vB_Template::preRegister('header'$preRegister); 
Reply With Quote
  #4  
Old 11-16-2009, 04:05 AM
Silver89 Silver89 is offline
 
Join Date: Nov 2009
Posts: 19
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Okay I have managed to get the php include for 4.0 working with the following code:

Template:
Code:
{vb:raw globalHeader}

Plugin:
PHP Code:
ob_start();
  include(
"../header.php");
  
$globalHeader ob_get_contents();
ob_end_clean();

$preRegister['globalHeader'] = $globalHeader;
vB_Template::preRegister('header'$preRegister); 

However what I really want to do is basically create my own custom template page, the problem with this current include is that the vb code inside ../header.php is just printed instead of being executed, what can I do to fix this?

Many Thanks
Reply With Quote
  #5  
Old 11-16-2009, 08:34 AM
cory_booth cory_booth is offline
 
Join Date: Jul 2006
Posts: 224
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Along the same lines....

What would be the easiest way to include php pages in the CMS?
For example, I run HamWeather on my site. PReviosuly - using vbAdvanced - I made some templates that called in php files to display the weather. Can I do the same via CMS?

Something like this for example:

PHP Code:
<?php 

$doPrintNWS 
false;

require(
"/home1/mysite/public_html/modules/advforecast.php"); ?> 

<html>

<body style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; background-color:#F5F5FF">

<table style="font-size:9px;"> 

<tr align="center" valign="top">

<?php print "<td>$forecasticons[0]</td><td>$forecasticons[1]</td><td>$forecasticons[2]</td><td>$forecasticons[3]</td><td>$forecasticons[4]</td><td>$forecasticons[5]</td><td>$forecasticons[6]</td><td>$forecasticons[7]</td>\n"?> 

</tr> 

<tr align="center" valign="top">

<?php print "<td>$forecasttemp[0]</td><td>$forecasttemp[1]</td><td>$forecasttemp[2]</td><td>$forecasttemp[3]</td><td>$forecasttemp[4]</td><td>$forecasttemp[5]</td><td>$forecasttemp[6]</td><td>$forecasttemp[7]</td>\n"?> 

</tr>

</table> 

</body>

</html>
Reply With Quote
  #6  
Old 12-05-2009, 02:50 PM
Red Spider's Avatar
Red Spider Red Spider is offline
 
Join Date: Jan 2006
Posts: 141
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Silver89 View Post
Okay I have managed to get the php include for 4.0 working with the following code:

Template:
Code:
{vb:raw globalHeader}

Plugin:
PHP Code:
ob_start();
  include(
"../header.php");
  
$globalHeader ob_get_contents();
ob_end_clean();

$preRegister['globalHeader'] = $globalHeader;
vB_Template::preRegister('header'$preRegister); 
copied word for word and just changed the variable name - but wont work - any ideas?
Reply With Quote
  #7  
Old 12-05-2009, 04:15 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
vB_Template::preRegister('header', array('globalHeader' => $globalHeader)); 
Reply With Quote
  #8  
Old 12-05-2009, 04:33 PM
Red Spider's Avatar
Red Spider Red Spider is offline
 
Join Date: Jan 2006
Posts: 141
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
PHP Code:
vB_Template::preRegister('header', array('globalHeader' => $globalHeader)); 
thanks Lynne, but that doesnt work either :'(
Reply With Quote
  #9  
Old 12-05-2009, 04:49 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It doesn't help when you just say something doesn't work. The best thing to do is say "This is my exact code in the ____ hook location {post code} and this is exactly what I have in my template {post about five lines above and below added code also}."

My guess would be you don't have the correct hook location. Did you look in the code to see where the header is rendered? And then looked above the code to pick a hook above there? Or did you just randomly pick a hook location?
Reply With Quote
  #10  
Old 12-07-2009, 01:34 PM
rudejason rudejason is offline
 
Join Date: Dec 2009
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Red Spider View Post
copied word for word and just changed the variable name - but wont work - any ideas?
THANK YOU SO MUCH!!!! i have looked for about 3 hrs total on how to make this work!
All i could find on this board was a link to the manual. That guy that always posts the link and says stuff about people must not like the manual needs to up date it with the code on how to use the variables in the template. I bet then he would no longer need to post the link.

Thanks again!
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 05: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.23290 seconds
  • Memory Usage 2,277KB
  • Queries Executed 11 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (7)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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
  • 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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete