phpDocumentor Smarty
[ class tree: Smarty ] [ index: Smarty ] [ all elements ]

Source for file Smarty.class.php

Documentation is available at Smarty.class.php

  1. <?php
  2.  
  3. /**
  4.  * Project:     Smarty: the PHP compiling template engine
  5.  * File:        Smarty.class.php
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  20.  *
  21.  * For questions, help, comments, discussion, etc., please join the
  22.  * Smarty mailing list. Send a blank e-mail to
  23.  *
  24.  * You may contact the authors of Smarty by e-mail at:
  25.  *
  26.  * Or, write to:
  27.  * Monte Ohrt
  28.  * Director of Technology, ispi
  29.  * 237 S. 70th suite 220
  30.  * Lincoln, NE 68510
  31.  *
  32.  * The latest version of Smarty can be obtained from:
  33.  * http://smarty.php.net/
  34.  *
  35.  * @link http://smarty.php.net/
  36.  * @copyright 2001-2003 ispi of Lincoln, Inc.
  37.  * @author Monte Ohrt <[email protected]>
  38.  * @author Andrei Zmievski <[email protected]>
  39.  * @package Smarty
  40.  * @version 2.6.0
  41.  */
  42.  
  43. /* $Id: Smarty.class.php,v 1.1 2005/10/17 18:37:39 jeichorn Exp $ */
  44.  
  45. /**
  46.  * DIR_SEP isn't used anymore, but third party apps might
  47.  */
  48. if(!defined('DIR_SEP')) {
  49.     define('DIR_SEP'DIRECTORY_SEPARATOR);
  50. }
  51.  
  52. /**
  53.  * set SMARTY_DIR to absolute path to Smarty library files.
  54.  * if not defined, include_path will be used. Sets SMARTY_DIR only if user
  55.  * application has not already defined it.
  56.  */
  57.  
  58. if (!defined('SMARTY_DIR')) {
  59.     define('SMARTY_DIR'dirname(__FILE__DIRECTORY_SEPARATOR);
  60. }
  61.  
  62. define('SMARTY_PHP_PASSTHRU',   0);
  63. define('SMARTY_PHP_QUOTE',      1);
  64. define('SMARTY_PHP_REMOVE',     2);
  65. define('SMARTY_PHP_ALLOW',      3);
  66.  
  67. /**
  68.  * @package Smarty
  69.  */
  70. class Smarty
  71. {
  72.     /**#@+
  73.      * Smarty Configuration Section
  74.      */
  75.  
  76.     /**
  77.      * The name of the directory where templates are located.
  78.      *
  79.      * @var string 
  80.      */
  81.     var $template_dir    =  'templates';
  82.  
  83.     /**
  84.      * The directory where compiled templates are located.
  85.      *
  86.      * @var string 
  87.      */
  88.     var $compile_dir     =  'templates_c';
  89.  
  90.     /**
  91.      * The directory where config files are located.
  92.      *
  93.      * @var string 
  94.      */
  95.     var $config_dir      =  'configs';
  96.  
  97.     /**
  98.      * An array of directories searched for plugins.
  99.      *
  100.      * @var array 
  101.      */
  102.     var $plugins_dir     =  array('plugins');
  103.  
  104.     /**
  105.      * If debugging is enabled, a debug console window will display
  106.      * when the page loads (make sure your browser allows unrequested
  107.      * popup windows)
  108.      *
  109.      * @var boolean 
  110.      */
  111.     var $debugging       =  false;
  112.  
  113.     /**
  114.      * This is the path to the debug console template. If not set,
  115.      * the default one will be used.
  116.      *
  117.      * @var string 
  118.      */
  119.     var $debug_tpl       =  '';
  120.  
  121.     /**
  122.      * This determines if debugging is enable-able from the browser.
  123.      * <ul>
  124.      *  <li>NONE => no debugging control allowed</li>
  125.      *  <li>URL => enable debugging when SMARTY_DEBUG is found in the URL.</li>
  126.      * </ul>
  127.      * @link http://www.foo.dom/index.php?SMARTY_DEBUG
  128.      * @var string 
  129.      */
  130.     var $debugging_ctrl  =  'NONE';
  131.  
  132.     /**
  133.      * This tells Smarty whether to check for recompiling or not. Recompiling
  134.      * does not need to happen unless a template or config file is changed.
  135.      * Typically you enable this during development, and disable for
  136.      * production.
  137.      *
  138.      * @var boolean 
  139.      */
  140.     var $compile_check   =  true;
  141.  
  142.     /**
  143.      * This forces templates to compile every time. Useful for development
  144.      * or debugging.
  145.      *
  146.      * @var boolean 
  147.      */
  148.     var $force_compile   =  false;
  149.  
  150.     /**
  151.      * This enables template caching.
  152.      * <ul>
  153.      *  <li>0 = no caching</li>
  154.      *  <li>1 = use class cache_lifetime value</li>
  155.      *  <li>2 = use cache_lifetime in cache file</li>
  156.      * </ul>
  157.      * @var integer 
  158.      */
  159.     var $caching         =  0;
  160.  
  161.     /**
  162.      * The name of the directory for cache files.
  163.      *
  164.      * @var string 
  165.      */
  166.     var $cache_dir       =  'cache';
  167.  
  168.     /**
  169.      * This is the number of seconds cached content will persist.
  170.      * <ul>
  171.      *  <li>0 = always regenerate cache</li>
  172.      *  <li>-1 = never expires</li>
  173.      * </ul>
  174.      *
  175.      * @var integer 
  176.      */
  177.     var $cache_lifetime  =  3600;
  178.  
  179.     /**
  180.      * Only used when $caching is enabled. If true, then If-Modified-Since headers
  181.      * are respected with cached content, and appropriate HTTP headers are sent.
  182.      * This way repeated hits to a cached page do not send the entire page to the
  183.      * client every time.
  184.      *
  185.      * @var boolean 
  186.      */
  187.     var $cache_modified_check = false;
  188.  
  189.     /**
  190.      * This determines how Smarty handles "<?php ... ?>" tags in templates.
  191.      * possible values:
  192.      * <ul>
  193.      *  <li>SMARTY_PHP_PASSTHRU -> print tags as plain text</li>
  194.      *  <li>SMARTY_PHP_QUOTE    -> escape tags as entities</li>
  195.      *  <li>SMARTY_PHP_REMOVE   -> remove php tags</li>
  196.      *  <li>SMARTY_PHP_ALLOW    -> execute php tags</li>
  197.      * </ul>
  198.      *
  199.      * @var integer 
  200.      */
  201.     var $php_handling    =  SMARTY_PHP_PASSTHRU;
  202.  
  203.     /**
  204.      * This enables template security. When enabled, many things are restricted
  205.      * in the templates that normally would go unchecked. This is useful when
  206.      * untrusted parties are editing templates and you want a reasonable level
  207.      * of security. (no direct execution of PHP in templates for example)
  208.      *
  209.      * @var boolean 
  210.      */
  211.     var $security       =   false;
  212.  
  213.     /**
  214.      * This is the list of template directories that are considered secure. This
  215.      * is used only if {@link $security} is enabled. One directory per array
  216.      * element.  {@link $template_dir} is in this list implicitly.
  217.      *
  218.      * @var array 
  219.      */
  220.     var $secure_dir     =   array();
  221.  
  222.     /**
  223.      * These are the security settings for Smarty. They are used only when
  224.      * {@link $security} is enabled.
  225.      *
  226.      * @var array 
  227.      */
  228.     var $security_settings  = array(
  229.                                     'PHP_HANDLING'    => false,
  230.                                     'IF_FUNCS'        => array('array''list',
  231.                                                                'isset''empty',
  232.                                                                'count''sizeof',
  233.                                                                'in_array''is_array',
  234.                                                                'true','false'),
  235.                                     'INCLUDE_ANY'     => false,
  236.                                     'PHP_TAGS'        => false,
  237.                                     'MODIFIER_FUNCS'  => array('count'),
  238.                                     'ALLOW_CONSTANTS' => false
  239.                                    );
  240.  
  241.     /**
  242.      * This is an array of directories where trusted php scripts reside.
  243.      * {@link $security} is disabled during their inclusion/execution.
  244.      *
  245.      * @var array 
  246.      */
  247.     var $trusted_dir        = array();
  248.  
  249.     /**
  250.      * The left delimiter used for the template tags.
  251.      *
  252.      * @var string 
  253.      */
  254.     var $left_delimiter  =  '{';
  255.  
  256.     /**
  257.      * The right delimiter used for the template tags.
  258.      *
  259.      * @var string 
  260.      */
  261.     var $right_delimiter =  '}';
  262.  
  263.     /**
  264.      * The order in which request variables are registered, similar to
  265.      * variables_order in php.ini E = Environment, G = GET, P = POST,
  266.      * C = Cookies, S = Server
  267.      *
  268.      * @var string 
  269.      */
  270.     var $request_vars_order    = "EGPCS";
  271.  
  272.     /**
  273.      * Indicates wether $HTTP_*_VARS[] (request_use_auto_globals=false)
  274.      * are uses as request-vars or $_*[]-vars. note: if
  275.      * request_use_auto_globals is true, then $request_vars_order has
  276.      * no effect, but the php-ini-value "gpc_order"
  277.      *
  278.      * @var boolean 
  279.      */
  280.     var $request_use_auto_globals      = false;
  281.  
  282.     /**
  283.      * Set this if you want different sets of compiled files for the same
  284.      * templates. This is useful for things like different languages.
  285.      * Instead of creating separate sets of templates per language, you
  286.      * set different compile_ids like 'en' and 'de'.
  287.      *
  288.      * @var string 
  289.      */
  290.     var $compile_id            = null;
  291.  
  292.     /**
  293.      * This tells Smarty whether or not to use sub dirs in the cache/ and
  294.      * templates_c/ directories. sub directories better organized, but
  295.      * may not work well with PHP safe mode enabled.
  296.      *
  297.      * @var boolean 
  298.      *
  299.      */
  300.     var $use_sub_dirs          = true;
  301.  
  302.     /**
  303.      * This is a list of the modifiers to apply to all template variables.
  304.      * Put each modifier in a separate array element in the order you want
  305.      * them applied. example: <code>array('escape:"htmlall"');</code>
  306.      *
  307.      * @var array 
  308.      */
  309.     var $default_modifiers        = array();
  310.  
  311.     /**
  312.      * This is the resource type to be used when not specified
  313.      * at the beginning of the resource path. examples:
  314.      * $smarty->display('file:index.tpl');
  315.      * $smarty->display('db:index.tpl');
  316.      * $smarty->display('index.tpl'); // will use default resource type
  317.      * {include file="file:index.tpl"}
  318.      * {include file="db:index.tpl"}
  319.      * {include file="index.tpl"} {* will use default resource type *}
  320.      *
  321.      * @var array 
  322.      */
  323.     var $default_resource_type    = 'file';
  324.  
  325.     /**
  326.      * The function used for cache file handling. If not set, built-in caching is used.
  327.      *
  328.      * @var null|stringfunction name
  329.      */
  330.     var $cache_handler_func   = null;
  331.  
  332.     /**
  333.      * These are the variables from the globals array that are
  334.      * assigned to all templates automatically. This isn't really
  335.      * necessary any more, you can use the $smarty var to access them
  336.      * directly.
  337.      *
  338.      * @var array 
  339.      */
  340.     var $global_assign   =  array('HTTP_SERVER_VARS' => array('SCRIPT_NAME'));
  341.  
  342.     /**
  343.      * The value of "undefined". Leave it alone :-)
  344.      *
  345.      * @var null 
  346.      */
  347.     var $undefined       =  null;
  348.  
  349.     /**
  350.      * This indicates which filters are automatically loaded into Smarty.
  351.      *
  352.      * @var array array of filter names
  353.      */
  354.     var $autoload_filters = array();
  355.  
  356.     /**#@+
  357.      * @var boolean 
  358.      */
  359.     /**
  360.      * This tells if config file vars of the same name overwrite each other or not.
  361.      * if disabled, same name variables are accumulated in an array.
  362.      */
  363.     var $config_overwrite = true;
  364.  
  365.     /**
  366.      * This tells whether or not to automatically booleanize config file variables.
  367.      * If enabled, then the strings "on", "true", and "yes" are treated as boolean
  368.      * true, and "off", "false" and "no" are treated as boolean false.
  369.      */
  370.     var $config_booleanize = true;
  371.  
  372.     /**
  373.      * This tells whether hidden sections [.foobar] are readable from the
  374.      * tempalates or not. Normally you would never allow this since that is
  375.      * the point behind hidden sections: the application can access them, but
  376.      * the templates cannot.
  377.      */
  378.     var $config_read_hidden = false;
  379.  
  380.     /**
  381.      * This tells whether or not automatically fix newlines in config files.
  382.      * It basically converts \r (mac) or \r\n (dos) to \n
  383.      */
  384.     var $config_fix_newlines = true;
  385.     /**#@-*/
  386.  
  387.     /**
  388.      * If a template cannot be found, this PHP function will be executed.
  389.      * Useful for creating templates on-the-fly or other special action.
  390.      *
  391.      * @var string function name
  392.      */
  393.     var $default_template_handler_func = '';
  394.  
  395.     /**
  396.      * The file that contains the compiler class. This can a full
  397.      * pathname, or relative to the php_include path.
  398.      *
  399.      * @var string 
  400.      */
  401.     var $compiler_file        =    'Smarty_Compiler.class.php';
  402.  
  403.     /**
  404.      * The class used for compiling templates.
  405.      *
  406.      * @var string 
  407.      */
  408.     var $compiler_class        =   'Smarty_Compiler';
  409.  
  410.     /**
  411.      * The class used to load config vars.
  412.      *
  413.      * @var string 
  414.      */
  415.     var $config_class          =   'Config_File';
  416.  
  417. /**#@+
  418.  * END Smarty Configuration Section
  419.  * There should be no need to touch anything below this line.
  420.  * @access private
  421.  */
  422.     /**
  423.      * error messages. true/false
  424.      *
  425.      * @var boolean 
  426.      */
  427.     var $_error_msg            false;
  428.  
  429.     /**
  430.      * where assigned template vars are kept
  431.      *
  432.      * @var array 
  433.      */
  434.     var $_tpl_vars             array();
  435.  
  436.     /**
  437.      * stores run-time $smarty.* vars
  438.      *
  439.      * @var null|array
  440.      */
  441.     var $_smarty_vars          null;
  442.  
  443.     /**
  444.      * keeps track of sections
  445.      *
  446.      * @var array 
  447.      */
  448.     var $_sections             array();
  449.  
  450.     /**
  451.      * keeps track of foreach blocks
  452.      *
  453.      * @var array 
  454.      */
  455.     var $_foreach              array();
  456.  
  457.     /**
  458.      * keeps track of tag hierarchy
  459.      *
  460.      * @var array 
  461.      */
  462.     var $_tag_stack            array();
  463.  
  464.     /**
  465.      * configuration object
  466.      *
  467.      * @var Config_file 
  468.      */
  469.     var $_conf_obj             null;
  470.  
  471.     /**
  472.      * loaded configuration settings
  473.      *
  474.      * @var array 
  475.      */
  476.     var $_config               array(array('vars'  => array()'files' => array()));
  477.  
  478.     /**
  479.      * md5 checksum of the string 'Smarty'
  480.      *
  481.      * @var string 
  482.      */
  483.     var $_smarty_md5           'f8d698aea36fcbead2b9d5359ffca76f';
  484.  
  485.     /**
  486.      * Smarty version number
  487.      *
  488.      * @var string 
  489.      */
  490.     var $_version              '2.6.0';
  491.  
  492.     /**
  493.      * current template inclusion depth
  494.      *
  495.      * @var integer 
  496.      */
  497.     var $_inclusion_depth      0;
  498.  
  499.     /**
  500.      * for different compiled templates
  501.      *
  502.      * @var string 
  503.      */
  504.     var $_compile_id           null;
  505.  
  506.     /**
  507.      * text in URL to enable debug mode
  508.      *
  509.      * @var string 
  510.      */
  511.     var $_smarty_debug_id      'SMARTY_DEBUG';
  512.  
  513.     /**
  514.      * debugging information for debug console
  515.      *
  516.      * @var array 
  517.      */
  518.     var $_smarty_debug_info    array();
  519.  
  520.     /**
  521.      * info that makes up a cache file
  522.      *
  523.      * @var array 
  524.      */
  525.     var $_cache_info           array();
  526.  
  527.     /**
  528.      * default file permissions
  529.      *
  530.      * @var integer 
  531.      */
  532.     var $_file_perms           0644;
  533.  
  534.     /**
  535.      * default dir permissions
  536.      *
  537.      * @var integer 
  538.      */
  539.     var $_dir_perms               0771;
  540.  
  541.     /**
  542.      * registered objects
  543.      *
  544.      * @var array 
  545.      */
  546.     var $_reg_objects           array();
  547.  
  548.     /**
  549.      * table keeping track of plugins
  550.      *
  551.      * @var array 
  552.      */
  553.     var $_plugins              array(
  554.                                        'modifier'      => array(),
  555.                                        'function'      => array(),
  556.                                        'block'         => array(),
  557.                                        'compiler'      => array(),
  558.                                        'prefilter'     => array(),
  559.                                        'postfilter'    => array(),
  560.                                        'outputfilter'  => array(),
  561.                                        'resource'      => array(),
  562.                                        'insert'        => array());
  563.  
  564.  
  565.     /**
  566.      * cache serials
  567.      *
  568.      * @var array 
  569.      */
  570.     var $_cache_serials array();
  571.  
  572.     /**
  573.      * name of optional cache include file
  574.      *
  575.      * @var string 
  576.      */
  577.     var $_cache_include null;
  578.  
  579.     /**
  580.      * indicate if the current code is used in a compiled
  581.      * include
  582.      *
  583.      * @var string 
  584.      */
  585.     var $_cache_including false;
  586.  
  587.     /**#@-*/
  588.     /**
  589.      * The class constructor.
  590.      *
  591.      * @uses $global_assign uses {@link assign()} to assign each corresponding
  592.      *                       value from $GLOBALS to the template vars
  593.      */
  594.     function Smarty()
  595.     {
  596.         foreach ($this->global_assign as $key => $var_name{
  597.             if (is_array($var_name)) {
  598.                 foreach ($var_name as $var{
  599.                     if (isset($GLOBALS[$key][$var])) {
  600.                         $this->assign($var$GLOBALS[$key][$var]);
  601.                     else {
  602.                         $this->assign($var$this->undefined);
  603.                     }
  604.                 }
  605.             else {
  606.                 if (isset($GLOBALS[$var_name])) {
  607.                     $this->assign($var_name$GLOBALS[$var_name]);
  608.                 else {
  609.                     $this->assign($var_name$this->undefined);
  610.                 }
  611.             }
  612.         }
  613.     }
  614.  
  615.  
  616.     /**
  617.      * assigns values to template variables
  618.      *
  619.      * @param array|string$tpl_var the template variable name(s)
  620.      * @param mixed $value the value to assign
  621.      */
  622.     function assign($tpl_var$value null)
  623.     {
  624.         if (is_array($tpl_var)){
  625.             foreach ($tpl_var as $key => $val{
  626.                 if ($key != ''{
  627.                     $this->_tpl_vars[$key$val;
  628.                 }
  629.             }
  630.         else {
  631.             if ($tpl_var != '')
  632.                 $this->_tpl_vars[$tpl_var$value;
  633.         }
  634.     }
  635.  
  636.     /**
  637.      * assigns values to template variables by reference
  638.      *
  639.      * @param string $tpl_var the template variable name
  640.      * @param mixed $value the referenced value to assign
  641.      */
  642.     function assign_by_ref($tpl_var&$value)
  643.     {
  644.         if ($tpl_var != '')
  645.             $this->_tpl_vars[$tpl_var&$value;
  646.     }
  647.  
  648.     /**
  649.      * appends values to template variables
  650.      *
  651.      * @param array|string$tpl_var the template variable name(s)
  652.      * @param mixed $value the value to append
  653.      */
  654.     function append($tpl_var$value=null$merge=false)
  655.     {
  656.         if (is_array($tpl_var)) {
  657.             // $tpl_var is an array, ignore $value
  658.             foreach ($tpl_var as $_key => $_val{
  659.                 if ($_key != ''{
  660.                     if(!@is_array($this->_tpl_vars[$_key])) {
  661.                         settype($this->_tpl_vars[$_key],'array');
  662.                     }
  663.                     if($merge && is_array($_val)) {
  664.                         foreach($_val as $_mkey => $_mval{
  665.                             $this->_tpl_vars[$_key][$_mkey$_mval;
  666.                         }
  667.                     else {
  668.                         $this->_tpl_vars[$_key][$_val;
  669.                     }
  670.                 }
  671.             }
  672.         else {
  673.             if ($tpl_var != '' && isset($value)) {
  674.                 if(!@is_array($this->_tpl_vars[$tpl_var])) {
  675.                     settype($this->_tpl_vars[$tpl_var],'array');
  676.                 }
  677.                 if($merge && is_array($value)) {
  678.                     foreach($value as $_mkey => $_mval{
  679.                         $this->_tpl_vars[$tpl_var][$_mkey$_mval;
  680.                     }
  681.                 else {
  682.                     $this->_tpl_vars[$tpl_var][$value;
  683.                 }
  684.             }
  685.         }
  686.     }
  687.  
  688.     /**
  689.      * appends values to template variables by reference
  690.      *
  691.      * @param string $tpl_var the template variable name
  692.      * @param mixed $value the referenced value to append
  693.      */
  694.     function append_by_ref($tpl_var&$value$merge=false)
  695.     {
  696.         if ($tpl_var != '' && isset($value)) {
  697.             if(!@is_array($this->_tpl_vars[$tpl_var])) {
  698.              settype($this->_tpl_vars[$tpl_var],'array');
  699.             }
  700.             if ($merge && is_array($value)) {
  701.                 foreach($value as $_key => $_val{
  702.                     $this->_tpl_vars[$tpl_var][$_key&$value[$_key];
  703.                 }
  704.             else {
  705.                 $this->_tpl_vars[$tpl_var][&$value;
  706.             }
  707.         }
  708.     }
  709.  
  710.  
  711.     /**
  712.      * clear the given assigned template variable.
  713.      *
  714.      * @param string $tpl_var the template variable to clear
  715.      */
  716.     function clear_assign($tpl_var)
  717.     {
  718.         if (is_array($tpl_var))
  719.             foreach ($tpl_var as $curr_var)
  720.                 unset($this->_tpl_vars[$curr_var]);
  721.         else
  722.             unset($this->_tpl_vars[$tpl_var]);
  723.     }
  724.  
  725.  
  726.     /**
  727.      * Registers custom function to be used in templates
  728.      *
  729.      * @param string $function the name of the template function
  730.      * @param string $function_impl the name of the PHP function to register
  731.      */
  732.     function register_function($function$function_impl$cacheable=true$cache_attrs=null)
  733.     {
  734.         $this->_plugins['function'][$function=
  735.             array($function_implnullnullfalse$cacheable$cache_attrs);
  736.  
  737.     }
  738.  
  739.     /**
  740.      * Unregisters custom function
  741.      *
  742.      * @param string $function name of template function
  743.      */
  744.     function unregister_function($function)
  745.     {
  746.         unset($this->_plugins['function'][$function]);
  747.     }
  748.  
  749.     /**
  750.      * Registers object to be used in templates
  751.      *
  752.      * @param string $object name of template object
  753.      * @param object &$object_impl the referenced PHP object to register
  754.      * @param null|array$allowed list of allowed methods (empty = all)
  755.      * @param boolean $smarty_args smarty argument format, else traditional
  756.      * @param null|array$block_functs list of methods that are block format
  757.      */
  758.     function register_object($object&$object_impl$allowed array()$smarty_args true$block_methods array())
  759.     {
  760.         settype($allowed'array');
  761.         settype($smarty_args'boolean');
  762.         $this->_reg_objects[$object=
  763.             array(&$object_impl$allowed$smarty_args$block_methods);
  764.     }
  765.  
  766.     /**
  767.      * Unregisters object
  768.      *
  769.      * @param string $object name of template object
  770.      */
  771.     function unregister_object($object)
  772.     {
  773.         unset($this->_reg_objects[$object]);
  774.     }
  775.  
  776.  
  777.     /**
  778.      * Registers block function to be used in templates
  779.      *
  780.      * @param string $block name of template block
  781.      * @param string $block_impl PHP function to register
  782.      */
  783.     function register_block($block$block_impl$cacheable=true$cache_attrs=null)
  784.     {
  785.         $this->_plugins['block'][$block=
  786.             array($block_implnullnullfalse$cacheable$cache_attrs);
  787.     }
  788.  
  789.     /**
  790.      * Unregisters block function
  791.      *
  792.      * @param string $block name of template function
  793.      */
  794.     function unregister_block($block)
  795.     {
  796.         unset($this->_plugins['block'][$block]);
  797.     }
  798.  
  799.     /**
  800.      * Registers compiler function
  801.      *
  802.      * @param string $function name of template function
  803.      * @param string $function_impl name of PHP function to register
  804.      */
  805.     function register_compiler_function($function$function_impl$cacheable=true)
  806.     {
  807.         $this->_plugins['compiler'][$function=
  808.             array($function_implnullnullfalse$cacheable);
  809.     }
  810.  
  811.     /**
  812.      * Unregisters compiler function
  813.      *
  814.      * @param string $function name of template function
  815.      */
  816.     function unregister_compiler_function($function)
  817.     {
  818.         unset($this->_plugins['compiler'][$function]);
  819.     }
  820.  
  821.     /**
  822.      * Registers modifier to be used in templates
  823.      *
  824.      * @param string $modifier name of template modifier
  825.      * @param string $modifier_impl name of PHP function to register
  826.      */
  827.     function register_modifier($modifier$modifier_impl)
  828.     {
  829.         $this->_plugins['modifier'][$modifier=
  830.             array($modifier_implnullnullfalse);
  831.     }
  832.  
  833.     /**
  834.      * Unregisters modifier
  835.      *
  836.      * @param string $modifier name of template modifier
  837.      */
  838.     function unregister_modifier($modifier)
  839.     {
  840.         unset($this->_plugins['modifier'][$modifier]);
  841.     }
  842.  
  843.     /**
  844.      * Registers a resource to fetch a template
  845.      *
  846.      * @param string $type name of resource
  847.      * @param array $functions array of functions to handle resource
  848.      */
  849.     function register_resource($type$functions)
  850.     {
  851.         if (count($functions)==4{
  852.             $this->_plugins['resource'][$type=
  853.                 array($functionsfalse);
  854.  
  855.         elseif (count($functions)==5{
  856.             $this->_plugins['resource'][$type=
  857.                 array(array(array(&$functions[0]$functions[1])
  858.                             ,array(&$functions[0]$functions[2])
  859.                             ,array(&$functions[0]$functions[3])
  860.                             ,array(&$functions[0]$functions[4]))
  861.                       ,false);
  862.  
  863.         else {
  864.             $this->trigger_error("malformed function-list for '$typein register_resource");
  865.  
  866.         }
  867.     }
  868.  
  869.     /**
  870.      * Unregisters a resource
  871.      *
  872.      * @param string $type name of resource
  873.      */
  874.     function unregister_resource($type)
  875.     {
  876.         unset($this->_plugins['resource'][$type]);
  877.     }
  878.  
  879.     /**
  880.      * Registers a prefilter function to apply
  881.      * to a template before compiling
  882.      *
  883.      * @param string $function name of PHP function to register
  884.      */
  885.     function register_prefilter($function)
  886.     {
  887.     $_name (is_array($function)) $function[1$function;
  888.         $this->_plugins['prefilter'][$_name]
  889.             = array($functionnullnullfalse);
  890.     }
  891.  
  892.     /**
  893.      * Unregisters a prefilter function
  894.      *
  895.      * @param string $function name of PHP function
  896.      */
  897.     function unregister_prefilter($function)
  898.     {
  899.         unset($this->_plugins['prefilter'][$function]);
  900.     }
  901.  
  902.     /**
  903.      * Registers a postfilter function to apply
  904.      * to a compiled template after compilation
  905.      *
  906.      * @param string $function name of PHP function to register
  907.      */
  908.     function register_postfilter($function)
  909.     {
  910.     $_name (is_array($function)) $function[1$function;
  911.         $this->_plugins['postfilter'][$_name]
  912.             = array($functionnullnullfalse);
  913.     }
  914.  
  915.     /**
  916.      * Unregisters a postfilter function
  917.      *
  918.      * @param string $function name of PHP function
  919.      */
  920.     function unregister_postfilter($function)
  921.     {
  922.         unset($this->_plugins['postfilter'][$function]);
  923.     }
  924.  
  925.     /**
  926.      * Registers an output filter function to apply
  927.      * to a template output
  928.      *
  929.      * @param string $function name of PHP function
  930.      */
  931.     function register_outputfilter($function)
  932.     {
  933.     $_name (is_array($function)) $function[1$function;
  934.         $this->_plugins['outputfilter'][$_name]
  935.             = array($functionnullnullfalse);
  936.     }
  937.  
  938.     /**
  939.      * Unregisters an outputfilter function
  940.      *
  941.      * @param string $function name of PHP function
  942.      */
  943.     function unregister_outputfilter($function)
  944.     {
  945.         unset($this->_plugins['outputfilter'][$function]);
  946.     }
  947.  
  948.     /**
  949.      * load a filter of specified type and name
  950.      *
  951.      * @param string $type filter type
  952.      * @param string $name filter name
  953.      */
  954.     function load_filter($type$name)
  955.     {
  956.         switch ($type{
  957.             case 'output':
  958.                 $_params array('plugins' => array(array($type 'filter'$namenullnullfalse)));
  959.                 require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.load_plugins.php');
  960.                 smarty_core_load_plugins($_params$this);
  961.                 break;
  962.  
  963.             case 'pre':
  964.             case 'post':
  965.                 if (!isset($this->_plugins[$type 'filter'][$name]))
  966.                     $this->_plugins[$type 'filter'][$namefalse;
  967.                 break;
  968.         }
  969.     }
  970.  
  971.     /**
  972.      * clear cached content for the given template and cache id
  973.      *
  974.      * @param string $tpl_file name of template file
  975.      * @param string $cache_id name of cache_id
  976.      * @param string $compile_id name of compile_id
  977.      * @param string $exp_time expiration time
  978.      * @return boolean 
  979.      */
  980.     function clear_cache($tpl_file null$cache_id null$compile_id null$exp_time null)
  981.     {
  982.  
  983.         if (!isset($compile_id))
  984.             $compile_id $this->compile_id;
  985.  
  986.     if (!isset($tpl_file))
  987.         $compile_id null;
  988.  
  989.     $_auto_id $this->_get_auto_id($cache_id$compile_id);
  990.  
  991.         if (!empty($this->cache_handler_func)) {
  992.             return call_user_func_array($this->cache_handler_func,
  993.                                   array('clear'&$this&$dummy$tpl_file$cache_id$compile_id$exp_time));
  994.         else {
  995.             $_params array('auto_base' => $this->cache_dir,
  996.                             'auto_source' => $tpl_file,
  997.                             'auto_id' => $_auto_id,
  998.                             'exp_time' => $exp_time);
  999.             require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.rm_auto.php');
  1000.             return smarty_core_rm_auto($_params$this);
  1001.         }
  1002.  
  1003.     }
  1004.  
  1005.  
  1006.     /**
  1007.      * clear the entire contents of cache (all templates)
  1008.      *
  1009.      * @param string $exp_time expire time
  1010.      * @return boolean results of {@link smarty_core_rm_auto()}
  1011.      */
  1012.     function clear_all_cache($exp_time null)
  1013.     {
  1014.         if (!empty($this->cache_handler_func)) {
  1015.             $dummy null;
  1016.             call_user_func_array($this->cache_handler_func,
  1017.                            array('clear'&$this&$dummynullnullnull$exp_time));
  1018.         else {
  1019.             $_params array('auto_base' => $this->cache_dir,
  1020.                             'auto_source' => null,
  1021.                             'auto_id' => null,
  1022.                             'exp_time' => $exp_time);
  1023.             require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.rm_auto.php');
  1024.             return smarty_core_rm_auto($_params$this);
  1025.         }
  1026.     }
  1027.  
  1028.  
  1029.     /**
  1030.      * test to see if valid cache exists for this template
  1031.      *
  1032.      * @param string $tpl_file name of template file
  1033.      * @param string $cache_id 
  1034.      * @param string $compile_id 
  1035.      * @return string|falseresults of {@link _read_cache_file()}
  1036.      */
  1037.     function is_cached($tpl_file$cache_id null$compile_id null)
  1038.     {
  1039.         if (!$this->caching)
  1040.             return false;
  1041.  
  1042.         if (!isset($compile_id))
  1043.             $compile_id $this->compile_id;
  1044.  
  1045.         $_params array(
  1046.             'tpl_file' => $tpl_file,
  1047.             'cache_id' => $cache_id,
  1048.             'compile_id' => $compile_id
  1049.         );
  1050.         require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.read_cache_file.php');
  1051.         return smarty_core_read_cache_file($_params$this);
  1052.     }
  1053.  
  1054.  
  1055.     /**
  1056.      * clear all the assigned template variables.
  1057.      *
  1058.      */
  1059.     function clear_all_assign()
  1060.     {
  1061.         $this->_tpl_vars array();
  1062.     }
  1063.  
  1064.     /**
  1065.      * clears compiled version of specified template resource,
  1066.      * or all compiled template files if one is not specified.
  1067.      * This function is for advanced use only, not normally needed.
  1068.      *
  1069.      * @param string $tpl_file 
  1070.      * @param string $compile_id 
  1071.      * @param string $exp_time 
  1072.      * @return boolean results of {@link smarty_core_rm_auto()}
  1073.      */
  1074.     function clear_compiled_tpl($tpl_file null$compile_id null$exp_time null)
  1075.     {
  1076.         if (!isset($compile_id)) {
  1077.             $compile_id $this->compile_id;
  1078.         }
  1079.         $_params array('auto_base' => $this->compile_dir,
  1080.                         'auto_source' => $tpl_file,
  1081.                         'auto_id' => $compile_id,
  1082.                         'exp_time' => $exp_time,
  1083.                         'extensions' => array('.inc''.php'));
  1084.         require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.rm_auto.php');
  1085.         return smarty_core_rm_auto($_params$this);
  1086.     }
  1087.  
  1088.     /**
  1089.      * Checks whether requested template exists.
  1090.      *
  1091.      * @param string $tpl_file 
  1092.      * @return boolean 
  1093.      */
  1094.     function template_exists($tpl_file)
  1095.     {
  1096.         $_params array('resource_name' => $tpl_file'quiet'=>true'get_source'=>false);
  1097.         return $this->_fetch_resource_info($_params);
  1098.     }
  1099.  
  1100.     /**
  1101.      * Returns an array containing template variables
  1102.      *
  1103.      * @param string $name 
  1104.      * @param string $type 
  1105.      * @return array 
  1106.      */
  1107.     function &get_template_vars($name=null)
  1108.     {
  1109.         if(!isset($name)) {
  1110.             return $this->_tpl_vars;
  1111.         }
  1112.         if(isset($this->_tpl_vars[$name])) {
  1113.             return $this->_tpl_vars[$name];
  1114.         }
  1115.     }
  1116.  
  1117.     /**
  1118.      * Returns an array containing config variables
  1119.      *
  1120.      * @param string $name 
  1121.      * @param string $type 
  1122.      * @return array 
  1123.      */
  1124.     function &get_config_vars($name=null)
  1125.     {
  1126.         if(!isset($name&& is_array($this->_config[0])) {
  1127.             return $this->_config[0]['vars'];
  1128.         else if(isset($this->_config[0]['vars'][$name])) {
  1129.             return $this->_config[0]['vars'][$name];
  1130.         }
  1131.     }
  1132.  
  1133.     /**
  1134.      * trigger Smarty error
  1135.      *
  1136.      * @param string $error_msg 
  1137.      * @param integer $error_type 
  1138.      */
  1139.     function trigger_error($error_msg$error_type E_USER_WARNING)
  1140.     {
  1141.         trigger_error("Smarty error$error_msg"$error_type);
  1142.     }
  1143.  
  1144.  
  1145.     /**
  1146.      * executes & displays the template results
  1147.      *
  1148.      * @param string $resource_name 
  1149.      * @param string $cache_id 
  1150.      * @param string $compile_id 
  1151.      */
  1152.     function display($resource_name$cache_id null$compile_id null)
  1153.     {
  1154.         $this->fetch($resource_name$cache_id$compile_idtrue);
  1155.     }
  1156.  
  1157.     /**
  1158.      * executes & returns or displays the template results
  1159.      *
  1160.      * @param string $resource_name 
  1161.      * @param string $cache_id 
  1162.      * @param string $compile_id 
  1163.      * @param boolean $display 
  1164.      */
  1165.     function fetch($resource_name$cache_id null$compile_id null$display false)
  1166.     {
  1167.         static $_cache_info array();
  1168.  
  1169.         $_smarty_old_error_level $this->debugging error_reporting(error_reporting(error_reporting(~E_NOTICE);
  1170.  
  1171.         if (!$this->debugging && $this->debugging_ctrl == 'URL'
  1172.                && @strstr($GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING']$this->_smarty_debug_id)) {
  1173.             // enable debugging from URL
  1174.                         $this->debugging true;
  1175.         }
  1176.  
  1177.         if ($this->debugging{
  1178.             // capture time for debugging info
  1179.                         $_params array();
  1180.             require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.get_microtime.php');
  1181.             $_debug_start_time smarty_core_get_microtime($_params$this);
  1182.             $this->_smarty_debug_info[array('type'      => 'template',
  1183.                                                 'filename'  => $resource_name,
  1184.                                                 'depth'     => 0);
  1185.             $_included_tpls_idx count($this->_smarty_debug_info1;
  1186.         }
  1187.  
  1188.         if (!isset($compile_id)) {
  1189.             $compile_id $this->compile_id;
  1190.         }
  1191.  
  1192.         $this->_compile_id $compile_id;
  1193.         $this->_inclusion_depth 0;
  1194.  
  1195.         if ($this->caching{
  1196.             // save old cache_info, initialize cache_info
  1197.                         array_push($_cache_info$this->_cache_info);
  1198.             $this->_cache_info array();
  1199.             $_params array(
  1200.                 'tpl_file' => $resource_name,
  1201.                 'cache_id' => $cache_id,
  1202.                 'compile_id' => $compile_id,
  1203.                 'results' => null
  1204.             );
  1205.             require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.read_cache_file.php');
  1206.             if (smarty_core_read_cache_file($_params$this)) {
  1207.                 $_smarty_results $_params['results'];
  1208.                 if (@count($this->_cache_info['insert_tags'])) {
  1209.                     $_params array('plugins' => $this->_cache_info['insert_tags']);
  1210.                     require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.load_plugins.php');
  1211.                     smarty_core_load_plugins($_params$this);
  1212.                     $_params array('results' => $_smarty_results);
  1213.                     require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.process_cached_inserts.php');
  1214.                     $_smarty_results smarty_core_process_cached_inserts($_params$this);
  1215.                 }
  1216.                 if (@count($this->_cache_info['cache_serials'])) {
  1217.                     $_params array('results' => $_smarty_results);
  1218.                     require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.process_compiled_include.php');
  1219.                     $_smarty_results smarty_core_process_compiled_include($_params$this);
  1220.                 }
  1221.  
  1222.  
  1223.                 if ($display{
  1224.                     if ($this->debugging)
  1225.                     {
  1226.                         // capture time for debugging info
  1227.                                                 $_params array();
  1228.                         require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.get_microtime.php');
  1229.                         $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'smarty_core_get_microtime($_params$this$_debug_start_time;
  1230.                         require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.display_debug_console.php');
  1231.                         $_smarty_results .= smarty_core_display_debug_console($_params$this);
  1232.                     }
  1233.                     if ($this->cache_modified_check{
  1234.                         $_last_modified_date @substr($GLOBALS['HTTP_SERVER_VARS']['HTTP_IF_MODIFIED_SINCE']0strpos($GLOBALS['HTTP_SERVER_VARS']['HTTP_IF_MODIFIED_SINCE']'GMT'3);
  1235.                         $_gmt_mtime gmdate('D, d M Y H:i:s'$this->_cache_info['timestamp']).' GMT';
  1236.                         if (@count($this->_cache_info['insert_tags']== 0
  1237.                             && !$this->_cache_serials
  1238.                             && $_gmt_mtime == $_last_modified_date{
  1239.                             if (php_sapi_name()=='cgi')
  1240.                                 header("Status: 304 Not Modified");
  1241.                             else
  1242.                                 header("HTTP/1.1 304 Not Modified");
  1243.  
  1244.                         else {
  1245.                             header("Last-Modified: ".$_gmt_mtime);
  1246.                             echo $_smarty_results;
  1247.                         }
  1248.                     else {
  1249.                             echo $_smarty_results;
  1250.                     }
  1251.                     error_reporting($_smarty_old_error_level);
  1252.                     // restore initial cache_info
  1253.                                         $this->_cache_info array_pop($_cache_info);
  1254.                     return true;
  1255.                 else {
  1256.                     error_reporting($_smarty_old_error_level);
  1257.                     // restore initial cache_info
  1258.                                         $this->_cache_info array_pop($_cache_info);
  1259.                     return $_smarty_results;
  1260.                 }
  1261.             else {
  1262.                 $this->_cache_info['template'][$resource_nametrue;
  1263.                 if ($this->cache_modified_check{
  1264.                     header("Last-Modified: ".gmdate('D, d M Y H:i:s'time()).' GMT');
  1265.                 }
  1266.             }
  1267.         }
  1268.  
  1269.         // load filters that are marked as autoload
  1270.                 if (count($this->autoload_filters)) {
  1271.             foreach ($this->autoload_filters as $_filter_type => $_filters{
  1272.                 foreach ($_filters as $_filter{
  1273.                     $this->load_filter($_filter_type$_filter);
  1274.                 }
  1275.             }
  1276.         }
  1277.  
  1278.         $_smarty_compile_path $this->_get_compile_path($resource_name);
  1279.  
  1280.         // if we just need to display the results, don't perform output
  1281.         // buffering - for speed
  1282.                 $_cache_including $this->_cache_including;
  1283.         $this->_cache_including false;
  1284.         if ($display && !$this->caching && count($this->_plugins['outputfilter']== 0{
  1285.             if ($this->_is_compiled($resource_name$_smarty_compile_path)
  1286.                     || $this->_compile_resource($resource_name$_smarty_compile_path))
  1287.             {
  1288.                 include($_smarty_compile_path);
  1289.             }
  1290.         else {
  1291.             ob_start();
  1292.             if ($this->_is_compiled($resource_name$_smarty_compile_path)
  1293.                     || $this->_compile_resource($resource_name$_smarty_compile_path))
  1294.             {
  1295.                 include($_smarty_compile_path);
  1296.             }
  1297.             $_smarty_results ob_get_contents();
  1298.             ob_end_clean();
  1299.  
  1300.             foreach ((array)$this->_plugins['outputfilter'as $_output_filter{
  1301.                 $_smarty_results call_user_func_array($_output_filter[0]array($_smarty_results&$this));
  1302.             }
  1303.         }
  1304.  
  1305.         if ($this->caching{
  1306.             $_params array('tpl_file' => $resource_name,
  1307.                         'cache_id' => $cache_id,
  1308.                         'compile_id' => $compile_id,
  1309.                         'results' => $_smarty_results);
  1310.             require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.write_cache_file.php');
  1311.             smarty_core_write_cache_file($_params$this);
  1312.             require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.process_cached_inserts.php');
  1313.             $_smarty_results smarty_core_process_cached_inserts($_params$this);
  1314.  
  1315.             if ($this->_cache_serials{
  1316.                 // strip nocache-tags from output
  1317.                                 $_smarty_results preg_replace('!(\{/?nocache\:[0-9a-f]{32}#\d+\})!s'
  1318.                                                 ,''
  1319.                                                 ,$_smarty_results);
  1320.             }
  1321.             // restore initial cache_info
  1322.                         $this->_cache_info array_pop($_cache_info);
  1323.         }
  1324.         $this->_cache_including $_cache_including;
  1325.  
  1326.         if ($display{
  1327.             if (isset($_smarty_results)) echo $_smarty_results}
  1328.             if ($this->debugging{
  1329.                 // capture time for debugging info
  1330.                                 $_params array();
  1331.                 require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.get_microtime.php');
  1332.                 $this->_smarty_debug_info[$_included_tpls_idx]['exec_time'(smarty_core_get_microtime($_params$this$_debug_start_time);
  1333.                 require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.display_debug_console.php');
  1334.                 echo smarty_core_display_debug_console($_params$this);
  1335.             }
  1336.             error_reporting($_smarty_old_error_level);
  1337.             return;
  1338.         else {
  1339.             error_reporting($_smarty_old_error_level);
  1340.             if (isset($_smarty_results)) return $_smarty_results}
  1341.         }
  1342.     }
  1343.  
  1344.     /**
  1345.      * load configuration values
  1346.      *
  1347.      * @param string $file 
  1348.      * @param string $section 
  1349.      * @param string $scope 
  1350.      */
  1351.     function config_load($file$section null$scope 'global')
  1352.     {
  1353.         require_once($this->_get_plugin_filepath('function''config_load'));
  1354.         smarty_function_config_load(array('file' => $file'section' => $section'scope' => $scope)$this);
  1355.     }
  1356.  
  1357.     /**
  1358.      * return a reference to a registered object
  1359.      *
  1360.      * @param string $name 
  1361.      * @return object 
  1362.      */
  1363.     function &get_registered_object($name{
  1364.         if (!isset($this->_reg_objects[$name]))
  1365.         $this->_trigger_fatal_error("'$nameis not a registered object");
  1366.  
  1367.         if (!is_object($this->_reg_objects[$name][0]))
  1368.         $this->_trigger_fatal_error("registered '$nameis not an object");
  1369.  
  1370.         return $this->_reg_objects[$name][0];
  1371.     }
  1372.  
  1373.     /**
  1374.      * clear configuration values
  1375.      *
  1376.      * @param string $var 
  1377.      */
  1378.     function clear_config($var null)
  1379.     {
  1380.         if(!isset($var)) {
  1381.             // clear all values
  1382.             $this->_config array(array('vars'  => array(),
  1383.                                          'files' => array()));
  1384.         else {
  1385.             unset($this->_config[0]['vars'][$var]);
  1386.         }
  1387.     }
  1388.  
  1389.     /**
  1390.      * get filepath of requested plugin
  1391.      *
  1392.      * @param string $type 
  1393.      * @param string $name 
  1394.      * @return string|false
  1395.      */
  1396.     function _get_plugin_filepath($type$name)
  1397.     {
  1398.         $_params array('type' => $type'name' => $name);
  1399.         require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.assemble_plugin_filepath.php');
  1400.         return smarty_core_assemble_plugin_filepath($_params$this);
  1401.     }
  1402.  
  1403.    /**
  1404.      * test if resource needs compiling
  1405.      *
  1406.      * @param string $resource_name 
  1407.      * @param string $compile_path 
  1408.      * @return boolean 
  1409.      */
  1410.     function _is_compiled($resource_name$compile_path)
  1411.     {
  1412.         if (!$this->force_compile && file_exists($compile_path)) {
  1413.             if (!$this->compile_check{
  1414.                 // no need to check compiled file
  1415.                 return true;
  1416.             else {
  1417.                 // get file source and timestamp
  1418.                 $_params array('resource_name' => $resource_name'get_source'=>false);
  1419.                 if (!$this->_fetch_resource_info($_params$this)) {
  1420.                     return false;
  1421.                 }
  1422.                 if ($_params['resource_timestamp'<= filemtime($compile_path)) {
  1423.                     // template not expired, no recompile
  1424.                     return true;
  1425.                 else {
  1426.                     // compile template
  1427.                     return false;
  1428.                 }
  1429.             }
  1430.         else {
  1431.             // compiled template does not exist, or forced compile
  1432.             return false;
  1433.         }
  1434.     }
  1435.  
  1436.    /**
  1437.      * compile the template
  1438.      *
  1439.      * @param string $resource_name 
  1440.      * @param string $compile_path 
  1441.      * @return boolean 
  1442.      */
  1443.     function _compile_resource($resource_name$compile_path)
  1444.     {
  1445.  
  1446.         $_params array('resource_name' => $resource_name);
  1447.         if (!$this->_fetch_resource_info($_params)) {
  1448.             return false;
  1449.         }
  1450.  
  1451.         $_source_content $_params['source_content'];
  1452.         $_resource_timestamp $_params['resource_timestamp'];
  1453.         $_cache_include    substr($compile_path0-4).'.inc';
  1454.  
  1455.         if ($this->_compile_source($resource_name$_source_content$_compiled_content$_cache_include)) {
  1456.             // if a _cache_serial was set, we also have to write an include-file:
  1457.             if ($this->_cache_include_info{
  1458.                 require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.write_compiled_include.php');
  1459.                 smarty_core_write_compiled_include(array_merge($this->_cache_include_infoarray('compiled_content'=>$_compiled_content)),  $this);
  1460.             }
  1461.  
  1462.             $_params array('compile_path'=>$compile_path'compiled_content' => $_compiled_content'resource_timestamp' => $_resource_timestamp);
  1463.             require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.write_compiled_resource.php');
  1464.             smarty_core_write_compiled_resource($_params$this);
  1465.  
  1466.             return true;
  1467.         else {
  1468.             $this->trigger_error($smarty_compiler->_error_msg);
  1469.             return false;
  1470.         }
  1471.  
  1472.     }
  1473.  
  1474.    /**
  1475.      * compile the given source
  1476.      *
  1477.      * @param string $resource_name 
  1478.      * @param string $source_content 
  1479.      * @param string $compiled_content 
  1480.      * @return boolean 
  1481.      */
  1482.     function _compile_source($resource_name&$source_content&$compiled_content$cache_include_path=null)
  1483.     {
  1484.         if (file_exists(SMARTY_DIR $this->compiler_file)) {
  1485.             require_once(SMARTY_DIR $this->compiler_file);
  1486.         else {
  1487.             // use include_path
  1488.             require_once($this->compiler_file);
  1489.         }
  1490.  
  1491.  
  1492.         $smarty_compiler new $this->compiler_class;
  1493.  
  1494.         $smarty_compiler->template_dir      $this->template_dir;
  1495.         $smarty_compiler->compile_dir       $this->compile_dir;
  1496.         $smarty_compiler->plugins_dir       $this->plugins_dir;
  1497.         $smarty_compiler->config_dir        $this->config_dir;
  1498.         $smarty_compiler->force_compile     $this->force_compile;
  1499.         $smarty_compiler->caching           $this->caching;
  1500.         $smarty_compiler->php_handling      $this->php_handling;
  1501.         $smarty_compiler->left_delimiter    $this->left_delimiter;
  1502.         $smarty_compiler->right_delimiter   $this->right_delimiter;
  1503.         $smarty_compiler->_version          $this->_version;
  1504.         $smarty_compiler->security          $this->security;
  1505.         $smarty_compiler->secure_dir        $this->secure_dir;
  1506.         $smarty_compiler->security_settings $this->security_settings;
  1507.         $smarty_compiler->trusted_dir       $this->trusted_dir;
  1508.         $smarty_compiler->_reg_objects      &$this->_reg_objects;
  1509.         $smarty_compiler->_plugins          &$this->_plugins;
  1510.         $smarty_compiler->_tpl_vars         &$this->_tpl_vars;
  1511.         $smarty_compiler->default_modifiers $this->default_modifiers;
  1512.         $smarty_compiler->compile_id        $this->_compile_id;
  1513.         $smarty_compiler->_config            $this->_config;
  1514.         $smarty_compiler->request_use_auto_globals  $this->request_use_auto_globals;
  1515.  
  1516.         $smarty_compiler->_cache_serial null;
  1517.         $smarty_compiler->_cache_include $cache_include_path;
  1518.  
  1519.  
  1520.         $_results $smarty_compiler->_compile_file($resource_name$source_content$compiled_content);
  1521.  
  1522.         if ($smarty_compiler->_cache_serial{
  1523.             $this->_cache_include_info array(
  1524.                 'cache_serial'=>$smarty_compiler->_cache_serial
  1525.                 ,'plugins_code'=>$smarty_compiler->_plugins_code
  1526.                 ,'include_file_path' => $cache_include_path);
  1527.  
  1528.         else {
  1529.             $this->_cache_include_info null;
  1530.  
  1531.         }
  1532.  
  1533.         return $_results;
  1534.     }
  1535.  
  1536.     /**
  1537.      * Get the compile path for this resource
  1538.      *
  1539.      * @param string $resource_name 
  1540.      * @return string results of {@link _get_auto_filename()}
  1541.      */
  1542.     function _get_compile_path($resource_name)
  1543.     {
  1544.         return $this->_get_auto_filename($this->compile_dir$resource_name,
  1545.                                          $this->_compile_id'.php';
  1546.     }
  1547.  
  1548.     /**
  1549.      * fetch the template info. Gets timestamp, and source
  1550.      * if get_source is true
  1551.      *
  1552.      * sets $source_content to the source of the template, and
  1553.      * $resource_timestamp to its time stamp
  1554.      * @param string $resource_name 
  1555.      * @param string $source_content 
  1556.      * @param integer $resource_timestamp 
  1557.      * @param boolean $get_source 
  1558.      * @param boolean $quiet 
  1559.      * @return boolean 
  1560.      */
  1561.  
  1562.     function _fetch_resource_info(&$params)
  1563.     {
  1564.         if(!isset($params['get_source'])) $params['get_source'true}
  1565.         if(!isset($params['quiet'])) $params['quiet'false}
  1566.  
  1567.         $_return false;
  1568.         $_params array('resource_name' => $params['resource_name'];
  1569.         if (isset($params['resource_base_path']))
  1570.             $_params['resource_base_path'$params['resource_base_path'];
  1571.  
  1572.         if ($this->_parse_resource_name($_params)) {
  1573.             $_resource_type $_params['resource_type'];
  1574.             $_resource_name $_params['resource_name'];
  1575.             switch ($_resource_type{
  1576.                 case 'file':
  1577.                     if ($params['get_source']{
  1578.                         $params['source_content'$this->_read_file($_resource_name);
  1579.                     }
  1580.                     $params['resource_timestamp'filemtime($_resource_name);
  1581.                     $_return is_file($_resource_name);
  1582.                     break;
  1583.  
  1584.                 default:
  1585.                     // call resource functions to fetch the template source and timestamp
  1586.                     if ($params['get_source']{
  1587.                         $_source_return = isset($this->_plugins['resource'][$_resource_type]&&
  1588.                             call_user_func_array($this->_plugins['resource'][$_resource_type][0][0],
  1589.                                                  array($_resource_name&$params['source_content']&$this));
  1590.                     else {
  1591.                         $_source_return true;
  1592.                     }
  1593.  
  1594.                     $_timestamp_return = isset($this->_plugins['resource'][$_resource_type]&&
  1595.                         call_user_func_array($this->_plugins['resource'][$_resource_type][0][1],
  1596.                                              array($_resource_name&$params['resource_timestamp']&$this));
  1597.  
  1598.                     $_return $_source_return && $_timestamp_return;
  1599.                     break;
  1600.             }
  1601.         }
  1602.  
  1603.         if (!$_return{
  1604.             // see if we can get a template with the default template handler
  1605.             if (!empty($this->default_template_handler_func)) {
  1606.                 if (!is_callable($this->default_template_handler_func)) {
  1607.                     $this->trigger_error("default template handler function \"$this->default_template_handler_func\" doesn't exist.");
  1608.                 else {
  1609.                     $_return call_user_func_array(
  1610.                         $this->default_template_handler_func,
  1611.                         array($_params['resource_type']$_params['resource_name']&$params['source_content']&$params['resource_timestamp']&$this));
  1612.                 }
  1613.             }
  1614.         }
  1615.  
  1616.         if (!$_return{
  1617.             if (!$params['quiet']{
  1618.                 $this->trigger_error('unable to read resource: "' $params['resource_name''"');
  1619.             }
  1620.         else if ($_return && $this->security{
  1621.             require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.is_secure.php');
  1622.             if (!smarty_core_is_secure($_params$this)) {
  1623.                 if (!$params['quiet'])
  1624.                     $this->trigger_error('(secure mode) accessing "' $params['resource_name''" is not allowed');
  1625.                 $params['source_content'null;
  1626.                 $params['resource_timestamp'null;
  1627.                 return false;
  1628.             }
  1629.         }
  1630.         return $_return;
  1631.     }
  1632.  
  1633.  
  1634.     /**
  1635.      * parse out the type and name from the resource
  1636.      *
  1637.      * @param string $resource_base_path 
  1638.      * @param string $resource_name 
  1639.      * @param string $resource_type 
  1640.      * @param string $resource_name 
  1641.      * @return boolean 
  1642.      */
  1643.  
  1644.     function _parse_resource_name(&$params)
  1645.     {
  1646.  
  1647.         // split tpl_path by the first colon
  1648.         $_resource_name_parts explode(':'$params['resource_name']2);
  1649.  
  1650.         if (count($_resource_name_parts== 1{
  1651.             // no resource type given
  1652.             $params['resource_type'$this->default_resource_type;
  1653.             $params['resource_name'$_resource_name_parts[0];
  1654.         else {
  1655.             if(strlen($_resource_name_parts[0]== 1{
  1656.                 // 1 char is not resource type, but part of filepath
  1657.                 $params['resource_type'$this->default_resource_type;
  1658.                 $params['resource_name'$params['resource_name'];
  1659.             else {
  1660.                 $params['resource_type'$_resource_name_parts[0];
  1661.                 $params['resource_name'$_resource_name_parts[1];
  1662.             }
  1663.         }
  1664.  
  1665.         if ($params['resource_type'== 'file'{
  1666.             if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/"$params['resource_name'])) {
  1667.                 // relative pathname to $params['resource_base_path']
  1668.                 // use the first directory where the file is found
  1669.                 if (isset($params['resource_base_path'])) {
  1670.                     $_resource_base_path = (array)$params['resource_base_path'];
  1671.                 else {
  1672.                     $_resource_base_path = (array)$this->template_dir;
  1673.                     $_resource_base_path['.';
  1674.                 }
  1675.                 foreach ($_resource_base_path as $_curr_path{
  1676.                     $_fullpath $_curr_path DIRECTORY_SEPARATOR $params['resource_name'];
  1677.                     if (file_exists($_fullpath&& is_file($_fullpath)) {
  1678.                         $params['resource_name'$_fullpath;
  1679.                         return true;
  1680.                     }
  1681.                     // didn't find the file, try include_path
  1682.                     $_params array('file_path' => $_fullpath);
  1683.                     require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.get_include_path.php');
  1684.                     if(smarty_core_get_include_path($_params$this)) {
  1685.                         $params['resource_name'$_params['new_file_path'];
  1686.                         return true;
  1687.                     }
  1688.                 }
  1689.                 return false;
  1690.             }
  1691.         elseif (empty($this->_plugins['resource'][$params['resource_type']])) {
  1692.             $_params array('type' => $params['resource_type']);
  1693.             require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.load_resource_plugin.php');
  1694.             smarty_core_load_resource_plugin($_params$this);
  1695.         }
  1696.  
  1697.         return true;
  1698.     }
  1699.  
  1700.  
  1701.     /**
  1702.      * Handle modifiers
  1703.      *
  1704.      * @param string|null$modifier_name 
  1705.      * @param array|null$map_array 
  1706.      * @return string result of modifiers
  1707.      */
  1708.     function _run_mod_handler()
  1709.     {
  1710.         $_args func_get_args();
  1711.         list($_modifier_name$_map_arrayarray_splice($_args02);
  1712.         list($_func_name$_tpl_file$_tpl_line=
  1713.             $this->_plugins['modifier'][$_modifier_name];
  1714.  
  1715.         $_var $_args[0];
  1716.         foreach ($_var as $_key => $_val{
  1717.             $_args[0$_val;
  1718.             $_var[$_keycall_user_func_array($_func_name$_args);
  1719.         }
  1720.         return $_var;
  1721.     }
  1722.  
  1723.     /**
  1724.      * Remove starting and ending quotes from the string
  1725.      *
  1726.      * @param string $string 
  1727.      * @return string 
  1728.      */
  1729.     function _dequote($string)
  1730.     {
  1731.         if (($string{0== "'" || $string{0== '"'&&
  1732.             $string{strlen($string)-1== $string{0})
  1733.             return substr($string1-1);
  1734.         else
  1735.             return $string;
  1736.     }
  1737.  
  1738.  
  1739.     /**
  1740.      * read in a file from line $start for $lines.
  1741.      * read the entire file if $start and $lines are null.
  1742.      *
  1743.      * @param string $filename 
  1744.      * @param integer $start 
  1745.      * @param integer $lines 
  1746.      * @return string 
  1747.      */
  1748.     function _read_file($filename$start=null$lines=null)
  1749.     {
  1750.         if (!($fd @fopen($filename'r'))) {
  1751.             return false;
  1752.         }
  1753.         flock($fdLOCK_SH);
  1754.         if ($start == null && $lines == null{
  1755.             // read the entire file
  1756.             $contents fread($fdfilesize($filename));
  1757.         else {
  1758.             if $start {
  1759.                 // skip the first lines before $start
  1760.                 for ($loop=1$loop $start$loop++{
  1761.                     fgets($fd65536);
  1762.                 }
  1763.             }
  1764.             if $lines == null {
  1765.                 // read the rest of the file
  1766.                 while (!feof($fd)) {
  1767.                     $contents .= fgets($fd65536);
  1768.                 }
  1769.             else {
  1770.                 // read up to $lines lines
  1771.                 for ($loop=0$loop $lines$loop++{
  1772.                     $contents .= fgets($fd65536);
  1773.                     if (feof($fd)) {
  1774.                         break;
  1775.                     }
  1776.                 }
  1777.             }
  1778.         }
  1779.         fclose($fd);
  1780.         return $contents;
  1781.     }
  1782.  
  1783.     /**
  1784.      * get a concrete filename for automagically created content
  1785.      *
  1786.      * @param string $auto_base 
  1787.      * @param string $auto_source 
  1788.      * @param string $auto_id 
  1789.      * @return string 
  1790.      * @staticvar string|null
  1791.      * @staticvar string|null
  1792.      */
  1793.     function _get_auto_filename($auto_base$auto_source null$auto_id null)
  1794.     {
  1795.         $_compile_dir_sep =  $this->use_sub_dirs DIRECTORY_SEPARATOR '^';
  1796.  
  1797.         if(@is_dir($auto_base)) {
  1798.             $_return $auto_base DIRECTORY_SEPARATOR;
  1799.         else {
  1800.             // auto_base not found, try include_path
  1801.             $_params array('file_path' => $auto_base);
  1802.             require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.get_include_path.php');
  1803.             smarty_core_get_include_path($_params$this);
  1804.             $_return = isset($_params['new_file_path']$_params['new_file_path'DIRECTORY_SEPARATOR null;
  1805.         }
  1806.  
  1807.         if(isset($auto_id)) {
  1808.             // make auto_id safe for directory names
  1809.             $auto_id str_replace('%7C',$_compile_dir_sep,(urlencode($auto_id)));
  1810.             // split into separate directories
  1811.             $_return .= $auto_id $_compile_dir_sep;
  1812.         }
  1813.  
  1814.         if(isset($auto_source)) {
  1815.             // make source name safe for filename
  1816.             $_filename urlencode(basename($auto_source));
  1817.             $_crc32 crc32($auto_source$_compile_dir_sep;
  1818.             // prepend %% to avoid name conflicts with
  1819.             // with $params['auto_id'] names
  1820.             $_crc32 '%%' substr($_crc32,0,3$_compile_dir_sep '%%' $_crc32;
  1821.             $_return .= $_crc32 $_filename;
  1822.         }
  1823.  
  1824.         return $_return;
  1825.     }
  1826.  
  1827.     /**
  1828.      * unlink a file, possibly using expiration time
  1829.      *
  1830.      * @param string $resource 
  1831.      * @param integer $exp_time 
  1832.      */
  1833.     function _unlink($resource$exp_time null)
  1834.     {
  1835.         if(isset($exp_time)) {
  1836.             if(time(@filemtime($resource>= $exp_time{
  1837.                 return @unlink($resource);
  1838.             }
  1839.         else {
  1840.             return @unlink($resource);
  1841.         }
  1842.     }
  1843.  
  1844.     /**
  1845.      * returns an auto_id for auto-file-functions
  1846.      *
  1847.      * @param string $cache_id 
  1848.      * @param string $compile_id 
  1849.      * @return string|null
  1850.      */
  1851.     function _get_auto_id($cache_id=null$compile_id=null{
  1852.     if (isset($cache_id))
  1853.         return (isset($compile_id)) $cache_id '|' $compile_id  $cache_id;
  1854.     elseif(isset($compile_id))
  1855.         return $compile_id;
  1856.     else
  1857.         return null;
  1858.     }
  1859.  
  1860.     /**
  1861.      * trigger Smarty plugin error
  1862.      *
  1863.      * @param string $error_msg 
  1864.      * @param string $tpl_file 
  1865.      * @param integer $tpl_line 
  1866.      * @param string $file 
  1867.      * @param integer $line 
  1868.      * @param integer $error_type 
  1869.      */
  1870.     function _trigger_fatal_error($error_msg$tpl_file null$tpl_line null,
  1871.             $file null$line null$error_type E_USER_ERROR)
  1872.     {
  1873.         if(isset($file&& isset($line)) {
  1874.             $info ' ('.basename($file)."line $line)";
  1875.         else {
  1876.             $info null;
  1877.         }
  1878.         if (isset($tpl_line&& isset($tpl_file)) {
  1879.             trigger_error("Smarty error: [in " $tpl_file " line " .
  1880.                           $tpl_line "]$error_msg$info"$error_type);
  1881.         else {
  1882.             trigger_error("Smarty error$error_msg$info"$error_type);
  1883.         }
  1884.     }
  1885.  
  1886.  
  1887.     /**
  1888.      * callback function for preg_replace, to call a non-cacheable block
  1889.      * @return string 
  1890.      */
  1891.     function _process_compiled_include_callback($match{
  1892.         $_func '_smarty_tplfunc_'.$match[2].'_'.$match[3];
  1893.         ob_start();
  1894.         $_func($this);
  1895.         $_ret ob_get_contents();
  1896.         ob_end_clean();
  1897.         return $_ret;
  1898.     }
  1899.  
  1900.  
  1901.     /**
  1902.      * called for included templates
  1903.      *
  1904.      * @param string $_smarty_include_tpl_file 
  1905.      * @param string $_smarty_include_vars 
  1906.      */
  1907.  
  1908.     // $_smarty_include_tpl_file, $_smarty_include_vars
  1909.  
  1910.     
  1911.     function _smarty_include($params)
  1912.     {
  1913.         if ($this->debugging{
  1914.             $_params array();
  1915.             require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.get_microtime.php');
  1916.             $debug_start_time smarty_core_get_microtime($_params$this);
  1917.             $this->_smarty_debug_info[array('type'      => 'template',
  1918.                                                   'filename'  => $params['smarty_include_tpl_file'],
  1919.                                                   'depth'     => ++$this->_inclusion_depth);
  1920.             $included_tpls_idx count($this->_smarty_debug_info1;
  1921.         }
  1922.  
  1923.         $this->_tpl_vars array_merge($this->_tpl_vars$params['smarty_include_vars']);
  1924.  
  1925.         // config vars are treated as local, so push a copy of the
  1926.         // current ones onto the front of the stack
  1927.         array_unshift($this->_config$this->_config[0]);
  1928.  
  1929.         $_smarty_compile_path $this->_get_compile_path($params['smarty_include_tpl_file']);
  1930.  
  1931.  
  1932.         if ($this->_is_compiled($params['smarty_include_tpl_file']$_smarty_compile_path)
  1933.             || $this->_compile_resource($params['smarty_include_tpl_file']$_smarty_compile_path))
  1934.         {
  1935.             include($_smarty_compile_path);
  1936.         }
  1937.  
  1938.         // pop the local vars off the front of the stack
  1939.         array_shift($this->_config);
  1940.  
  1941.         $this->_inclusion_depth--;
  1942.  
  1943.         if ($this->debugging{
  1944.             // capture time for debugging info
  1945.             $_params array();
  1946.             require_once(SMARTY_DIR 'core' DIRECTORY_SEPARATOR 'core.get_microtime.php');
  1947.             $this->_smarty_debug_info[$included_tpls_idx]['exec_time'smarty_core_get_microtime($_params$this$debug_start_time;
  1948.         }
  1949.  
  1950.         if ($this->caching{
  1951.             $this->_cache_info['template'][$params['smarty_include_tpl_file']] true;
  1952.         }
  1953.     }
  1954.  
  1955.  
  1956.     /**
  1957.      * get or set an array of cached attributes for function that is
  1958.      * not cacheable
  1959.      * @return array 
  1960.      */
  1961.     function &_smarty_cache_attrs($cache_serial$count{
  1962.         $_cache_attrs =$this->_cache_info['cache_attrs'][$cache_serial][$count];
  1963.  
  1964.         if ($this->_cache_including{
  1965.             /* return next set of cache_attrs */
  1966.             $_return =current($_cache_attrs);
  1967.             next($_cache_attrs);
  1968.             return $_return;
  1969.  
  1970.         else {
  1971.             /* add a reference to a new set of cache_attrs */
  1972.             $_cache_attrs[array();
  1973.             return $_cache_attrs[count($_cache_attrs)-1];
  1974.  
  1975.         }
  1976.  
  1977.     }
  1978.  
  1979.  
  1980.     /**
  1981.      * wrapper for include() retaining $this
  1982.      * @return mixed 
  1983.      */
  1984.     function _include($filename$once=false$params=null)
  1985.     {
  1986.         if ($once{
  1987.             return include_once($filename);
  1988.         else {
  1989.             return include($filename);
  1990.         }
  1991.     }
  1992.  
  1993.  
  1994.     /**
  1995.      * wrapper for eval() retaining $this
  1996.      * @return mixed 
  1997.      */
  1998.     function _eval($code$params=null)
  1999.     {
  2000.         return eval($code);
  2001.     }
  2002.     /**#@-*/
  2003.  
  2004. }
  2005.  
  2006. /* vim: set expandtab: */
  2007.  
  2008. ?>

Documentation generated on Tue, 24 Oct 2006 09:26:12 -0500 by phpDocumentor 1.3.1