PDA

View Full Version : Custom PHP in headinclude/navbar, how?


effgee
01-09-2007, 09:21 PM
Hi everyone!

The guys from the vbulletin.com forum sent me over here :) I'd like to include custom PHP in two of my templates ('headinclude' and 'navbar'; for a PHP style sheet switcher, to be exact) and am seriously stuck as to how to get vBulletin to parse my code. Here's what I have so far:

1. two external PHP files:
rootdir/_custom_includes/switcher.php
rootdir/_custom_includes/Styleswitcher.php


2. the code I need to include in the 'headinclude' template:
(goes inside the <head> tag, replaces 'traditional' links to style sheets)
<?php
// BEGIN STYLESWITCHER CODE
if(!isset($reqPath)){ $reqPath = "./"; }
require_once($reqPath ."_custom_includes/Styleswitcher.php");

$ss = new Styleswitcher();
$ss->addStyle("basic", "basic.css", "", "", true);
$ss->addStyle("blue", "blue.css");
$ss->addStyle("green", "green.css");

... more identical stuff here ...

// End Styleswitcher code
?>


3. the code I need to include in 'navbar':
(the controls for the style sheet switcher)
<form action="_custom_includes/switcher.php" method="post">
<!-- Automatically redirect to the referer -->
<input type="hidden" name="referer" id="referer" value="<?php print $_SERVER['PHP_SELF']; ?>" />
<input type="hidden" name="inputStyle1" id="inputStyle1" value="fonts" />
<input type="hidden" name="inputStyle2" id="inputStyle2" value="style" />

<strong>Font Style:</strong><br />
<input type="radio" name="fonts" id="fontStyle1" value="normal" <?php $ss->printSetInputChecked("fonts", "normal"); ?>/> <label for="fontStyle1">Normal text (smaller)</label>
<input type="radio" name="fonts" id="fontStyle2" value="large" <?php $ss->printSetInputChecked("fonts", "large"); ?>/> <label for="fontStyle2">Large text</label><br />

... addtl. form elements here ...

<input type="submit" name="setChanges" value="Change styles" />
</form>


I have read something about creating a custom plug-in to reference external files in the vBulletin reference but am totally clueless in trying to apply the info given therein to my particular situation - especially considering the PHP code for the form controls (see "3" above) I need to include in the 'navbar' template (*). Any ideas on how to achieve this? If at all possible, "dummy-style" answers would be much appreciated - my knowledge of PHP and similarly fear-inducing stuff is spotty at best.

Thanks much!

effgee


(* - e.g., do I put the code for these controls in a separate file?)

noppid
01-10-2007, 04:20 PM
Since this will be in the header, you likely need to make a global start hook plugin. Try putting the above code in a global start hook.

hook code global start

// BEGIN STYLESWITCHER CODE
if(!isset($reqPath)){ $reqPath = "./"; }
require_once($reqPath ."_custom_includes/Styleswitcher.php");

$ss = new Styleswitcher();
$ss->addStyle("basic", "basic.css", "", "", true);
$ss->addStyle("blue", "blue.css");
$ss->addStyle("green", "green.css");

... more identical stuff here ...

// End Styleswitcher code
$SS_script = $_SERVER['PHP_SELF'];
$SS_normal = $ss->printSetInputChecked("fonts", "normal")
$SS_large = $ss->printSetInputChecked("fonts", "large");
eval('$SS_template = "' . fetch_template('SS_template') . '";');



SS_template

<form action="_custom_includes/switcher.php" method="post">
<!-- Automatically redirect to the referer -->
<input type="hidden" name="referer" id="referer" value="$SS_script" />
<input type="hidden" name="inputStyle1" id="inputStyle1" value="fonts" />
<input type="hidden" name="inputStyle2" id="inputStyle2" value="style" />

<strong>Font Style:</strong><br />
<input type="radio" name="fonts" id="fontStyle1" value="normal"$SS_normal /> <label for="fontStyle1">Normal text (smaller)</label>
<input type="radio" name="fonts" id="fontStyle2" value="large"$SS_large /> <label for="fontStyle2">Large text</label><br />

... addtl. form elements here ...

<input type="submit" name="setChanges" value="Change styles" />
</form>


and put $SS_template in the header template. I think that should work. I have not tested it though.

don't forget to cache the template. ;)