mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 03:14:27 +02:00
- bugfix for custom delimiter at extends resource and {extends} tag
This commit is contained in:
@@ -24,6 +24,8 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase {
|
|||||||
{
|
{
|
||||||
$this->compiler = $compiler;
|
$this->compiler = $compiler;
|
||||||
$this->smarty = $compiler->smarty;
|
$this->smarty = $compiler->smarty;
|
||||||
|
$this->_rdl = preg_quote($this->smarty->right_delimiter);
|
||||||
|
$this->_ldl = preg_quote($this->smarty->left_delimiter);
|
||||||
$this->required_attributes = array('file');
|
$this->required_attributes = array('file');
|
||||||
// check and get attributes
|
// check and get attributes
|
||||||
$_attr = $this->_get_attributes($args);
|
$_attr = $this->_get_attributes($args);
|
||||||
@@ -35,9 +37,9 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase {
|
|||||||
// save file dependency
|
// save file dependency
|
||||||
$compiler->template->properties['file_dependency'][sha1($_template->getTemplateFilepath())] = array($_template->getTemplateFilepath(), $_template->getTemplateTimestamp());
|
$compiler->template->properties['file_dependency'][sha1($_template->getTemplateFilepath())] = array($_template->getTemplateFilepath(), $_template->getTemplateTimestamp());
|
||||||
$_old_source = $compiler->template->template_source;
|
$_old_source = $compiler->template->template_source;
|
||||||
if (preg_match_all('/(' . $this->smarty->left_delimiter . 'block(.+?)' . $this->smarty->right_delimiter . ')/', $_old_source, $s, PREG_OFFSET_CAPTURE) !=
|
if (preg_match_all("!({$this->_ldl}block(.+?){$this->_rdl})!", $_old_source, $s, PREG_OFFSET_CAPTURE) !=
|
||||||
preg_match_all('/(' . $this->smarty->left_delimiter . '\/block(.*?)' . $this->smarty->right_delimiter . ')/', $_old_source, $c, PREG_OFFSET_CAPTURE)) {
|
preg_match_all("!({$this->_ldl}/block(.*?){$this->_rdl})!", $_old_source, $c, PREG_OFFSET_CAPTURE)) {
|
||||||
$this->compiler->trigger_template_error(" unmatched {block} {/block} pairs");
|
$this->compiler->trigger_template_error('unmatched {block} {/block} pairs');
|
||||||
}
|
}
|
||||||
$block_count = count($s[0]);
|
$block_count = count($s[0]);
|
||||||
for ($i = 0; $i < $block_count; $i++) {
|
for ($i = 0; $i < $block_count; $i++) {
|
||||||
@@ -53,10 +55,10 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_CompileBase {
|
|||||||
|
|
||||||
protected function saveBlockData($block_content, $block_tag, $template)
|
protected function saveBlockData($block_content, $block_tag, $template)
|
||||||
{
|
{
|
||||||
if (0 == preg_match("/(.?)(name=)(.*?)(?=(\s|{$this->smarty->right_delimiter}))/", $block_tag, $_match)) {
|
if (0 == preg_match("!(.?)(name=)(.*?)(?=(\s|{$this->_rdl}))!", $block_tag, $_match)) {
|
||||||
$this->compiler->trigger_template_error("\"" . $block_tag . "\" missing name attribute");
|
$this->compiler->trigger_template_error("\"" . $block_tag . "\" missing name attribute");
|
||||||
} else {
|
} else {
|
||||||
$_name = trim($_match[3], "\"'");
|
$_name = trim($_match[3], '\'"');
|
||||||
if (isset($this->smarty->block_data[$_name])) {
|
if (isset($this->smarty->block_data[$_name])) {
|
||||||
if (strpos($this->smarty->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
if (strpos($this->smarty->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
||||||
$this->smarty->block_data[$_name]['source'] =
|
$this->smarty->block_data[$_name]['source'] =
|
||||||
|
@@ -16,6 +16,8 @@ class Smarty_Internal_Resource_Extends {
|
|||||||
public function __construct($smarty)
|
public function __construct($smarty)
|
||||||
{
|
{
|
||||||
$this->smarty = $smarty;
|
$this->smarty = $smarty;
|
||||||
|
$this->_rdl = preg_quote($smarty->right_delimiter);
|
||||||
|
$this->_ldl = preg_quote($smarty->left_delimiter);
|
||||||
}
|
}
|
||||||
// classes used for compiling Smarty templates from file resource
|
// classes used for compiling Smarty templates from file resource
|
||||||
public $compiler_class = 'Smarty_Internal_SmartyTemplateCompiler';
|
public $compiler_class = 'Smarty_Internal_SmartyTemplateCompiler';
|
||||||
@@ -88,7 +90,7 @@ class Smarty_Internal_Resource_Extends {
|
|||||||
foreach ($_files as $_filepath) {
|
foreach ($_files as $_filepath) {
|
||||||
// read template file
|
// read template file
|
||||||
if ($_filepath === false) {
|
if ($_filepath === false) {
|
||||||
throw new Exception("Unable to load template \"file : {$_file}\"");
|
throw new Exception("Unable to load template 'file : {$_file}'");
|
||||||
}
|
}
|
||||||
if ($_filepath != $_files[0]) {
|
if ($_filepath != $_files[0]) {
|
||||||
$_template->properties['file_dependency'][sha1($_filepath)] = array($_filepath, filemtime($_filepath));
|
$_template->properties['file_dependency'][sha1($_filepath)] = array($_filepath, filemtime($_filepath));
|
||||||
@@ -96,9 +98,9 @@ class Smarty_Internal_Resource_Extends {
|
|||||||
$_template->template_filepath = $_filepath;
|
$_template->template_filepath = $_filepath;
|
||||||
$_content = file_get_contents($_filepath);
|
$_content = file_get_contents($_filepath);
|
||||||
if ($_filepath != $_files[count($_files)-1]) {
|
if ($_filepath != $_files[count($_files)-1]) {
|
||||||
if (preg_match_all('/(' . $this->smarty->left_delimiter . 'block(.+?)' . $this->smarty->right_delimiter . ')/', $_content, $_open, PREG_OFFSET_CAPTURE) !=
|
if (preg_match_all("!({$this->_ldl}block(.+?){$this->_rdl})!", $_content, $_open, PREG_OFFSET_CAPTURE) !=
|
||||||
preg_match_all('/(' . $this->smarty->left_delimiter . '\/block(.*?)' . $this->smarty->right_delimiter . ')/', $_content, $_close, PREG_OFFSET_CAPTURE)) {
|
preg_match_all("!({$this->_ldl}/block(.*?){$this->_rdl})!", $_content, $_close, PREG_OFFSET_CAPTURE)) {
|
||||||
$this->smarty->trigger_error(" unmatched {block} {/block} pairs");
|
$this->smarty->trigger_error('unmatched {block} {/block} pairs');
|
||||||
}
|
}
|
||||||
$_block_count = count($_open[0]);
|
$_block_count = count($_open[0]);
|
||||||
for ($_i = 0; $_i < $_block_count; $_i++) {
|
for ($_i = 0; $_i < $_block_count; $_i++) {
|
||||||
@@ -115,10 +117,10 @@ class Smarty_Internal_Resource_Extends {
|
|||||||
}
|
}
|
||||||
protected function saveBlockData($block_content, $block_tag, $_filepath)
|
protected function saveBlockData($block_content, $block_tag, $_filepath)
|
||||||
{
|
{
|
||||||
if (0 == preg_match("/(.?)(name=)(.*?)(?=(\s|{$this->smarty->right_delimiter}))/", $block_tag, $_match)) {
|
if (0 == preg_match("!(.?)(name=)(.*?)(?=(\s|{$this->_rdl}))!", $block_tag, $_match)) {
|
||||||
$this->smarty->trigger_error("\"" . $block_tag . "\" missing name attribute");
|
$this->smarty->trigger_error("'{$block_tag}' missing name attribute");
|
||||||
} else {
|
} else {
|
||||||
$_name = trim($_match[3], "\"'");
|
$_name = trim($_match[3], '\'"');
|
||||||
if (isset($this->smarty->block_data[$_name])) {
|
if (isset($this->smarty->block_data[$_name])) {
|
||||||
if (strpos($this->smarty->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
if (strpos($this->smarty->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
||||||
$this->smarty->block_data[$_name]['source'] =
|
$this->smarty->block_data[$_name]['source'] =
|
||||||
@@ -151,7 +153,7 @@ class Smarty_Internal_Resource_Extends {
|
|||||||
public function getCompiledFilepath($_template)
|
public function getCompiledFilepath($_template)
|
||||||
{
|
{
|
||||||
$_compile_id = isset($_template->compile_id) ? preg_replace('![^\w\|]+!', '_', $_template->compile_id) : null;
|
$_compile_id = isset($_template->compile_id) ? preg_replace('![^\w\|]+!', '_', $_template->compile_id) : null;
|
||||||
$_files = explode('|', $_template->resource_name);
|
$_files = explode('|', $_template->resource_name);
|
||||||
// calculate Uid if not already done
|
// calculate Uid if not already done
|
||||||
if ($_template->templateUid == '') {
|
if ($_template->templateUid == '') {
|
||||||
$_template->getTemplateFilepath();
|
$_template->getTemplateFilepath();
|
||||||
|
Reference in New Issue
Block a user