cache) > 0) { user_error('You cannot Template::cache() more than once per initialization', E_USER_WARNING); } else { foreach ($namearray AS $name) { $template = $this->_load($name); $template = $this->_parse($template); $this->cache["$name"] = $template; } } } // ###################### Start Template::fetch ###################### function fetch($name) { if (isset($this->cache["$name"])) { $template = $this->cache["$name"]; } else { $this->uncached[] = $name; $template = $this->_load($name); $template = $this->_parse($template); } $this->usage["$name"]++; return $template; } // ###################### Start Template::flush ###################### function flush($template) { global $DB_sql; ob_start(); if (empty($template)) { user_error('Template::flush() produced no output', E_USER_WARNING); exit; } if (DEVDEBUG AND $_GET['query']) { if (is_array($DB_sql->query_history)) { echo '
';
				foreach ($DB_sql->query_history AS $query)
				{
					echo $query . "\n\n
\n\n"; } echo '
'; } exit; } if ($this->doneflush) { user_error('You cannot Template::flush() more than once per initialization', E_USER_WARNING); exit; } if (DEVDEBUG) { foreach ($this->usage AS $name => $count) { $optlist[] = '"; } $debug .= "\r

\r\r"; $debug .= "\r\t\r\t"; $debug .= "\r\t\r\r\r\t
" . 'construct_debug_info_list()' . "$revisionTotal queries used: " . sizeof($DB_sql->query_history) . ""; $debug .= "
"; $debug .= "\r" . iff(is_array($this->uncached), sizeof($uncached) . " Uncached Template(s)\r
\r") . "\r

"; $template = str_replace('', "\r\r$debug\r\r\r", $template); } print(stripslashes($template)); } // ###################### Start Template::_load ###################### function _load($name) { global $bugsys; if (($template = @file_get_contents("{$bugsys->options['ts_includepath']}$name.tpl")) !== false) { return $template; } else { echo "could not load template file {$bugsys->options['ts_includepath']}$name.tpl"; exit; } } // ###################### Start Template::_parse ##################### function _parse($template) { $template = stripslashes($template); $template = str_replace('"', '\"', $template); $template = $this->_parse_phrases($template); $template = $this->_parse_conditionals($template); return $template; } // ################## Start Template::_parse_phrases ################# function _parse_phrases($template) { $tag_start = ' $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 = '" . construct_phrase(\'' . $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; } // ############### Start Template::_parse_conditionals ############### function _parse_conditionals($template) { // Tag locations $location_start = -1; $location_end = -1; // Tag data $tag_start = ' 1) { $location_start = $location_start + 1; $location_end = $location_start + 2; } // Strip out the opening ' 2) { user_error('Multiple else statements encountered while parsing conditionals in template', E_USER_WARNING); } // Set the data $iftrue = $data[0]; $iffalse = $data[1]; } // Nope, reassign variables else { $iftrue = $parsed; $iffalse = null; } // Put the condition and iftrue in the iff() function $parsed_expression = '" . iff(' . stripslashes($expression_condition) . ',"' . $iftrue . '","' . $iffalse . '") . "'; // Parse the iff()'d expression back into the template data $template = substr_replace($template, $parsed_expression, $location_start, $location_end + strlen($tag_end) - $location_start); } // Repeat this process until it can't find any more // expressions, then send back the parsed template data // for final output return $template; } } /*=====================================================================*\ || ################################################################### || # $HeadURL$ || # $Id$ || ################################################################### \*=====================================================================*/ ?>