query("SELECT * FROM " . self::$dbCacheTable . " WHERE filename IN ('" . implode("', '", $namearray) . "')"); while ($tpl = $cache->fetchArray()) { self::$cache[$tpl['filename']] = $tpl; } } /** * Fluent interface-compatible constructor */ public static function fetch() { $obj = new ReflectionClass(__CLASS__); $args = func_get_args(); return $obj->newInstanceArgs($args); } /** * Constructor * * @param string File name */ public function __construct($path) { $this->file = $path; // checks to see if the template has been cached if (isset(self::$cache[$this->file])) { if (!self::$dbCacheTable || filemtime(sprintf(self::$templatePath, $this->file)) <= self::$cache[$this->file]['timestamp']) { $this->template = self::$cache[$this->file]['template']; return; } } // it hasn't been cached $path = sprintf(self::$templatePath, $this->file); if (!is_file($path) || !is_readable($path)) { throw new Exception("Could not load the template $path"); } $this->template = $this->_parseTemplate(file_get_contents($path)); self::$cache[$this->file]['template'] = $this->template; // store the template in the database if (self::$dbCacheTable) { BSApp::$db->query("REPLACE INTO " . self::$dbCacheTable . " SET template = '" . BSApp::$db->escapeString($this->template) . "', timestamp = " . TIMENOW . ", filename = '" . $this->file . "'"); self::$cache[$this->file]['time'] = TIMENOW; } } /** * Returns the template data * * @return string Final template data */ public function getTemplate() { return $this->template; } /** * This function globalizes/extracts the assigned variables and then * returns the output buffer * * @param string Unevaluated template * * @return fluent interface */ public function evaluate() { extract($this->vars); extract(self::$globalVars); ob_start(); $this->template = str_replace(array('$this->', 'self::'), 'null', $this->template); // don't want internal access coming from a template $this->template = '?>' . $this->template; $test = eval($this->template); $output = ob_get_clean(); if ($output === false) { throw new Exception('A parse error was encountered while evaluating the template'); } $this->template = $output; return $this; } /** * Output a template fully compiled to the browser */ public function flush() { ob_start(); if (empty($this->template)) { throw new Exception('There is no output to print'); } echo $this->template; } /** * Returns the debug block * * @return string */ public static function get_debug_block() { if (!BSApp::get_debug()) { return; } $debugBlock = "\n
Query Debug |
";
$debugBlock .= "\n\t\t\t$query[query]\n\n\t\t\t ($query[time]) \n\n\t\t | \n\t