Initial repo created
[timetracker.git] / WEB-INF / lib / smarty / Smarty.class.php
1 <?php
2
3 /**
4  * Project:     Smarty: the PHP compiling template engine
5  * File:        Smarty.class.php
6  * SVN:         $Id: Smarty.class.php 3895 2010-12-31 13:47:12Z uwe.tews@googlemail.com $
7  * 
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  * 
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  * 
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  * 
22  * For questions, help, comments, discussion, etc., please join the
23  * Smarty mailing list. Send a blank e-mail to
24  * smarty-discussion-subscribe@googlegroups.com
25  * 
26  * @link http://www.smarty.net/
27  * @copyright 2008 New Digital Group, Inc.
28  * @author Monte Ohrt <monte at ohrt dot com> 
29  * @author Uwe Tews 
30  * @package Smarty
31  * @version 3.0.7
32  */
33
34 /**
35  * define shorthand directory separator constant
36  */
37 if (!defined('DS')) {
38     define('DS', DIRECTORY_SEPARATOR);
39
40
41 /**
42  * set SMARTY_DIR to absolute path to Smarty library files.
43  * Sets SMARTY_DIR only if user application has not already defined it.
44  */
45 if (!defined('SMARTY_DIR')) {
46     define('SMARTY_DIR', dirname(__FILE__) . DS);
47
48
49 /**
50  * set SMARTY_SYSPLUGINS_DIR to absolute path to Smarty internal plugins.
51  * Sets SMARTY_SYSPLUGINS_DIR only if user application has not already defined it.
52  */
53 if (!defined('SMARTY_SYSPLUGINS_DIR')) {
54     define('SMARTY_SYSPLUGINS_DIR', SMARTY_DIR . 'sysplugins' . DS);
55
56 if (!defined('SMARTY_PLUGINS_DIR')) {
57     define('SMARTY_PLUGINS_DIR', SMARTY_DIR . 'plugins' . DS);
58
59 if (!defined('SMARTY_RESOURCE_CHAR_SET')) {
60     define('SMARTY_RESOURCE_CHAR_SET', 'UTF-8');
61
62 if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) {
63     define('SMARTY_RESOURCE_DATE_FORMAT', '%b %e, %Y');
64
65
66 /**
67  * register the class autoloader
68  */
69 if (!defined('SMARTY_SPL_AUTOLOAD')) {
70     define('SMARTY_SPL_AUTOLOAD', 0);
71
72
73 if (SMARTY_SPL_AUTOLOAD && set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false) {
74     $registeredAutoLoadFunctions = spl_autoload_functions();
75     if (!isset($registeredAutoLoadFunctions['spl_autoload'])) {
76         spl_autoload_register();
77     } 
78 } else {
79     spl_autoload_register('smartyAutoload');
80
81
82 /**
83  * This is the main Smarty class
84  */
85 class Smarty extends Smarty_Internal_Data {
86         /**
87         * constant definitions
88         */
89     // smarty version
90     const SMARTY_VERSION = 'Smarty-3.0.7'; 
91         //define variable scopes
92         const SCOPE_LOCAL = 0;
93         const SCOPE_PARENT = 1;
94         const SCOPE_ROOT = 2;
95         const SCOPE_GLOBAL = 3;
96         // define caching modes
97         const CACHING_OFF = 0;
98         const CACHING_LIFETIME_CURRENT = 1;
99         const CACHING_LIFETIME_SAVED = 2;
100         /** modes for handling of "<?php ... ?>" tags in templates. **/
101         const PHP_PASSTHRU = 0; //-> print tags as plain text
102         const PHP_QUOTE = 1; //-> escape tags as entities
103         const PHP_REMOVE = 2; //-> escape tags as entities
104         const PHP_ALLOW = 3; //-> escape tags as entities
105         // filter types
106         const FILTER_POST = 'post';
107         const FILTER_PRE = 'pre';
108         const FILTER_OUTPUT = 'output';
109         const FILTER_VARIABLE = 'variable';
110         // plugin types
111         const PLUGIN_FUNCTION = 'function';
112         const PLUGIN_BLOCK = 'block';
113         const PLUGIN_COMPILER = 'compiler';
114         const PLUGIN_MODIFIER = 'modifier';
115
116         /**
117         * static variables
118         */
119     // assigned global tpl vars
120     static $global_tpl_vars = array(); 
121
122         /**
123         * variables
124         */
125     // auto literal on delimiters with whitspace
126     public $auto_literal = true; 
127     // display error on not assigned variables
128     public $error_unassigned = false; 
129     // template directory
130     public $template_dir = null; 
131     // default template handler
132     public $default_template_handler_func = null; 
133     // compile directory
134     public $compile_dir = null; 
135     // plugins directory
136     public $plugins_dir = null; 
137     // cache directory
138     public $cache_dir = null; 
139     // config directory
140     public $config_dir = null; 
141     // force template compiling?
142     public $force_compile = false; 
143     // check template for modifications?
144     public $compile_check = true; 
145     // locking concurrent compiles
146     public $compile_locking = true; 
147     // use sub dirs for compiled/cached files?
148     public $use_sub_dirs = false; 
149     // compile_error?
150     public $compile_error = false; 
151     // caching enabled
152     public $caching = false; 
153     // merge compiled includes
154     public $merge_compiled_includes = false; 
155     // cache lifetime
156     public $cache_lifetime = 3600; 
157     // force cache file creation
158     public $force_cache = false; 
159     // cache_id
160     public $cache_id = null; 
161     // compile_id
162     public $compile_id = null; 
163     // template delimiters
164     public $left_delimiter = "{";
165     public $right_delimiter = "}"; 
166     // security
167     public $security_class = 'Smarty_Security';
168     public $security_policy = null;
169     public $php_handling = self::PHP_PASSTHRU;
170     public $allow_php_tag = false;
171     public $allow_php_templates = false;
172     public $direct_access_security = true; 
173     public $trusted_dir = array();
174     // debug mode
175     public $debugging = false;
176     public $debugging_ctrl = 'NONE';
177     public $smarty_debug_id = 'SMARTY_DEBUG';
178     public $debug_tpl = null; 
179     // When set, smarty does uses this value as error_reporting-level.
180     public $error_reporting = null; 
181     // config var settings
182     public $config_overwrite = true; //Controls whether variables with the same name overwrite each other.
183     public $config_booleanize = true; //Controls whether config values of on/true/yes and off/false/no get converted to boolean
184     public $config_read_hidden = false; //Controls whether hidden config sections/vars are read from the file.                                                      
185     // config vars
186     public $config_vars = array(); 
187     // assigned tpl vars
188     public $tpl_vars = array(); 
189     // dummy parent object
190     public $parent = null; 
191     // global template functions
192     public $template_functions = array(); 
193     // resource type used if none given
194     public $default_resource_type = 'file'; 
195     // caching type
196     public $caching_type = 'file'; 
197     // internal cache resource types
198     public $cache_resource_types = array('file'); 
199     // internal config properties
200     public $properties = array(); 
201     // config type
202     public $default_config_type = 'file'; 
203     // cached template objects
204     public $template_objects = null; 
205     // check If-Modified-Since headers
206     public $cache_modified_check = false; 
207     // registered plugins
208     public $registered_plugins = array(); 
209     // plugin search order
210     public $plugin_search_order = array('function', 'block', 'compiler', 'class'); 
211     // registered objects
212     public $registered_objects = array(); 
213     // registered classes
214     public $registered_classes = array(); 
215     // registered filters
216     public $registered_filters = array(); 
217     // registered resources
218     public $registered_resources = array(); 
219     // autoload filter
220     public $autoload_filters = array(); 
221     // status of filter on variable output
222     public $variable_filter = true; 
223     // default modifier
224     public $default_modifiers = array(); 
225     // global internal smarty  vars
226     static $_smarty_vars = array(); 
227     // start time for execution time calculation
228     public $start_time = 0; 
229     // default file permissions
230     public $_file_perms = 0644; 
231     // default dir permissions
232     public $_dir_perms = 0771; 
233     // block tag hierarchy
234     public $_tag_stack = array(); 
235     // flag if {block} tag is compiled for template inheritance
236     public $inheritance = false;
237     // generate deprecated function call notices?
238     public $deprecation_notices = true;
239     // Smarty 2 BC
240     public $_version = self::SMARTY_VERSION;
241     // self pointer to Smarty object
242     public $smarty;
243
244     /**
245      * Class constructor, initializes basic smarty properties
246      */
247     public function __construct()
248     { 
249                 // selfpointer need by some other class methods
250                 $this->smarty = $this;
251         if (is_callable('mb_internal_encoding')) {
252             mb_internal_encoding(SMARTY_RESOURCE_CHAR_SET);
253         } 
254         $this->start_time = microtime(true); 
255         // set default dirs
256         $this->template_dir = array('.' . DS . 'templates' . DS);
257         $this->compile_dir = '.' . DS . 'templates_c' . DS;
258         $this->plugins_dir = array(SMARTY_PLUGINS_DIR);
259         $this->cache_dir = '.' . DS . 'cache' . DS;
260         $this->config_dir = '.' . DS . 'configs' . DS;
261         $this->debug_tpl = SMARTY_DIR . 'debug.tpl';
262         if (isset($_SERVER['SCRIPT_NAME'])) {
263             $this->assignGlobal('SCRIPT_NAME', $_SERVER['SCRIPT_NAME']);
264         } 
265     } 
266
267     /**
268      * Class destructor
269      */
270     public function __destruct()
271     { 
272     } 
273
274     /**
275      * fetches a rendered Smarty template
276      * 
277      * @param string $template the resource handle of the template file or template object
278      * @param mixed $cache_id cache id to be used with this template
279      * @param mixed $compile_id compile id to be used with this template
280      * @param object $ |null $parent next higher level of Smarty variables
281      * @return string rendered template output
282      */
283     public function fetch($template, $cache_id = null, $compile_id = null, $parent = null, $display = false)
284     {
285         if (!empty($cache_id) && is_object($cache_id)) {
286             $parent = $cache_id;
287             $cache_id = null;
288         } 
289         if ($parent === null) {
290             // get default Smarty data object
291             $parent = $this;
292         } 
293         // create template object if necessary
294         ($template instanceof $this->template_class)? $_template = $template :
295         $_template = $this->createTemplate ($template, $cache_id, $compile_id, $parent, false);
296         if (isset($this->error_reporting)) {
297                 $_smarty_old_error_level = error_reporting($this->error_reporting);
298         }
299         // check URL debugging control
300         if (!$this->debugging && $this->debugging_ctrl == 'URL') {
301             if (isset($_SERVER['QUERY_STRING'])) {
302                 $_query_string = $_SERVER['QUERY_STRING'];
303             } else {
304                 $_query_string = '';
305             } 
306             if (false !== strpos($_query_string, $this->smarty_debug_id)) {
307                 if (false !== strpos($_query_string, $this->smarty_debug_id . '=on')) {
308                     // enable debugging for this browser session
309                     setcookie('SMARTY_DEBUG', true);
310                     $this->debugging = true;
311                 } elseif (false !== strpos($_query_string, $this->smarty_debug_id . '=off')) {
312                     // disable debugging for this browser session
313                     setcookie('SMARTY_DEBUG', false);
314                     $this->debugging = false;
315                 } else {
316                     // enable debugging for this page
317                     $this->debugging = true;
318                 } 
319             } else {
320                 if (isset($_COOKIE['SMARTY_DEBUG'])) {
321                     $this->debugging = true;
322                 } 
323             } 
324         } 
325         // obtain data for cache modified check
326         if ($this->cache_modified_check && $this->caching && $display) {
327             $_isCached = $_template->isCached() && !$_template->has_nocache_code;
328             if ($_isCached) {
329                 $_gmt_mtime = gmdate('D, d M Y H:i:s', $_template->getCachedTimestamp()) . ' GMT';
330             } else {
331                 $_gmt_mtime = '';
332             } 
333         } 
334         // return rendered template
335         if ((!$this->caching || $_template->resource_object->isEvaluated) && (isset($this->autoload_filters['output']) || isset($this->registered_filters['output']))) {
336             $_output = Smarty_Internal_Filter_Handler::runFilter('output', $_template->getRenderedTemplate(), $_template);
337         } else {
338             $_output = $_template->getRenderedTemplate();
339         } 
340         $_template->rendered_content = null;
341         if (isset($this->error_reporting)) {
342                 error_reporting($_smarty_old_error_level);
343         } 
344         // display or fetch
345         if ($display) {
346             if ($this->caching && $this->cache_modified_check) {
347                 $_last_modified_date = @substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3);
348                 if ($_isCached && $_gmt_mtime == $_last_modified_date) {
349                     if (php_sapi_name() == 'cgi')
350                         header('Status: 304 Not Modified');
351                     else
352                         header('HTTP/1.1 304 Not Modified');
353                 } else {
354                     header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->getCachedTimestamp()) . ' GMT');
355                     echo $_output;
356                 } 
357             } else {
358                 echo $_output;
359             } 
360             // debug output
361             if ($this->debugging) {
362                 Smarty_Internal_Debug::display_debug($this);
363             } 
364             return;
365         } else {
366             // return fetched content
367             return $_output;
368         } 
369     } 
370
371     /**
372      * displays a Smarty template
373      * 
374      * @param string $ |object $template the resource handle of the template file  or template object
375      * @param mixed $cache_id cache id to be used with this template
376      * @param mixed $compile_id compile id to be used with this template
377      * @param object $parent next higher level of Smarty variables
378      */
379     public function display($template, $cache_id = null, $compile_id = null, $parent = null)
380     { 
381         // display template
382         $this->fetch ($template, $cache_id, $compile_id, $parent, true);
383     } 
384
385     /**
386      * test if cache i valid
387      * 
388      * @param string $ |object $template the resource handle of the template file or template object
389      * @param mixed $cache_id cache id to be used with this template
390      * @param mixed $compile_id compile id to be used with this template
391      * @param object $parent next higher level of Smarty variables
392      * @return boolean cache status
393      */
394     public function isCached($template, $cache_id = null, $compile_id = null, $parent = null)
395     {
396         if ($parent === null) {
397                 $parent = $this;
398         }
399         if (!($template instanceof $this->template_class)) {
400             $template = $this->createTemplate ($template, $cache_id, $compile_id, $parent, false);
401         } 
402         // return cache status of template
403         return $template->isCached();
404     } 
405
406     /**
407      * creates a data object
408      * 
409      * @param object $parent next higher level of Smarty variables
410      * @returns object data object
411      */
412     public function createData($parent = null)
413     {
414         return new Smarty_Data($parent, $this);
415     } 
416
417     /**
418      * creates a template object
419      * 
420      * @param string $template the resource handle of the template file
421      * @param mixed $cache_id cache id to be used with this template
422      * @param mixed $compile_id compile id to be used with this template
423      * @param object $parent next higher level of Smarty variables
424      * @param boolean $do_clone flag is Smarty object shall be cloned
425      * @returns object template object
426      */
427     public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true)
428     {
429         if (!empty($cache_id) && (is_object($cache_id) || is_array($cache_id))) {
430             $parent = $cache_id;
431             $cache_id = null;
432         } 
433         if (!empty($parent) && is_array($parent)) {
434             $data = $parent;
435             $parent = null;
436         } else {
437             $data = null;
438         } 
439         if (!is_object($template)) {
440             // we got a template resource
441             // already in template cache?
442             $_templateId =  sha1($template . $cache_id . $compile_id);
443             if (isset($this->template_objects[$_templateId]) && $this->caching) {
444                 // return cached template object
445                 $tpl = $this->template_objects[$_templateId];
446             } else {
447                 // create new template object
448                 if ($do_clone) {
449                         $tpl = new $this->template_class($template, clone $this, $parent, $cache_id, $compile_id);
450                 } else {
451                         $tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id);
452                 }
453             } 
454         } else {
455             // just return a copy of template class
456             $tpl = $template;
457         } 
458         // fill data if present
459         if (!empty($data) && is_array($data)) {
460             // set up variable values
461             foreach ($data as $_key => $_val) {
462                 $tpl->tpl_vars[$_key] = new Smarty_variable($_val);
463             } 
464         } 
465         return $tpl;
466     } 
467     
468      
469
470     /**
471      * Check if a template resource exists
472      * 
473      * @param string $resource_name template name
474      * @return boolean status
475      */
476     function templateExists($resource_name)
477     { 
478         // create template object
479         $save = $this->template_objects;
480         $tpl = new $this->template_class($resource_name, $this); 
481         // check if it does exists
482         $result = $tpl->isExisting();
483         $this->template_objects = $save;
484         return $result;
485     } 
486
487     /**
488      * Returns a single or all global  variables
489      * 
490      * @param object $smarty 
491      * @param string $varname variable name or null
492      * @return string variable value or or array of variables
493      */
494     function getGlobal($varname = null)
495     {
496         if (isset($varname)) {
497             if (isset(self::$global_tpl_vars[$varname])) {
498                 return self::$global_tpl_vars[$varname]->value;
499             } else {
500                 return '';
501             } 
502         } else {
503             $_result = array();
504             foreach (self::$global_tpl_vars AS $key => $var) {
505                 $_result[$key] = $var->value;
506             } 
507             return $_result;
508         } 
509     } 
510
511     /**
512     * Empty cache folder
513     * 
514     * @param integer $exp_time expiration time
515     * @param string $type resource type
516     * @return integer number of cache files deleted
517     */
518     function clearAllCache($exp_time = null, $type = null)
519     { 
520        // load cache resource and call clearAll
521         return $this->loadCacheResource($type)->clearAll($exp_time);
522     }        
523
524     /**
525     * Empty cache for a specific template
526     * 
527     * @param string $template_name template name
528     * @param string $cache_id cache id
529     * @param string $compile_id compile id
530     * @param integer $exp_time expiration time
531     * @param string $type resource type
532     * @return integer number of cache files deleted
533     */
534     function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
535     { 
536        // load cache resource and call clear
537         return $this->loadCacheResource($type)->clear($template_name, $cache_id, $compile_id, $exp_time);
538     }
539
540     /**
541      * Loads security class and enables security
542      */
543     public function enableSecurity($security_class = null)
544     {
545         if ($security_class instanceof Smarty_Security) {
546                         $this->security_policy = $security_class;
547                         return;
548                 }
549         if ($security_class == null) {
550                 $security_class = $this->security_class;
551         }
552         if (class_exists($security_class)) {
553             $this->security_policy = new $security_class($this);
554         } else {
555             throw new SmartyException("Security class '$security_class' is not defined");
556         } 
557     } 
558
559     /**
560      * Disable security
561      */
562     public function disableSecurity()
563     {
564        $this->security_policy = null;
565     } 
566
567     /**
568     * Loads cache resource.
569     * 
570     * @param string $type cache resource type
571     * @return object of cache resource
572     */
573     public function loadCacheResource($type = null) {
574         if (!isset($type)) {
575             $type = $this->caching_type;
576         } 
577         if (in_array($type, $this->cache_resource_types)) {
578             $cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type);
579             return new $cache_resource_class($this);
580         } 
581         else {
582             // try plugins dir
583             $cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type);
584             if ($this->loadPlugin($cache_resource_class)) {
585                 return new $cache_resource_class($this);
586             } 
587             else {
588                 throw new SmartyException("Unable to load cache resource '{$type}'");
589             } 
590         } 
591     } 
592
593
594     /**
595      * Set template directory
596      * 
597      * @param string $ |array $template_dir folder(s) of template sorces
598      */
599     public function setTemplateDir($template_dir)
600     {
601         $this->template_dir = (array)$template_dir;
602         return;
603     } 
604
605     /**
606      * Adds template directory(s) to existing ones
607      * 
608      * @param string $ |array $template_dir folder(s) of template sources
609      */
610     public function addTemplateDir($template_dir)
611     {
612         $this->template_dir = array_unique(array_merge((array)$this->template_dir, (array)$template_dir));
613         return;
614     } 
615  
616     /**
617      * Adds directory of plugin files
618      * 
619      * @param object $smarty 
620      * @param string $ |array $ plugins folder
621      * @return 
622      */
623     function addPluginsDir($plugins_dir)
624     {
625         $this->plugins_dir = array_unique(array_merge((array)$this->plugins_dir, (array)$plugins_dir));
626         return;
627     } 
628
629
630     /**
631      * return a reference to a registered object
632      * 
633      * @param string $name object name
634      * @return object 
635      */
636     function getRegisteredObject($name)
637     {
638         if (!isset($this->registered_objects[$name]))
639             throw new SmartyException("'$name' is not a registered object");
640
641         if (!is_object($this->registered_objects[$name][0]))
642             throw new SmartyException("registered '$name' is not an object");
643
644         return $this->registered_objects[$name][0];
645     } 
646
647
648     /**
649      * return name of debugging template
650      * 
651      * @return string 
652      */
653     function getDebugTemplate()
654     {
655         return $this->debug_tpl;
656     } 
657
658     /**
659      * set the debug template
660      * 
661      * @param string $tpl_name 
662      * @return bool 
663      */
664     function setDebugTemplate($tpl_name)
665     {
666         return $this->debug_tpl = $tpl_name;
667     } 
668
669     /**
670      * Takes unknown classes and loads plugin files for them
671      * class name format: Smarty_PluginType_PluginName
672      * plugin filename format: plugintype.pluginname.php
673      * 
674      * @param string $plugin_name class plugin name to load
675      * @return string |boolean filepath of loaded file or false
676      */
677     public function loadPlugin($plugin_name, $check = true)
678     { 
679         // if function or class exists, exit silently (already loaded)
680         if ($check && (is_callable($plugin_name) || class_exists($plugin_name, false)))
681             return true; 
682         // Plugin name is expected to be: Smarty_[Type]_[Name]
683         $_plugin_name = strtolower($plugin_name);
684         $_name_parts = explode('_', $_plugin_name, 3); 
685         // class name must have three parts to be valid plugin
686         if (count($_name_parts) < 3 || $_name_parts[0] !== 'smarty') {
687             throw new SmartyException("plugin {$plugin_name} is not a valid name format");
688             return false;
689         } 
690         // if type is "internal", get plugin from sysplugins
691         if ($_name_parts[1] == 'internal') {
692             $file = SMARTY_SYSPLUGINS_DIR . $_plugin_name . '.php';
693             if (file_exists($file)) {
694                 require_once($file);
695                 return $file;
696             } else {
697                 return false;
698             } 
699         } 
700         // plugin filename is expected to be: [type].[name].php
701         $_plugin_filename = "{$_name_parts[1]}.{$_name_parts[2]}.php"; 
702         // loop through plugin dirs and find the plugin
703         foreach((array)$this->plugins_dir as $_plugin_dir) {
704             if (strpos('/\\', substr($_plugin_dir, -1)) === false) {
705                 $_plugin_dir .= DS;
706             } 
707             $file = $_plugin_dir . $_plugin_filename;
708             if (file_exists($file)) {
709                 require_once($file);
710                 return $file;
711             } 
712         } 
713         // no plugin loaded
714         return false;
715     } 
716
717     /**
718     * clean up properties on cloned object
719      */
720     public function __clone()
721     {
722         // clear config vars
723         $this->config_vars = array(); 
724         // clear assigned tpl vars
725         $this->tpl_vars = array();
726         // clear objects for external methods
727         unset($this->register);  
728         unset($this->filter);  
729         }
730
731
732     /**
733      * Handle unknown class methods
734          *
735      * @param string $name unknown methode name
736      * @param array $args aurgument array
737      */
738     public function __call($name, $args)
739     {
740         static $camel_func;
741         if (!isset($camel_func))
742             $camel_func = create_function('$c', 'return "_" . strtolower($c[1]);'); 
743         // see if this is a set/get for a property
744         $first3 = strtolower(substr($name, 0, 3));
745         if (in_array($first3, array('set', 'get')) && substr($name, 3, 1) !== '_') {
746             // try to keep case correct for future PHP 6.0 case-sensitive class methods
747             // lcfirst() not available < PHP 5.3.0, so improvise
748             $property_name = strtolower(substr($name, 3, 1)) . substr($name, 4); 
749             // convert camel case to underscored name
750             $property_name = preg_replace_callback('/([A-Z])/', $camel_func, $property_name);
751             if (!property_exists($this, $property_name)) {
752                 throw new SmartyException("property '$property_name' does not exist.");
753                 return false;
754             } 
755             if ($first3 == 'get')
756                 return $this->$property_name;
757             else
758                 return $this->$property_name = $args[0];
759         }
760        // Smarty Backward Compatible wrapper
761                 if (strpos($name,'_') !== false) {
762                 if (!isset($this->wrapper)) {
763                  $this->wrapper = new Smarty_Internal_Wrapper($this);
764                 } 
765                 return $this->wrapper->convert($name, $args);
766         }
767         // external Smarty methods ?
768         foreach(array('filter','register') as $external) {  
769                 if (method_exists("Smarty_Internal_{$external}",$name)) {
770                         if (!isset($this->$external)) {
771                                 $class = "Smarty_Internal_{$external}";
772                         $this->$external = new $class($this);
773                         } 
774                         return call_user_func_array(array($this->$external,$name), $args);
775                         }
776                 }
777                 if (in_array($name,array('clearCompiledTemplate','compileAllTemplates','compileAllConfig','testInstall','getTags'))) {
778                 if (!isset($this->utility)) {
779                 $this->utility = new Smarty_Internal_Utility($this);
780                 } 
781                 return call_user_func_array(array($this->utility,$name), $args);
782                 }
783          // PHP4 call to constructor?
784         if (strtolower($name) == 'smarty') {
785             throw new SmartyException('Please use parent::__construct() to call parent constuctor');
786             return false;
787         } 
788         throw new SmartyException("Call of unknown function '$name'.");
789    } 
790
791
792 /**
793  * Autoloader
794  */
795 function smartyAutoload($class)
796 {
797     $_class = strtolower($class);
798     if (substr($_class, 0, 16) === 'smarty_internal_' || $_class == 'smarty_security') {
799         include SMARTY_SYSPLUGINS_DIR . $_class . '.php';
800     } 
801
802
803 /**
804  * Smarty exception class
805  */
806 Class SmartyException extends Exception {
807 }
808
809 /**
810  * Smarty compiler exception class
811  */
812 Class SmartyCompilerException extends SmartyException  {
813 }
814
815 ?>