From fe63ad36b83ae7c3b6e72b3b7e7ad1ce8bfefdad Mon Sep 17 00:00:00 2001 From: "uwe.tews@googlemail.com" Date: Sat, 13 Nov 2010 04:10:52 +0000 Subject: [PATCH] - reverted location of loadPlugin() to Smarty class - fixed comments in plugins --- change_log.txt | 2 + libs/Smarty.class.php | 48 ++++++++++++++ libs/plugins/block.php.php | 3 +- libs/plugins/block.textformat.php | 3 +- libs/plugins/function.cycle.php | 1 - libs/plugins/function.fetch.php | 1 - libs/plugins/function.html_checkboxes.php | 2 - libs/plugins/function.html_image.php | 4 +- libs/plugins/function.html_options.php | 2 - libs/plugins/function.html_radios.php | 2 - libs/plugins/function.html_select_date.php | 10 +-- libs/plugins/function.html_select_time.php | 11 ++-- libs/plugins/function.html_table.php | 1 - libs/plugins/function.mailto.php | 1 - libs/plugins/function.math.php | 1 - libs/plugins/function.popup.php | 1 - libs/plugins/function.popup_init.php | 1 - .../smarty_internal_compile_debug.php | 2 +- ...arty_internal_compile_private_modifier.php | 2 +- .../smarty_internal_config_file_compiler.php | 4 +- libs/sysplugins/smarty_internal_filter.php | 2 +- .../smarty_internal_filter_handler.php | 2 +- .../smarty_internal_plugin_loader.php | 64 ------------------- libs/sysplugins/smarty_internal_template.php | 4 +- .../smarty_internal_templatecompilerbase.php | 6 +- 25 files changed, 71 insertions(+), 109 deletions(-) delete mode 100644 libs/sysplugins/smarty_internal_plugin_loader.php diff --git a/change_log.txt b/change_log.txt index 3b704f52..8fb16c7a 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,5 +1,7 @@ 13/11/2010 - bugfix on {debug} +- reverted location of loadPlugin() to Smarty class +- fixed comments in plugins ===== Smarty 3.0.2 ===== diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index b67cab4d..96bfac73 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -660,6 +660,54 @@ class Smarty extends Smarty_Internal_Data { return $this->debug_tpl = $tpl_name; } + /** + * Takes unknown classes and loads plugin files for them + * class name format: Smarty_PluginType_PluginName + * plugin filename format: plugintype.pluginname.php + * + * @param string $plugin_name class plugin name to load + * @return string |boolean filepath of loaded file or false + */ + public function loadPlugin($plugin_name, $check = true) + { + // if function or class exists, exit silently (already loaded) + if ($check && (is_callable($plugin_name) || class_exists($plugin_name, false))) + return true; + // Plugin name is expected to be: Smarty_[Type]_[Name] + $_plugin_name = strtolower($plugin_name); + $_name_parts = explode('_', $_plugin_name, 3); + // class name must have three parts to be valid plugin + if (count($_name_parts) < 3 || $_name_parts[0] !== 'smarty') { + throw new SmartyException("plugin {$plugin_name} is not a valid name format"); + return false; + } + // if type is "internal", get plugin from sysplugins + if ($_name_parts[1] == 'internal') { + $file = SMARTY_SYSPLUGINS_DIR . $_plugin_name . '.php'; + if (file_exists($file)) { + require_once($file); + return $file; + } else { + return false; + } + } + // plugin filename is expected to be: [type].[name].php + $_plugin_filename = "{$_name_parts[1]}.{$_name_parts[2]}.php"; + // loop through plugin dirs and find the plugin + foreach((array)$this->plugins_dir as $_plugin_dir) { + if (strpos('/\\', substr($_plugin_dir, -1)) === false) { + $_plugin_dir .= DS; + } + $file = $_plugin_dir . $_plugin_filename; + if (file_exists($file)) { + require_once($file); + return $file; + } + } + // no plugin loaded + return false; + } + /** * clean up properties on cloned object */ diff --git a/libs/plugins/block.php.php b/libs/plugins/block.php.php index 51a5a316..8fedd8b4 100644 --- a/libs/plugins/block.php.php +++ b/libs/plugins/block.php.php @@ -11,9 +11,8 @@ * Smarty {php}{/php} block plugin * * @param string $content contents of the block - * @param object $smarty Smarty object - * @param boolean $ &$repeat repeat flag * @param object $template template object + * @param boolean $ &$repeat repeat flag * @return string content re-formatted */ function smarty_block_php($params, $content, $template, &$repeat) diff --git a/libs/plugins/block.textformat.php b/libs/plugins/block.textformat.php index a91c0417..517fd62d 100644 --- a/libs/plugins/block.textformat.php +++ b/libs/plugins/block.textformat.php @@ -27,9 +27,8 @@ * * @author Monte Ohrt * @param string $content contents of the block - * @param object $smarty Smarty object - * @param boolean &$repeat repeat flag * @param object $template template object + * @param boolean &$repeat repeat flag * @return string content re-formatted */ function smarty_block_textformat($params, $content, $template, &$repeat) diff --git a/libs/plugins/function.cycle.php b/libs/plugins/function.cycle.php index 1c0ee905..98e3e287 100644 --- a/libs/plugins/function.cycle.php +++ b/libs/plugins/function.cycle.php @@ -39,7 +39,6 @@ * @author credit to Jason Sweat * @version 1.3 * @param array - * @param object $smarty Smarty object * @param object $template template object * @return string|null */ diff --git a/libs/plugins/function.fetch.php b/libs/plugins/function.fetch.php index 0046d9eb..21ea69ba 100644 --- a/libs/plugins/function.fetch.php +++ b/libs/plugins/function.fetch.php @@ -16,7 +16,6 @@ * (Smarty online manual) * @author Monte Ohrt * @param array $params parameters - * @param object $smarty Smarty object * @param object $template template object * @return string|null if the assign parameter is passed, Smarty assigns the * result to a template variable diff --git a/libs/plugins/function.html_checkboxes.php b/libs/plugins/function.html_checkboxes.php index dd3cddfc..6a1a3ffd 100644 --- a/libs/plugins/function.html_checkboxes.php +++ b/libs/plugins/function.html_checkboxes.php @@ -34,7 +34,6 @@ * - separator (optional) - ie
or   * - output (optional) - the output next to each checkbox * - assign (optional) - assign the output as an array to this variable - * @param object $smarty Smarty object * @param object $template template object * @return string * @uses smarty_function_escape_special_chars() @@ -42,7 +41,6 @@ function smarty_function_html_checkboxes($params, $template) { require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); - //$smarty->loadPlugin('Smarty_shared_escape_special_chars'); $name = 'checkbox'; $values = null; diff --git a/libs/plugins/function.html_image.php b/libs/plugins/function.html_image.php index 3515bbcc..57c26658 100644 --- a/libs/plugins/function.html_image.php +++ b/libs/plugins/function.html_image.php @@ -29,7 +29,6 @@ * - basedir = base directory for absolute paths, default * is environment variable DOCUMENT_ROOT * - path_prefix = prefix for path output (optional, default empty) - * @param object $smarty Smarty object * @param object $template template object * @return string * @uses smarty_function_escape_special_chars() @@ -37,8 +36,7 @@ function smarty_function_html_image($params, $template) { require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); - //$smarty->loadPlugin('Smarty_shared_escape_special_chars'); - + $alt = ''; $file = ''; $height = ''; diff --git a/libs/plugins/function.html_options.php b/libs/plugins/function.html_options.php index 1054ed07..65c77c65 100644 --- a/libs/plugins/function.html_options.php +++ b/libs/plugins/function.html_options.php @@ -24,7 +24,6 @@ * - options (required if no values supplied) - associative array * - selected (optional) - string default not set * - output (required if not options supplied) - array - * @param object $smarty Smarty object * @param object $template template object * @return string * @uses smarty_function_escape_special_chars() @@ -32,7 +31,6 @@ function smarty_function_html_options($params, $template) { require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); - //$smarty->loadPlugin('Smarty_shared_escape_special_chars'); $name = null; $values = null; diff --git a/libs/plugins/function.html_radios.php b/libs/plugins/function.html_radios.php index cad7b8dd..c6b27edf 100644 --- a/libs/plugins/function.html_radios.php +++ b/libs/plugins/function.html_radios.php @@ -35,7 +35,6 @@ * - separator (optional) - ie
or   * - output (optional) - the output next to each radio button * - assign (optional) - assign the output as an array to this variable - * @param object $smarty Smarty object * @param object $template template object * @return string * @uses smarty_function_escape_special_chars() @@ -43,7 +42,6 @@ function smarty_function_html_radios($params, $template) { require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); - //$smarty->loadPlugin('Smarty_shared_escape_special_chars'); $name = 'radio'; $values = null; diff --git a/libs/plugins/function.html_select_date.php b/libs/plugins/function.html_select_date.php index 19b69421..1d57fdc7 100644 --- a/libs/plugins/function.html_select_date.php +++ b/libs/plugins/function.html_select_date.php @@ -34,7 +34,6 @@ * @author Andrei Zmievski * @author Monte Ohrt * @param array $params parameters - * @param object $smarty Smarty object * @param object $template template object * @return string */ @@ -43,9 +42,6 @@ function smarty_function_html_select_date($params, $template) require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'); require_once(SMARTY_PLUGINS_DIR . 'function.html_options.php'); - //$smarty->loadPlugin('Smarty_shared_escape_special_chars'); - //$smarty->loadPlugin('Smarty_shared_make_timestamp'); - //$smarty->loadPlugin('Smarty_function_html_options'); /* Default values. */ $prefix = "Date_"; @@ -219,7 +215,7 @@ function smarty_function_html_select_date($params, $template) 'values' => $month_values, 'selected' => (int)$time[1] ? strftime($month_value_format, mktime(0, 0, 0, (int)$time[1], 1, 2000)) : '', 'print_result' => false), - $smarty, $template); + $template); $month_result .= ''; } @@ -255,7 +251,7 @@ function smarty_function_html_select_date($params, $template) 'values' => $day_values, 'selected' => $time[2], 'print_result' => false), - $smarty, $template); + $template); $day_result .= ''; } @@ -302,7 +298,7 @@ function smarty_function_html_select_date($params, $template) 'values' => $yearvals, 'selected' => $time[0], 'print_result' => false), - $smarty, $template); + $template); $year_result .= ''; } } diff --git a/libs/plugins/function.html_select_time.php b/libs/plugins/function.html_select_time.php index f2ca70f8..ddde4f5a 100644 --- a/libs/plugins/function.html_select_time.php +++ b/libs/plugins/function.html_select_time.php @@ -18,7 +18,6 @@ * @author Roberto Berto * @credits Monte Ohrt * @param array $params parameters - * @param object $smarty Smarty object * @param object $template template object * @return string * @uses smarty_make_timestamp() @@ -27,8 +26,6 @@ function smarty_function_html_select_time($params, $template) { require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php'); require_once(SMARTY_PLUGINS_DIR . 'function.html_options.php'); - //$smarty->loadPlugin('Smarty_shared_make_timestamp'); - //$smarty->loadPlugin('Smarty_function_html_options'); /* Default values. */ $prefix = "Time_"; @@ -108,7 +105,7 @@ function smarty_function_html_select_time($params, $template) 'values' => $hours, 'selected' => strftime($hour_fmt, $time), 'print_result' => false), - $smarty, $template); + $template); $html_result .= "\n"; } @@ -135,7 +132,7 @@ function smarty_function_html_select_time($params, $template) 'values' => $minutes, 'selected' => $selected, 'print_result' => false), - $smarty, $template); + $template); $html_result .= "\n"; } @@ -163,7 +160,7 @@ function smarty_function_html_select_time($params, $template) 'values' => $seconds, 'selected' => $selected, 'print_result' => false), - $smarty, $template); + $template); $html_result .= "\n"; } @@ -187,7 +184,7 @@ function smarty_function_html_select_time($params, $template) 'values' => array('am', 'pm'), 'selected' => strtolower(strftime('%p', $time)), 'print_result' => false), - $smarty, $template); + $template); $html_result .= "\n"; } diff --git a/libs/plugins/function.html_table.php b/libs/plugins/function.html_table.php index 6752221a..7986a9bc 100644 --- a/libs/plugins/function.html_table.php +++ b/libs/plugins/function.html_table.php @@ -44,7 +44,6 @@ * - hdir = horizontal direction (default: "right", means left-to-right) * - inner = inner loop (default "cols": print $loop line by line, * $loop will be printed column by column otherwise) - * @param object $smarty Smarty object * @param object $template template object * @return string */ diff --git a/libs/plugins/function.mailto.php b/libs/plugins/function.mailto.php index ad4d9e2b..976218f5 100644 --- a/libs/plugins/function.mailto.php +++ b/libs/plugins/function.mailto.php @@ -45,7 +45,6 @@ * - newsgroups = (optional) newsgroup(s) to post to * - followupto = (optional) address(es) to follow up to * - extra = (optional) extra tags for the href link - * @param object $smarty Smarty object * @param object $template template object * @return string */ diff --git a/libs/plugins/function.math.php b/libs/plugins/function.math.php index 5d717635..cd90020a 100644 --- a/libs/plugins/function.math.php +++ b/libs/plugins/function.math.php @@ -17,7 +17,6 @@ * (Smarty online manual) * @author Monte Ohrt * @param array $params parameters - * @param object $smarty Smarty object * @param object $template template object * @return string|null */ diff --git a/libs/plugins/function.popup.php b/libs/plugins/function.popup.php index 2d3650ff..6d09d05b 100644 --- a/libs/plugins/function.popup.php +++ b/libs/plugins/function.popup.php @@ -16,7 +16,6 @@ * (Smarty online manual) * @author Monte Ohrt * @param array $params parameters - * @param object $smarty Smarty object * @param object $template template object * @return string */ diff --git a/libs/plugins/function.popup_init.php b/libs/plugins/function.popup_init.php index bcbab56d..7d8ac7a8 100644 --- a/libs/plugins/function.popup_init.php +++ b/libs/plugins/function.popup_init.php @@ -16,7 +16,6 @@ * (Smarty online manual) * @author Monte Ohrt * @param array $params parameters - * @param object $smarty Smarty object * @param object $template template object * @return string */ diff --git a/libs/sysplugins/smarty_internal_compile_debug.php b/libs/sysplugins/smarty_internal_compile_debug.php index 55b8a957..f6189e7e 100644 --- a/libs/sysplugins/smarty_internal_compile_debug.php +++ b/libs/sysplugins/smarty_internal_compile_debug.php @@ -30,7 +30,7 @@ class Smarty_Internal_Compile_Debug extends Smarty_Internal_CompileBase { $this->compiler->tag_nocache = true; // display debug template - $_output = "smarty->plugins_dir); Smarty_Internal_Debug::display_debug(\$_smarty_tpl); ?>"; + $_output = "smarty->loadPlugin('Smarty_Internal_Debug'); Smarty_Internal_Debug::display_debug(\$_smarty_tpl); ?>"; return $_output; } } diff --git a/libs/sysplugins/smarty_internal_compile_private_modifier.php b/libs/sysplugins/smarty_internal_compile_private_modifier.php index e4a4e588..1648db2e 100644 --- a/libs/sysplugins/smarty_internal_compile_private_modifier.php +++ b/libs/sysplugins/smarty_internal_compile_private_modifier.php @@ -46,7 +46,7 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa } } // check for plugin modifiercompiler - } else if (Smarty_Internal_Plugin_Loader::loadPlugin('smarty_modifiercompiler_' . $modifier, $compiler->smarty->plugins_dir)) { + } else if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) { $plugin = 'smarty_modifiercompiler_' . $modifier; $output = $plugin($single_modifier, $compiler); // check for plugin modifier diff --git a/libs/sysplugins/smarty_internal_config_file_compiler.php b/libs/sysplugins/smarty_internal_config_file_compiler.php index d13cdfa8..e9dfbdb0 100644 --- a/libs/sysplugins/smarty_internal_config_file_compiler.php +++ b/libs/sysplugins/smarty_internal_config_file_compiler.php @@ -22,8 +22,8 @@ class Smarty_Internal_Config_File_Compiler { { $this->smarty = $smarty; // get required plugins - Smarty_Internal_Plugin_Loader::loadPlugin('Smarty_Internal_Configfilelexer', $this->smarty->plugins_dir); - Smarty_Internal_Plugin_Loader::loadPlugin('Smarty_Internal_Configfileparser', $this->smarty->plugins_dir); + $this->smarty->loadPlugin('Smarty_Internal_Configfilelexer'); + $this->smarty->loadPlugin('Smarty_Internal_Configfileparser'); $this->config_data['sections'] = array(); $this->config_data['vars'] = array(); } diff --git a/libs/sysplugins/smarty_internal_filter.php b/libs/sysplugins/smarty_internal_filter.php index 846a729e..90214ad4 100644 --- a/libs/sysplugins/smarty_internal_filter.php +++ b/libs/sysplugins/smarty_internal_filter.php @@ -72,7 +72,7 @@ class Smarty_Internal_Filter { { $_plugin = "smarty_{$type}filter_{$name}"; $_filter_name = $_plugin; - if (Smarty_Internal_Plugin_Loader::loadPlugin($_plugin, $this->smarty->plugins_dir)) { + if ($this->smarty->loadPlugin($_plugin)) { if (class_exists($_plugin, false)) { $_plugin = array($_plugin, 'execute'); } diff --git a/libs/sysplugins/smarty_internal_filter_handler.php b/libs/sysplugins/smarty_internal_filter_handler.php index 32401492..1992b55e 100644 --- a/libs/sysplugins/smarty_internal_filter_handler.php +++ b/libs/sysplugins/smarty_internal_filter_handler.php @@ -34,7 +34,7 @@ class Smarty_Internal_Filter_Handler { if (!empty($smarty->autoload_filters[$type])) { foreach ((array)$smarty->autoload_filters[$type] as $name) { $plugin_name = "Smarty_{$type}filter_{$name}"; - if (Smarty_Internal_Plugin_Loader::loadPlugin($plugin_name, $smarty->plugins_dir)) { + if ($smarty->loadPlugin($plugin_name)) { if (function_exists($plugin_name)) { // use loaded Smarty2 style plugin $output = $plugin_name($output, $smarty); diff --git a/libs/sysplugins/smarty_internal_plugin_loader.php b/libs/sysplugins/smarty_internal_plugin_loader.php deleted file mode 100644 index 1c43ecca..00000000 --- a/libs/sysplugins/smarty_internal_plugin_loader.php +++ /dev/null @@ -1,64 +0,0 @@ - diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index 59613054..ee3ffcdc 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -245,7 +245,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data { // compile template if (!is_object($this->compiler_object)) { // load compiler - Smarty_Internal_Plugin_Loader::loadPlugin($this->resource_object->compiler_class,$this->smarty->plugins_dir); + $this->smarty->loadPlugin($this->resource_object->compiler_class); $this->compiler_object = new $this->resource_object->compiler_class($this->resource_object->template_lexer_class, $this->resource_object->template_parser_class, $this->smarty); } // compile locking @@ -705,7 +705,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data { } else { // try plugins dir $_resource_class = 'Smarty_Resource_' . ucfirst($resource_type); - if (Smarty_Internal_Plugin_Loader::loadPlugin($_resource_class,$this->smarty->plugins_dir)) { + if ($this->smarty->loadPlugin($_resource_class)) { if (class_exists($_resource_class, false)) { return new $_resource_class($this->smarty); } else { diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index 89d5df1b..cca15784 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -193,7 +193,7 @@ class Smarty_Internal_TemplateCompilerBase { } // check plugins from plugins folder foreach ($this->smarty->plugin_search_order as $plugin_type) { - if ($plugin_type == Smarty::PLUGIN_BLOCK && Smarty_Internal_Plugin_Loader::loadPlugin('smarty_compiler_' . $tag, $this->smarty->plugins_dir)) { + if ($plugin_type == Smarty::PLUGIN_BLOCK && $this->smarty->loadPlugin('smarty_compiler_' . $tag)) { $plugin = 'smarty_compiler_' . $tag; if (is_callable($plugin)) { return $plugin($args, $this->smarty); @@ -231,7 +231,7 @@ class Smarty_Internal_TemplateCompilerBase { if ($function = $this->getPlugin($base_tag, Smarty::PLUGIN_BLOCK)) { return $this->callTagCompiler('private_block_plugin', $args, $parameter, $tag, $function); } - if (Smarty_Internal_Plugin_Loader::loadPlugin('smarty_compiler_' . $tag, $this->smarty->plugins_dir)) { + if ($this->smarty->loadPlugin('smarty_compiler_' . $tag)) { $plugin = 'smarty_compiler_' . $tag; if (is_callable($plugin)) { return $plugin($args, $this->smarty); @@ -272,7 +272,7 @@ class Smarty_Internal_TemplateCompilerBase { } // lazy load internal compiler plugin $class_name = 'Smarty_Internal_Compile_' . $tag; - if (Smarty_Internal_Plugin_Loader::loadPlugin($class_name, $this->smarty->plugins_dir)) { + if ($this->smarty->loadPlugin($class_name)) { // use plugin if found self::$_tag_objects[$tag] = new $class_name; // compile this tag