I've been trying to make a page that uses the vB templates based on something that I think Zachery posted (can't remember who) but it doesn't ouput anything to the browser at all. Can someone take a look at it and suggest why it might not be working. I have checked that all the database tables are there and properly populated.
PHP Code:
<?php
// ## Config
$errorPages['pagenf'] = 2; // page id of your page not found error
$_GET['styleid'] = 13;
// ## Changes Directory so it can accesss vBulletin IF we are outside the forums folder, if not this is not nessary ##
chdir("./forum");
// ## Error Reporting ( we use error reporting in php so we can control the display of error messages
// ## we will use this because all vBulletin files follow the same error reporting rules) ##
//error_reporting(E_ALL & ~E_NOTICE);
// ## this here defines the "this_script" function, which if you use template conditionals, it will come in handy :) ##
define('THIS_SCRIPT', 'website');
// ## this action here cache's the templates so that everytime their needed a querry wont be needed to run
// ## the names in there are just the template names :), there must be a comma after everyone but the last ##
$globaltemplates = array(
'site_main',
'site_header',
'site_footer',
'site_nav_cat',
'site_nav_item'
);
// ## Grabs global.php this grabs vbulletins global.php so we can use the most basic of vBulletins functions ##
require_once("./global.php");
if (!$DB_site) echo 'no db object'; // Nope won't print that
// ## Sort $PATH_INFO into usable vars
if (isset($PATH_INFO)) {
$vars = explode('/', $PATH_INFO);
$numVars = count($vars);
if ($numVars % 2 == 0) {
$vars[] = '';
$numVars++;
}
for ($i = 1; $i < $numVars; $i +=2) {
$qsVars[$vars[$i]] = $vars[$i+1];
}
}
// ## Decide which page to display
if (is_numeric($qsVars['page'])) {
$pageid = $qsVars['page'];
}
else {
$pageid = 1;
}
$pageInfo = $DB_site->query_first('SELECT * FROM site_pages WHERE pageid="' . $pageid . '"');
if (!$pageInfo['viewable']) {
// If the query gave no result or the page is not viewable send out the page not found error
$pageid = $errorPages['pagenf'];
}
$content = $pageInfo['content'];
$pagetitle = $pageInfo['pagename'];
// ## Generate navigation
$result = $DB_site->query('SELECT * FROM site_navigation WHERE viewable = 1');
while ($item = $DB_site->fetch_array($result)) {
if ($item['iscat'] == 1) {
$category[$item['order']] = $item['name'];
}
else {
$object[$item['parent']][$item['order']] = $item['url'] . '||' . $item['name'];
}
}
foreach ($category as $key => $value) {
$objectCount[$key] = count($object[$key]);
}
$catCount = count($category);
ob_start();
for ($i=1; $i <= $catCount; $i++) {
$catname = $category[$i];
eval('print_output("' . fetch_template('site_nav_cat') . '");');
for ($j=1; $j <= $objectCount[$i]; $j++) {
$obj = explode('||', $object[$i][$j]);
$navurl = $obj[0];
$navname = $obj[1];
eval('print_output("' . fetch_template('site_nav_item') . '");');
}
}
$navigation = ob_get_contents();
ob_end_flush();
// ## ok this next set of lines "eval"'s our templates so they can be called inside the template we will print out ##
eval('$header = "' . fetch_template('site_header') . '";');
eval('$footer = "' . fetch_template('site_small') . '";');
// ## this calls to print out one main template ##
eval('print_output("' . fetch_template('site_main') . '");');
echo 'damn'; // it won't even echo this
?>
I'm thinking it might be me using output buffering but in the php manual it says you can use it inside another one...
Thanks,
Martin