\*=====================================================================*/
/**
-* Database-Driven Template System (template.php)
-*
-* @package ISSO
-*/
+ * Database-Driven Template System (template.php)
+ *
+ * @package ISSO
+ */
require_once(ISSO . '/Functions.php');
/**
-* File-Based Template System
-*
-* This framework merely replaces the template loading functions with
-* file-system based ones. It has an optional caching system in which
-* template data will remain stored in the database as long as the filesystem
-* file is modified. To do this, pass a table name to setDatabaseCache() and make sure
-* there's a DB module that has access to a table with this schema:
-*
-* CREATE TABLE template (filename VARCHAR (250) NOT NULL, template TEXT NOT NULL, timestamp INT NOT NULL);
-*
-* @author Blue Static
-* @copyright Copyright (c)2005 - 2008, Blue Static
-* @package ISSO
-*
-*/
+ * File-Based Template System
+ *
+ * This framework merely replaces the template loading functions with
+ * file-system based ones. It has an optional caching system in which
+ * template data will remain stored in the database as long as the filesystem
+ * file is modified. To do this, pass a table name to setDatabaseCache() and make sure
+ * there's a DB module that has access to a table with this schema:
+ *
+ * CREATE TABLE template (filename VARCHAR (250) NOT NULL, template TEXT NOT NULL, timestamp INT NOT NULL);
+ *
+ * @author Blue Static
+ * @copyright Copyright (c)2005 - 2008, Blue Static
+ * @package ISSO
+ *
+ */
class BSTemplate
{
/**
- * The path, from the path of the application, where templates are stored
- * @var string
- */
+ * The path, from the path of the application, where templates are stored
+ * @var string
+ */
private $templateDir = '';
/**
- * The extension all the template files have
- * @var string
- */
+ * The extension all the template files have
+ * @var string
+ */
private $extension = 'tpl';
/**
- * The database table name for the template cache
- * @var string
- */
+ * The database table name for the template cache
+ * @var string
+ */
private $dbCacheTable = null;
/**
- * The name of the function phrases are fetched with
- * @var string
- */
+ * The name of the function phrases are fetched with
+ * @var string
+ */
private $langcall = 'gettext';
/**
- * The name of the function phrases are sprintf() parsed with
- * @var string
- */
+ * The name of the function phrases are sprintf() parsed with
+ * @var string
+ */
private $langconst = 'sprintf';
/**
- * Array of pre-compiled templates that are stored to decrease server load
- * @var array
- */
+ * Array of pre-compiled templates that are stored to decrease server load
+ * @var array
+ */
protected $cache = array();
/**
- * A list of templates that weren't cached, but are still used
- * @var array
- */
+ * A list of templates that weren't cached, but are still used
+ * @var array
+ */
protected $uncached = array();
/**
- * Whether or not the page has been flush()'d already
- * @var bool
- */
+ * Whether or not the page has been flush()'d already
+ * @var bool
+ */
private $doneflush = false;
/**
- * The name of a function that is called before template parsing of phrases and conditionals occurs
- * @var string
- */
+ * The name of a function that is called before template parsing of phrases and conditionals occurs
+ * @var string
+ */
private $preParseHook = ':undefined:';
- // ###################################################################
/**
- * Sets the template directory name
- *
- * @param string Template directory name
- */
+ * Sets the template directory name
+ *
+ * @param string Template directory name
+ */
public function setTemplateDirectory($dir)
{
$this->templateDir = BSFunctions::fetch_source_path($dir);
}
- // ###################################################################
/**
- * Sets the file extension for the templates
- *
- * @param string File extension
- */
+ * Sets the file extension for the templates
+ *
+ * @param string File extension
+ */
public function setExtension($ext)
{
$this->extension = $ext;
}
- // ###################################################################
/**
- * Sets the name of the table to access for the datbase cache
- *
- * @param string DB table name
- */
+ * Sets the name of the table to access for the datbase cache
+ *
+ * @param string DB table name
+ */
public function setDatabaseCache($table)
{
$this->dbCacheTable = $table;
}
- // ###################################################################
/**
- * Sets the pre-parse hook method which is called before any other
- * processing is done on the template.
- *
- * @param string Method name
- */
+ * 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
- */
+ * 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)
}
}
- // ###################################################################
/**
- * 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
- */
+ * 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]))
return $template;
}
- // ###################################################################
/**
- * Output a template fully compiled to the browser
- *
- * @param string Compiled and ready template
- */
+ * Output a template fully compiled to the browser
+ *
+ * @param string Compiled and ready template
+ */
public function flush($template)
{
ob_start();
print($template);
}
- // ###################################################################
/**
- * Loads an additional template from the database
- *
- * @param string The name of the template
- *
- * @return string Template data from the database
- */
+ * Loads an additional template from the database
+ *
+ * @param string The name of the template
+ *
+ * @return string Template data from the database
+ */
protected function _loadTemplate($name)
{
$path = $this->templateDir . $name . '.' . $this->extension;
}
}
- // ###################################################################
/**
- * A wrapper for all the parsing functions and compiling functins
- *
- * @param string Unparsed template data
- *
- * @return string Parsed template data
- */
+ * A wrapper for all the parsing functions and compiling functins
+ *
+ * @param string Unparsed template data
+ *
+ * @return string Parsed template data
+ */
protected function _parseTemplate($template)
{
$template = str_replace('"', '\"', $template);
return $template;
}
- // ###################################################################
/**
- * Parses anything with curly braces {} (including phrases)
- *
- * @param string Template data
- *
- * @return string Parsed template data
- */
+ * Parses anything with curly braces {} (including phrases)
+ *
+ * @param string Template data
+ *
+ * @return string Parsed template data
+ */
private function _parseBlocksAndTokens($template)
{
$stack = array();
}
}
- // ###################################################################
/**
- * Parses a curly brace token {}
- *
- * @param string Token
- *
- * @return string Parsed value
- */
+ * Parses a curly brace token {}
+ *
+ * @param string Token
+ *
+ * @return string Parsed value
+ */
private function _parseToken($token)
{
// knock of the braces
}
}
- // ###################################################################
/**
- * Prepares language and locale information inside templates
- *
- * @param string Template data to be processed
- *
- * @return string Language-ready template data
- */
+ * Prepares language and locale information inside templates
+ *
+ * @param string Template data to be processed
+ *
+ * @return string Language-ready template data
+ */
private function _parsePhrases($template)
{
$tagStart = '<lang ';
return $template;
}
- // ###################################################################
/**
- * Parser for in-line template conditionals
- *
- * @param string Template data awaiting processing
- *
- * @return string Parsed template data
- */
+ * Parser for in-line template conditionals
+ *
+ * @param string Template data awaiting processing
+ *
+ * @return string Parsed template data
+ */
private function _parseConditionals($template)
{
// tag data