db = $db;
}
// ###################################################################
/**
* Sets the table name and column information
*
* @param string The database table name
* @param string Name of the column that stores the name of the template
* @param string Name of the column that stores template data
*/
public function setDatabaseTable($tableName, $nameColumn, $dataColumn)
{
$this->tableName = $tableName;
$this->nameColumn = $nameColumn;
$this->dataColumn = $dataColumn;
}
// ###################################################################
/**
* Sets the pre-parse hook method which is called before any other
* processing is done on the template.
*
* @param string Method name
*/
public function setPreParseHook($hook)
{
$this->preParseHook = $hook;
}
// ###################################################################
/**
* Takes an array of template names, loads them, and then stores a
* parsed version for optimum speed.
*
* @param array List of template names to be cached
*/
public function cache($namearray)
{
if (sizeof($this->cache) > 0)
{
trigger_error('You cannot cache templates more than once per initialization');
}
else
{
$templates = $this->db->query("SELECT * FROM " . $this->tableName . " WHERE " . $this->nameColumn . " IN ('" . implode("', '", $namearray) . "')" . ($this->extrawhere ? ' ' . $this->extrawhere : ''));
while ($template = $this->db->fetch_array($templates))
{
$this->cache[ $template[ $this->nameColumn ] ] = $this->_parse($template[ $this->dataColumn ]);
$this->usage[ $template[ $this->nameColumn ] ] = 0;
}
}
}
// ###################################################################
/**
* Loads a template from the cache or the _load function and stores the
* parsed version of it
*
* @param string The name of the template
*
* @return string A parsed and loaded template
*/
public function fetch($name)
{
if (isset($this->cache["$name"]))
{
$template = $this->cache["$name"];
}
else
{
$this->uncached[] = $name;
BSRegister::Debug("Manually loading template '$name'");
$template = $this->_loadTemplate($name);
$template = $this->_parseTemplate($template);
}
if (!isset($this->usage["$name"]))
{
$this->usage["$name"] = 0;
}
$this->usage["$name"]++;
return $template;
}
// ###################################################################
/**
* Output a template fully compiled to the browser
*
* @param string Compiled and ready template
*/
public function flush($template)
{
ob_start();
if (empty($template))
{
trigger_error('There was no output to print');
exit;
}
if ($this->doneflush)
{
trigger_error('A template has already been sent to the output buffer');
exit;
}
$debugBlock = '';
if (BSRegister::GetDebug())
{
if (defined('SVN') AND preg_match('#^\$Id:?#', constant('SVN')))
{
$debugBlock .= preg_replace('#\$' . 'Id: (.+?) ([0-9].+?) [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(.+?) (.+?) \$#', "\n
\n" . '
Query Debug |
";
$debugBlock .= "\n\t\t\t$query[query]\n\n\t\t\t ($query[time]) \n\n\t\t | \n\t