Fix plugin behavior for inserts with script attribute.

This commit is contained in:
andrey
2002-03-19 22:21:22 +00:00
parent 6ea8450ccf
commit 138421b6b5
4 changed files with 40 additions and 18 deletions

View File

@@ -1444,7 +1444,7 @@ function _run_insert_handler($args)
function _load_plugins($plugins) function _load_plugins($plugins)
{ {
foreach ($plugins as $plugin_info) { 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]; $plugin = &$this->_plugins[$type][$name];
/* /*
@@ -1508,6 +1508,14 @@ function _run_insert_handler($args)
continue; 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. * Plugin specific processing and error checking.

View File

@@ -194,7 +194,8 @@ class Smarty_Compiler extends Smarty {
$plugins_code = '<?php $this->_load_plugins(array('; $plugins_code = '<?php $this->_load_plugins(array(';
foreach ($this->_plugin_info as $plugin_type => $plugins) { foreach ($this->_plugin_info as $plugin_type => $plugins) {
foreach ($plugins as $plugin_name => $plugin_info) { 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 .= ")); ?>"; $plugins_code .= ")); ?>";
@@ -408,10 +409,7 @@ class Smarty_Compiler extends Smarty {
\*======================================================================*/ \*======================================================================*/
function _compile_custom_tag($tag_command, $tag_args) function _compile_custom_tag($tag_command, $tag_args)
{ {
$this->_add_plugin('function', $this->_add_plugin('function', $tag_command);
$tag_command,
$this->_current_file,
$this->_current_line_no);
$arg_list = array(); $arg_list = array();
$attrs = $this->_parse_attrs($tag_args); $attrs = $this->_parse_attrs($tag_args);
@@ -438,13 +436,17 @@ class Smarty_Compiler extends Smarty {
$this->_syntax_error("missing insert name"); $this->_syntax_error("missing insert name");
} }
if (!empty($attrs['script'])) {
$delayed_loading = true;
}
foreach ($attrs as $arg_name => $arg_value) { foreach ($attrs as $arg_name => $arg_value) {
if (is_bool($arg_value)) if (is_bool($arg_value))
$arg_value = $arg_value ? 'true' : 'false'; $arg_value = $arg_value ? 'true' : 'false';
$arg_list[] = "'$arg_name' => $arg_value"; $arg_list[] = "'$arg_name' => $arg_value";
} }
$this->_add_plugin('insert', $name); $this->_add_plugin('insert', $name, $delayed_loading);
return "<?php echo \$this->_run_insert_handler(array(".implode(', ', (array)$arg_list).")); ?>\n"; return "<?php echo \$this->_run_insert_handler(array(".implode(', ', (array)$arg_list).")); ?>\n";
} }
@@ -1173,14 +1175,15 @@ class Smarty_Compiler extends Smarty {
Function: _add_plugin Function: _add_plugin
Purpose: Purpose:
\*======================================================================*/ \*======================================================================*/
function _add_plugin($type, $name) function _add_plugin($type, $name, $delayed_loading = null)
{ {
if (!isset($this->_plugin_info[$type])) { if (!isset($this->_plugin_info[$type])) {
$this->_plugin_info[$type] = array(); $this->_plugin_info[$type] = array();
} }
if (!isset($this->_plugin_info[$type][$name])) { if (!isset($this->_plugin_info[$type][$name])) {
$this->_plugin_info[$type][$name] = array($this->_current_file, $this->_plugin_info[$type][$name] = array($this->_current_file,
$this->_current_line_no); $this->_current_line_no,
$delayed_loading);
} }
} }

View File

@@ -1444,7 +1444,7 @@ function _run_insert_handler($args)
function _load_plugins($plugins) function _load_plugins($plugins)
{ {
foreach ($plugins as $plugin_info) { 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]; $plugin = &$this->_plugins[$type][$name];
/* /*
@@ -1508,6 +1508,14 @@ function _run_insert_handler($args)
continue; 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. * Plugin specific processing and error checking.

View File

@@ -194,7 +194,8 @@ class Smarty_Compiler extends Smarty {
$plugins_code = '<?php $this->_load_plugins(array('; $plugins_code = '<?php $this->_load_plugins(array(';
foreach ($this->_plugin_info as $plugin_type => $plugins) { foreach ($this->_plugin_info as $plugin_type => $plugins) {
foreach ($plugins as $plugin_name => $plugin_info) { 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 .= ")); ?>"; $plugins_code .= ")); ?>";
@@ -408,10 +409,7 @@ class Smarty_Compiler extends Smarty {
\*======================================================================*/ \*======================================================================*/
function _compile_custom_tag($tag_command, $tag_args) function _compile_custom_tag($tag_command, $tag_args)
{ {
$this->_add_plugin('function', $this->_add_plugin('function', $tag_command);
$tag_command,
$this->_current_file,
$this->_current_line_no);
$arg_list = array(); $arg_list = array();
$attrs = $this->_parse_attrs($tag_args); $attrs = $this->_parse_attrs($tag_args);
@@ -438,13 +436,17 @@ class Smarty_Compiler extends Smarty {
$this->_syntax_error("missing insert name"); $this->_syntax_error("missing insert name");
} }
if (!empty($attrs['script'])) {
$delayed_loading = true;
}
foreach ($attrs as $arg_name => $arg_value) { foreach ($attrs as $arg_name => $arg_value) {
if (is_bool($arg_value)) if (is_bool($arg_value))
$arg_value = $arg_value ? 'true' : 'false'; $arg_value = $arg_value ? 'true' : 'false';
$arg_list[] = "'$arg_name' => $arg_value"; $arg_list[] = "'$arg_name' => $arg_value";
} }
$this->_add_plugin('insert', $name); $this->_add_plugin('insert', $name, $delayed_loading);
return "<?php echo \$this->_run_insert_handler(array(".implode(', ', (array)$arg_list).")); ?>\n"; return "<?php echo \$this->_run_insert_handler(array(".implode(', ', (array)$arg_list).")); ?>\n";
} }
@@ -1173,14 +1175,15 @@ class Smarty_Compiler extends Smarty {
Function: _add_plugin Function: _add_plugin
Purpose: Purpose:
\*======================================================================*/ \*======================================================================*/
function _add_plugin($type, $name) function _add_plugin($type, $name, $delayed_loading = null)
{ {
if (!isset($this->_plugin_info[$type])) { if (!isset($this->_plugin_info[$type])) {
$this->_plugin_info[$type] = array(); $this->_plugin_info[$type] = array();
} }
if (!isset($this->_plugin_info[$type][$name])) { if (!isset($this->_plugin_info[$type][$name])) {
$this->_plugin_info[$type][$name] = array($this->_current_file, $this->_plugin_info[$type][$name] = array($this->_current_file,
$this->_current_line_no); $this->_current_line_no,
$delayed_loading);
} }
} }