Update version.php to 3.3.0
[isso.git] / Template.php
index 5e135667f8b904776c0ed388a73051a97c56c3bb..dfe30c12ae088949b8201e41d30c9c52b1d0d790 100644 (file)
@@ -2,7 +2,7 @@
 /*=====================================================================*\
 || ###################################################################
 || # Blue Static ISSO Framework
-|| # Copyright (c)2005-2008 Blue Static
+|| # Copyright (c)2005-2009 Blue Static
 || #
 || # This program is free software; you can redistribute it and/or modify
 || # it under the terms of the GNU General Public License as published by
@@ -39,262 +39,241 @@ require_once(ISSO . '/Functions.php');
  * CREATE TABLE template (filename VARCHAR (250) NOT NULL, template TEXT NOT NULL, timestamp INT NOT NULL);
  *
  * @author             Blue Static
- * @copyright  Copyright (c)2005 - 2008, Blue Static
+ * @copyright  Copyright (c)2005 - 2009, Blue Static
  * @package            ISSO
  * 
  */
 class BSTemplate
 {
        /**
-        * The path, from the path of the application, where templates are stored
+        * The name of a function that is called before template parsing of phrases and conditionals occurs
         * @var string
         */
-       private $templateDir = '';
+       public static $preParseHook = ':undefined:';
+
+       /**
+        * The database table name for the template cache
+        * @var string
+        */
+       public static $dbCacheTable = null;
        
        /**
-        * The extension all the template files have
+        * The name of the function phrases are fetched with
         * @var string
         */
-       private $extension = 'tpl';
+       public static $langcall = 'gettext';
        
        /**
-        * The database table name for the template cache
+        * The template path pattern; for instance, this could be: ./templates/%s.tpl
         * @var string
         */
-       private $dbCacheTable = null;
+       public static $templatePath = '%s';
        
        /**
-        * The name of the function phrases are fetched with
-        * @var string
+        * Array of pre-compiled templates that are stored for optimization
+        * @var array
         */
-       private $langcall = 'gettext';
+       protected static $cache = array();
        
        /**
         * The name of the function phrases are sprintf() parsed with
         * @var string
         */
-       private $langconst = 'sprintf';
+       public static $langconst = 'sprintf';
        
        /**
-        * Array of pre-compiled templates that are stored to decrease server load
-        * @var array
+        * Template variables to populate
+        * @var array
         */
-       protected $cache = array();
+       public $vars = array();
        
        /**
-        * A list of templates that weren't cached, but are still used
-        * @var array
+        * Global variables
+        * @var array
         */
-       protected $uncached = array();
+       public static $globalVars = array();
        
        /**
-        * Whether or not the page has been flush()'d already
-        * @var bool
+        * The path of the template file
+        * @var string
         */
-       private $doneflush = false;
+       protected $path;
        
        /**
-        * The name of a function that is called before template parsing of phrases and conditionals occurs
-        * @var string
+        * The name of the template
+        * @var string
         */
-       private $preParseHook = ':undefined:';
+       protected $name;
        
        /**
-        * Sets the template directory name
+        * Template contents
+        * @var string
+        */
+       protected $template;
+       
+       /**
+        * Takes an array of template names, loads them, and then stores a
+        * parsed version for optimum speed.
         *
-        * @param       string  Template directory name
+        * @param       array   List of template names to be cached
         */
-       public function setTemplateDirectory($dir)
+       public static function cache($namearray)
        {
-               $this->templateDir = BSFunctions::fetch_source_path($dir);
+               if (!self::$dbCacheTable)
+               {
+                       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())
+               {
+                       self::$cache[$tpl['filename']] = $tpl;
+               }
        }
        
        /**
-        * Sets the file extension for the templates
-        *
-        * @param       string  File extension
+        * Fluent interface-compatible constructor
         */
-       public function setExtension($ext)
+       public static function fetch()
        {
-               $this->extension = $ext;
+               $obj = new ReflectionClass(__CLASS__);
+               $args = func_get_args();
+               return $obj->newInstanceArgs($args);
        }
        
        /**
-        * Sets the name of the table to access for the datbase cache
-        *
-        * @param       string  DB table name
+        * Constructor
+        * 
+        * @param       string  File name
         */
-       public function setDatabaseCache($table)
+       public function __construct($name)
        {
-               $this->dbCacheTable = $table;
+               $this->name = $name;
+               $this->path = self::_path($name);
+               
+               // checks to see if the template has been cached
+               if (isset(self::$cache[$this->path]))
+               {
+                       if (!self::$dbCacheTable || filemtime($this->path) <= self::$cache[$this->path]['timestamp'])
+                       {
+                               $this->template = self::$cache[$this->path]['template'];
+                               return;
+                       }
+               }
+               
+               // it hasn't been cached
+               if (!is_file($this->path) || !is_readable($this->path))
+               {
+                       throw new Exception("Could not load the template {$this->path}");
+               }
+               $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->path . "'");
+                       self::$cache[$this->path]['time'] = TIMENOW;
+               }
        }
        
        /**
-        * Sets the pre-parse hook method which is called before any other
-        * processing is done on the template.
+        * Evaluates and returns the template. This is equivalent to calling:
+        * $tpl->evaluate()->getTemplate()
         *
-        * @param       string  Method name
+        * @return      string
         */
-       public function setPreParseHook($hook)
+       public function __toString()
        {
-               $this->preParseHook = $hook;
+               return $this->evaluate()->getTemplate();
        }
        
        /**
-        * Takes an array of template names, loads them, and then stores a
-        * parsed version for optimum speed.
+        * Returns the template data
         *
-        * @param       array   List of template names to be cached
+        * @return      string  Final template data
         */
-       public function cache($namearray)
+       public function getTemplate()
        {
-               if (sizeof($this->cache) > 0)
-               {
-                       throw new Exception('You cannot cache templates more than once per initialization');
-               }
-               else
-               {
-                       $dbCache = array();
-                       if ($this->dbCacheTable)
-                       {
-                               $db =& BSApp::$db;
-                               $cache = $db->query("SELECT * FROM {$this->dbCacheTable} WHERE filename IN ('" . implode("', '", $namearray) . "')");
-                               while ($tpl = $cache->fetchArray())
-                               {
-                                       $time = filemtime($this->templateDir . $tpl['filename'] . '.' . $this->extension);
-                                       $template = $tpl['template'];
-                                       if ($time > $tpl['timestamp'])
-                                       {
-                                               $template = $this->_parseTemplate($this->_loadTemplate($tpl['filename']));
-                                               $db->query("UPDATE {$this->dbCacheTable} SET template = '" . $db->escapeString($template) . "', timestamp = " . TIMENOW . " WHERE filename = '" . $tpl['filename'] . "'");
-                                               $tpl['template'] = $template;
-                                       }
-                                       $dbCache["$tpl[filename]"] = $template;
-                               }
-                       }
-                       foreach ($namearray as $name)
-                       {
-                               if ($this->dbCacheTable)
-                               {
-                                       if (isset($dbCache["$name"]))
-                                       {
-                                               $template = $dbCache["$name"];
-                                       }
-                                       else
-                                       {
-                                               $template = $this->_parseTemplate($this->_loadTemplate($name));
-                                               $db->query("INSERT INTO {$this->dbCacheTable} (filename, template, timestamp) VALUES ('$name', '" . $db->escapeString($template) . "', " . TIMENOW . ")");
-                                       }
-                               }
-                               else
-                               {
-                                       $template = $this->_parseTemplate($this->_loadTemplate($name));
-                               }
-                               
-                               $this->cache[$name] = $template;
-                       }
-               }
+               return $this->template;
        }
        
        /**
-        * Loads a template from the cache or the _load function and stores the
-        * parsed version of it
-        *
-        * @param       string  The name of the template
+        * This function globalizes/extracts the assigned variables and then
+        * returns the output buffer
+        * 
+        * @param       string  Unevaluated template
         *
-        * @return      string  A parsed and loaded template
+        * @return      fluent interface
         */
-       public function fetch($name)
+       public function evaluate()
        {
-               if (isset($this->cache[$name]))
-               {
-                       $template = $this->cache[$name];
-               }
-               else
+               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)
                {
-                       $this->uncached[$name] = (isset($this->uncached[$name]) ? $this->uncached[$name] + 1 : 0);
-                       BSApp::debug("Manually loading template '$name'");
-                       $template = $this->_loadTemplate($name);
-                       $template = $this->_parseTemplate($template);
+                       throw new Exception('A parse error was encountered while evaluating the template');
                }
                
-               return $template;
+               $this->template = $output;
+               
+               return $this;
        }
        
        /**
         * Output a template fully compiled to the browser
-        *
-        * @param       string  Compiled and ready template
         */
-       public function flush($template)
+       public function flush()
        {
                ob_start();
                
-               if (empty($template))
-               {
-                       throw new Exception('There was no output to print');
-               }
-               
-               if ($this->doneflush)
+               if (empty($this->template))
                {
-                       throw new Exception('A template has already been sent to the output buffer');
+                       throw new Exception('There is no output to print');
                }
                
-               $debugBlock = '';
-               if (BSApp::get_debug())
-               {                       
-                       $debugBlock .= "\n<div align=\"center\">Executed in " . round(BSFunctions::fetch_microtime_diff('0 ' . $_SERVER['REQUEST_TIME']), 10) . ' seconds</div>';
-                       $debugBlock .= "\n<br /><div align=\"center\">" . BSApp::get_debug_list() . "</div>";
-                       
-                       if (sizeof($this->uncached) > 0)
-                       {
-                               foreach ($this->uncached as $name => $count)
-                               {
-                                       $tpls[] = $name . "($count)";
-                               }
-                               $debugBlock .= "<br /><div style=\"color: red\" align=\"center\"><strong>Uncached Templates:</strong>" . implode(', ', $tpls) . " )</div>\n";
-                       }
-                       
-                       if (BSApp::$db)
-                       {
-                               $queries = BSApp::$db->getHistory();
-                               
-                               $debugBlock .= "<br />\n" . '<table cellpadding="4" cellspacing="1" border="0" align="center" width="30%" style="background-color: rgb(60, 60, 60); color: white">' . "\n\t" . '<tr><td><strong>Query Debug</strong></td></tr>';
-                               
-                               foreach ($queries as $query)
-                               {
-                                       $debugBlock .= "\n\t<tr style=\"background-color: rgb(230, 230, 230); color: black\">";
-                                       $debugBlock .= "\n\t\t<td>";
-                                       $debugBlock .= "\n\t\t\t$query[query]\n\n\t\t\t<div style=\"font-size: 9px;\">($query[time])</div>\n<!--\n$query[trace]\n-->\n\t\t</td>\n\t</tr>";
-                               }
-                               
-                               $debugBlock .= "\n</table>\n\n\n";
-                       }
-                       
-                       $template = str_replace('</body>', $debugBlock . '</body>', $template);
-               }
-
-               print($template);
+               echo $this->template;
        }
        
        /**
-        * Loads an additional template from the database
-        *
-        * @param       string  The name of the template
+        * Returns the debug block
         *
-        * @return      string  Template data from the database
+        * @return      string
         */
-       protected function _loadTemplate($name)
+       public static function get_debug_block()
        {
-               $path = $this->templateDir . $name . '.' . $this->extension;
-               if (is_file($path) && is_readable($path))
+               if (!BSApp::get_debug())
                {
-                       return @file_get_contents($path);
+                       return;
                }
-               else
+               
+               $debugBlock = "\n<div align=\"center\">Executed in " . round(BSFunctions::fetch_microtime_diff('0 ' . $_SERVER['REQUEST_TIME']), 10) . ' seconds</div>';
+               $debugBlock .= "\n<br /><div align=\"center\">" . BSApp::get_debug_list() . "</div>";
+                                       
+               if (BSApp::$db)
                {
-                       throw new Exception("Could not load the template '$path'");
+                       $queries = BSApp::$db->getHistory();
+                       
+                       $debugBlock .= "<br />\n" . '<table cellpadding="4" cellspacing="1" border="0" align="center" width="30%" style="background-color: rgb(60, 60, 60); color: white">' . "\n\t" . '<tr><td><strong>Query Debug</strong></td></tr>';
+                       
+                       foreach ($queries as $query)
+                       {
+                               $debugBlock .= "\n\t<tr style=\"background-color: rgb(230, 230, 230); color: black\">";
+                               $debugBlock .= "\n\t\t<td>";
+                               $debugBlock .= "\n\t\t\t$query[query]\n\n\t\t\t<div style=\"font-size: 9px;\">($query[time])</div>\n<!--\n$query[trace]\n-->\n\t\t</td>\n\t</tr>";
+                       }
+                       
+                       $debugBlock .= "\n</table>\n\n\n";
                }
+               
+               return $debugBlock;
        }
        
        /**
@@ -306,330 +285,71 @@ class BSTemplate
         */
        protected function _parseTemplate($template)
        {
-               $template = str_replace('"', '\"', $template);
-               
-               if (function_exists($this->preParseHook))
+               if (function_exists(self::$preParseHook))
                {
-                       $template = call_user_func($this->preParseHook, $template);
+                       $template = call_user_func(self::$preParseHook, $template, $this);
                }
                
-               $template = $this->_parseBlocksAndTokens($template);
-               $template = $this->_parsePhrases($template);
-               $template = $this->_parseConditionals($template);
+               $template = $this->_parseTokens($template);
                return $template;
        }
        
        /**
-        * Parses anything with curly braces {} (including phrases)
+        * Parses tokens <% %>
         *
         * @param       string  Template data
         *
         * @return      string  Parsed template data
         */
-       private function _parseBlocksAndTokens($template)
+       protected function _parseTokens($template)
        {
                $stack = array();
                $tokens = array();
                
-               while (1)
-               {
-                       for ($i = 0; $i < strlen($template); $i++)
-                       {
-                               // we've run through the template and there's nothing in the stack--done
-                               if ($i == strlen($template) - 1 && sizeof($stack) == 0)
-                               {
-                                       return $template;
-                               }
-                               
-                               if ($template[$i] == '{')
-                               {
-                                       // ignore escaped sequences
-                                       if ($template[$i - 1] != '\\')
-                                       {
-                                               array_push($stack, $i);
-                                       }
-                               }
-                               else if ($template[$i] == '}')
-                               {
-                                       // there's no stack so it was probably escaped
-                                       if (sizeof($stack) == 0)
-                                       {
-                                               continue;
-                                       }
-                                       // we're good and nested
-                                       else if (sizeof($stack) == 1)
-                                       {
-                                               $open = array_pop($stack);
-                                               $token = substr($template, $open, $i - $open + 1);
-                                               $template = str_replace($token, $this->_parseToken($token), $template);
-                                               break;
-                                       }
-                                       // just pop it off
-                                       else
-                                       {
-                                               array_pop($stack);
-                                       }
-                               }
-                       }
-               }
-       }
-       
-       /**
-        * Parses a curly brace token {}
-        *
-        * @param       string  Token
-        *
-        * @return      string  Parsed value
-        */
-       private function _parseToken($token)
-       {
-               // knock of the braces
-               $token = substr($token, 1, strlen($token) - 2);
-               
-               // language token
-               if ($token[0] == '@' && $token[1] == '\\' && $token[2] == '"')
-               {
-                       return '" . ' . $this->langcall . '(\'' . str_replace(array('\\\"', "'"), array('"', "\'"), substr($token, 3, strlen($token) - 5)) . '\')' . ' . "';
-               }
-               // normal PHP code
-               else
-               {
-                       return '" . (' . $token . ') . "';
-               }
-       }
-       
-       /**
-        * Prepares language and locale information inside templates
-        *
-        * @param       string  Template data to be processed
-        *
-        * @return      string  Language-ready template data
-        */
-       private function _parsePhrases($template)
-       {
-               $tagStart = '<lang ';
-               $tagEnd = '</lang>';
-               
-               $start = -1; // start of open tag
-               $end = -1; // start of the close tag
-               $varEnd = -1; // end of the open tag
-               
-               while ($start <= strlen($template))
+               for ($i = 0; $i < strlen($template); $i++)
                {
-                       // reset
-                       $varMap = array(); // storage for all the substitution indices
-                       
-                       // Find the start language object tag
-                       $start = strpos($template, $tagStart, $end + 1);
-                       if ($start === false)
+                       // opening tag
+                       if ($template[$i] == '<' && $template[$i + 1] == '%')
                        {
-                               break;
+                               array_push($stack, $i);
                        }
-                       
-                       // look ahead to parse out all the variables
-                       $i = $start + strlen($tagStart); // current position
-                       $capture = ''; // current capture
-                       $capturePos = $i; // the place to start capturing
-                       $varNum = -1; // variable placeholder index
-                       while ($i < strlen($template))
+                       // closing tag
+                       else if ($template[$i] == '%' && $template[$i + 1] == '>')
                        {
-                               if ($template[$i] == '=')
+                               // there's no stack, so it's a bad template
+                               if (sizeof($stack) == 0)
                                {
-                                       // backtrack to find the previous variable substitution
-                                       $backPos = $i;
-                                       while ($backPos >= $start)
-                                       {
-                                               if ($template[$backPos] == '"')
-                                               {
-                                                       // startPosition + length(startTag) + length(=\")
-                                                       $varMap[intval($varNum)] = BSFunctions::substring($template, $capturePos + 3, $backPos - 1);
-                                                       // remove our old substitution from the capture
-                                                       $capture = BSFunctions::substring($template, $backPos + 1, $i);
-                                                       break;
-                                               }
-                                               $backPos--;
-                                       }
-                                       
-                                       // do we have a valid index?
-                                       if (intval($capture) > 0)
-                                       {
-                                               // set aside the index and restart capturing
-                                               $varNum = $capture;
-                                               $capture = '';
-                                               $capturePos = $i;
-                                       }
-                                       else
-                                       {
-                                               throw new Exception('Invalid language variable index "' . $capture . '"');
-                                       }
+                                       throw new Exception('Malformed template data: unexpected closing substitution tag');
                                }
-                               else if ($template[$i] == '>' && $template[$i - 1] == '"')
+                               // we're good and nested
+                               else if (sizeof($stack) == 1)
                                {
-                                       // the final variable substitution
-                                       $varMap[intval($varNum)] = BSFunctions::substring($template, $capturePos + 3, $i - 2);
-                                       $varEnds = $i;
-                                       break;
+                                       $open = array_pop($stack);
+                                       $echo = ($template[$open + 2] == '-' ? 'echo ' : '');
+                                       $replace = '<?php ' . $echo . BSFunctions::substring($template, $open + ($echo ? 3 : 2), $i) . ' ?>';
+                                       $template = substr_replace($template, $replace, $open, ($i + 2) - $open);
                                }
-                               
-                               $capture .= $template[$i];
-                               $i++;
-                       }
-                       
-                       // locate the end tag
-                       $end = strpos($template, $tagEnd, $i);
-                       if ($end === false)
-                       {
-                               break;
-                       }
-                       
-                       // this is the string that gets variable replacement
-                       $str = BSFunctions::substring($template, $varEnds + 1, $end);
-                       
-                       // create the complete varmap
-                       
-                       for ($i = max(array_keys($varMap)); $i > 0; $i--)
-                       {
-                               if (!isset($varMap[$i]))
+                               // just pop it off
+                               else
                                {
-                                       $varMap[$i] = '<strong>[MISSING SUBSTITUTION INDEX: ' . $i . ']</strong>';
-                               }
-                       }
-                       
-                       // put all the keys in corresponding argument order
-                       ksort($varMap);
-                       
-                       // FINALLY, construct the call to sprintf()
-                       $template = substr_replace($template, '" . ' . $this->langconst . '(\'' . $str . '\', "' . implode('", "', $varMap) . '") . "', $start, ($end + strlen($tagEnd)) - $start);
-               }
+                                       array_pop($stack);
+                               } // end else
+                       } // end if
+               } // end for
                
                return $template;
        }
        
        /**
-        * Parser for in-line template conditionals
+        * Returns the full path of a template given a name
         *
-        * @param       string  Template data awaiting processing
+        * @param       string  Template name
         *
-        * @return      string  Parsed template data
+        * @return      string  Template path
         */
-       private function _parseConditionals($template)
+       protected static function _path($name)
        {
-               // tag data
-               $tag_start = '<if condition=\"';
-               $tag_start_end = '\">';
-               $tag_else = '<else />';
-               $tag_end = '</if>';
-               
-               // tag stack
-               $stack = array();
-               
-               // the information about the current active tag
-               $tag_full = array();
-               $parsed = array();
-               
-               // start at 0
-               $offset = 0;
-               
-               while (1)
-               {
-                       if (strpos($template, $tag_start) === false)
-                       {
-                               break;
-                       }
-                       
-                       for ($i = $offset; $i < strlen($template); $i++)
-                       {
-                               // we've found ourselves a conditional!
-                               if (substr($template, $i, strlen($tag_start)) == $tag_start)
-                               {
-                                       // push the position into the tag stack
-                                       if ($tag_full)
-                                       {
-                                               array_push($stack, $i);
-                                       }
-                                       else
-                                       {
-                                               $tag_full['posi'] = $i;
-                                       }
-                               }
-                               // locate else tags
-                               else if (substr($template, $i, strlen($tag_else)) == $tag_else)
-                               {
-                                       if (sizeof($stack) == 0 && !isset($tag_full['else']))
-                                       {
-                                               $tag_full['else'] = $i;
-                                       }
-                               }
-                               // do we have an end tag?
-                               else if (substr($template, $i, strlen($tag_end)) == $tag_end)
-                               {
-                                       if (sizeof($stack) != 0)
-                                       {
-                                               array_pop($stack);
-                                               continue;
-                                       }
-                                       
-                                       // calculate the position of the end tag
-                                       $tag_full['posf'] = $i + strlen($tag_end) - 1;
-                                       
-                                       // extract the entire conditional from the template
-                                       $fullspread = substr($template, $tag_full['posi'], $tag_full['posf'] - $tag_full['posi'] + 1);
-                                       
-                                       // 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
-                                       $parsed[0] = stripslashes(substr($conditional, 0, $temp_end));
-                                       
-                                       // remove the expression from the conditional
-                                       $conditional = substr($conditional, strlen($parsed[0]) + strlen($tag_start_end));
-                                       
-                                       // remove the tailing end tag
-                                       $conditional = substr($conditional, 0, strlen($conditional) - strlen($tag_end));
-                                       
-                                       // handle the else
-                                       if (isset($tag_full['else']))
-                                       {
-                                               // now relative to the start of the <if>
-                                               $relpos = $tag_full['else'] - $tag_full['posi'];
-                                               
-                                               // calculate the length of the expression and opening tag
-                                               $length = strlen($parsed[0]) + strlen($tag_start) + strlen($tag_start_end);
-                                               
-                                               // relative to the start of iftrue
-                                               $elsepos = $relpos - $length;
-       
-                                               $parsed[1] = substr($conditional, 0, $elsepos);
-                                               $parsed[2] = substr($conditional, $elsepos + strlen($tag_else));
-                                       }
-                                       // no else to handle
-                                       else
-                                       {
-                                               $parsed[1] = $conditional;
-                                               $parsed[2] = '';
-                                       }
-                                       
-                                       // final parsed output
-                                       $parsed = '" . ((' . stripslashes($parsed[0]) . ') ? "' . $parsed[1] . '" : "' . $parsed[2] . '") . "';
-                                       
-                                       // replace the conditional
-                                       $template = str_replace($fullspread, $parsed, $template);
-                                       
-                                       // reset the parser
-                                       $offset = $tag_full['posi'] + strlen($tag_start) + strlen($tag_start_end);
-                                       $tag_full = array();
-                                       $stack = array();
-                                       $parsed = array();
-                                       unset($fullspread, $conditional, $temp_end, $relpos, $length, $elsepos);
-                                       break;
-                               }
-                       }
-               }
-
-               return $template;
+               return sprintf(self::$templatePath, $name);
        }
 }