mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 03:14:27 +02:00
- bugfix on modifier and block plugins with same name
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
05/02/2010
|
||||
- bugfix on modifier and block plugins with same name
|
||||
|
||||
02/02/2010
|
||||
- retaining newlines at registered functions and function plugins
|
||||
|
||||
|
@@ -90,8 +90,13 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
|
||||
}
|
||||
$compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $_tpl->properties['file_dependency']);
|
||||
$compiler->template->properties['function'] = array_merge($compiler->template->properties['function'], $_tpl->properties['function']);
|
||||
$compiler->template->required_plugins['compiled'] = array_merge($compiler->template->required_plugins['compiled'], $_tpl->required_plugins['compiled']);
|
||||
$compiler->template->required_plugins['cache'] = array_merge($compiler->template->required_plugins['cache'], $_tpl->required_plugins['cache']);
|
||||
foreach($_tpl->required_plugins as $code => $tmp1) {
|
||||
foreach($tmp1 as $name => $tmp) {
|
||||
foreach($tmp as $type => $data) {
|
||||
$compiler->template->required_plugins[$code][$name][$type] = $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($_tpl);
|
||||
} else {
|
||||
$_output = $compiler->template->extracted_compiled_code;
|
||||
|
@@ -68,25 +68,26 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
||||
$plugins_string = '';
|
||||
if (!empty($compiler->template->required_plugins['compiled'])) {
|
||||
$plugins_string = '<?php ';
|
||||
foreach($compiler->template->required_plugins['compiled'] as $plugin_name => $data) {
|
||||
$plugin = 'smarty_' . $data['type'] . '_' . $plugin_name;
|
||||
$plugins_string .= "if (!is_callable('{$plugin}')) include '{$data['file']}';\n";
|
||||
foreach($compiler->template->required_plugins['compiled'] as $tmp) {
|
||||
foreach($tmp as $data) {
|
||||
$plugins_string .= "if (!is_callable('{$data['function']}')) include '{$data['file']}';\n";
|
||||
}
|
||||
}
|
||||
$plugins_string .= '?>';
|
||||
}
|
||||
if (!empty($compiler->template->required_plugins['cache'])) {
|
||||
$plugins_string .= "<?php echo '/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php ";
|
||||
foreach($compiler->template->required_plugins['cache'] as $plugin_name => $data) {
|
||||
$plugin = 'smarty_' . $data['type'] . '_' . $plugin_name;
|
||||
$plugins_string .= "if (!is_callable(\'{$plugin}\')) include \'{$data['file']}\';\n";
|
||||
foreach($compiler->template->required_plugins['nocache'] as $tmp) {
|
||||
foreach($tmp as $data) {
|
||||
$plugins_string .= "if (!is_callable('{$data['function']}')) include '{$data['file']}';\n";
|
||||
}
|
||||
}
|
||||
$plugins_string .= "?>/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/';?>\n";
|
||||
}
|
||||
$compiler->template->properties['function'][$_name]['compiled'] = $plugins_string . $compiler->template->extracted_compiled_code;
|
||||
$compiler->template->properties['function'][$_name]['nocache_hash'] = $compiler->template->properties['nocache_hash'];
|
||||
$compiler->template->properties['function'][$_name]['has_nocache_code'] = $compiler->template->has_nocache_code;
|
||||
// $compiler->template->properties['function'][$_name]['plugins'] = $compiler->template->required_plugins;
|
||||
$this->compiler->smarty->template_functions[$_name] = $compiler->template->properties['function'][$_name];
|
||||
$compiler->template->properties['function'][$_name]['has_nocache_code'] = $compiler->template->has_nocache_code;
|
||||
$this->compiler->smarty->template_functions[$_name] = $compiler->template->properties['function'][$_name];
|
||||
// restore old compiler status
|
||||
$compiler->template->extracted_compiled_code = $saved_data[1];
|
||||
$compiler->template->extract_code = $saved_data[2];
|
||||
|
@@ -68,7 +68,7 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
// storage for block data
|
||||
public $block_data = array();
|
||||
// required plugins
|
||||
public $required_plugins = array('compiled' => array(), 'cache' => array());
|
||||
public $required_plugins = array('compiled' => array(), 'nocache' => array());
|
||||
|
||||
/**
|
||||
* Create template data object
|
||||
@@ -451,8 +451,13 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
}
|
||||
if ($this->parent instanceof Smarty_Template or $this->parent instanceof Smarty_Internal_Template) {
|
||||
$this->parent->properties['file_dependency'] = array_merge($this->parent->properties['file_dependency'], $this->properties['file_dependency']);
|
||||
$this->parent->required_plugins['compiled'] = array_merge($this->parent->required_plugins['compiled'], $this->required_plugins['compiled']);
|
||||
$this->parent->required_plugins['cache'] = array_merge($this->parent->required_plugins['cache'], $this->required_plugins['cache']);
|
||||
foreach($this->required_plugins as $code => $tmp1) {
|
||||
foreach($tmp1 as $name => $tmp) {
|
||||
foreach($tmp as $type => $data) {
|
||||
$this->parent->required_plugins[$code][$name][$type] = $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($this->smarty->debugging) {
|
||||
Smarty_Internal_Debug::end_render($this);
|
||||
@@ -722,18 +727,20 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
|
||||
if (!$cache) {
|
||||
if (!empty($this->required_plugins['compiled'])) {
|
||||
$plugins_string = '<?php ';
|
||||
foreach($this->required_plugins['compiled'] as $plugin_name => $data) {
|
||||
$plugin = 'smarty_' . $data['type'] . '_' . $plugin_name;
|
||||
$plugins_string .= "if (!is_callable('{$plugin}')) include '{$data['file']}';\n";
|
||||
foreach($this->required_plugins['compiled'] as $tmp) {
|
||||
foreach($tmp as $data) {
|
||||
$plugins_string .= "if (!is_callable('{$data['function']}')) include '{$data['file']}';\n";
|
||||
}
|
||||
}
|
||||
$plugins_string .= '?>';
|
||||
}
|
||||
if (!empty($this->required_plugins['cache'])) {
|
||||
if (!empty($this->required_plugins['nocache'])) {
|
||||
$this->has_nocache_code = true;
|
||||
$plugins_string .= "<?php echo '/*%%SmartyNocache:{$this->properties['nocache_hash']}%%*/<?php ";
|
||||
foreach($this->required_plugins['cache'] as $plugin_name => $data) {
|
||||
$plugin = 'smarty_' . $data['type'] . '_' . $plugin_name;
|
||||
$plugins_string .= "if (!is_callable(\'{$plugin}\')) include \'{$data['file']}\';\n";
|
||||
foreach($this->required_plugins['nocache'] as $tmp) {
|
||||
foreach($tmp as $data) {
|
||||
$plugins_string .= "if (!is_callable('{$data['function']}')) include '{$data['file']}';\n";
|
||||
}
|
||||
}
|
||||
$plugins_string .= "?>/*/%%SmartyNocache:{$this->properties['nocache_hash']}%%*/';?>\n";
|
||||
}
|
||||
|
@@ -15,15 +15,13 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
// hash for nocache sections
|
||||
private $nocache_hash = null;
|
||||
// suppress generation of nocache code
|
||||
public $suppressNocacheProcessing = false;
|
||||
public $suppressNocacheProcessing = false;
|
||||
// compile tag objects
|
||||
static $_tag_objects = array();
|
||||
// tag stack
|
||||
public $_tag_stack = array();
|
||||
// current template
|
||||
public $template = null;
|
||||
// required plugins
|
||||
public $required_plugins_call = array();
|
||||
|
||||
/**
|
||||
* Initialize compiler
|
||||
@@ -270,23 +268,47 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
*/
|
||||
public function getPlugin($plugin_name, $type)
|
||||
{
|
||||
if (isset($this->template->required_plugins_call[$plugin_name][$type])) {
|
||||
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
|
||||
if (isset($this->template->required_plugins['compiled'][$plugin_name])) {
|
||||
$this->template->required_plugins['cache'][$plugin_name] = $this->template->required_plugins['compiled'][$plugin_name];
|
||||
}
|
||||
} else {
|
||||
if (isset($this->template->required_plugins['cache'][$plugin_name])) {
|
||||
$this->template->required_plugins['compiled'][$plugin_name] = $this->template->required_plugins['cache'][$plugin_name];
|
||||
}
|
||||
$function = null;
|
||||
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
|
||||
if (isset($this->template->required_plugins['nocache'][$plugin_name][$type])) {
|
||||
$function = $this->template->required_plugins['nocache'][$plugin_name][$type]['function'];
|
||||
} else if (isset($this->template->required_plugins['compiled'][$plugin_name][$type])) {
|
||||
$this->template->required_plugins['nocache'][$plugin_name][$type] = $this->template->required_plugins['compiled'][$plugin_name][$type];
|
||||
$function = $this->template->required_plugins['nocache'][$plugin_name][$type]['function'];
|
||||
}
|
||||
} else {
|
||||
if (isset($this->template->required_plugins['compiled'][$plugin_name][$type])) {
|
||||
$function = $this->template->required_plugins['compiled'][$plugin_name][$type]['function'];
|
||||
} else if (isset($this->template->required_plugins['compiled'][$plugin_name][$type])) {
|
||||
$this->template->required_plugins['compiled'][$plugin_name][$type] = $this->template->required_plugins['nocache'][$plugin_name][$type];
|
||||
$function = $this->template->required_plugins['compiled'][$plugin_name][$type]['function'];
|
||||
}
|
||||
}
|
||||
if (isset($function)) {
|
||||
if ($type == 'modifier') {
|
||||
$this->template->saved_modifer[$plugin_name] = true;
|
||||
}
|
||||
return $this->template->required_plugins_call[$plugin_name][$type];
|
||||
return $function;
|
||||
}
|
||||
/**
|
||||
* if (isset($this->template->required_plugins_call[$plugin_name][$type])) {
|
||||
* if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
|
||||
* if (isset($this->template->required_plugins['compiled'][$plugin_name])) {
|
||||
* $this->template->required_plugins['cache'][$plugin_name] = $this->template->required_plugins['compiled'][$plugin_name];
|
||||
* }
|
||||
* } else {
|
||||
* if (isset($this->template->required_plugins['cache'][$plugin_name])) {
|
||||
* $this->template->required_plugins['compiled'][$plugin_name] = $this->template->required_plugins['cache'][$plugin_name];
|
||||
* }
|
||||
* }
|
||||
* if ($type == 'modifier') {
|
||||
* $this->template->saved_modifer[$plugin_name] = true;
|
||||
* }
|
||||
* return $this->template->required_plugins_call[$plugin_name][$type];
|
||||
* }
|
||||
*/
|
||||
// loop through plugin dirs and find the plugin
|
||||
$plugin = 'smarty_' . $type . '_' . $plugin_name;
|
||||
$function = 'smarty_' . $type . '_' . $plugin_name;
|
||||
$found = false;
|
||||
foreach((array)$this->smarty->plugins_dir as $_plugin_dir) {
|
||||
$file = rtrim($_plugin_dir, '/\\') . DS . $type . '.' . $plugin_name . '.php';
|
||||
@@ -298,23 +320,31 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
}
|
||||
if ($found) {
|
||||
// if (is_callable($plugin)) {
|
||||
$this->template->required_plugins_call[$plugin_name][$type] = $plugin;
|
||||
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
|
||||
$this->template->required_plugins['cache'][$plugin_name]['file'] = $file;
|
||||
$this->template->required_plugins['cache'][$plugin_name]['type'] = $type;
|
||||
$this->template->required_plugins['nocache'][$plugin_name][$type]['file'] = $file;
|
||||
$this->template->required_plugins['nocache'][$plugin_name][$type]['function'] = $function;
|
||||
} else {
|
||||
$this->template->required_plugins['compiled'][$plugin_name]['file'] = $file;
|
||||
$this->template->required_plugins['compiled'][$plugin_name]['type'] = $type;
|
||||
$this->template->required_plugins['compiled'][$plugin_name][$type]['file'] = $file;
|
||||
$this->template->required_plugins['compiled'][$plugin_name][$type]['function'] = $function;
|
||||
}
|
||||
/**
|
||||
* $this->template->required_plugins_call[$plugin_name][$type] = $plugin;
|
||||
* if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
|
||||
* $this->template->required_plugins['cache'][$plugin_name]['file'] = $file;
|
||||
* $this->template->required_plugins['cache'][$plugin_name]['type'] = $type;
|
||||
* } else {
|
||||
* $this->template->required_plugins['compiled'][$plugin_name]['file'] = $file;
|
||||
* $this->template->required_plugins['compiled'][$plugin_name]['type'] = $type;
|
||||
* }
|
||||
*/
|
||||
if ($type == 'modifier') {
|
||||
$this->template->saved_modifer[$plugin_name] = true;
|
||||
}
|
||||
|
||||
return $plugin;
|
||||
return $function;
|
||||
}
|
||||
if (is_callable($plugin)) {
|
||||
if (is_callable($function)) {
|
||||
// plugin function is defined in the script
|
||||
return $plugin;
|
||||
return $function;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -344,8 +374,8 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
// make sure we include modifer plugins for nocache code
|
||||
if (isset($this->template->saved_modifer)) {
|
||||
foreach ($this->template->saved_modifer as $plugin_name => $dummy) {
|
||||
if (isset($this->template->required_plugins['compiled'][$plugin_name])) {
|
||||
$this->template->required_plugins['cache'][$plugin_name] = $this->template->required_plugins['compiled'][$plugin_name];
|
||||
if (isset($this->template->required_plugins['compiled'][$plugin_name]['modifier'])) {
|
||||
$this->template->required_plugins['nocache'][$plugin_name]['modifier'] = $this->template->required_plugins['compiled'][$plugin_name]['modifier'];
|
||||
}
|
||||
}
|
||||
unset($this->template->saved_modifer);
|
||||
|
Reference in New Issue
Block a user