public static $globalVars = array();
/**
- * The file name of the template
+ * The path of the template file
* @var string
*/
- protected $filename;
+ protected $path;
+
+ /**
+ * The name of the template
+ * @var string
+ */
+ protected $name;
/**
* Template contents
return; // there's no point in pre-caching file templates
}
+ $namearray = array_map(array('self', '_path'), $namearray);
$cache = BSApp::$db->query("SELECT * FROM " . self::$dbCacheTable . " WHERE filename IN ('" . implode("', '", $namearray) . "')");
while ($tpl = $cache->fetchArray())
{
*
* @param string File name
*/
- public function __construct($path)
+ public function __construct($name)
{
- $this->file = $path;
+ $this->name = $name;
+ $this->path = self::_path($name);
// checks to see if the template has been cached
- if (isset(self::$cache[$this->file]))
+ if (isset(self::$cache[$this->path]))
{
- if (!self::$dbCacheTable || filemtime(sprintf(self::$templatePath, $this->file)) <= self::$cache[$this->file]['timestamp'])
+ if (!self::$dbCacheTable || filemtime($this->path) <= self::$cache[$this->path]['timestamp'])
{
- $this->template = self::$cache[$this->file]['template'];
+ $this->template = self::$cache[$this->path]['template'];
return;
}
}
// it hasn't been cached
- $path = sprintf(self::$templatePath, $this->file);
- if (!is_file($path) || !is_readable($path))
+ if (!is_file($this->path) || !is_readable($this->path))
{
- throw new Exception("Could not load the template $path");
+ throw new Exception("Could not load the template {$this->path}");
}
- $this->template = $this->_parseTemplate(file_get_contents($path));
- self::$cache[$this->file]['template'] = $this->template;
+ $this->template = $this->_parseTemplate(file_get_contents($this->path));
+ self::$cache[$this->path]['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;
+ BSApp::$db->query("REPLACE INTO " . self::$dbCacheTable . " SET template = '" . BSApp::$db->escapeString($this->template) . "', timestamp = " . TIMENOW . ", filename = '" . $this->path . "'");
+ self::$cache[$this->path]['time'] = TIMENOW;
}
}
return $template;
}
+
+ /**
+ * Returns the full path of a template given a name
+ *
+ * @param string Template name
+ *
+ * @return string Template path
+ */
+ protected static function _path($name)
+ {
+ return sprintf(self::$templatePath, $name);
+ }
}
?>
\ No newline at end of file