Code

Readded smarty
[gosa.git] / gosa-core / include / smarty / sysplugins / smarty_internal_templatebase.php
diff --git a/gosa-core/include/smarty/sysplugins/smarty_internal_templatebase.php b/gosa-core/include/smarty/sysplugins/smarty_internal_templatebase.php
new file mode 100644 (file)
index 0000000..2471fc8
--- /dev/null
@@ -0,0 +1,760 @@
+<?php\r
+/**\r
+ * Smarty Internal Plugin Smarty Template  Base\r
+ *\r
+ * This file contains the basic shared methodes for template handling\r
+ *\r
+ * @package Smarty\r
+ * @subpackage Template\r
+ * @author Uwe Tews\r
+ */\r
+\r
+/**\r
+ * Class with shared template methodes\r
+ *\r
+ * @package Smarty\r
+ * @subpackage Template\r
+ */\r
+abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {\r
+\r
+    /**\r
+     * fetches a rendered Smarty template\r
+     *\r
+     * @param string $template          the resource handle of the template file or template object\r
+     * @param mixed  $cache_id          cache id to be used with this template\r
+     * @param mixed  $compile_id        compile id to be used with this template\r
+     * @param object $parent            next higher level of Smarty variables\r
+     * @param bool   $display           true: display, false: fetch\r
+     * @param bool   $merge_tpl_vars    if true parent template variables merged in to local scope\r
+     * @param bool   $no_output_filter  if true do not run output filter\r
+     * @return string rendered template output\r
+     */\r
+    public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null, $display = false, $merge_tpl_vars = true, $no_output_filter = false)\r
+    {\r
+        if ($template === null && $this instanceof $this->template_class) {\r
+            $template = $this;\r
+        }\r
+        if (!empty($cache_id) && is_object($cache_id)) {\r
+            $parent = $cache_id;\r
+            $cache_id = null;\r
+        }\r
+        if ($parent === null && ($this instanceof Smarty || is_string($template))) {\r
+            $parent = $this;\r
+        }\r
+        // create template object if necessary\r
+        $_template = ($template instanceof $this->template_class)\r
+            ? $template\r
+            : $this->smarty->createTemplate($template, $cache_id, $compile_id, $parent, false);\r
+        // if called by Smarty object make sure we use current caching status\r
+        if ($this instanceof Smarty) {\r
+            $_template->caching = $this->caching;\r
+        }\r
+        // merge all variable scopes into template\r
+        if ($merge_tpl_vars) {\r
+            // save local variables\r
+            $save_tpl_vars = $_template->tpl_vars;\r
+            $save_config_vars = $_template->config_vars;\r
+            $ptr_array = array($_template);\r
+            $ptr = $_template;\r
+            while (isset($ptr->parent)) {\r
+                $ptr_array[] = $ptr = $ptr->parent;\r
+            }\r
+            $ptr_array = array_reverse($ptr_array);\r
+            $parent_ptr = reset($ptr_array);\r
+            $tpl_vars = $parent_ptr->tpl_vars;\r
+            $config_vars = $parent_ptr->config_vars;\r
+            while ($parent_ptr = next($ptr_array)) {\r
+                if (!empty($parent_ptr->tpl_vars)) {\r
+                    $tpl_vars = array_merge($tpl_vars, $parent_ptr->tpl_vars);\r
+                }\r
+                if (!empty($parent_ptr->config_vars)) {\r
+                    $config_vars = array_merge($config_vars, $parent_ptr->config_vars);\r
+                }\r
+            }\r
+            if (!empty(Smarty::$global_tpl_vars)) {\r
+                $tpl_vars = array_merge(Smarty::$global_tpl_vars, $tpl_vars);\r
+            }\r
+            $_template->tpl_vars = $tpl_vars;\r
+            $_template->config_vars = $config_vars;\r
+        }\r
+        // dummy local smarty variable\r
+        if (!isset($_template->tpl_vars['smarty'])) {\r
+            $_template->tpl_vars['smarty'] = new Smarty_Variable;\r
+        }\r
+        if (isset($this->smarty->error_reporting)) {\r
+            $_smarty_old_error_level = error_reporting($this->smarty->error_reporting);\r
+        }\r
+        // check URL debugging control\r
+        if (!$this->smarty->debugging && $this->smarty->debugging_ctrl == 'URL') {\r
+            if (isset($_SERVER['QUERY_STRING'])) {\r
+                $_query_string = $_SERVER['QUERY_STRING'];\r
+            } else {\r
+                $_query_string = '';\r
+            }\r
+            if (false !== strpos($_query_string, $this->smarty->smarty_debug_id)) {\r
+                if (false !== strpos($_query_string, $this->smarty->smarty_debug_id . '=on')) {\r
+                    // enable debugging for this browser session\r
+                    setcookie('SMARTY_DEBUG', true);\r
+                    $this->smarty->debugging = true;\r
+                } elseif (false !== strpos($_query_string, $this->smarty->smarty_debug_id . '=off')) {\r
+                    // disable debugging for this browser session\r
+                    setcookie('SMARTY_DEBUG', false);\r
+                    $this->smarty->debugging = false;\r
+                } else {\r
+                    // enable debugging for this page\r
+                    $this->smarty->debugging = true;\r
+                }\r
+            } else {\r
+                if (isset($_COOKIE['SMARTY_DEBUG'])) {\r
+                    $this->smarty->debugging = true;\r
+                }\r
+            }\r
+        }\r
+        // must reset merge template date\r
+        $_template->smarty->merged_templates_func = array();\r
+        // get rendered template\r
+        // disable caching for evaluated code\r
+        if ($_template->source->recompiled) {\r
+            $_template->caching = false;\r
+        }\r
+        // checks if template exists\r
+        if (!$_template->source->exists) {\r
+            if ($_template->parent instanceof Smarty_Internal_Template) {\r
+                $parent_resource = " in '{$_template->parent->template_resource}'";\r
+            } else {\r
+                $parent_resource = '';\r
+            }\r
+            throw new SmartyException("Unable to load template {$_template->source->type} '{$_template->source->name}'{$parent_resource}");\r
+        }\r
+        // read from cache or render\r
+        if (!($_template->caching == Smarty::CACHING_LIFETIME_CURRENT || $_template->caching == Smarty::CACHING_LIFETIME_SAVED) || !$_template->cached->valid) {\r
+            // render template (not loaded and not in cache)\r
+            if (!$_template->source->uncompiled) {\r
+                $_smarty_tpl = $_template;\r
+                if ($_template->source->recompiled) {\r
+                    if ($this->smarty->debugging) {\r
+                        Smarty_Internal_Debug::start_compile($_template);\r
+                    }\r
+                    $code = $_template->compiler->compileTemplate($_template);\r
+                    if ($this->smarty->debugging) {\r
+                        Smarty_Internal_Debug::end_compile($_template);\r
+                    }\r
+                    if ($this->smarty->debugging) {\r
+                        Smarty_Internal_Debug::start_render($_template);\r
+                    }\r
+                    try {\r
+                        ob_start();\r
+                        eval("?>" . $code);\r
+                        unset($code);\r
+                    } catch (Exception $e) {\r
+                        ob_get_clean();\r
+                        throw $e;\r
+                    }\r
+                } else {\r
+                    if (!$_template->compiled->exists || ($_template->smarty->force_compile && !$_template->compiled->isCompiled)) {\r
+                        $_template->compileTemplateSource();\r
+                    }\r
+                    if ($this->smarty->debugging) {\r
+                        Smarty_Internal_Debug::start_render($_template);\r
+                    }\r
+                    if (!$_template->compiled->loaded) {\r
+                        include($_template->compiled->filepath);\r
+                        if ($_template->mustCompile) {\r
+                            // recompile and load again\r
+                            $_template->compileTemplateSource();\r
+                            include($_template->compiled->filepath);\r
+                        }\r
+                        $_template->compiled->loaded = true;\r
+                    } else {\r
+                        $_template->decodeProperties($_template->compiled->_properties, false);\r
+                    }\r
+                    try {\r
+                        ob_start();\r
+                        if (empty($_template->properties['unifunc']) || !is_callable($_template->properties['unifunc'])) {\r
+                            throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'");\r
+                        }\r
+                        $_template->properties['unifunc']($_template);\r
+                        if (isset($_template->_capture_stack[0])) {\r
+                            $_template->capture_error();\r
+                        }\r
+                    } catch (Exception $e) {\r
+                        ob_get_clean();\r
+                        throw $e;\r
+                    }\r
+                }\r
+            } else {\r
+                if ($_template->source->uncompiled) {\r
+                    if ($this->smarty->debugging) {\r
+                        Smarty_Internal_Debug::start_render($_template);\r
+                    }\r
+                    try {\r
+                        ob_start();\r
+                        $_template->source->renderUncompiled($_template);\r
+                    } catch (Exception $e) {\r
+                        ob_get_clean();\r
+                        throw $e;\r
+                    }\r
+                } else {\r
+                    throw new SmartyException("Resource '$_template->source->type' must have 'renderUncompiled' method");\r
+                }\r
+            }\r
+            $_output = ob_get_clean();\r
+            if (!$_template->source->recompiled && empty($_template->properties['file_dependency'][$_template->source->uid])) {\r
+                $_template->properties['file_dependency'][$_template->source->uid] = array($_template->source->filepath, $_template->source->timestamp, $_template->source->type);\r
+            }\r
+            if ($_template->parent instanceof Smarty_Internal_Template) {\r
+                $_template->parent->properties['file_dependency'] = array_merge($_template->parent->properties['file_dependency'], $_template->properties['file_dependency']);\r
+                foreach ($_template->required_plugins as $code => $tmp1) {\r
+                    foreach ($tmp1 as $name => $tmp) {\r
+                        foreach ($tmp as $type => $data) {\r
+                            $_template->parent->required_plugins[$code][$name][$type] = $data;\r
+                        }\r
+                    }\r
+                }\r
+            }\r
+            if ($this->smarty->debugging) {\r
+                Smarty_Internal_Debug::end_render($_template);\r
+            }\r
+            // write to cache when nessecary\r
+            if (!$_template->source->recompiled && ($_template->caching == Smarty::CACHING_LIFETIME_SAVED || $_template->caching == Smarty::CACHING_LIFETIME_CURRENT)) {\r
+                if ($this->smarty->debugging) {\r
+                    Smarty_Internal_Debug::start_cache($_template);\r
+                }\r
+                $_template->properties['has_nocache_code'] = false;\r
+                // get text between non-cached items\r
+                $cache_split = preg_split("!/\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*/!s", $_output);\r
+                // get non-cached items\r
+                preg_match_all("!/\*%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*\/(.+?)/\*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*/!s", $_output, $cache_parts);\r
+                $output = '';\r
+                // loop over items, stitch back together\r
+                foreach ($cache_split as $curr_idx => $curr_split) {\r
+                    // escape PHP tags in template content\r
+                    $output .= preg_replace('/(<%|%>|<\?php|<\?|\?>)/', '<?php echo \'$1\'; ?>', $curr_split);\r
+                    if (isset($cache_parts[0][$curr_idx])) {\r
+                        $_template->properties['has_nocache_code'] = true;\r
+                        // remove nocache tags from cache output\r
+                        $output .= preg_replace("!/\*/?%%SmartyNocache:{$_template->properties['nocache_hash']}%%\*/!", '', $cache_parts[0][$curr_idx]);\r
+                    }\r
+                }\r
+                if (!$no_output_filter && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) {\r
+                    $output = Smarty_Internal_Filter_Handler::runFilter('output', $output, $_template);\r
+                }\r
+                // rendering (must be done before writing cache file because of {function} nocache handling)\r
+                $_smarty_tpl = $_template;\r
+                try {\r
+                    ob_start();\r
+                    eval("?>" . $output);\r
+                    $_output = ob_get_clean();\r
+                } catch (Exception $e) {\r
+                    ob_get_clean();\r
+                    throw $e;\r
+                }\r
+                // write cache file content\r
+                $_template->writeCachedContent($output);\r
+                if ($this->smarty->debugging) {\r
+                    Smarty_Internal_Debug::end_cache($_template);\r
+                }\r
+            } else {\r
+                // var_dump('renderTemplate', $_template->has_nocache_code, $_template->template_resource, $_template->properties['nocache_hash'], $_template->parent->properties['nocache_hash'], $_output);\r
+                if (!empty($_template->properties['nocache_hash']) && !empty($_template->parent->properties['nocache_hash'])) {\r
+                    // replace nocache_hash\r
+                    $_output = preg_replace("/{$_template->properties['nocache_hash']}/", $_template->parent->properties['nocache_hash'], $_output);\r
+                    $_template->parent->has_nocache_code = $_template->parent->has_nocache_code || $_template->has_nocache_code;\r
+                }\r
+            }\r
+        } else {\r
+            if ($this->smarty->debugging) {\r
+                Smarty_Internal_Debug::start_cache($_template);\r
+            }\r
+            try {\r
+                ob_start();\r
+                $_template->properties['unifunc']($_template);\r
+                if (isset($_template->_capture_stack[0])) {\r
+                    $_template->capture_error();\r
+                }\r
+                $_output = ob_get_clean();\r
+            } catch (Exception $e) {\r
+                ob_get_clean();\r
+                throw $e;\r
+            }\r
+            if ($this->smarty->debugging) {\r
+                Smarty_Internal_Debug::end_cache($_template);\r
+            }\r
+        }\r
+        if ((!$this->caching || $_template->source->recompiled) && !$no_output_filter && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))) {\r
+            $_output = Smarty_Internal_Filter_Handler::runFilter('output', $_output, $_template);\r
+        }\r
+        if (isset($this->error_reporting)) {\r
+            error_reporting($_smarty_old_error_level);\r
+        }\r
+        // display or fetch\r
+        if ($display) {\r
+            if ($this->caching && $this->cache_modified_check) {\r
+                $_isCached = $_template->isCached() && !$_template->has_nocache_code;\r
+                $_last_modified_date = @substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3);\r
+                if ($_isCached && $_template->cached->timestamp <= strtotime($_last_modified_date)) {\r
+                    switch (PHP_SAPI) {\r
+                        case 'cgi':         // php-cgi < 5.3\r
+                        case 'cgi-fcgi':    // php-cgi >= 5.3\r
+                        case 'fpm-fcgi':    // php-fpm >= 5.3.3\r
+                            header('Status: 304 Not Modified');\r
+                            break;\r
+\r
+                        case 'cli':\r
+                            if (/* ^phpunit */!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'])/* phpunit$ */) {\r
+                                $_SERVER['SMARTY_PHPUNIT_HEADERS'][] = '304 Not Modified';\r
+                            }\r
+                            break;\r
+\r
+                        default:\r
+                            header('HTTP/1.1 304 Not Modified');\r
+                            break;\r
+                    }\r
+                } else {\r
+                    switch (PHP_SAPI) {\r
+                        case 'cli':\r
+                            if (/* ^phpunit */!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'])/* phpunit$ */) {\r
+                                $_SERVER['SMARTY_PHPUNIT_HEADERS'][] = 'Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT';\r
+                            }\r
+                            break;\r
+\r
+                        default:\r
+                            header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT');\r
+                            break;\r
+                    }\r
+                    echo $_output;\r
+                }\r
+            } else {\r
+                echo $_output;\r
+            }\r
+            // debug output\r
+            if ($this->smarty->debugging) {\r
+                Smarty_Internal_Debug::display_debug($this);\r
+            }\r
+            if ($merge_tpl_vars) {\r
+                // restore local variables\r
+                $_template->tpl_vars = $save_tpl_vars;\r
+                $_template->config_vars =  $save_config_vars;\r
+            }\r
+            return;\r
+        } else {\r
+            if ($merge_tpl_vars) {\r
+                // restore local variables\r
+                $_template->tpl_vars = $save_tpl_vars;\r
+                $_template->config_vars =  $save_config_vars;\r
+            }\r
+            // return fetched content\r
+            return $_output;\r
+        }\r
+    }\r
+\r
+    /**\r
+     * displays a Smarty template\r
+     *\r
+     * @param string $template   the resource handle of the template file or template object\r
+     * @param mixed  $cache_id   cache id to be used with this template\r
+     * @param mixed  $compile_id compile id to be used with this template\r
+     * @param object $parent     next higher level of Smarty variables\r
+     */\r
+    public function display($template = null, $cache_id = null, $compile_id = null, $parent = null)\r
+    {\r
+        // display template\r
+        $this->fetch($template, $cache_id, $compile_id, $parent, true);\r
+    }\r
+\r
+    /**\r
+     * test if cache is valid\r
+     *\r
+     * @param string|object $template   the resource handle of the template file or template object\r
+     * @param mixed         $cache_id   cache id to be used with this template\r
+     * @param mixed         $compile_id compile id to be used with this template\r
+     * @param object        $parent     next higher level of Smarty variables\r
+     * @return boolean cache status\r
+     */\r
+    public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null)\r
+    {\r
+        if ($template === null && $this instanceof $this->template_class) {\r
+            return $this->cached->valid;\r
+        }\r
+        if (!($template instanceof $this->template_class)) {\r
+            if ($parent === null) {\r
+                $parent = $this;\r
+            }\r
+            $template = $this->smarty->createTemplate($template, $cache_id, $compile_id, $parent, false);\r
+        }\r
+        // return cache status of template\r
+        return $template->cached->valid;\r
+    }\r
+\r
+    /**\r
+     * creates a data object\r
+     *\r
+     * @param object $parent next higher level of Smarty variables\r
+     * @returns Smarty_Data data object\r
+     */\r
+    public function createData($parent = null)\r
+    {\r
+        return new Smarty_Data($parent, $this);\r
+    }\r
+\r
+    /**\r
+     * Registers plugin to be used in templates\r
+     *\r
+     * @param string   $type       plugin type\r
+     * @param string   $tag        name of template tag\r
+     * @param callback $callback   PHP callback to register\r
+     * @param boolean  $cacheable  if true (default) this fuction is cachable\r
+     * @param array    $cache_attr caching attributes if any\r
+     * @throws SmartyException when the plugin tag is invalid\r
+     */\r
+    public function registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = null)\r
+    {\r
+        if (isset($this->smarty->registered_plugins[$type][$tag])) {\r
+            throw new SmartyException("Plugin tag \"{$tag}\" already registered");\r
+        } elseif (!is_callable($callback)) {\r
+            throw new SmartyException("Plugin \"{$tag}\" not callable");\r
+        } else {\r
+            $this->smarty->registered_plugins[$type][$tag] = array($callback, (bool) $cacheable, (array) $cache_attr);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Unregister Plugin\r
+     *\r
+     * @param string $type of plugin\r
+     * @param string $tag name of plugin\r
+     */\r
+    public function unregisterPlugin($type, $tag)\r
+    {\r
+        if (isset($this->smarty->registered_plugins[$type][$tag])) {\r
+            unset($this->smarty->registered_plugins[$type][$tag]);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Registers a resource to fetch a template\r
+     *\r
+     * @param string $type name of resource type\r
+     * @param Smarty_Resource|array $callback or instance of Smarty_Resource, or array of callbacks to handle resource (deprecated)\r
+     */\r
+    public function registerResource($type, $callback)\r
+    {\r
+        $this->smarty->registered_resources[$type] = $callback instanceof Smarty_Resource ? $callback : array($callback, false);\r
+    }\r
+\r
+    /**\r
+     * Unregisters a resource\r
+     *\r
+     * @param string $type name of resource type\r
+     */\r
+    public function unregisterResource($type)\r
+    {\r
+        if (isset($this->smarty->registered_resources[$type])) {\r
+            unset($this->smarty->registered_resources[$type]);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Registers a cache resource to cache a template's output\r
+     *\r
+     * @param string               $type     name of cache resource type\r
+     * @param Smarty_CacheResource $callback instance of Smarty_CacheResource to handle output caching\r
+     */\r
+    public function registerCacheResource($type, Smarty_CacheResource $callback)\r
+    {\r
+        $this->smarty->registered_cache_resources[$type] = $callback;\r
+    }\r
+\r
+    /**\r
+     * Unregisters a cache resource\r
+     *\r
+     * @param string $type name of cache resource type\r
+     */\r
+    public function unregisterCacheResource($type)\r
+    {\r
+        if (isset($this->smarty->registered_cache_resources[$type])) {\r
+            unset($this->smarty->registered_cache_resources[$type]);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Registers object to be used in templates\r
+     *\r
+     * @param string  $object        name of template object\r
+     * @param object  $object_impl   the referenced PHP object to register\r
+     * @param array   $allowed       list of allowed methods (empty = all)\r
+     * @param boolean $smarty_args   smarty argument format, else traditional\r
+     * @param array   $block_methods list of block-methods\r
+     * @param array $block_functs list of methods that are block format\r
+     * @throws SmartyException if any of the methods in $allowed or $block_methods are invalid\r
+     */\r
+    public function registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())\r
+    {\r
+        // test if allowed methodes callable\r
+        if (!empty($allowed)) {\r
+            foreach ((array) $allowed as $method) {\r
+                if (!is_callable(array($object_impl, $method))) {\r
+                    throw new SmartyException("Undefined method '$method' in registered object");\r
+                }\r
+            }\r
+        }\r
+        // test if block methodes callable\r
+        if (!empty($block_methods)) {\r
+            foreach ((array) $block_methods as $method) {\r
+                if (!is_callable(array($object_impl, $method))) {\r
+                    throw new SmartyException("Undefined method '$method' in registered object");\r
+                }\r
+            }\r
+        }\r
+        // register the object\r
+        $this->smarty->registered_objects[$object_name] =\r
+            array($object_impl, (array) $allowed, (boolean) $smarty_args, (array) $block_methods);\r
+    }\r
+\r
+    /**\r
+     * return a reference to a registered object\r
+     *\r
+     * @param string $name object name\r
+     * @return object\r
+     * @throws SmartyException if no such object is found\r
+     */\r
+    public function getRegisteredObject($name)\r
+    {\r
+        if (!isset($this->smarty->registered_objects[$name])) {\r
+            throw new SmartyException("'$name' is not a registered object");\r
+        }\r
+        if (!is_object($this->smarty->registered_objects[$name][0])) {\r
+            throw new SmartyException("registered '$name' is not an object");\r
+        }\r
+        return $this->smarty->registered_objects[$name][0];\r
+    }\r
+\r
+    /**\r
+     * unregister an object\r
+     *\r
+     * @param string $name object name\r
+     * @throws SmartyException if no such object is found\r
+     */\r
+    public function unregisterObject($name)\r
+    {\r
+        unset($this->smarty->registered_objects[$name]);\r
+        return;\r
+    }\r
+\r
+    /**\r
+     * Registers static classes to be used in templates\r
+     *\r
+     * @param string $class name of template class\r
+     * @param string $class_impl the referenced PHP class to register\r
+     * @throws SmartyException if $class_impl does not refer to an existing class\r
+     */\r
+    public function registerClass($class_name, $class_impl)\r
+    {\r
+        // test if exists\r
+        if (!class_exists($class_impl)) {\r
+            throw new SmartyException("Undefined class '$class_impl' in register template class");\r
+        }\r
+        // register the class\r
+        $this->smarty->registered_classes[$class_name] = $class_impl;\r
+    }\r
+\r
+    /**\r
+     * Registers a default plugin handler\r
+     *\r
+     * @param callable $callback class/method name\r
+     * @throws SmartyException if $callback is not callable\r
+     */\r
+    public function registerDefaultPluginHandler($callback)\r
+    {\r
+        if (is_callable($callback)) {\r
+            $this->smarty->default_plugin_handler_func = $callback;\r
+        } else {\r
+            throw new SmartyException("Default plugin handler '$callback' not callable");\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Registers a default template handler\r
+     *\r
+     * @param callable $callback class/method name\r
+     * @throws SmartyException if $callback is not callable\r
+     */\r
+    public function registerDefaultTemplateHandler($callback)\r
+    {\r
+        if (is_callable($callback)) {\r
+            $this->smarty->default_template_handler_func = $callback;\r
+        } else {\r
+            throw new SmartyException("Default template handler '$callback' not callable");\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Registers a default template handler\r
+     *\r
+     * @param callable $callback class/method name\r
+     * @throws SmartyException if $callback is not callable\r
+     */\r
+    public function registerDefaultConfigHandler($callback)\r
+    {\r
+        if (is_callable($callback)) {\r
+            $this->smarty->default_config_handler_func = $callback;\r
+        } else {\r
+            throw new SmartyException("Default config handler '$callback' not callable");\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Registers a filter function\r
+     *\r
+     * @param string $type filter type\r
+     * @param callback $callback\r
+     */\r
+    public function registerFilter($type, $callback)\r
+    {\r
+        $this->smarty->registered_filters[$type][$this->_get_filter_name($callback)] = $callback;\r
+    }\r
+\r
+    /**\r
+     * Unregisters a filter function\r
+     *\r
+     * @param string $type filter type\r
+     * @param callback $callback\r
+     */\r
+    public function unregisterFilter($type, $callback)\r
+    {\r
+        $name = $this->_get_filter_name($callback);\r
+        if (isset($this->smarty->registered_filters[$type][$name])) {\r
+            unset($this->smarty->registered_filters[$type][$name]);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Return internal filter name\r
+     *\r
+     * @param callback $function_name\r
+     */\r
+    public function _get_filter_name($function_name)\r
+    {\r
+        if (is_array($function_name)) {\r
+            $_class_name = (is_object($function_name[0]) ?\r
+                            get_class($function_name[0]) : $function_name[0]);\r
+            return $_class_name . '_' . $function_name[1];\r
+        } else {\r
+            return $function_name;\r
+        }\r
+    }\r
+\r
+    /**\r
+     * load a filter of specified type and name\r
+     *\r
+     * @param string $type filter type\r
+     * @param string $name filter name\r
+     * @return bool\r
+     */\r
+    public function loadFilter($type, $name)\r
+    {\r
+        $_plugin = "smarty_{$type}filter_{$name}";\r
+        $_filter_name = $_plugin;\r
+        if ($this->smarty->loadPlugin($_plugin)) {\r
+            if (class_exists($_plugin, false)) {\r
+                $_plugin = array($_plugin, 'execute');\r
+            }\r
+            if (is_callable($_plugin)) {\r
+                $this->smarty->registered_filters[$type][$_filter_name] = $_plugin;\r
+                return true;\r
+            }\r
+        }\r
+        throw new SmartyException("{$type}filter \"{$name}\" not callable");\r
+        return false;\r
+    }\r
+\r
+    /**\r
+     * unload a filter of specified type and name\r
+     *\r
+     * @param string $type filter type\r
+     * @param string $name filter name\r
+     * @return bool\r
+     */\r
+    public function unloadFilter($type, $name)\r
+    {\r
+        $_filter_name = "smarty_{$type}filter_{$name}";\r
+        if (isset($this->smarty->registered_filters[$type][$_filter_name])) {\r
+            unset ($this->smarty->registered_filters[$type][$_filter_name]);\r
+            return true;\r
+        } else {\r
+            return false;\r
+        }\r
+    }\r
+\r
+    /**\r
+     * preg_replace callback to convert camelcase getter/setter to underscore property names\r
+     *\r
+     * @param string $match match string\r
+     * @return string  replacemant\r
+     */\r
+    private function replaceCamelcase($match) {\r
+        return "_" . strtolower($match[1]);\r
+    }\r
+\r
+    /**\r
+     * Handle unknown class methods\r
+     *\r
+     * @param string $name unknown method-name\r
+     * @param array  $args argument array\r
+     */\r
+    public function __call($name, $args)\r
+    {\r
+        static $_prefixes = array('set' => true, 'get' => true);\r
+        static $_resolved_property_name = array();\r
+        static $_resolved_property_source = array();\r
+\r
+        // method of Smarty object?\r
+        if (method_exists($this->smarty, $name)) {\r
+            return call_user_func_array(array($this->smarty, $name), $args);\r
+        }\r
+        // see if this is a set/get for a property\r
+        $first3 = strtolower(substr($name, 0, 3));\r
+        if (isset($_prefixes[$first3]) && isset($name[3]) && $name[3] !== '_') {\r
+            if (isset($_resolved_property_name[$name])) {\r
+                $property_name = $_resolved_property_name[$name];\r
+            } else {\r
+                // try to keep case correct for future PHP 6.0 case-sensitive class methods\r
+                // lcfirst() not available < PHP 5.3.0, so improvise\r
+                $property_name = strtolower(substr($name, 3, 1)) . substr($name, 4);\r
+                // convert camel case to underscored name\r
+                $property_name = preg_replace_callback('/([A-Z])/', array($this,'replaceCamelcase'), $property_name);\r
+                $_resolved_property_name[$name] = $property_name;\r
+            }\r
+            if (isset($_resolved_property_source[$property_name])) {\r
+                $_is_this = $_resolved_property_source[$property_name];\r
+            } else {\r
+                $_is_this = null;\r
+                if (property_exists($this, $property_name)) {\r
+                    $_is_this = true;\r
+                } else if (property_exists($this->smarty, $property_name)) {\r
+                    $_is_this = false;\r
+                }\r
+                $_resolved_property_source[$property_name] = $_is_this;\r
+            }\r
+            if ($_is_this) {\r
+                if ($first3 == 'get')\r
+                    return $this->$property_name;\r
+                else\r
+                    return $this->$property_name = $args[0];\r
+            } else if ($_is_this === false) {\r
+                if ($first3 == 'get')\r
+                    return $this->smarty->$property_name;\r
+                else\r
+                    return $this->smarty->$property_name = $args[0];\r
+            } else {\r
+                throw new SmartyException("property '$property_name' does not exist.");\r
+                return false;\r
+            }\r
+        }\r
+        // must be unknown\r
+        throw new SmartyException("Call of unknown method '$name'.");\r
+    }\r
+\r
+}\r
+\r
+?>
\ No newline at end of file