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) . "')" . iff($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'" . iff($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 locations $location_start = -1; $location_end = -1; // Tag data $tag_start = '#', '" . iff(\\1,"', $template); $data = str_replace('', '","', $data); $data = str_replace('', '") . "', $data); return $data; /*$stack = array(); for ($i = 0; $i < strlen($template); $i++) { // get the current character $char = $template[ $i ]; // is the char equal to the first character of the expression? if ($char == substr($tag_start, 0, 1) OR $char == substr($tag_end, 0, 1)) { // we've found ourselves a condition! if (substr($template, $i, strlen($tag_start)) == $tag_start) { // where do we end the condition $end = strpos($template, $tag_start_end, $i); $end += strlen($tag_start_end); //echo $template[ $end - 2 ] . $template[ $end - 1 ] . $template[ $end ] . $template[ $end + 1 ] . $template[ $end + 2 ] . " (" . $template[ $end ] . ") "; //echo " { " . $template[ $end - 1 ] . " } "; //echo " >>>>>> " . $end . " >>>>>> "; // extract the condition $condition = substr($template, $i, $end - $i); //echo "||||||" . $_isso->sanitize($condition) . "||||||"; // complete the open array_push($stack, $i); //print_r($stack); } // do we have an end? // make sure that it's the whole tag else if (substr($template, $i, strlen($tag_end)) == $tag_end) { // calculate the end of the tag $end = $i + strlen($tag_end); //echo ">>>>> $end <<<<<<"; //print_r($stack); // find the most recently opened condition $last = array_pop($stack); // get the full condition $fullspread = substr($template, $last, $end - $last); // remove the beginning tag $conditional = substr($fullspread, strlen($tag_start)); // find the end of the expression $temp_end = strpos($conditional, $tag_start_end); // save the expression $expression = stripslashes(substr($conditional, 0, $temp_end)); // remove the condition from the broken conditional $conditional = substr($conditional, strlen($expression) + strlen($tag_start_end)); // remove the tailing end tag $conditional = substr($conditional, 0, strlen($conditional) - strlen($tag_end)); //echo ">>>>>>> " . $_isso->sanitize($conditional) . " >>>>>>>"; // place it in iff() $parsed = '" . iff(' . stripslashes($expression) . ',"' . $conditional . '","") . "'; echo "<<<< " . $_isso->sanitize($parsed) . " >>>> "; // replace it back into the template $template = substr_replace($template, $parsed, $i, $i - $end + strlen($tag_end)); echo ">>>>>>>>>>> $template <<<<<<<<<<"; exit; //echo "<<<<<<<<<<<<<<<<< $conditional >>>>>>>>>>>"; } } }*/ return ''; //return $template; // ------------------------------ // ------ END //exit; while (1) { // Do we have an $tag_else $location_else = strpos($parsed, $tag_else); if ($location_else !== false) { $data = explode($tag_else, $parsed); // um... wtf? if (count($data) > 2) { trigger_error('Multiple else statements encountered while parsing conditionals in template', ERR_ALERT); } // 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$ || ################################################################### \*=====================================================================*/ ?>