PDA

View Full Version : How To: vBulletin Action Template Caching


Greg
06-23-2005, 03:40 PM
Here's a quick and dirty template to use vbulletin actions to do a job in one file, wizard.php.


<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'wizard');

// #################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array();

// pre-cache templates used by specific actions
// this is where you put the name of the templates each task uses
$actiontemplates = array(
'form' => array(
'main_template',
),
'calculate' => array(
'output_template',
),
);

if( empty($_POST['do']) )
{
$_POST['do'] = 'form';
}

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');

// display the form
if ($_POST['do'] == 'form')
{
// code here to display form
}
// calculate the results
if ($_POST['do'] == 'calculate')
{
// code here to caulate and show result
}
?>


http://www.some-site-somewhere.com/wizard.php will display the main form

having the following code in the form that is displayed by the above and clicking submit will bring up the result of calculate...


<form action="wizard.php" method="post">
What two numbers do you want to add?<br />
<input type="text" name="num1" size="10" maxlength="10" value="" /><br />
<input type="text" name="num2" size="10" maxlength="10" value="" /><br />
<input type="hidden" name="do" value="calculate" /><br />
<input type="submit" value="Calculate" /><br />
</form>


That's quick and dirty, this is a vBulletin 3.0.7 example. You should run the POST vars through globalize too.

rex_b
06-23-2005, 03:46 PM
Well this is my process code that I use to house in process.php.

Where would it go?

$item = $_POST['item'];
echo "You chose:<br> " . $item . " as your style <br>" . $item2 . " as your ship size<br>" . $item3 . " you would like to dress up<br>" . $item4 . " about wanting kids around<br><br><br>";

if ( $item == Elegant && $item2 == Small && $item3 == Yes && $item4 == No ) {
echo "We recommend that you try out Seadream Yacht Club, Radisson Seven Seas,
Seabourn, and SilverSea<br><br><br>These cruises are:<br>Elegant, refined, and understated, with white glove service<br>Small intimate ships to harder to reach ports (350 passengers)<br>Formal, sophisticated, atmosphere<br>Not kid oriented.";
}
if ( $item == Middle && $item2 == Middle && $item3 == Middle && $item4 == Middle ) {
echo "We recommend that you try out Holland Cruises, Celebrity Cruises, and Princess Cruises<br><br><br>These cruises are:<br>An upscale, but active atmosphere<br>Mid sized ships with good facilites and amenities (up to 3500 passengers)<br>A mix of dress up opportunities and resort casual dress<br>Kids OK, With ship sponsered activities.";
}
if ( $item == Fun && $item2 == Large && $item3 == No && $item4 == Yes ) {
echo "We recommend that you try out Disney, Carnival, and Royal Caribbean<br><br><br>These cruises are:<br>Non-stop action, Las Vegas-style Glitz, and late night parties<br>Mega-liners with maximum facilities, and amenities (Up to 4,000 passengers)
<br>Can be completely casual, or up to formal, depending on night, and dining choice<br>Extremely family friendly, kids are a focus";
}
else {
echo "Currently there are no cruises that match your request. Please try again.";
}

rex_b
06-23-2005, 04:19 PM
This is my whole php file. and I'm just lost with the instructs above.

<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'test'); // change this depending on your filename

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array(

);

// get special data templates from the datastore
$specialtemplates = array(

);

// pre-cache templates used by all actions
$globaltemplates = array(
'CRUISEWIZARD',
);

// pre-cache templates used by specific actions
$actiontemplates = array(

);

// ######################### REQUIRE BACK-END ############################
chdir('/home2/speedpro/public_html/forum');
require('./global.php');

// ################################################## #####################
// ######################## START MAIN SCRIPT ############################
// ################################################## #####################

$navbits = array();
$navbits[$parent] = 'Cruise Wizard

';

$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('CRUISEWIZARD') . '");');

$item = $_POST['item'];
echo "You chose:<br> " . $item . " as your style <br>" . $item2 . " as your ship size<br>" . $item3 . " you would like to dress up<br>" . $item4 . " about wanting kids around<br><br><br>";

if ( $item == Elegant && $item2 == Small && $item3 == Yes && $item4 == No ) {
echo "We recommend that you try out Seadream Yacht Club, Radisson Seven Seas,
Seabourn, and SilverSea<br><br><br>These cruises are:<br>Elegant, refined, and understated, with white glove service<br>Small intimate ships to harder to reach ports (350 passengers)<br>Formal, sophisticated, atmosphere<br>Not kid oriented.";
}
if ( $item == Middle && $item2 == Middle && $item3 == Middle && $item4 == Middle ) {
echo "We recommend that you try out Holland Cruises, Celebrity Cruises, and Princess Cruises<br><br><br>These cruises are:<br>An upscale, but active atmosphere<br>Mid sized ships with good facilites and amenities (up to 3500 passengers)<br>A mix of dress up opportunities and resort casual dress<br>Kids OK, With ship sponsered activities.";
}
if ( $item == Fun && $item2 == Large && $item3 == No && $item4 == Yes ) {
echo "We recommend that you try out Disney, Carnival, and Royal Caribbean<br><br><br>These cruises are:<br>Non-stop action, Las Vegas-style Glitz, and late night parties<br>Mega-liners with maximum facilities, and amenities (Up to 4,000 passengers)
<br>Can be completely casual, or up to formal, depending on night, and dining choice<br>Extremely family friendly, kids are a focus";
}
else {
echo "Currently there are no cruises that match your request. Please try again.";
}

?>

Greg
06-23-2005, 05:55 PM
You can't echo from the vBulletin included back end. The php code is ok, but the html has to go in the templates. You have to recode everything after your global.php include.

Look at the vBulletin files, they are excellent examples.