pre_parse_hook - Name of the function to execute on * a template before the parsing occurs * * @author Iris Studios, Inc. * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc. * @version $Revision$ * @package ISSO * */ class Template { /** * Framework registry object * @var object * @access private */ var $registry = null; /** * Name of the database table templates are in * @var string * @access private */ var $tablename = ''; /** * Name of the table column template names are in * @var string * @access private */ var $namecolumn = ''; /** * Name of the table column templates are in * @var string * @access private */ var $datacolumn = ''; /** * Additional WHERE clauses for the template fetch SQL * @var string * @access private */ var $extrawhere = ''; /** * The name of the function phrases are fetched with * @var string * @access private */ var $langcall = '$GLOBALS[\'isso:null-framework\']->modules[\'localize\']->string'; /** * The name of the function phrases are sprintf() parsed with * @var string * @access private */ var $langconst = 'sprintf'; /** * Array of pre-compiled templates that are stored to decrease server load * @var array * @access private */ var $cache = array(); /** * A list of the number of times each template has been used * @var array * @access private */ var $usage = array(); /** * A list of templates that weren't cached, but are still used * @var array * @access private */ var $uncached = array(); /** * Whether or not the page has been flush()'d already * @var bool * @access private */ var $doneflush = false; /** * The name of a function that is called before template parsing of phrases and conditionals occurs * @var string * @access private */ var $pre_parse_hook = ':=NO METHOD=:'; /** * Fields array that is used in this module * @var array * @access private */ var $fields = array( 'tablename' => array(REQ_YES, null, false), 'namecolumn' => array(REQ_YES, null, false), 'datacolumn' => array(REQ_YES, null, false), 'extrawhere' => array(REQ_NO, null, false), 'langcall' => array(REQ_YES, null, true), 'langconst' => array(REQ_YES, null, true), 'pre_parse_hook' => array(REQ_NO, null, false) ); // ################################################################### /** * Constructor */ function __construct(&$registry) { $this->registry =& $registry; } // ################################################################### /** * (PHP 4) Constructor */ function Template(&$registry) { $this->__construct($registry); } // ################################################################### /** * Sets an ISSO field * * @access public * * @param string Field name * @param mixed Value of the field */ function set($name, $value) { $this->registry->do_set($name, $value, 'template'); } // ################################################################### /** * Takes an array of template names, loads them, and then stores a * parsed version for optimum speed. * * @access public * * @param array List of template names to be cached */ function cache($namearray) { $this->registry->check_isso_fields(); if (sizeof($this->cache) > 0) { trigger_error('You cannot cache templates more than once per initialization', E_USER_WARNING); } else { $templates = $this->registry->modules[ISSO_DB_LAYER]->query("SELECT * FROM " . $this->tablename . " WHERE " . $this->namecolumn . " IN ('" . implode("', '", $namearray) . "')" . ($this->extrawhere ? $this->extrawhere : '')); while ($template = $this->registry->modules[ISSO_DB_LAYER]->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 * * @access public * * @param string The name of the template * * @return string A parsed and loaded template */ function fetch($name) { if (isset($this->cache["$name"])) { $template = $this->cache["$name"]; } else { $this->uncached[] = $name; $this->registry->debug("Manually loading template `$name`"); $template = $this->_load($name); $template = $this->_parse($template); } if (!isset($this->usage["$name"])) { $this->usage["$name"] = 0; } $this->usage["$name"]++; return $template; } // ################################################################### /** * Output a template fully compiled to the browser * * @access public * * @param string Compiled and ready template */ function flush($template) { ob_start(); if (empty($template)) { trigger_error('There was no output to print', E_USER_ERROR); exit; } if ($this->registry->debug AND isset($_GET['query'])) { if (is_array($this->registry->modules[ISSO_DB_LAYER]->history)) { echo '
'; foreach ($this->registry->modules[ISSO_DB_LAYER]->history AS $query) { echo $query . "\n\n'; } exit; } if ($this->doneflush) { trigger_error('A template has already been sent to the output buffer', E_USER_ERROR); exit; } $template = str_replace('
\n\n"; } echo '