Code

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