vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Include php page (https://vborg.vbsupport.ru/showthread.php?t=228056)

Silver89 11-15-2009 10:05 PM

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

kh99 11-15-2009 10:22 PM

nvm

Dismounted 11-16-2009 03:53 AM

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


Silver89 11-16-2009 04:05 AM

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

cory_booth 11-16-2009 08:34 AM

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>


Red Spider 12-05-2009 02:50 PM

Quote:

Originally Posted by Silver89 (Post 1915044)
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?

Lynne 12-05-2009 04:15 PM

PHP Code:

vB_Template::preRegister('header', array('globalHeader' => $globalHeader)); 


Red Spider 12-05-2009 04:33 PM

Quote:

Originally Posted by Lynne (Post 1925775)
PHP Code:

vB_Template::preRegister('header', array('globalHeader' => $globalHeader)); 


thanks Lynne, but that doesnt work either :'(

Lynne 12-05-2009 04:49 PM

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?

rudejason 12-07-2009 01:34 PM

Quote:

Originally Posted by Red Spider (Post 1925734)
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!

Tom McConnell 01-04-2010 07:35 PM

Example above:
Code:

{vb:raw globalHeader}
This is put in the vb "footer" template:
Code:

{vb:raw myname_footer}
Plugin code above:
PHP Code:

ob_start();
  include(
"../header.php");
  
$globalHeader ob_get_contents();
ob_end_clean();
 
$preRegister['globalHeader'] = $globalHeader;
vB_Template::preRegister('header'$preRegister); 

Plugin code in my plugin named "myname_footer":
PHP Code:

ob_start();
  include(
"../header.php");
  
$myname_footer ob_get_contents();
ob_end_clean();
 
$preRegister['myname_footer'] = $myname_footer;
vB_Template::preRegister('footer'$preRegister); 

Notice last line template name change.
Change "myname_footer" to what you like.

Red Spider 01-04-2010 08:02 PM

hi tom, i'm confused by your post - i'm trying to do a header include

grimwolge 03-01-2010 07:11 PM

HTML Code:

ob_start();
  include("../header.php");
  $myname_footer = ob_get_contents();
ob_end_clean();
 
$preRegister['myname_footer'] = $myname_footer;
vB_Template::preRegister('footer', $preRegister);

What file, or where? does this get inserted into?

When I was running vBulletin 3.x it went into global.php

But now that i've upgraded to vBulletin 4, I don't know where that code goes.

Thanks

Nick

manuel.ho 03-24-2010 12:07 AM

intente con todas las variaciones seƱaladas aquƭ. Alguien ha logrado hacer esto con exito?

Jamie G 03-28-2010 12:30 AM

Hi guys.

Trying to get some php code into my forum to get it to display the frontpage slider.

I've done this.

PHP Code:

ob_start();
   include(
'ss.php');
   
$slider ob_get_contents();
ob_end_clean();

$preRegister['slider'] = $slider;
vB_Template::preRegister('forumhome'$preRegister); 

Still can't get it to display at all!

What am i doing wrong?

Lynne 03-28-2010 01:40 AM

Just noticing the obvious error, but the name of the template is not forumhome, it is FORUMHOME.

Jamie G 03-28-2010 01:58 AM

Still doesn't work.... Ok,

So let's start from scratch.

I have this.

PHP Code:

?php
// START of "Frontpage Slideshow" settings
    
$nameOfSlideshowToDisplay "myslideshow";                     // Enter the name of your slideshow. Slideshows are in folders inside /fpss/slideshows/.
    
$URLofyoursite "http://www.******.com";                         // Enter your site's URL.
    
$AbsoluteServerPathofyoursite "/***/***/public_html";        // Enter the root path of your site on the server.
    
    // do not edit below this line
    
include_once($AbsoluteServerPathofyoursite."/fpss/mod_fpslideshow.php");
// END of "Frontpage Slideshow" settings
?> 

It tells me I should put this where I wish for it to call for the frontpage slideshow. I'd like it just below the navbar. But I can't put PHP in the template. So I've taken that above code and saved it as ss.php.

So I've gone into add plugin, and done the following.

PHP Code:

ob_start();
   include(
'ss.php');
   
$slider ob_get_contents();
ob_end_clean();

$preRegister['slider'] = $slider;
vB_Template::preRegister('FORUMHOME'$preRegister); 

I've then saved the plugin and gone into FORUMHOME and entered

PHP Code:

{vb:raw slider

I still have nothing appear. Hopefully with this full view of what I've done, you may be able to assist me in getting this working as It's getting annoying now!

hydn 05-05-2010 08:33 PM

This works perfectly! Thanks!

Quote:

Originally Posted by Tom McConnell (Post 1947170)
Example above:
Code:

{vb:raw globalHeader}
This is put in the vb "footer" template:
Code:

{vb:raw myname_footer}
Plugin code above:
PHP Code:

ob_start();
  include(
"../header.php");
  
$globalHeader ob_get_contents();
ob_end_clean();
 
$preRegister['globalHeader'] = $globalHeader;
vB_Template::preRegister('header'$preRegister); 

Plugin code in my plugin named "myname_footer":
PHP Code:

ob_start();
  include(
"../header.php");
  
$myname_footer ob_get_contents();
ob_end_clean();
 
$preRegister['myname_footer'] = $myname_footer;
vB_Template::preRegister('footer'$preRegister); 

Notice last line template name change.
Change "myname_footer" to what you like.



All times are GMT. The time now is 04:59 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01161 seconds
  • Memory Usage 1,810KB
  • 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
  • (6)bbcode_code_printable
  • (1)bbcode_html_printable
  • (15)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (18)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete