diff --git a/libs/sysplugins/smarty_internal_cache.php b/libs/sysplugins/smarty_internal_cache.php new file mode 100644 index 00000000..d8f6a6fc --- /dev/null +++ b/libs/sysplugins/smarty_internal_cache.php @@ -0,0 +1,101 @@ + +* @author Uwe Tews +* @package Smarty +* @version 3-SVN$Rev: 3286 $ +*/ + +class Smarty_Internal_Cache { + + protected $smarty; + + function __construct($smarty) { + $this->smarty = $smarty; + } + + /** + * Loads cache resource. + * + * @return object of cache resource + */ + public function loadResource($type = null) { + if (!isset($type)) { + $type = $this->smarty->caching_type; + } + // already loaded? + if (isset($this->smarty->cache_resource_objects[$type])) { + return $this->smarty->cache_resource_objects[$type]; + } + if (in_array($type, $this->smarty->cache_resource_types)) { + $cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type); + return $this->smarty->cache_resource_objects[$type] = new $cache_resource_class($this->smarty); + } + else { + // try plugins dir + $cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type); + if ($this->smarty->loadPlugin($cache_resource_class)) { + return $this->smarty->cache_resource_objects[$type] = new $cache_resource_class($this->smarty); + } + else { + throw new Exception("Unable to load cache resource '{$type}'"); + } + } + } + + /** + * Empty cache folder + * + * @param integer $exp_time expiration time + * @param string $type resource type + * @return integer number of cache files deleted + */ + function clearAll($exp_time = null, $type = null) + { + return $this->loadResource($type)->clearAll($exp_time); + } + + /** + * Empty cache for a specific template + * + * @param string $template_name template name + * @param string $cache_id cache id + * @param string $compile_id compile id + * @param integer $exp_time expiration time + * @param string $type resource type + * @return integer number of cache files deleted + */ + function clear($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null) + { + // load cache resource + $cacheResource = $this->loadResource($type); + + return $cacheResource->clear($template_name, $cache_id, $compile_id, $exp_time); + } + +} diff --git a/libs/sysplugins/smarty_internal_register.php b/libs/sysplugins/smarty_internal_register.php new file mode 100644 index 00000000..cf5b9739 --- /dev/null +++ b/libs/sysplugins/smarty_internal_register.php @@ -0,0 +1,246 @@ + +* @author Uwe Tews +* @package Smarty +* @version 3-SVN$Rev: 3286 $ +*/ + +class Smarty_Internal_Register { + + protected $smarty; + + function __construct($smarty) { + $this->smarty = $smarty; + } + + /** + * Registers block function to be used in templates + * + * @param string $block_tag name of template block + * @param string $block_impl PHP function to register + * @param boolean $cacheable if true (default) this fuction is cachable + * @param array $cache_attr caching attributes if any + */ + function block($block_tag, $block_impl, $cacheable = true, $cache_attr = array()) + { + if (isset($this->smarty->registered_plugins['block'][$block_tag])) { + throw new Exception("Plugin tag \"{$block_tag}\" already registered"); + } elseif (!is_callable($block_impl)) { + throw new Exception("Plugin \"{$block_tag}\" not callable"); + } else { + $this->smarty->registered_plugins['block'][$block_tag] = + array($block_impl, $cacheable, $cache_attr); + } + } + + /** + * Registers compiler function + * + * @param string $compiler_tag of template function + * @param string $compiler_impl name of PHP function to register + * @param boolean $cacheable if true (default) this fuction is cachable + */ + function compilerFunction($compiler_tag, $compiler_impl, $cacheable = true) + { + if (isset($this->smarty->registered_plugins['compiler'][$compiler_tag])) { + throw new Exception("Plugin tag \"{$compiler_tag}\" already registered"); + } elseif (!is_callable($compiler_impl)) { + throw new Exception("Plugin \"{$compiler_tag}\" not callable"); + } else { + $this->smarty->registered_plugins['compiler'][$compiler_tag] = + array($compiler_impl, $cacheable); + } + } + + /** + * Registers custom function to be used in templates + * + * @param string $function_tag the name of the template function + * @param string $function_impl the name of the PHP function to register + * @param boolean $cacheable if true (default) this fuction is cachable + * @param array $cache_attr caching attributes if any + */ + function templateFunction($function_tag, $function_impl, $cacheable = true, $cache_attr = array()) + { + if (isset($this->smarty->registered_plugins['function'][$function_tag])) { + throw new Exception("Plugin tag \"{$function_tag}\" already registered"); + } elseif (!is_callable($function_impl)) { + throw new Exception("Plugin \"{$function_tag}\" not callable"); + } else { + $this->smarty->registered_plugins['function'][$function_tag] = + array($function_impl, $cacheable, $cache_attr); + } + } + + /** + * Registers modifier to be used in templates + * + * @param string $modifier_name name of template modifier + * @param string $modifier_impl name of PHP function to register + */ + function modifier($modifier_name, $modifier_impl) + { + if (isset($this->smarty->registered_plugins['modifier'][$modifier_name])) { + throw new Exception("Plugin \"{$modifier}\" already registered"); + } elseif (!is_callable($modifier_impl)) { + throw new Exception("Plugin \"{$modifier}\" not callable"); + } else { + $this->smarty->registered_plugins['modifier'][$modifier_name] = + array($modifier_impl); + } + } + + /** + * Registers object to be used in templates + * + * @param string $object name of template object + * @param object $ &$object_impl the referenced PHP object to register + * @param mixed null | array $allowed list of allowed methods (empty = all) + * @param boolean $smarty_args smarty argument format, else traditional + * @param mixed null | array $block_functs list of methods that are block format + */ + function templateObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) + { + // test if allowed methodes callable + if (!empty($allowed)) { + foreach ((array)$allowed as $method) { + if (!is_callable(array($object_impl, $method))) { + throw new Exception("Undefined method '$method' in registered object"); + } + } + } + // test if block methodes callable + if (!empty($block_methods)) { + foreach ((array)$block_methods as $method) { + if (!is_callable(array($object_impl, $method))) { + throw new Exception("Undefined method '$method' in registered object"); + } + } + } + // register the object + $this->smarty->registered_objects[$object_name] = + array($object_impl, (array)$allowed, (boolean)$smarty_args, (array)$block_methods); + } + + /** + * Registers an output filter function to apply + * to a template output + * + * @param callback $function_name + */ + function outputFilter($function_name) + { + $this->smarty->registered_filters['output'][$this->smarty->_get_filter_name($function_name)] = $function_name; + } + + /** + * Registers a postfilter function to apply + * to a compiled template after compilation + * + * @param callback $function_name + */ + function postFilter($function_name) + { + $this->smarty->registered_filters['post'][$this->smarty->_get_filter_name($function_name)] = $function_name; + } + + /** + * Registers a prefilter function to apply + * to a template before compiling + * + * @param callback $function_name + */ + function preFilter($function_name) + { + $this->smarty->registered_filters['pre'][$this->smarty->_get_filter_name($function_name)] = $function_name; + } + + /** + * Registers a resource to fetch a template + * + * @param string $resource_type name of resource type + * @param array $function_names array of functions to handle resource + */ + function resource($resource_type, $function_names) + { + if (count($function_names) == 4) { + $this->smarty->_plugins['resource'][$resource_type] = + array($function_names, false); + } elseif (count($function_names) == 5) { + $this->smarty->_plugins['resource'][$resource_type] = + array(array(array(&$function_names[0], $function_names[1]), + array(&$function_names[0], $function_names[2]), + array(&$function_names[0], $function_names[3]), + array(&$function_names[0], $function_names[4])), + false); + } else { + throw new Exception("malformed function-list for '$resource_type' in register_resource"); + } + } + + /** + * Registers an output filter function which + * runs over any variable output + * + * @param callback $function_name + */ + function variableFilter($function_name) + { + $this->smarty->registered_filters['variable'][$this->smarty->_get_filter_name($function_name)] = $function_name; + } + + /** + * Registers a default plugin handler + * + * @param $function_name mixed string | array $plugin class/methode name + */ + function defaultPluginHandler($function_name) + { + if (is_callable($function_name)) { + $this->smarty->default_plugin_handler_func = $function_name; + } else { + throw new Exception("Default plugin handler '$function_name' not callable"); + } + } + + /** + * Registers a default template handler + * + * @param $function_name mixed string | array class/method name + */ + function defaultTemplateHandler($function_name) + { + if (is_callable($function_name)) { + $this->smarty->default_template_handler_func = $function_name; + } else { + throw new Exception("Default template handler '$function' not callable"); + } + } + +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_unregister.php b/libs/sysplugins/smarty_internal_unregister.php new file mode 100644 index 00000000..9d5c7454 --- /dev/null +++ b/libs/sysplugins/smarty_internal_unregister.php @@ -0,0 +1,150 @@ + +* @author Uwe Tews +* @package Smarty +* @version 3-SVN$Rev: 3286 $ +*/ + +class Smarty_Internal_Unregister { + + protected $smarty; + + function __construct($smarty) { + $this->smarty = $smarty; + } + + /** + * Unregisters block function + * + * @param string $block_tag name of template function + */ + function block($block_tag) + { + if (isset($this->smarty->registered_plugins['block'][$block_tag])) { + unset($this->smarty->registered_plugins['block'][$block_tag]); + } + } + + /** + * Unregisters compiler function + * + * @param string $compiler_tag name of template function + */ + function compilerFunction($compiler_tag) + { + if (isset($this->smarty->registered_plugins['compiler'][$compiler_tag])) { + unset($this->smarty->registered_plugins['compiler'][$compiler_tag]); + } + } + + /** + * Unregisters custom function + * + * @param string $function_tag name of template function + */ + function templateFunction($function_tag) + { + if (isset($this->smarty->registered_plugins['function'][$function_tag])) { + unset($this->smarty->registered_plugins['function'][$function_tag]); + } + } + + /** + * Unregisters modifier + * + * @param string $modifier name of template modifier + */ + function modifier($modifier) + { + if (isset($this->smarty->registered_plugins['modifier'][$modifier])) { + unset($this->smarty->registered_plugins['modifier'][$modifier]); + } + } + + /** + * Unregisters template object + * + * @param string $object_name name of template object + */ + function templateObject($object_name) + { + unset($this->smarty->registered_objects[$object_name]); + } + + /** + * Unregisters an output filter + * + * @param callback $function_name + */ + function outputFilter($function_name) + { + unset($this->smarty->registered_filters['output'][$this->smarty->_get_filter_name($function_name)]); + } + + /** + * Unregisters a postfilter function + * + * @param callback $function_name + */ + function postFilter($function_name) + { + unset($this->smarty->registered_filters['post'][$this->smarty->_get_filter_name($function_name)]); + } + + /** + * Unregisters a prefilter function + * + * @param callback $function_name + */ + function preFilter($function_name) + { + unset($this->smarty->registered_filters['pre'][$this->smarty->_get_filter_name($function_name)]); + } + + /** + * Unregisters a resource + * + * @param string $resource_name name of resource + */ + function resource($resource_name) + { + unset($this->smarty->plugins['resource'][$resource_name]); + } + + /** + * Unregisters a variablefilter function + * + * @param callback $function_name + */ + function variableFilter($function_name) + { + unset($this->smarty->registered_filters['variable'][$this->smarty->_get_filter_name($function_name)]); + } + +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_utility.php b/libs/sysplugins/smarty_internal_utility.php new file mode 100644 index 00000000..ce73db5c --- /dev/null +++ b/libs/sysplugins/smarty_internal_utility.php @@ -0,0 +1,261 @@ + +* @author Uwe Tews +* @package Smarty +* @version 3-SVN$Rev: 3286 $ +*/ + +class Smarty_Internal_Utility { + + protected $smarty; + + function __construct($smarty) { + $this->smarty = $smarty; + } + + /** + * Compile all template files + * + * @param string $extension file extension + * @param bool $force_compile force all to recompile + * @param int $time_limit + * @param int $max_errors + * @return integer number of template files recompiled + */ + function compileAllTemplates($extention = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null) + { + function _get_time() + { + $_mtime = microtime(); + $_mtime = explode(" ", $_mtime); + return (double)($_mtime[1]) + (double)($_mtime[0]); + } + // set default directory + if ($dir_name === null) { + $dir_name = $this->smarty->template_dir; + } + // switch off time limit + if (function_exists('set_time_limit')) { + @set_time_limit($time_limit); + } + $this->smarty->force_compile = $force_compile; + $_count = 0; + $_error_count = 0; + // loop over array of template directories + foreach((array)$this->smarty->template_dir as $_dir) { + $_compileDirs = new RecursiveDirectoryIterator($_dir); + $_compile = new RecursiveIteratorIterator($_compileDirs); + foreach ($_compile as $_fileinfo) { + if (strpos($_fileinfo, '.svn') !== false) continue; + $_file = $_fileinfo->getFilename(); + if (!substr_compare($_file, $extention, - strlen($extention)) == 0) continue; + if ($_fileinfo->getPath() == substr($_dir, 0, -1)) { + $_template_file = $_file; + } else { + $_template_file = substr($_fileinfo->getPath(), strlen($_dir)) . '\\' . $_file; + } + echo '
', $_dir, '---', $_template_file; + flush(); + $_start_time = _get_time(); + try { + $_tpl = $this->smarty->createTemplate($_template_file); + $_tpl->getCompiledTemplate(); + } + catch (Exception $e) { + echo 'Error: ', $e->getMessage(), "

"; + $_error_count++; + } + echo ' done in ', _get_time() - $_start_time, ' seconds'; + if ($max_errors !== null && $_error_count == $max_errors) { + echo '

too many errors'; + exit(); + } + } + } + return $_count; + } + + /** + * Delete compiled template file + * + * @param string $resource_name template name + * @param string $compile_id compile id + * @param integer $exp_time expiration time + * @return integer number of template files deleted + */ + function clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null) + { + $_compile_id = isset($compile_id) ? preg_replace('![^\w\|]+!','_',$compile_id) : null; + $_dir_sep = $this->smarty->use_sub_dirs ? DS : '^'; + if (isset($resource_name)) { + $_resource_part_1 = $resource_name . '.php'; + $_resource_part_2 = $resource_name . '.cache' . '.php'; + } else { + $_resource_part = ''; + } + $_dir = $this->smarty->compile_dir; + if ($this->smarty->use_sub_dirs && isset($_compile_id)) { + $_dir .= $_compile_id . $_dir_sep; + } + if (isset($_compile_id)) { + $_compile_id_part = $this->smarty->compile_dir . $_compile_id . $_dir_sep; + } + $_count = 0; + $_compileDirs = new RecursiveDirectoryIterator($_dir); + $_compile = new RecursiveIteratorIterator($_compileDirs, RecursiveIteratorIterator::CHILD_FIRST); + foreach ($_compile as $_file) { + if (strpos($_file, '.svn') !== false) continue; + if ($_file->isDir()) { + if (!$_compile->isDot()) { + // delete folder if empty + @rmdir($_file->getPathname()); + } + } else { + if ((!isset($_compile_id) || (strlen((string)$_file) > strlen($_compile_id_part) && substr_compare((string)$_file, $_compile_id_part, 0, strlen($_compile_id_part)) == 0)) && + (!isset($resource_name) || (strlen((string)$_file) > strlen($_resource_part_1) && substr_compare((string)$_file, $_resource_part_1, - strlen($_resource_part_1), strlen($_resource_part_1)) == 0) || + (strlen((string)$_file) > strlen($_resource_part_2) && substr_compare((string)$_file, $_resource_part_2, - strlen($_resource_part_2), strlen($_resource_part_2)) == 0))) { + if (isset($exp_time)) { + if (time() - @filemtime($_file) >= $exp_time) { + $_count += @unlink((string) $_file) ? 1 : 0; + } + } else { + $_count += @unlink((string) $_file) ? 1 : 0; + } + } + } + } + return $_count; + } + + /** + * Returns a single or all template variables + * + * @param string $varname variable name or null + * @return string variable value or or array of variables + */ + function getTemplateVars($varname = null, $_ptr = null, $search_parents = true) + { + if (isset($varname)) { + $_var = $this->smarty->getVariable($varname, $_ptr, $search_parents); + if (is_object($_var)) { + return $_var->value; + } else { + return null; + } + } else { + $_result = array(); + if ($_ptr === null) { + $_ptr = $this->smarty; + } while ($_ptr !== null) { + foreach ($_ptr->tpl_vars AS $key => $var) { + $_result[$key] = $var->value; + } + // not found, try at parent + if ($search_parents) { + $_ptr = $_ptr->parent; + } else { + $_ptr = null; + } + } + if ($search_parents) { + foreach ($this->smarty->global_tpl_vars AS $key => $var) { + $_result[$key] = $var->value; + } + } + return $_result; + } + } + + function testInstall() + { + echo "
\n";
+    
+        echo "Smarty Installation test...\n";
+    
+        echo "Testing template directory...\n";
+    
+        foreach((array)$this->smarty->template_dir as $template_dir) {
+            if (!is_dir($template_dir))
+                echo "FAILED: $template_dir is not a directory.\n";
+            elseif (!is_readable($template_dir))
+                echo "FAILED: $template_dir is not readable.\n";
+            else
+                echo "$template_dir is OK.\n";
+        } 
+    
+        echo "Testing compile directory...\n";
+    
+        if (!is_dir($this->smarty->compile_dir))
+            echo "FAILED: $this->smarty->compile_dir is not a directory.\n";
+        elseif (!is_readable($this->smarty->compile_dir))
+            echo "FAILED: $this->smarty->compile_dir is not readable.\n";
+        elseif (!is_writable($this->smarty->compile_dir))
+            echo "FAILED: $this->smarty->compile_dir is not writable.\n";
+        else
+            echo "{$this->smarty->compile_dir} is OK.\n";
+    
+        echo "Testing plugins directory...\n";
+    
+        foreach((array)$this->smarty->plugins_dir as $plugin_dir) {
+            if (!is_dir($plugin_dir))
+                echo "FAILED: $plugin_dir is not a directory.\n";
+            elseif (!is_readable($plugin_dir))
+                echo "FAILED: $plugin_dir is not readable.\n";
+            else
+                echo "$plugin_dir is OK.\n";
+        } 
+    
+        echo "Testing cache directory...\n";
+    
+        if (!is_dir($this->smarty->cache_dir))
+            echo "FAILED: $this->smarty->cache_dir is not a directory.\n";
+        elseif (!is_readable($this->smarty->cache_dir))
+            echo "FAILED: $this->smarty->cache_dir is not readable.\n";
+        elseif (!is_writable($this->smarty->cache_dir))
+            echo "FAILED: $this->smarty->cache_dir is not writable.\n";
+        else
+            echo "{$this->smarty->cache_dir} is OK.\n";
+    
+        echo "Testing configs directory...\n";
+    
+        if (!is_dir($this->smarty->config_dir))
+            echo "FAILED: $this->smarty->config_dir is not a directory.\n";
+        elseif (!is_readable($this->smarty->config_dir))
+            echo "FAILED: $this->smarty->config_dir is not readable.\n";
+        else
+            echo "{$this->smarty->config_dir} is OK.\n";
+    
+        echo "Tests complete.\n";
+    
+        echo "
\n"; + + return true; + } + +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_wrapper.php b/libs/sysplugins/smarty_internal_wrapper.php new file mode 100644 index 00000000..5ecf71b7 --- /dev/null +++ b/libs/sysplugins/smarty_internal_wrapper.php @@ -0,0 +1,126 @@ + +* @author Uwe Tews +* @package Smarty +* @version 3-SVN$Rev: 3286 $ +*/ + +/* + * Smarty Backward Compatability Wrapper + */ + +class Smarty_Internal_Wrapper { + + protected $smarty; + + function __construct($smarty) { + $this->smarty = $smarty; + } + + /** + * Converts smarty2-style function call to smarty 3-style function call + * This is expensive, be sure to port your code to Smarty 3! + * + * @param string $name Smarty 2 function name + * @param array $args Smarty 2 function args + */ + function convert($name, $args) { + // throw notice about deprecated function + if($this->smarty->deprecation_notices) + trigger_error("function call '$name' is unknown or deprecated.",E_USER_NOTICE); + // get first and last part of function name + $name_parts = explode('_',$name,2); + switch($name_parts[0]) { + case 'register': + case 'unregister': + $myobj = $name_parts[0] == 'register' ? $this->smarty->register : $this->smarty->unregister; + switch($name_parts[1]) { + case 'function': + return call_user_func_array(array($myobj,'templateFunction'),$args); + break; + case 'object': + return call_user_func_array(array($myobj,'templateObject'),$args); + break; + case 'compiler_function': + return call_user_func_array(array($myobj,'compilerFunction'),$args); + break; + default: + return call_user_func_array(array($myobj,$name_parts[1]),$args); + break; + } + break; + case 'get': + switch($name_parts[1]) { + case 'template_vars': + return call_user_func_array(array($this->smarty->utility,'getTemplateVars'),$args); + break; + case 'config_vars': + return call_user_func_array(array($this->smarty,'getConfigVars'),$args); + break; + default: + return call_user_func_array(array($myobj,$name_parts[1]),$args); + break; + } + break; + case 'clear': + switch($name_parts[1]) { + case 'all_assign': + return call_user_func_array(array($this->smarty,'clearAllAssign'),$args); + break; + } + break; + case 'config': + switch($name_parts[1]) { + case 'load': + return call_user_func_array(array($this->smarty,'configLoad'),$args); + break; + } + break; + default: + // convert foo_bar_baz to fooBarBaz style names + $name_parts = explode('_',$name); + foreach($name_parts as $idx=>$part) { + if($idx==0) + $name_parts[$idx] = strtolower($part); + else + $name_parts[$idx] = ucfirst($part); + } + $func_name = implode('',$name_parts); + if(!method_exists($this->smarty,$func_name)) { + throw new Exception("unknown method '$name'"); + return false; + } + return call_user_func_array(array($this->smarty,$func_name),$args); + break; + } + return false; + } +} + +?> \ No newline at end of file