mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
Fix plugin behavior for inserts with script attribute.
This commit is contained in:
@@ -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.
|
||||
|
@@ -194,7 +194,8 @@ class Smarty_Compiler extends Smarty {
|
||||
$plugins_code = '<?php $this->_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 "<?php echo \$this->_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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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.
|
||||
|
@@ -194,7 +194,8 @@ class Smarty_Compiler extends Smarty {
|
||||
$plugins_code = '<?php $this->_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 "<?php echo \$this->_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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user