vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Custom PHP in headinclude/navbar, how? (https://vborg.vbsupport.ru/showthread.php?t=136043)

effgee 01-09-2007 09:21 PM

Custom PHP in headinclude/navbar, how?
 
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:
Code:

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)
Code:

<?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)
Code:

<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
PHP Code:

 // 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
HTML Code:

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


All times are GMT. The time now is 05:59 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.01422 seconds
  • Memory Usage 1,737KB
  • 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
  • (3)bbcode_code_printable
  • (1)bbcode_html_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (2)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