Update the comment formatting to not use the pound bar anymore and to put a space...
[isso.git] / Template.php
index b15d749219200d6852f286a8ebaa896e92f6ae94..5e135667f8b904776c0ed388a73051a97c56c3bb 100644 (file)
 \*=====================================================================*/
 
 /**
-* Database-Driven Template System (template.php)
-*
-* @package     ISSO
-*/
+ * Database-Driven Template System (template.php)
+ *
+ * @package    ISSO
+ */
 
 require_once(ISSO . '/Functions.php');
 
 /**
-* File-Based Template System
-*
-* This framework merely replaces the template loading functions with
-* file-system based ones. It has an optional caching system in which
-* template data will remain stored in the database as long as the filesystem
-* file is modified. To do this, pass a table name to setDatabaseCache() and make sure
-* there's a DB module that has access to a table with this schema:
-*
-* 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
-* @package             ISSO
-* 
-*/
+ * File-Based Template System
+ *
+ * This framework merely replaces the template loading functions with
+ * file-system based ones. It has an optional caching system in which
+ * template data will remain stored in the database as long as the filesystem
+ * file is modified. To do this, pass a table name to setDatabaseCache() and make sure
+ * there's a DB module that has access to a table with this schema:
+ *
+ * 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
+ * @package            ISSO
+ 
+ */
 class BSTemplate
 {
        /**
-       * The path, from the path of the application, where templates are stored
-       * @var  string
-       */
+        * The path, from the path of the application, where templates are stored
+        * @var string
+        */
        private $templateDir = '';
        
        /**
-       * The extension all the template files have
-       * @var  string
-       */
+        * The extension all the template files have
+        * @var string
+        */
        private $extension = 'tpl';
        
        /**
-       * The database table name for the template cache
-       * @var string
-       */
+        * The database table name for the template cache
+        * @var string
+        */
        private $dbCacheTable = null;
        
        /**
-       * The name of the function phrases are fetched with
-       * @var  string
-       */
+        * The name of the function phrases are fetched with
+        * @var string
+        */
        private $langcall = 'gettext';
        
        /**
-       * The name of the function phrases are sprintf() parsed with
-       * @var  string
-       */
+        * The name of the function phrases are sprintf() parsed with
+        * @var string
+        */
        private $langconst = 'sprintf';
        
        /**
-       * Array of pre-compiled templates that are stored to decrease server load
-       * @var  array
-       */
+        * Array of pre-compiled templates that are stored to decrease server load
+        * @var array
+        */
        protected $cache = array();
        
        /**
-       * A list of templates that weren't cached, but are still used
-       * @var  array
-       */
+        * A list of templates that weren't cached, but are still used
+        * @var array
+        */
        protected $uncached = array();
        
        /**
-       * Whether or not the page has been flush()'d already
-       * @var  bool
-       */
+        * Whether or not the page has been flush()'d already
+        * @var bool
+        */
        private $doneflush = false;
        
        /**
-       * The name of a function that is called before template parsing of phrases and conditionals occurs
-       * @var  string
-       */
+        * The name of a function that is called before template parsing of phrases and conditionals occurs
+        * @var string
+        */
        private $preParseHook = ':undefined:';
        
-       // ###################################################################
        /**
-       * Sets the template directory name
-       *
-       * @param        string  Template directory name
-       */
+        * Sets the template directory name
+        *
+        * @param       string  Template directory name
+        */
        public function setTemplateDirectory($dir)
        {
                $this->templateDir = BSFunctions::fetch_source_path($dir);
        }
        
-       // ###################################################################
        /**
-       * Sets the file extension for the templates
-       *
-       * @param        string  File extension
-       */
+        * Sets the file extension for the templates
+        *
+        * @param       string  File extension
+        */
        public function setExtension($ext)
        {
                $this->extension = $ext;
        }
        
-       // ###################################################################
        /**
-       * Sets the name of the table to access for the datbase cache
-       *
-       * @param        string  DB table name
-       */
+        * Sets the name of the table to access for the datbase cache
+        *
+        * @param       string  DB table name
+        */
        public function setDatabaseCache($table)
        {
                $this->dbCacheTable = $table;
        }
        
-       // ###################################################################
        /**
-       * Sets the pre-parse hook method which is called before any other
-       * processing is done on the template.
-       *
-       * @param        string  Method name
-       */
+        * Sets the pre-parse hook method which is called before any other
+        * processing is done on the template.
+        *
+        * @param       string  Method name
+        */
        public function setPreParseHook($hook)
        {
                $this->preParseHook = $hook;
        }
        
-       // ###################################################################
        /**
-       * Takes an array of template names, loads them, and then stores a
-       * parsed version for optimum speed.
-       *
-       * @param        array   List of template names to be cached
-       */
+        * Takes an array of template names, loads them, and then stores a
+        * parsed version for optimum speed.
+        *
+        * @param       array   List of template names to be cached
+        */
        public function cache($namearray)
        {
                if (sizeof($this->cache) > 0)
@@ -201,15 +196,14 @@ class BSTemplate
                }
        }
        
-       // ###################################################################
        /**
-       * Loads a template from the cache or the _load function and stores the
-       * parsed version of it
-       *
-       * @param        string  The name of the template
-       *
-       * @return       string  A parsed and loaded 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
+        *
+        * @return      string  A parsed and loaded template
+        */
        public function fetch($name)
        {
                if (isset($this->cache[$name]))
@@ -227,12 +221,11 @@ class BSTemplate
                return $template;
        }
        
-       // ###################################################################
        /**
-       * Output a template fully compiled to the browser
-       *
-       * @param        string  Compiled and ready template
-       */
+        * Output a template fully compiled to the browser
+        *
+        * @param       string  Compiled and ready template
+        */
        public function flush($template)
        {
                ob_start();
@@ -284,14 +277,13 @@ class BSTemplate
                print($template);
        }
        
-       // ###################################################################
        /**
-       * Loads an additional template from the database
-       *
-       * @param        string  The name of the template
-       *
-       * @return       string  Template data from the database
-       */
+        * Loads an additional template from the database
+        *
+        * @param       string  The name of the template
+        *
+        * @return      string  Template data from the database
+        */
        protected function _loadTemplate($name)
        {
                $path = $this->templateDir . $name . '.' . $this->extension;
@@ -305,14 +297,13 @@ class BSTemplate
                }
        }
        
-       // ###################################################################
        /**
-       * A wrapper for all the parsing functions and compiling functins
-       *
-       * @param        string  Unparsed template data
-       *
-       * @return       string  Parsed template data
-       */
+        * A wrapper for all the parsing functions and compiling functins
+        *
+        * @param       string  Unparsed template data
+        *
+        * @return      string  Parsed template data
+        */
        protected function _parseTemplate($template)
        {
                $template = str_replace('"', '\"', $template);
@@ -328,14 +319,13 @@ class BSTemplate
                return $template;
        }
        
-       // ###################################################################
        /**
-       * Parses anything with curly braces {} (including phrases)
-       *
-       * @param        string  Template data
-       *
-       * @return       string  Parsed template data
-       */
+        * Parses anything with curly braces {} (including phrases)
+        *
+        * @param       string  Template data
+        *
+        * @return      string  Parsed template data
+        */
        private function _parseBlocksAndTokens($template)
        {
                $stack = array();
@@ -384,14 +374,13 @@ class BSTemplate
                }
        }
        
-       // ###################################################################
        /**
-       * Parses a curly brace token {}
-       *
-       * @param        string  Token
-       *
-       * @return       string  Parsed value
-       */
+        * Parses a curly brace token {}
+        *
+        * @param       string  Token
+        *
+        * @return      string  Parsed value
+        */
        private function _parseToken($token)
        {
                // knock of the braces
@@ -409,14 +398,13 @@ class BSTemplate
                }
        }
        
-       // ###################################################################
        /**
-       * Prepares language and locale information inside templates
-       *
-       * @param        string  Template data to be processed
-       *
-       * @return       string  Language-ready template data
-       */
+        * 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 ';
@@ -517,14 +505,13 @@ class BSTemplate
                return $template;
        }
        
-       // ###################################################################
        /**
-       * Parser for in-line template conditionals
-       *
-       * @param        string  Template data awaiting processing
-       *
-       * @return       string  Parsed template data
-       */
+        * Parser for in-line template conditionals
+        *
+        * @param       string  Template data awaiting processing
+        *
+        * @return      string  Parsed template data
+        */
        private function _parseConditionals($template)
        {
                // tag data