library/smarty/libs/SmartyBC.class.php
changeset 0 4869aea77e21
equal deleted inserted replaced
-1:000000000000 0:4869aea77e21
       
     1 <?php
       
     2 /**
       
     3  * Project:     Smarty: the PHP compiling template engine
       
     4  * File:        SmartyBC.class.php
       
     5  * SVN:         $Id: $
       
     6  * This library is free software; you can redistribute it and/or
       
     7  * modify it under the terms of the GNU Lesser General Public
       
     8  * License as published by the Free Software Foundation; either
       
     9  * version 2.1 of the License, or (at your option) any later version.
       
    10  * This library is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    13  * Lesser General Public License for more details.
       
    14  * You should have received a copy of the GNU Lesser General Public
       
    15  * License along with this library; if not, write to the Free Software
       
    16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    17  * For questions, help, comments, discussion, etc., please join the
       
    18  * Smarty mailing list. Send a blank e-mail to
       
    19  * smarty-discussion-subscribe@googlegroups.com
       
    20  *
       
    21  * @link      http://www.smarty.net/
       
    22  * @copyright 2008 New Digital Group, Inc.
       
    23  * @author    Monte Ohrt <monte at ohrt dot com>
       
    24  * @author    Uwe Tews
       
    25  * @author    Rodney Rehm
       
    26  * @package   Smarty
       
    27  */
       
    28 /**
       
    29  * @ignore
       
    30  */
       
    31 require_once(dirname(__FILE__) . '/Smarty.class.php');
       
    32 
       
    33 /**
       
    34  * Smarty Backward Compatability Wrapper Class
       
    35  *
       
    36  * @package Smarty
       
    37  */
       
    38 class SmartyBC extends Smarty {
       
    39     /**
       
    40      * Smarty 2 BC
       
    41      *
       
    42      * @var string
       
    43      */
       
    44     public $_version = self::SMARTY_VERSION;
       
    45 
       
    46     /**
       
    47      * Initialize new SmartyBC object
       
    48      *
       
    49      * @param array $options options to set during initialization, e.g. array( 'forceCompile' => false )
       
    50      */
       
    51     public function __construct(array $options = array()) {
       
    52         parent::__construct($options);
       
    53     }
       
    54 
       
    55     /**
       
    56      * wrapper for assign_by_ref
       
    57      *
       
    58      * @param string $tpl_var the template variable name
       
    59      * @param mixed &$value the referenced value to assign
       
    60      */
       
    61     public function assign_by_ref($tpl_var, &$value) {
       
    62         $this->assignByRef($tpl_var, $value);
       
    63     }
       
    64 
       
    65     /**
       
    66      * wrapper for append_by_ref
       
    67      *
       
    68      * @param string $tpl_var the template variable name
       
    69      * @param mixed &$value the referenced value to append
       
    70      * @param boolean $merge flag if array elements shall be merged
       
    71      */
       
    72     public function append_by_ref($tpl_var, &$value, $merge = false) {
       
    73         $this->appendByRef($tpl_var, $value, $merge);
       
    74     }
       
    75 
       
    76     /**
       
    77      * clear the given assigned template variable.
       
    78      *
       
    79      * @param string $tpl_var the template variable to clear
       
    80      */
       
    81     public function clear_assign($tpl_var) {
       
    82         $this->clearAssign($tpl_var);
       
    83     }
       
    84 
       
    85     /**
       
    86      * Registers custom function to be used in templates
       
    87      *
       
    88      * @param string $function the name of the template function
       
    89      * @param string $function_impl the name of the PHP function to register
       
    90      * @param bool $cacheable
       
    91      * @param mixed $cache_attrs
       
    92      */
       
    93     public function register_function($function, $function_impl, $cacheable = true, $cache_attrs = null) {
       
    94         $this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs);
       
    95     }
       
    96 
       
    97     /**
       
    98      * Unregisters custom function
       
    99      *
       
   100      * @param string $function name of template function
       
   101      */
       
   102     public function unregister_function($function) {
       
   103         $this->unregisterPlugin('function', $function);
       
   104     }
       
   105 
       
   106     /**
       
   107      * Registers object to be used in templates
       
   108      *
       
   109      * @param string $object name of template object
       
   110      * @param object $object_impl the referenced PHP object to register
       
   111      * @param array $allowed list of allowed methods (empty = all)
       
   112      * @param boolean $smarty_args smarty argument format, else traditional
       
   113      * @param array $block_methods list of methods that are block format
       
   114      *
       
   115      * @throws SmartyException
       
   116      * @internal param array $block_functs list of methods that are block format
       
   117      */
       
   118     public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) {
       
   119         settype($allowed, 'array');
       
   120         settype($smarty_args, 'boolean');
       
   121         $this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods);
       
   122     }
       
   123 
       
   124     /**
       
   125      * Unregisters object
       
   126      *
       
   127      * @param string $object name of template object
       
   128      */
       
   129     public function unregister_object($object) {
       
   130         $this->unregisterObject($object);
       
   131     }
       
   132 
       
   133     /**
       
   134      * Registers block function to be used in templates
       
   135      *
       
   136      * @param string $block name of template block
       
   137      * @param string $block_impl PHP function to register
       
   138      * @param bool $cacheable
       
   139      * @param mixed $cache_attrs
       
   140      */
       
   141     public function register_block($block, $block_impl, $cacheable = true, $cache_attrs = null) {
       
   142         $this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs);
       
   143     }
       
   144 
       
   145     /**
       
   146      * Unregisters block function
       
   147      *
       
   148      * @param string $block name of template function
       
   149      */
       
   150     public function unregister_block($block) {
       
   151         $this->unregisterPlugin('block', $block);
       
   152     }
       
   153 
       
   154     /**
       
   155      * Registers compiler function
       
   156      *
       
   157      * @param string $function name of template function
       
   158      * @param string $function_impl name of PHP function to register
       
   159      * @param bool $cacheable
       
   160      */
       
   161     public function register_compiler_function($function, $function_impl, $cacheable = true) {
       
   162         $this->registerPlugin('compiler', $function, $function_impl, $cacheable);
       
   163     }
       
   164 
       
   165     /**
       
   166      * Unregisters compiler function
       
   167      *
       
   168      * @param string $function name of template function
       
   169      */
       
   170     public function unregister_compiler_function($function) {
       
   171         $this->unregisterPlugin('compiler', $function);
       
   172     }
       
   173 
       
   174     /**
       
   175      * Registers modifier to be used in templates
       
   176      *
       
   177      * @param string $modifier name of template modifier
       
   178      * @param string $modifier_impl name of PHP function to register
       
   179      */
       
   180     public function register_modifier($modifier, $modifier_impl) {
       
   181         $this->registerPlugin('modifier', $modifier, $modifier_impl);
       
   182     }
       
   183 
       
   184     /**
       
   185      * Unregisters modifier
       
   186      *
       
   187      * @param string $modifier name of template modifier
       
   188      */
       
   189     public function unregister_modifier($modifier) {
       
   190         $this->unregisterPlugin('modifier', $modifier);
       
   191     }
       
   192 
       
   193     /**
       
   194      * Registers a resource to fetch a template
       
   195      *
       
   196      * @param string $type name of resource
       
   197      * @param array $functions array of functions to handle resource
       
   198      */
       
   199     public function register_resource($type, $functions) {
       
   200         $this->registerResource($type, $functions);
       
   201     }
       
   202 
       
   203     /**
       
   204      * Unregisters a resource
       
   205      *
       
   206      * @param string $type name of resource
       
   207      */
       
   208     public function unregister_resource($type) {
       
   209         $this->unregisterResource($type);
       
   210     }
       
   211 
       
   212     /**
       
   213      * Registers a prefilter function to apply
       
   214      * to a template before compiling
       
   215      *
       
   216      * @param callable $function
       
   217      */
       
   218     public function register_prefilter($function) {
       
   219         $this->registerFilter('pre', $function);
       
   220     }
       
   221 
       
   222     /**
       
   223      * Unregisters a prefilter function
       
   224      *
       
   225      * @param callable $function
       
   226      */
       
   227     public function unregister_prefilter($function) {
       
   228         $this->unregisterFilter('pre', $function);
       
   229     }
       
   230 
       
   231     /**
       
   232      * Registers a postfilter function to apply
       
   233      * to a compiled template after compilation
       
   234      *
       
   235      * @param callable $function
       
   236      */
       
   237     public function register_postfilter($function) {
       
   238         $this->registerFilter('post', $function);
       
   239     }
       
   240 
       
   241     /**
       
   242      * Unregisters a postfilter function
       
   243      *
       
   244      * @param callable $function
       
   245      */
       
   246     public function unregister_postfilter($function) {
       
   247         $this->unregisterFilter('post', $function);
       
   248     }
       
   249 
       
   250     /**
       
   251      * Registers an output filter function to apply
       
   252      * to a template output
       
   253      *
       
   254      * @param callable $function
       
   255      */
       
   256     public function register_outputfilter($function) {
       
   257         $this->registerFilter('output', $function);
       
   258     }
       
   259 
       
   260     /**
       
   261      * Unregisters an outputfilter function
       
   262      *
       
   263      * @param callable $function
       
   264      */
       
   265     public function unregister_outputfilter($function) {
       
   266         $this->unregisterFilter('output', $function);
       
   267     }
       
   268 
       
   269     /**
       
   270      * load a filter of specified type and name
       
   271      *
       
   272      * @param string $type filter type
       
   273      * @param string $name filter name
       
   274      */
       
   275     public function load_filter($type, $name) {
       
   276         $this->loadFilter($type, $name);
       
   277     }
       
   278 
       
   279     /**
       
   280      * clear cached content for the given template and cache id
       
   281      *
       
   282      * @param  string $tpl_file name of template file
       
   283      * @param  string $cache_id name of cache_id
       
   284      * @param  string $compile_id name of compile_id
       
   285      * @param  string $exp_time expiration time
       
   286      *
       
   287      * @return boolean
       
   288      */
       
   289     public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null) {
       
   290         return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time);
       
   291     }
       
   292 
       
   293     /**
       
   294      * clear the entire contents of cache (all templates)
       
   295      *
       
   296      * @param  string $exp_time expire time
       
   297      *
       
   298      * @return boolean
       
   299      */
       
   300     public function clear_all_cache($exp_time = null) {
       
   301         return $this->clearCache(null, null, null, $exp_time);
       
   302     }
       
   303 
       
   304     /**
       
   305      * test to see if valid cache exists for this template
       
   306      *
       
   307      * @param  string $tpl_file name of template file
       
   308      * @param  string $cache_id
       
   309      * @param  string $compile_id
       
   310      *
       
   311      * @return boolean
       
   312      */
       
   313     public function is_cached($tpl_file, $cache_id = null, $compile_id = null) {
       
   314         return $this->isCached($tpl_file, $cache_id, $compile_id);
       
   315     }
       
   316 
       
   317     /**
       
   318      * clear all the assigned template variables.
       
   319      */
       
   320     public function clear_all_assign() {
       
   321         $this->clearAllAssign();
       
   322     }
       
   323 
       
   324     /**
       
   325      * clears compiled version of specified template resource,
       
   326      * or all compiled template files if one is not specified.
       
   327      * This function is for advanced use only, not normally needed.
       
   328      *
       
   329      * @param  string $tpl_file
       
   330      * @param  string $compile_id
       
   331      * @param  string $exp_time
       
   332      *
       
   333      * @return boolean results of {@link smarty_core_rm_auto()}
       
   334      */
       
   335     public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null) {
       
   336         return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time);
       
   337     }
       
   338 
       
   339     /**
       
   340      * Checks whether requested template exists.
       
   341      *
       
   342      * @param  string $tpl_file
       
   343      *
       
   344      * @return boolean
       
   345      */
       
   346     public function template_exists($tpl_file) {
       
   347         return $this->templateExists($tpl_file);
       
   348     }
       
   349 
       
   350     /**
       
   351      * Returns an array containing template variables
       
   352      *
       
   353      * @param  string $name
       
   354      *
       
   355      * @return array
       
   356      */
       
   357     public function get_template_vars($name = null) {
       
   358         return $this->getTemplateVars($name);
       
   359     }
       
   360 
       
   361     /**
       
   362      * Returns an array containing config variables
       
   363      *
       
   364      * @param  string $name
       
   365      *
       
   366      * @return array
       
   367      */
       
   368     public function get_config_vars($name = null) {
       
   369         return $this->getConfigVars($name);
       
   370     }
       
   371 
       
   372     /**
       
   373      * load configuration values
       
   374      *
       
   375      * @param string $file
       
   376      * @param string $section
       
   377      * @param string $scope
       
   378      */
       
   379     public function config_load($file, $section = null, $scope = 'global') {
       
   380         $this->ConfigLoad($file, $section, $scope);
       
   381     }
       
   382 
       
   383     /**
       
   384      * return a reference to a registered object
       
   385      *
       
   386      * @param  string $name
       
   387      *
       
   388      * @return object
       
   389      */
       
   390     public function get_registered_object($name) {
       
   391         return $this->getRegisteredObject($name);
       
   392     }
       
   393 
       
   394     /**
       
   395      * clear configuration values
       
   396      *
       
   397      * @param string $var
       
   398      */
       
   399     public function clear_config($var = null) {
       
   400         $this->clearConfig($var);
       
   401     }
       
   402 
       
   403     /**
       
   404      * trigger Smarty error
       
   405      *
       
   406      * @param string $error_msg
       
   407      * @param integer $error_type
       
   408      */
       
   409     public function trigger_error($error_msg, $error_type = E_USER_WARNING) {
       
   410         trigger_error("Smarty error: $error_msg", $error_type);
       
   411     }
       
   412 }