From 138421b6b5dfd31eab94388c5f33bd6c9074d171 Mon Sep 17 00:00:00 2001 From: andrey Date: Tue, 19 Mar 2002 22:21:22 +0000 Subject: [PATCH] Fix plugin behavior for inserts with script attribute. --- Smarty.class.php | 10 +++++++++- Smarty_Compiler.class.php | 19 +++++++++++-------- libs/Smarty.class.php | 10 +++++++++- libs/Smarty_Compiler.class.php | 19 +++++++++++-------- 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/Smarty.class.php b/Smarty.class.php index bf1447de..f11b924f 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -1444,7 +1444,7 @@ function _run_insert_handler($args) function _load_plugins($plugins) { foreach ($plugins as $plugin_info) { - list($type, $name, $tpl_file, $tpl_line) = $plugin_info; + list($type, $name, $tpl_file, $tpl_line, $delayed_loading) = $plugin_info; $plugin = &$this->_plugins[$type][$name]; /* @@ -1508,6 +1508,14 @@ function _run_insert_handler($args) continue; } } + /* + * In case of insert plugins, their code may be loaded later via + * 'script' attribute. + */ + else if ($type == 'insert' && $delayed_loading) { + $plugin_func = 'smarty_' . $type . '_' . $name; + $found = true; + } /* * Plugin specific processing and error checking. diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php index 46d6ab0b..59f1f8af 100644 --- a/Smarty_Compiler.class.php +++ b/Smarty_Compiler.class.php @@ -194,7 +194,8 @@ class Smarty_Compiler extends Smarty { $plugins_code = '_load_plugins(array('; foreach ($this->_plugin_info as $plugin_type => $plugins) { foreach ($plugins as $plugin_name => $plugin_info) { - $plugins_code .= "\narray('$plugin_type', '$plugin_name', '$plugin_info[0]', $plugin_info[1]),"; + $plugins_code .= "\narray('$plugin_type', '$plugin_name', '$plugin_info[0]', $plugin_info[1], "; + $plugins_code .= $plugin_info[2] ? 'true),' : 'false),'; } } $plugins_code .= ")); ?>"; @@ -408,10 +409,7 @@ class Smarty_Compiler extends Smarty { \*======================================================================*/ function _compile_custom_tag($tag_command, $tag_args) { - $this->_add_plugin('function', - $tag_command, - $this->_current_file, - $this->_current_line_no); + $this->_add_plugin('function', $tag_command); $arg_list = array(); $attrs = $this->_parse_attrs($tag_args); @@ -438,13 +436,17 @@ class Smarty_Compiler extends Smarty { $this->_syntax_error("missing insert name"); } + if (!empty($attrs['script'])) { + $delayed_loading = true; + } + foreach ($attrs as $arg_name => $arg_value) { if (is_bool($arg_value)) $arg_value = $arg_value ? 'true' : 'false'; $arg_list[] = "'$arg_name' => $arg_value"; } - $this->_add_plugin('insert', $name); + $this->_add_plugin('insert', $name, $delayed_loading); return "_run_insert_handler(array(".implode(', ', (array)$arg_list).")); ?>\n"; } @@ -1173,14 +1175,15 @@ class Smarty_Compiler extends Smarty { Function: _add_plugin Purpose: \*======================================================================*/ - function _add_plugin($type, $name) + function _add_plugin($type, $name, $delayed_loading = null) { if (!isset($this->_plugin_info[$type])) { $this->_plugin_info[$type] = array(); } if (!isset($this->_plugin_info[$type][$name])) { $this->_plugin_info[$type][$name] = array($this->_current_file, - $this->_current_line_no); + $this->_current_line_no, + $delayed_loading); } } diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index bf1447de..f11b924f 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -1444,7 +1444,7 @@ function _run_insert_handler($args) function _load_plugins($plugins) { foreach ($plugins as $plugin_info) { - list($type, $name, $tpl_file, $tpl_line) = $plugin_info; + list($type, $name, $tpl_file, $tpl_line, $delayed_loading) = $plugin_info; $plugin = &$this->_plugins[$type][$name]; /* @@ -1508,6 +1508,14 @@ function _run_insert_handler($args) continue; } } + /* + * In case of insert plugins, their code may be loaded later via + * 'script' attribute. + */ + else if ($type == 'insert' && $delayed_loading) { + $plugin_func = 'smarty_' . $type . '_' . $name; + $found = true; + } /* * Plugin specific processing and error checking. diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index 46d6ab0b..59f1f8af 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -194,7 +194,8 @@ class Smarty_Compiler extends Smarty { $plugins_code = '_load_plugins(array('; foreach ($this->_plugin_info as $plugin_type => $plugins) { foreach ($plugins as $plugin_name => $plugin_info) { - $plugins_code .= "\narray('$plugin_type', '$plugin_name', '$plugin_info[0]', $plugin_info[1]),"; + $plugins_code .= "\narray('$plugin_type', '$plugin_name', '$plugin_info[0]', $plugin_info[1], "; + $plugins_code .= $plugin_info[2] ? 'true),' : 'false),'; } } $plugins_code .= ")); ?>"; @@ -408,10 +409,7 @@ class Smarty_Compiler extends Smarty { \*======================================================================*/ function _compile_custom_tag($tag_command, $tag_args) { - $this->_add_plugin('function', - $tag_command, - $this->_current_file, - $this->_current_line_no); + $this->_add_plugin('function', $tag_command); $arg_list = array(); $attrs = $this->_parse_attrs($tag_args); @@ -438,13 +436,17 @@ class Smarty_Compiler extends Smarty { $this->_syntax_error("missing insert name"); } + if (!empty($attrs['script'])) { + $delayed_loading = true; + } + foreach ($attrs as $arg_name => $arg_value) { if (is_bool($arg_value)) $arg_value = $arg_value ? 'true' : 'false'; $arg_list[] = "'$arg_name' => $arg_value"; } - $this->_add_plugin('insert', $name); + $this->_add_plugin('insert', $name, $delayed_loading); return "_run_insert_handler(array(".implode(', ', (array)$arg_list).")); ?>\n"; } @@ -1173,14 +1175,15 @@ class Smarty_Compiler extends Smarty { Function: _add_plugin Purpose: \*======================================================================*/ - function _add_plugin($type, $name) + function _add_plugin($type, $name, $delayed_loading = null) { if (!isset($this->_plugin_info[$type])) { $this->_plugin_info[$type] = array(); } if (!isset($this->_plugin_info[$type][$name])) { $this->_plugin_info[$type][$name] = array($this->_current_file, - $this->_current_line_no); + $this->_current_line_no, + $delayed_loading); } }