/[cvs]/nfo/php/libs/net.php.smarty/Smarty.class.php
ViewVC logotype

Diff of /nfo/php/libs/net.php.smarty/Smarty.class.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed