mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
use parent_compiler object for storing required plugins
This commit is contained in:
@@ -167,6 +167,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
|||||||
$_tpl->compiled->nocache_hash = $compiler->template->compiled->nocache_hash;
|
$_tpl->compiled->nocache_hash = $compiler->template->compiled->nocache_hash;
|
||||||
$_tpl->allow_relative_path = true;
|
$_tpl->allow_relative_path = true;
|
||||||
$_tpl->loadCompiler();
|
$_tpl->loadCompiler();
|
||||||
|
$_tpl->compiler->parent_compiler = $compiler;
|
||||||
$_tpl->compiler->_tag_objects = $compiler->_tag_objects;
|
$_tpl->compiler->_tag_objects = $compiler->_tag_objects;
|
||||||
$_tpl->compiler->inheritance = true;
|
$_tpl->compiler->inheritance = true;
|
||||||
$_tpl->compiler->suppressHeader = true;
|
$_tpl->compiler->suppressHeader = true;
|
||||||
@@ -192,7 +193,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
|||||||
if ($_tpl->compiled->has_nocache_code) {
|
if ($_tpl->compiled->has_nocache_code) {
|
||||||
$compiler->template->compiled->has_nocache_code = true;
|
$compiler->template->compiled->has_nocache_code = true;
|
||||||
}
|
}
|
||||||
foreach ($_tpl->required_plugins as $key => $tmp1) {
|
foreach ($_tpl->compiled->required_plugins as $key => $tmp1) {
|
||||||
if ($compiler->nocache && $compiler->template->caching) {
|
if ($compiler->nocache && $compiler->template->caching) {
|
||||||
$code = 'nocache';
|
$code = 'nocache';
|
||||||
} else {
|
} else {
|
||||||
@@ -200,7 +201,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
|||||||
}
|
}
|
||||||
foreach ($tmp1 as $name => $tmp) {
|
foreach ($tmp1 as $name => $tmp) {
|
||||||
foreach ($tmp as $type => $data) {
|
foreach ($tmp as $type => $data) {
|
||||||
$compiler->template->required_plugins[$code][$name][$type] = $data;
|
$compiler->parent_compiler->template->compiled->required_plugins[$code][$name][$type] = $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -140,23 +140,6 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
|||||||
$output .= "/* {$_funcNameCaching} */\n";
|
$output .= "/* {$_funcNameCaching} */\n";
|
||||||
$output .= "if (!function_exists('{$_funcNameCaching}')) {\n";
|
$output .= "if (!function_exists('{$_funcNameCaching}')) {\n";
|
||||||
$output .= "function {$_funcNameCaching} (\$_smarty_tpl,\$params) {\n";
|
$output .= "function {$_funcNameCaching} (\$_smarty_tpl,\$params) {\n";
|
||||||
// build plugin include code
|
|
||||||
if (!empty($compiler->template->required_plugins['compiled'])) {
|
|
||||||
foreach ($compiler->template->required_plugins['compiled'] as $tmp) {
|
|
||||||
foreach ($tmp as $data) {
|
|
||||||
$output .= "if (!is_callable('{$data['function']}')) require_once '{$data['file']}';\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!empty($compiler->template->required_plugins['nocache'])) {
|
|
||||||
$output .= "echo '/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php ";
|
|
||||||
foreach ($compiler->template->required_plugins['nocache'] as $tmp) {
|
|
||||||
foreach ($tmp as $data) {
|
|
||||||
$output .= "if (!is_callable(\'{$data['function']}\')) require_once \'{$data['file']}\';\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$output .= "?>/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/';\n";
|
|
||||||
}
|
|
||||||
$output .= "ob_start();\n";
|
$output .= "ob_start();\n";
|
||||||
$output .= "\$_smarty_tpl->compiled->has_nocache_code = true;\n";
|
$output .= "\$_smarty_tpl->compiled->has_nocache_code = true;\n";
|
||||||
$output .= $_paramsCode;
|
$output .= $_paramsCode;
|
||||||
@@ -186,17 +169,6 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
|||||||
$output .= "/* {$_funcName} */\n";
|
$output .= "/* {$_funcName} */\n";
|
||||||
$output .= "if (!function_exists('{$_funcName}')) {\n";
|
$output .= "if (!function_exists('{$_funcName}')) {\n";
|
||||||
$output .= "function {$_funcName}(\$_smarty_tpl,\$params) {\n";
|
$output .= "function {$_funcName}(\$_smarty_tpl,\$params) {\n";
|
||||||
// build plugin include code
|
|
||||||
if (!empty($compiler->template->required_plugins['nocache'])) {
|
|
||||||
$compiler->template->required_plugins['compiled'] = array_merge($compiler->template->required_plugins['compiled'], $compiler->template->required_plugins['nocache']);
|
|
||||||
}
|
|
||||||
if (!empty($compiler->template->required_plugins['compiled'])) {
|
|
||||||
foreach ($compiler->template->required_plugins['compiled'] as $tmp) {
|
|
||||||
foreach ($tmp as $data) {
|
|
||||||
$output .= "if (!is_callable('{$data['function']}')) require_once '{$data['file']}';\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$output .= "\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\n";
|
$output .= "\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\n";
|
||||||
$output .= $_paramsCode;
|
$output .= $_paramsCode;
|
||||||
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value);\n}?>";
|
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value);\n}?>";
|
||||||
@@ -209,6 +181,14 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
|||||||
$output .= "?>\n";
|
$output .= "?>\n";
|
||||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
|
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
|
||||||
$compiler->parent_compiler->templateFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
|
$compiler->parent_compiler->templateFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
|
||||||
|
// nocache plugins must be copied
|
||||||
|
if (!empty($compiler->template->compiled->required_plugins['nocache'])) {
|
||||||
|
foreach ($compiler->template->compiled->required_plugins['nocache'] as $plugin => $tmp) {
|
||||||
|
foreach ($tmp as $type => $data) {
|
||||||
|
$compiler->parent_compiler->template->compiled->required_plugins['compiled'][$plugin][$type] = $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// restore old buffer
|
// restore old buffer
|
||||||
|
|
||||||
$compiler->parser->current_buffer = $saved_data[1];
|
$compiler->parser->current_buffer = $saved_data[1];
|
||||||
|
@@ -229,20 +229,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
|||||||
}
|
}
|
||||||
$compiler->parent_compiler->mergedSubTemplatesCode[$tpl->compiled->unifunc] = $compiled_code;
|
$compiler->parent_compiler->mergedSubTemplatesCode[$tpl->compiled->unifunc] = $compiled_code;
|
||||||
$has_compiled_template = true;
|
$has_compiled_template = true;
|
||||||
if (!empty($tpl->required_plugins['compiled'])) {
|
|
||||||
foreach ($tpl->required_plugins['compiled'] as $name => $callBack) {
|
|
||||||
if (!isset($compiler->template->required_plugins['compiled'][$name])) {
|
|
||||||
$compiler->template->required_plugins['compiled'][$name] = $callBack;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!empty($tpl->required_plugins['nocache'])) {
|
|
||||||
foreach ($tpl->required_plugins['nocache'] as $name => $callBack) {
|
|
||||||
if (!isset($compiler->template->required_plugins['nocache'][$name])) {
|
|
||||||
$compiler->template->required_plugins['nocache'][$name] = $callBack;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unset ($tpl);
|
unset ($tpl);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@@ -133,8 +133,8 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isset($compiler->template->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) ||
|
if (isset($compiler->parent_compiler->template->compiled->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) ||
|
||||||
isset($compiler->template->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file'])
|
isset($compiler->parent_compiler->template->compiled->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file'])
|
||||||
) {
|
) {
|
||||||
// was a plugin
|
// was a plugin
|
||||||
$compiler->known_modifier_type[$modifier] = 4;
|
$compiler->known_modifier_type[$modifier] = 4;
|
||||||
|
@@ -142,11 +142,11 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C
|
|||||||
$path = $compiler->smarty->loadPlugin($plugin_name, false);
|
$path = $compiler->smarty->loadPlugin($plugin_name, false);
|
||||||
if ($path) {
|
if ($path) {
|
||||||
if ($compiler->template->caching) {
|
if ($compiler->template->caching) {
|
||||||
$compiler->template->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['file'] = $path;
|
$compiler->parent_compiler->template->compiled->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['file'] = $path;
|
||||||
$compiler->template->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name;
|
$compiler->parent_compiler->template->compiled->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name;
|
||||||
} else {
|
} else {
|
||||||
$compiler->template->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['file'] = $path;
|
$compiler->parent_compiler->template->compiled->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['file'] = $path;
|
||||||
$compiler->template->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name;
|
$compiler->parent_compiler->template->compiled->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// not found
|
// not found
|
||||||
|
@@ -47,8 +47,8 @@ class Smarty_Internal_Extension_CodeFrame
|
|||||||
$output .= "function {$properties['unifunc']} (\$_smarty_tpl) {\n";
|
$output .= "function {$properties['unifunc']} (\$_smarty_tpl) {\n";
|
||||||
// include code for plugins
|
// include code for plugins
|
||||||
if (!$cache) {
|
if (!$cache) {
|
||||||
if (!empty($_template->required_plugins['compiled'])) {
|
if (!empty($_template->compiled->required_plugins['compiled'])) {
|
||||||
foreach ($_template->required_plugins['compiled'] as $tmp) {
|
foreach ($_template->compiled->required_plugins['compiled'] as $tmp) {
|
||||||
foreach ($tmp as $data) {
|
foreach ($tmp as $data) {
|
||||||
$file = addslashes($data['file']);
|
$file = addslashes($data['file']);
|
||||||
if (is_array($data['function'])) {
|
if (is_array($data['function'])) {
|
||||||
@@ -59,10 +59,10 @@ class Smarty_Internal_Extension_CodeFrame
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!empty($_template->required_plugins['nocache'])) {
|
if ($_template->caching && !empty($_template->compiled->required_plugins['nocache'])) {
|
||||||
$_template->has_nocache_code = true;
|
$_template->compiled->has_nocache_code = true;
|
||||||
$output .= "echo '/*%%SmartyNocache:{$_template->compiled->nocache_hash}%%*/<?php \$_smarty = \$_smarty_tpl->smarty; ";
|
$output .= "echo '/*%%SmartyNocache:{$_template->compiled->nocache_hash}%%*/<?php \$_smarty = \$_smarty_tpl->smarty; ";
|
||||||
foreach ($_template->required_plugins['nocache'] as $tmp) {
|
foreach ($_template->compiled->required_plugins['nocache'] as $tmp) {
|
||||||
foreach ($tmp as $data) {
|
foreach ($tmp as $data) {
|
||||||
$file = addslashes($data['file']);
|
$file = addslashes($data['file']);
|
||||||
if (is_Array($data['function'])) {
|
if (is_Array($data['function'])) {
|
||||||
|
@@ -48,14 +48,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
*/
|
*/
|
||||||
public $mustCompile = null;
|
public $mustCompile = null;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* required plugins
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public $required_plugins = array('compiled' => array(), 'nocache' => array());
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* blocks for template inheritance
|
* blocks for template inheritance
|
||||||
*
|
*
|
||||||
@@ -340,10 +332,10 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
}
|
}
|
||||||
if ($parentIsTpl) {
|
if ($parentIsTpl) {
|
||||||
$this->parent->tpl_function = array_merge($this->parent->tpl_function, $this->tpl_function);
|
$this->parent->tpl_function = array_merge($this->parent->tpl_function, $this->tpl_function);
|
||||||
foreach ($this->required_plugins as $code => $tmp1) {
|
foreach ($this->compiled->required_plugins as $code => $tmp1) {
|
||||||
foreach ($tmp1 as $name => $tmp) {
|
foreach ($tmp1 as $name => $tmp) {
|
||||||
foreach ($tmp as $type => $data) {
|
foreach ($tmp as $type => $data) {
|
||||||
$this->parent->required_plugins[$code][$name][$type] = $data;
|
$this->parent->compiled->required_plugins[$code][$name][$type] = $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -850,18 +850,18 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
{
|
{
|
||||||
$function = null;
|
$function = null;
|
||||||
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
|
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
|
||||||
if (isset($this->template->required_plugins['nocache'][$plugin_name][$plugin_type])) {
|
if (isset($this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type])) {
|
||||||
$function = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function'];
|
$function = $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['function'];
|
||||||
} elseif (isset($this->template->required_plugins['compiled'][$plugin_name][$plugin_type])) {
|
} elseif (isset($this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type])) {
|
||||||
$this->template->required_plugins['nocache'][$plugin_name][$plugin_type] = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type];
|
$this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type] = $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type];
|
||||||
$function = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function'];
|
$function = $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['function'];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isset($this->template->required_plugins['compiled'][$plugin_name][$plugin_type])) {
|
if (isset($this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type])) {
|
||||||
$function = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function'];
|
$function = $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['function'];
|
||||||
} elseif (isset($this->template->required_plugins['nocache'][$plugin_name][$plugin_type])) {
|
} elseif (isset($this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type])) {
|
||||||
$this->template->required_plugins['compiled'][$plugin_name][$plugin_type] = $this->template->required_plugins['nocache'][$plugin_name][$plugin_type];
|
$this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type] = $this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type];
|
||||||
$function = $this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function'];
|
$function = $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['function'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isset($function)) {
|
if (isset($function)) {
|
||||||
@@ -877,11 +877,11 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
|
|
||||||
if (is_string($file)) {
|
if (is_string($file)) {
|
||||||
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
|
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
|
||||||
$this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['file'] = $file;
|
$this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['file'] = $file;
|
||||||
$this->template->required_plugins['nocache'][$plugin_name][$plugin_type]['function'] = $function;
|
$this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name][$plugin_type]['function'] = $function;
|
||||||
} else {
|
} else {
|
||||||
$this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['file'] = $file;
|
$this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['file'] = $file;
|
||||||
$this->template->required_plugins['compiled'][$plugin_name][$plugin_type]['function'] = $function;
|
$this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name][$plugin_type]['function'] = $function;
|
||||||
}
|
}
|
||||||
if ($plugin_type == 'modifier') {
|
if ($plugin_type == 'modifier') {
|
||||||
$this->modifier_plugins[$plugin_name] = true;
|
$this->modifier_plugins[$plugin_name] = true;
|
||||||
@@ -918,11 +918,11 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
if ($script !== null) {
|
if ($script !== null) {
|
||||||
if (is_file($script)) {
|
if (is_file($script)) {
|
||||||
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
|
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
|
||||||
$this->template->required_plugins['nocache'][$tag][$plugin_type]['file'] = $script;
|
$this->parent_compiler->template->compiled->required_plugins['nocache'][$tag][$plugin_type]['file'] = $script;
|
||||||
$this->template->required_plugins['nocache'][$tag][$plugin_type]['function'] = $callback;
|
$this->parent_compiler->template->compiled->required_plugins['nocache'][$tag][$plugin_type]['function'] = $callback;
|
||||||
} else {
|
} else {
|
||||||
$this->template->required_plugins['compiled'][$tag][$plugin_type]['file'] = $script;
|
$this->parent_compiler->template->compiled->required_plugins['compiled'][$tag][$plugin_type]['file'] = $script;
|
||||||
$this->template->required_plugins['compiled'][$tag][$plugin_type]['function'] = $callback;
|
$this->parent_compiler->template->compiled->required_plugins['compiled'][$tag][$plugin_type]['function'] = $callback;
|
||||||
}
|
}
|
||||||
require_once $script;
|
require_once $script;
|
||||||
} else {
|
} else {
|
||||||
@@ -989,8 +989,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
"/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n";
|
"/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n";
|
||||||
// make sure we include modifier plugins for nocache code
|
// make sure we include modifier plugins for nocache code
|
||||||
foreach ($this->modifier_plugins as $plugin_name => $dummy) {
|
foreach ($this->modifier_plugins as $plugin_name => $dummy) {
|
||||||
if (isset($this->template->required_plugins['compiled'][$plugin_name]['modifier'])) {
|
if (isset($this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name]['modifier'])) {
|
||||||
$this->template->required_plugins['nocache'][$plugin_name]['modifier'] = $this->template->required_plugins['compiled'][$plugin_name]['modifier'];
|
$this->parent_compiler->template->compiled->required_plugins['nocache'][$plugin_name]['modifier'] = $this->parent_compiler->template->compiled->required_plugins['compiled'][$plugin_name]['modifier'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user