vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   How do I run a PHP script in my templates? (VB 3.03) (https://vborg.vbsupport.ru/showthread.php?t=136918)

larryd 01-19-2007 06:41 AM

How do I run a PHP script in my templates? (VB 3.03)
 
I have written my own code to randomly display a banner that is PHP/mySQL based. What I am trying to figure out is how to get the code which works great when I call it myself to work with Vbulletin.

The code is

PHP Code:


<?

include("include/dbconnect.php");

$result = mysql_query("SELECT * FROM $table where active = 'Y' ORDER BY RAND() LIMIT 0,1",$db);

$row = mysql_fetch_array($result);
$did = $row["did"];
$image_url = $row["image_url"];
$url = $row["url"];
$alt_text = $row["alt_text"];
$target = $row["target"];
$width = $row["width"];
$height = $row["height"];
$active = $row["active"];
$richtext = $row["richtext"];
$code = $row["code"];

if ($richtext == 'Y') { $banner = "$code"; } ELSE { $banner = "<a href='$url' target='$target'><img src='$image_url' border='0' alt='$alt_text' width='$width' height='$height'></a>"; }

echo "$banner";

?>

I tried calling this in my forum header template by saying

<script src="http://www.newcelica.org/banners/display.php"></script>

But it does not display anything. Any help is truly appreciated as I'm stumped on this one.

Dismounted 01-19-2007 07:09 AM

<script> tags are used for client-side scripting. PHP is server-side. Have you tried editing the core files directly?

larryd 01-19-2007 07:42 AM

you mean edit index.php rather then the templates. I suppose thats an option but figuring out how to get the placement exactly where you want it with out using the templates is a pita.

Dismounted 01-19-2007 08:37 AM

Just copy the script into the correct php file and ommit the "echo". And then just put $banner where you want it in the templates.

larryd 01-31-2007 04:52 PM

I tried that and it did not work; It doesn't display anything.

I added the following to the index.php file
require_once('/pathto/display_ar.php');

And in the display_ar.php file I simply set the variable $banner and I tried calling it in my header template and it did nothing.

Digitalus 01-31-2007 05:06 PM

Why dont you make a plugin?

Hook Location global_start

ob_start();
include('/pathto/display_ar.php'');
$banner = ob_get_contents();
ob_end_clean();

and put $banner in your template

larryd 01-31-2007 05:23 PM

tried that too.. I put it in the PHP Include Start Template. And it did nothing either.

Dismounted 02-02-2007 05:28 AM

Errr, vBulletin 3.0.3 has not got a plugin system.

alexhirurg 02-02-2007 12:01 PM

also don't forget to set your variable global in plugin - if you will make plugin!

global $banner;
$banner = .....

otherwise you will not see your variable in some templates.

Dismounted 02-03-2007 01:23 AM

Quote:

Originally Posted by alexhirurg (Post 1172902)
also don't forget to set your variable global in plugin - if you will make plugin!

global $banner;
$banner = .....

otherwise you will not see your variable in some templates.

Do you not understand vBulletin 3.0.3 doesn't have a plugin system?


All times are GMT. The time now is 01:09 AM.

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.00942 seconds
  • Memory Usage 1,734KB
  • 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
  • (1)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete