cache) > 0) { trigger_error('You cannot cache templates more than once per initialization', ERR_WARNING); } else { $templates = $_isso->db->query("SELECT * FROM " . $this->tablename . " WHERE " . $this->namecolumn . " IN ('" . implode("', '", $namearray) . "')" . (($this->extrawhere) ? $this->extrawhere : '')); while ($template = $_isso->db->fetch_array($templates)) { $template = $this->_parse($template); $this->cache[ $template[ $this->namecolumn ] ] = $template[ $this->datacolumn ]; $this->usage["$name"] = 0; } } } /** * Loads a template from the cache or the _load function and * stores the parsed version of it * * @param str The name of the template * * @return str A parsed and loaded template */ function fetch($name) { global $_isso; if (isset($this->cache["$name"])) { $template = $this->cache["$name"]; } else { $this->uncached[] = $name; $_isso->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 * * @param str Compiled and ready template */ function flush($template) { global $_isso; ob_start(); if (empty($template)) { trigger_error('There was no output to print', ERR_FATAL); exit; } if ($_isso->debug AND isset($_GET['query'])) { if (is_array($_isso->db->history)) { echo '
';
				foreach ($_isso->db->history AS $query)
				{
					echo $query . "\n\n
\n\n"; } echo '
'; } exit; } if ($this->doneflush) { trigger_error('A template has already been sent to the output buffer', ERR_FATAL); exit; } if ($_isso->debug) { // --- START $debug = "\n"; $debug = "\n
\n" . $_isso->_message('Debug Information', $debug, 1, true); $template = str_replace('', "\n\n\n
\n$debug\n
\n\n\n", $template); } print(stripslashes($template)); } /** * Loads an additional template from the database * * @param str The name of the template * * @return str Template data from the database */ function _load($name) { global $_isso; if ($template = $_isso->db->query("SELECT * FROM " . $this->tablename . " WHERE " . $this->namecolumn . " = '$name'" . (($this->extrawhere) ? $this->extrawhere : ''))) { return $template[ $this->datacolumn ]; } else { trigger_error("The template '$name' could not be loaded", ERR_FATAL); exit; } } /** * A wrapper for all the parsing functions and compiling functins * * @param str Unparsed template data * * @return str Parsed template data */ function _parse($template) { $template = stripslashes($template); $template = str_replace('"', '\"', $template); $template = $this->_parse_phrases($template); $template = $this->_parse_conditionals($template); return $template; } /** * Prepares language and locale information inside templates * * @param str Template data to be processed * * @return str Language-ready template data */ function _parse_phrases($template) { $tag_start = 'langcall . '(\'$1\') . "', $template); while (1) { // Find the start language object tag $location_start = strpos($template, $tag_start, $location_end + 1); if ($location_start === false) { break; } // Find the end tag $location_end = strpos($template, $tag_end, $location_end + strlen($tag_end)); if ($location_end === false) { break; } // Extract the language object $phrase_bunch = substr($template, $location_start, ($location_end + strlen($tag_end)) - $location_start); // Find the close to the opening $close_of_open = strpos($phrase_bunch, $tag_start_end); if ($close_of_open === false) { break; } // Extract the opening tag so it can be parsed $init_tag = substr($phrase_bunch, 0, ($close_of_open + strlen($tag_start_end))); $init_tag = str_replace($tag_start, '', $init_tag); $init_tag = substr($init_tag, 0, strlen($init_tag) - 1); // Get the args out of the tag $args = preg_split('#([0-9].*?)=#', $init_tag); foreach ($args AS $arg) { if ($arg AND $arg != ' ') { $arg = trim($arg); $arg = substr($arg, 2); $arg = substr($arg, 0, strlen($arg) - 2); $arglist[] = $arg; } } // Just get the phrase name $phrase_name = preg_replace('#(.*?)#i', '$2', $phrase_bunch); // Wrap the parsed data into the build function $function_wrap = '" . ' . $this->langconst . '(\'' . $phrase_name . '\', "' . implode('", "', $arglist) . '") . "'; // Replace the fully-parsed string back into the template $template = substr_replace($template, $function_wrap, $location_start, $location_end + strlen($tag_end) - $location_start); unset($arglist); } return $template; } /** * Parser for in-line template conditionals * * @param str Template data awaiting processing * * @return str Parsed template data */ function _parse_conditionals($template) { global $_isso; // tag data $tag_start = ' $fullspread, 'parsed' => '' ); if (substr_count($conditional, $tag_else) == 0) { $parsed["$depth"]["$last"]['parsed'] = '" . ((' . stripslashes($expression) . ') ? "' . $conditional . '" : "") . "'; } else { $parsed["$depth"]["$last"]['parsed'] = '" . ((' . stripslashes($expression) . ') ? "' . $conditional . '") . "'; } } } // sort so the top-most ones are done first ksort($parsed); foreach ($parsed AS $depth => $conditionals) { // sort so we do them in order ksort($conditionals); foreach ($conditionals AS $parsed) { // replace the old with the new $template = str_replace($parsed['raw'], $parsed['parsed'], $template); } } // hackish way to get end tags working $template = str_replace($tag_else, '" : "', $template); return $template; } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>