mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-09 12:54:26 +02:00
- fixed scope problem with parent variables when appending variables within templates.
- fixed code for {block} without childs (possible sources for notice errors removed)
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
04/13/2009
|
||||
- fixed scope problem with parent variables when appending variables within templates.
|
||||
- fixed code for {block} without childs (possible sources for notice errors removed)
|
||||
|
||||
04/12/2009
|
||||
- added append and prepend attribute to {block} tag
|
||||
|
||||
|
@@ -34,12 +34,14 @@ class Smarty_Internal_Compile_BlockClose extends Smarty_Internal_CompileBase {
|
||||
$this->compiler->trigger_template_error('mismatching name attributes "' . $saved_data[0]['name'] . '" and "' . $_attr['name'] . '"');
|
||||
}
|
||||
$_name = trim($saved_data[0]['name'], "'");
|
||||
if (isset($compiler->template->block_data[$_name])) {
|
||||
if ($compiler->template->block_data[$_name]['mode'] == 'prepend') {
|
||||
$_output = $compiler->template->block_data[$_name]['compiled'].$compiler->template->extracted_compiled_code;
|
||||
$_output = $compiler->template->block_data[$_name]['compiled'] . $compiler->template->extracted_compiled_code;
|
||||
} elseif ($compiler->template->block_data[$_name]['mode'] == 'append') {
|
||||
$_output = $compiler->template->extracted_compiled_code.$compiler->template->block_data[$_name]['compiled'];
|
||||
$_output = $compiler->template->extracted_compiled_code . $compiler->template->block_data[$_name]['compiled'];
|
||||
} elseif (!empty($compiler->template->block_data[$_name])) {
|
||||
$_output = $compiler->template->block_data[$_name]['compiled'];
|
||||
}
|
||||
} else {
|
||||
$_output = $compiler->template->extracted_compiled_code;
|
||||
}
|
||||
|
@@ -53,27 +53,31 @@ class Smarty_Internal_Compile_Extend extends Smarty_Internal_CompileBase {
|
||||
$tpl->suppressHeader = false;
|
||||
$_name = trim($_match[3], "\"'");
|
||||
|
||||
if (isset($this->compiler->template->block_data[$_name])) {
|
||||
if ($this->compiler->template->block_data[$_name]['mode'] == 'prepend') {
|
||||
$this->compiler->template->block_data[$_name]['compiled'] .= $compiled_content;
|
||||
$this->compiler->template->block_data[$_name]['source'] .= $matches[3];
|
||||
} elseif ($this->compiler->template->block_data[$_name]['mode'] == 'append') {
|
||||
$this->compiler->template->block_data[$_name]['compiled'] = $compiled_content . $this->compiler->template->block_data[$_name]['compiled'];
|
||||
$this->compiler->template->block_data[$_name]['source'] = $matches[3] . $this->compiler->template->block_data[$_name]['source'];
|
||||
} elseif (!isset($this->compiler->template->block_data[$_name])) {
|
||||
}
|
||||
} else {
|
||||
$this->compiler->template->block_data[$_name]['compiled'] = $compiled_content;
|
||||
$this->compiler->template->block_data[$_name]['source'] = $matches[3];
|
||||
}
|
||||
if (isset($this->compiler->template->block_data[$_name]['mode'])) {
|
||||
if ($this->compiler->template->block_data[$_name]['mode'] != 'replace') {
|
||||
if (preg_match('/(.?)(append=true)(.*)/', $matches[2], $_match) != 0) {
|
||||
$this->compiler->template->block_data[$_name]['mode'] = 'append';
|
||||
} elseif (preg_match('/(.?)(prepend=true)(.*)/', $matches[2], $_match) != 0) {
|
||||
$this->compiler->template->block_data[$_name]['mode'] = 'prepend';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->compiler->template->block_data[$_name]['mode'] = 'replace';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -86,9 +86,17 @@ class Smarty_Internal_TemplateBase {
|
||||
if ($_key != '') {
|
||||
if (!isset($this->tpl_vars[$_key])) {
|
||||
$this->check_tplvar($_key);
|
||||
$tpl_var_inst = $this->getVariable($_key, null, true, false);
|
||||
if ($tpl_var_inst instanceof Undefined_Smarty_Variable) {
|
||||
$this->tpl_vars[$_key] = new Smarty_variable(null, $nocache, $scope);
|
||||
} else {
|
||||
$this->tpl_vars[$_key] = clone $tpl_var_inst;
|
||||
if ($scope != SMARTY_LOCAL_SCOPE) {
|
||||
$this->tpl_vars[$_key]->scope = $scope;
|
||||
}
|
||||
if (!is_array($this->tpl_vars[$_key]->value)) {
|
||||
}
|
||||
}
|
||||
if (!(is_array($this->tpl_vars[$_key]->value) || $this->tpl_vars[$_key]->value instanceof ArrayAccess)) {
|
||||
settype($this->tpl_vars[$_key]->value, 'array');
|
||||
}
|
||||
if ($merge && is_array($_val)) {
|
||||
@@ -104,9 +112,17 @@ class Smarty_Internal_TemplateBase {
|
||||
if ($tpl_var != '' && isset($value)) {
|
||||
if (!isset($this->tpl_vars[$tpl_var])) {
|
||||
$this->check_tplvar($tpl_var);
|
||||
$tpl_var_inst = $this->getVariable($tpl_var, null, true, false);
|
||||
if ($tpl_var_inst instanceof Undefined_Smarty_Variable) {
|
||||
$this->tpl_vars[$tpl_var] = new Smarty_variable(null, $nocache, $scope);
|
||||
} else {
|
||||
$this->tpl_vars[$tpl_var] = clone $tpl_var_inst;
|
||||
if ($scope != SMARTY_LOCAL_SCOPE) {
|
||||
$this->tpl_vars[$tpl_var]->scope = $scope;
|
||||
}
|
||||
if (!is_array($this->tpl_vars[$tpl_var]->value)) {
|
||||
}
|
||||
}
|
||||
if (!(is_array($this->tpl_vars[$tpl_var]->value) || $this->tpl_vars[$tpl_var]->value instanceof ArrayAccess)) {
|
||||
settype($this->tpl_vars[$tpl_var]->value, 'array');
|
||||
}
|
||||
if ($merge && is_array($value)) {
|
||||
@@ -119,6 +135,7 @@ class Smarty_Internal_TemplateBase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* appends values to template variables by reference
|
||||
*
|
||||
@@ -189,12 +206,11 @@ class Smarty_Internal_TemplateBase {
|
||||
* @param boolean $search_parents search also in parent data
|
||||
* @return object the object of the variable
|
||||
*/
|
||||
public function getVariable($variable, $_ptr = null, $search_parents = true)
|
||||
public function getVariable($variable, $_ptr = null, $search_parents = true, $error_enable = true)
|
||||
{
|
||||
if ($_ptr === null) {
|
||||
$_ptr = $this;
|
||||
}
|
||||
while ($_ptr !== null) {
|
||||
} while ($_ptr !== null) {
|
||||
if (isset($_ptr->tpl_vars[$variable])) {
|
||||
// found it, return it
|
||||
return $_ptr->tpl_vars[$variable];
|
||||
@@ -211,7 +227,7 @@ class Smarty_Internal_TemplateBase {
|
||||
// found it, return it
|
||||
return $_ptr->global_tpl_vars[$variable];
|
||||
}
|
||||
if (Smarty::$error_unassigned) {
|
||||
if (Smarty::$error_unassigned && $error_enable) {
|
||||
throw new Exception('Undefined Smarty variable "' . $variable . '"');
|
||||
} else {
|
||||
return new Undefined_Smarty_Variable;
|
||||
@@ -298,7 +314,7 @@ class Smarty_Internal_TemplateBase {
|
||||
*/
|
||||
public function buildTemplateId ($_resource, $_cache_id, $_compile_id)
|
||||
{
|
||||
// return md5($_resource . md5($_cache_id) . md5($_compile_id));
|
||||
// return md5($_resource . md5($_cache_id) . md5($_compile_id));
|
||||
return crc32($_resource . $_cache_id . $_compile_id);
|
||||
}
|
||||
|
||||
@@ -329,7 +345,6 @@ class Smarty_Data extends Smarty_Internal_TemplateBase {
|
||||
public $parent = null;
|
||||
// config vars
|
||||
public $config_vars = array();
|
||||
|
||||
/**
|
||||
* create Smarty data object
|
||||
*/
|
||||
|
Reference in New Issue
Block a user