mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
- bugfix {capture} tags around recursive {include} calls did throw exception (Forum Topic 20549)
- bugfix $auto_literal = false did not work with { block} tags in child templates (Forum Topic 20581) - bugfix template inheritance: do not include code of {include} in overloaded {block} into compiled parent template (Issue 66} - bugfix template inheritance: {$smarty.block.child} in nested child {block} tags did not return expected result (Forum Topic 20564)
This commit is contained in:
@@ -1,4 +1,12 @@
|
|||||||
===== trunk =====
|
===== trunk =====
|
||||||
|
9.12.2011
|
||||||
|
- bugfix {capture} tags around recursive {include} calls did throw exception (Forum Topic 20549)
|
||||||
|
- bugfix $auto_literal = false did not work with { block} tags in child templates (Forum Topic 20581)
|
||||||
|
- bugfix template inheritance: do not include code of {include} in overloaded {block} into compiled
|
||||||
|
parent template (Issue 66}
|
||||||
|
- bugfix template inheritance: {$smarty.block.child} in nested child {block} tags did not return expected
|
||||||
|
result (Forum Topic 20564)
|
||||||
|
|
||||||
===== Smarty-3.1.6 =====
|
===== Smarty-3.1.6 =====
|
||||||
30.11.2011
|
30.11.2011
|
||||||
- bugfix is_cache() for individual cached subtemplates with $smarty->caching = CACHING_OFF did produce
|
- bugfix is_cache() for individual cached subtemplates with $smarty->caching = CACHING_OFF did produce
|
||||||
|
@@ -1,56 +1,56 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Smarty Internal Plugin Compile Block
|
* Smarty Internal Plugin Compile Block
|
||||||
*
|
*
|
||||||
* Compiles the {block}{/block} tags
|
* Compiles the {block}{/block} tags
|
||||||
*
|
*
|
||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage Compiler
|
* @subpackage Compiler
|
||||||
* @author Uwe Tews
|
* @author Uwe Tews
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty Internal Plugin Compile Block Class
|
* Smarty Internal Plugin Compile Block Class
|
||||||
*
|
*
|
||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage Compiler
|
* @subpackage Compiler
|
||||||
*/
|
*/
|
||||||
class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
|
class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attribute definition: Overwrites base class.
|
* Attribute definition: Overwrites base class.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
* @see Smarty_Internal_CompileBase
|
* @see Smarty_Internal_CompileBase
|
||||||
*/
|
*/
|
||||||
public $required_attributes = array('name');
|
public $required_attributes = array('name');
|
||||||
/**
|
/**
|
||||||
* Attribute definition: Overwrites base class.
|
* Attribute definition: Overwrites base class.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
* @see Smarty_Internal_CompileBase
|
* @see Smarty_Internal_CompileBase
|
||||||
*/
|
*/
|
||||||
public $shorttag_order = array('name', 'hide');
|
public $shorttag_order = array('name', 'hide');
|
||||||
/**
|
/**
|
||||||
* Attribute definition: Overwrites base class.
|
* Attribute definition: Overwrites base class.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
* @see Smarty_Internal_CompileBase
|
* @see Smarty_Internal_CompileBase
|
||||||
*/
|
*/
|
||||||
public $optional_attributes = array('hide');
|
public $optional_attributes = array('hide');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiles code for the {block} tag
|
* Compiles code for the {block} tag
|
||||||
*
|
*
|
||||||
* @param array $args array with attributes from parser
|
* @param array $args array with attributes from parser
|
||||||
* @param object $compiler compiler object
|
* @param object $compiler compiler object
|
||||||
* @return boolean true
|
* @return boolean true
|
||||||
*/
|
*/
|
||||||
public function compile($args, $compiler)
|
public function compile($args, $compiler)
|
||||||
{
|
{
|
||||||
// check and get attributes
|
// check and get attributes
|
||||||
$_attr = $this->getAttributes($compiler, $args);
|
$_attr = $this->getAttributes($compiler, $args);
|
||||||
$save = array($_attr, $compiler->parser->current_buffer, $compiler->nocache, $compiler->smarty->merge_compiled_includes);
|
$save = array($_attr, $compiler->parser->current_buffer, $compiler->nocache, $compiler->smarty->merge_compiled_includes, $compiler->merged_templates, $compiler->smarty->merged_templates_func, $compiler->template->properties, $compiler->template->has_nocache_code);
|
||||||
$this->openTag($compiler, 'block', $save);
|
$this->openTag($compiler, 'block', $save);
|
||||||
if ($_attr['nocache'] == true) {
|
if ($_attr['nocache'] == true) {
|
||||||
$compiler->nocache = true;
|
$compiler->nocache = true;
|
||||||
@@ -66,33 +66,54 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save or replace child block source by block name during parsing
|
* Save or replace child block source by block name during parsing
|
||||||
*
|
*
|
||||||
* @param string $block_content block source content
|
* @param string $block_content block source content
|
||||||
* @param string $block_tag opening block tag
|
* @param string $block_tag opening block tag
|
||||||
* @param object $template template object
|
* @param object $template template object
|
||||||
* @param string $filepath filepath of template source
|
* @param string $filepath filepath of template source
|
||||||
*/
|
*/
|
||||||
public static function saveBlockData($block_content, $block_tag, $template, $filepath)
|
public static function saveBlockData($block_content, $block_tag, $template, $filepath)
|
||||||
{
|
{
|
||||||
$_rdl = preg_quote($template->smarty->right_delimiter);
|
$_rdl = preg_quote($template->smarty->right_delimiter);
|
||||||
$_ldl = preg_quote($template->smarty->left_delimiter);
|
$_ldl = preg_quote($template->smarty->left_delimiter);
|
||||||
|
if ($template->smarty->auto_literal) {
|
||||||
if (0 == preg_match("!({$_ldl}block\s+)(name=)?(\w+|'.*'|\".*\")(\s*?)?((append|prepend|nocache)?(\s*)?(hide)?)?(\s*{$_rdl})!", $block_tag, $_match)) {
|
$al = '\s*';
|
||||||
|
} else {
|
||||||
|
$al = '';
|
||||||
|
}
|
||||||
|
if (0 == preg_match("!({$_ldl}{$al}block\s+)(name=)?(\w+|'.*'|\".*\")(\s*?)?((append|prepend|nocache)?(\s*)?(hide)?)?(\s*{$_rdl})!", $block_tag, $_match)) {
|
||||||
$error_text = 'Syntax Error in template "' . $template->source->filepath . '" "' . htmlspecialchars($block_tag) . '" illegal options';
|
$error_text = 'Syntax Error in template "' . $template->source->filepath . '" "' . htmlspecialchars($block_tag) . '" illegal options';
|
||||||
throw new SmartyCompilerException($error_text);
|
throw new SmartyCompilerException($error_text);
|
||||||
} else {
|
} else {
|
||||||
$_name = trim($_match[3], '\'"');
|
$_name = trim($_match[3], '\'"');
|
||||||
if ($_match[8] != 'hide' || isset($template->block_data[$_name])) { // replace {$smarty.block.child}
|
if ($_match[8] != 'hide' || isset($template->block_data[$_name])) { // replace {$smarty.block.child}
|
||||||
if (strpos($block_content, $template->smarty->left_delimiter . '$smarty.block.child' . $template->smarty->right_delimiter) !== false) {
|
// do we have {$smart.block.child} in nested {block} tags?
|
||||||
|
if (0 != preg_match_all("!({$_ldl}{$al}block\s+)(name=)?(\w+|'.*'|\".*\")([\s\S]*?{$_rdl})([\s\S]*?)({$_ldl}{$al}\\\$smarty\.block\.child{$_rdl})([\s\S]*?{$_ldl}{$al}/block{$_rdl})!", $block_content, $_match2)) {
|
||||||
|
foreach($_match2[3] as $name) {
|
||||||
|
// get it's replacement
|
||||||
|
$_name2 = trim($name, '\'"');
|
||||||
|
if (isset($template->block_data[$_name2])) {
|
||||||
|
$replacement = $template->block_data[$_name2]['source'];
|
||||||
|
} else {
|
||||||
|
$replacement = '';
|
||||||
|
}
|
||||||
|
// replace {$smarty.block.child} tag
|
||||||
|
$search = array("%({$_ldl}{$al}block[\s\S]*?{$name}[\s\S]*?{$_rdl})([\s\S]*?)({$_ldl}{$al}\\\$smarty\.block\.child{$_rdl})([\s\S]*?{$_ldl}{$al}/block{$_rdl})%","/<2F><><EFBFBD>child<6C><64><EFBFBD>/");
|
||||||
|
$replace = array('\2<><32><EFBFBD>child<6C><64><EFBFBD>', $replacement);
|
||||||
|
$block_content = preg_replace($search, $replace , $block_content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// do we have not nested {$smart.block.child}
|
||||||
|
if (0 != preg_match("/({$_ldl}{$al}\\\$smarty\.block\.child{$_rdl})/", $block_content, $_match2)) {
|
||||||
|
// get child replacement for this block
|
||||||
if (isset($template->block_data[$_name])) {
|
if (isset($template->block_data[$_name])) {
|
||||||
$block_content = str_replace($template->smarty->left_delimiter . '$smarty.block.child' . $template->smarty->right_delimiter,
|
$replacement = $template->block_data[$_name]['source'];
|
||||||
$template->block_data[$_name]['source'], $block_content);
|
|
||||||
unset($template->block_data[$_name]);
|
unset($template->block_data[$_name]);
|
||||||
} else {
|
} else {
|
||||||
$block_content = str_replace($template->smarty->left_delimiter . '$smarty.block.child' . $template->smarty->right_delimiter,
|
$replacement = '';
|
||||||
'', $block_content);
|
|
||||||
}
|
}
|
||||||
|
$block_content = preg_replace("/({$_ldl}{$al}\\\$smarty\.block\.child{$_rdl})/", $replacement, $block_content);
|
||||||
}
|
}
|
||||||
if (isset($template->block_data[$_name])) {
|
if (isset($template->block_data[$_name])) {
|
||||||
if (strpos($template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
if (strpos($template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) {
|
||||||
@@ -119,12 +140,12 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compile saved child block source
|
* Compile saved child block source
|
||||||
*
|
*
|
||||||
* @param object $compiler compiler object
|
* @param object $compiler compiler object
|
||||||
* @param string $_name optional name of child block
|
* @param string $_name optional name of child block
|
||||||
* @return string compiled code of schild block
|
* @return string compiled code of schild block
|
||||||
*/
|
*/
|
||||||
public static function compileChildBlock($compiler, $_name = null)
|
public static function compileChildBlock($compiler, $_name = null)
|
||||||
{
|
{
|
||||||
$_output = '';
|
$_output = '';
|
||||||
@@ -191,20 +212,20 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smarty Internal Plugin Compile BlockClose Class
|
* Smarty Internal Plugin Compile BlockClose Class
|
||||||
*
|
*
|
||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage Compiler
|
* @subpackage Compiler
|
||||||
*/
|
*/
|
||||||
class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
|
class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiles code for the {/block} tag
|
* Compiles code for the {/block} tag
|
||||||
*
|
*
|
||||||
* @param array $args array with attributes from parser
|
* @param array $args array with attributes from parser
|
||||||
* @param object $compiler compiler object
|
* @param object $compiler compiler object
|
||||||
* @return string compiled code
|
* @return string compiled code
|
||||||
*/
|
*/
|
||||||
public function compile($args, $compiler)
|
public function compile($args, $compiler)
|
||||||
{
|
{
|
||||||
$compiler->has_code = true;
|
$compiler->has_code = true;
|
||||||
@@ -213,6 +234,11 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase {
|
|||||||
$saved_data = $this->closeTag($compiler, array('block'));
|
$saved_data = $this->closeTag($compiler, array('block'));
|
||||||
$_name = trim($saved_data[0]['name'], "\"'");
|
$_name = trim($saved_data[0]['name'], "\"'");
|
||||||
if (isset($compiler->template->block_data[$_name]) && !isset($compiler->template->block_data[$_name]['compiled'])) {
|
if (isset($compiler->template->block_data[$_name]) && !isset($compiler->template->block_data[$_name]['compiled'])) {
|
||||||
|
// restore to status before {block} tag as new subtemplate code of parent {block} is not needed
|
||||||
|
$compiler->merged_templates = $saved_data[4];
|
||||||
|
$compiler->smarty->merged_templates_func = $saved_data[5];
|
||||||
|
$compiler->template->properties = $saved_data[6];
|
||||||
|
$compiler->template->has_nocache_code = $saved_data[7];
|
||||||
$_output = Smarty_Internal_Compile_Block::compileChildBlock($compiler, $_name);
|
$_output = Smarty_Internal_Compile_Block::compileChildBlock($compiler, $_name);
|
||||||
} else {
|
} else {
|
||||||
if (isset($saved_data[0]['hide']) && !isset($compiler->template->block_data[$_name]['source'])) {
|
if (isset($saved_data[0]['hide']) && !isset($compiler->template->block_data[$_name]['source'])) {
|
||||||
|
@@ -48,10 +48,10 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase {
|
|||||||
$assign = isset($_attr['assign']) ? $_attr['assign'] : 'null';
|
$assign = isset($_attr['assign']) ? $_attr['assign'] : 'null';
|
||||||
$append = isset($_attr['append']) ? $_attr['append'] : 'null';
|
$append = isset($_attr['append']) ? $_attr['append'] : 'null';
|
||||||
|
|
||||||
$compiler->_capture_stack[] = array($buffer, $assign, $append, $compiler->nocache);
|
$compiler->_capture_stack[0][] = array($buffer, $assign, $append, $compiler->nocache);
|
||||||
// maybe nocache because of nocache variables
|
// maybe nocache because of nocache variables
|
||||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||||
$_output = "<?php \$_smarty_tpl->_capture_stack[] = array($buffer, $assign, $append); ob_start(); ?>";
|
$_output = "<?php \$_smarty_tpl->_capture_stack[0][] = array($buffer, $assign, $append); ob_start(); ?>";
|
||||||
|
|
||||||
return $_output;
|
return $_output;
|
||||||
}
|
}
|
||||||
@@ -82,9 +82,9 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase {
|
|||||||
$compiler->tag_nocache = true;
|
$compiler->tag_nocache = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
list($buffer, $assign, $append, $compiler->nocache) = array_pop($compiler->_capture_stack);
|
list($buffer, $assign, $append, $compiler->nocache) = array_pop($compiler->_capture_stack[0]);
|
||||||
|
|
||||||
$_output = "<?php list(\$_capture_buffer, \$_capture_assign, \$_capture_append) = array_pop(\$_smarty_tpl->_capture_stack);\n";
|
$_output = "<?php list(\$_capture_buffer, \$_capture_assign, \$_capture_append) = array_pop(\$_smarty_tpl->_capture_stack[0]);\n";
|
||||||
$_output .= "if (!empty(\$_capture_buffer)) {\n";
|
$_output .= "if (!empty(\$_capture_buffer)) {\n";
|
||||||
$_output .= " if (isset(\$_capture_assign)) \$_smarty_tpl->assign(\$_capture_assign, ob_get_contents());\n";
|
$_output .= " if (isset(\$_capture_assign)) \$_smarty_tpl->assign(\$_capture_assign, ob_get_contents());\n";
|
||||||
$_output .= " if (isset( \$_capture_append)) \$_smarty_tpl->append( \$_capture_append, ob_get_contents());\n";
|
$_output .= " if (isset( \$_capture_append)) \$_smarty_tpl->append( \$_capture_append, ob_get_contents());\n";
|
||||||
|
@@ -97,7 +97,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
|||||||
* internal capture runtime stack
|
* internal capture runtime stack
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public $_capture_stack = array();
|
public $_capture_stack = array(0 => array());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create template data object
|
* Create template data object
|
||||||
|
@@ -1,34 +1,34 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Smarty Internal Plugin Smarty Template Base
|
* Smarty Internal Plugin Smarty Template Base
|
||||||
*
|
*
|
||||||
* This file contains the basic shared methodes for template handling
|
* This file contains the basic shared methodes for template handling
|
||||||
*
|
*
|
||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage Template
|
* @subpackage Template
|
||||||
* @author Uwe Tews
|
* @author Uwe Tews
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class with shared template methodes
|
* Class with shared template methodes
|
||||||
*
|
*
|
||||||
* @package Smarty
|
* @package Smarty
|
||||||
* @subpackage Template
|
* @subpackage Template
|
||||||
*/
|
*/
|
||||||
abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fetches a rendered Smarty template
|
* fetches a rendered Smarty template
|
||||||
*
|
*
|
||||||
* @param string $template the resource handle of the template file or template object
|
* @param string $template the resource handle of the template file or template object
|
||||||
* @param mixed $cache_id cache id to be used with this template
|
* @param mixed $cache_id cache id to be used with this template
|
||||||
* @param mixed $compile_id compile id to be used with this template
|
* @param mixed $compile_id compile id to be used with this template
|
||||||
* @param object $parent next higher level of Smarty variables
|
* @param object $parent next higher level of Smarty variables
|
||||||
* @param bool $display true: display, false: fetch
|
* @param bool $display true: display, false: fetch
|
||||||
* @param bool $merge_tpl_vars if true parent template variables merged in to local scope
|
* @param bool $merge_tpl_vars if true parent template variables merged in to local scope
|
||||||
* @param bool $no_output_filter if true do not run output filter
|
* @param bool $no_output_filter if true do not run output filter
|
||||||
* @return string rendered template output
|
* @return string rendered template output
|
||||||
*/
|
*/
|
||||||
public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null, $display = false, $merge_tpl_vars = true, $no_output_filter = false)
|
public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null, $display = false, $merge_tpl_vars = true, $no_output_filter = false)
|
||||||
{
|
{
|
||||||
if ($template === null && $this instanceof $this->template_class) {
|
if ($template === null && $this instanceof $this->template_class) {
|
||||||
@@ -43,8 +43,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
// create template object if necessary
|
// create template object if necessary
|
||||||
$_template = ($template instanceof $this->template_class)
|
$_template = ($template instanceof $this->template_class)
|
||||||
? $template
|
? $template
|
||||||
: $this->smarty->createTemplate($template, $cache_id, $compile_id, $parent, false);
|
: $this->smarty->createTemplate($template, $cache_id, $compile_id, $parent, false);
|
||||||
// if called by Smarty object make sure we use current caching status
|
// if called by Smarty object make sure we use current caching status
|
||||||
if ($this instanceof Smarty) {
|
if ($this instanceof Smarty) {
|
||||||
$_template->caching = $this->caching;
|
$_template->caching = $this->caching;
|
||||||
@@ -173,10 +173,16 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
if (empty($_template->properties['unifunc']) || !is_callable($_template->properties['unifunc'])) {
|
if (empty($_template->properties['unifunc']) || !is_callable($_template->properties['unifunc'])) {
|
||||||
throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'");
|
throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'");
|
||||||
}
|
}
|
||||||
|
array_unshift($_template->_capture_stack,array());
|
||||||
|
//
|
||||||
|
// render compiled template
|
||||||
|
//
|
||||||
$_template->properties['unifunc']($_template);
|
$_template->properties['unifunc']($_template);
|
||||||
if (isset($_template->_capture_stack[0])) {
|
// any unclosed {capture} tags ?
|
||||||
|
if (isset($_template->_capture_stack[0][0])) {
|
||||||
$_template->capture_error();
|
$_template->capture_error();
|
||||||
}
|
}
|
||||||
|
array_shift($_template->_capture_stack);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
ob_get_clean();
|
ob_get_clean();
|
||||||
throw $e;
|
throw $e;
|
||||||
@@ -268,10 +274,16 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
ob_start();
|
ob_start();
|
||||||
|
array_unshift($_template->_capture_stack,array());
|
||||||
|
//
|
||||||
|
// render cached template
|
||||||
|
//
|
||||||
$_template->properties['unifunc']($_template);
|
$_template->properties['unifunc']($_template);
|
||||||
if (isset($_template->_capture_stack[0])) {
|
// any unclosed {capture} tags ?
|
||||||
|
if (isset($_template->_capture_stack[0][0])) {
|
||||||
$_template->capture_error();
|
$_template->capture_error();
|
||||||
}
|
}
|
||||||
|
array_shift($_template->_capture_stack);
|
||||||
$_output = ob_get_clean();
|
$_output = ob_get_clean();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
ob_get_clean();
|
ob_get_clean();
|
||||||
@@ -297,30 +309,30 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
case 'cgi': // php-cgi < 5.3
|
case 'cgi': // php-cgi < 5.3
|
||||||
case 'cgi-fcgi': // php-cgi >= 5.3
|
case 'cgi-fcgi': // php-cgi >= 5.3
|
||||||
case 'fpm-fcgi': // php-fpm >= 5.3.3
|
case 'fpm-fcgi': // php-fpm >= 5.3.3
|
||||||
header('Status: 304 Not Modified');
|
header('Status: 304 Not Modified');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'cli':
|
case 'cli':
|
||||||
if (/* ^phpunit */!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'])/* phpunit$ */) {
|
if (/* ^phpunit */!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'])/* phpunit$ */) {
|
||||||
$_SERVER['SMARTY_PHPUNIT_HEADERS'][] = '304 Not Modified';
|
$_SERVER['SMARTY_PHPUNIT_HEADERS'][] = '304 Not Modified';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
header('HTTP/1.1 304 Not Modified');
|
header('HTTP/1.1 304 Not Modified');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (PHP_SAPI) {
|
switch (PHP_SAPI) {
|
||||||
case 'cli':
|
case 'cli':
|
||||||
if (/* ^phpunit */!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'])/* phpunit$ */) {
|
if (/* ^phpunit */!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'])/* phpunit$ */) {
|
||||||
$_SERVER['SMARTY_PHPUNIT_HEADERS'][] = 'Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT';
|
$_SERVER['SMARTY_PHPUNIT_HEADERS'][] = 'Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT');
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->cached->timestamp) . ' GMT');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
echo $_output;
|
echo $_output;
|
||||||
}
|
}
|
||||||
@@ -349,13 +361,13 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* displays a Smarty template
|
* displays a Smarty template
|
||||||
*
|
*
|
||||||
* @param string $template the resource handle of the template file or template object
|
* @param string $template the resource handle of the template file or template object
|
||||||
* @param mixed $cache_id cache id to be used with this template
|
* @param mixed $cache_id cache id to be used with this template
|
||||||
* @param mixed $compile_id compile id to be used with this template
|
* @param mixed $compile_id compile id to be used with this template
|
||||||
* @param object $parent next higher level of Smarty variables
|
* @param object $parent next higher level of Smarty variables
|
||||||
*/
|
*/
|
||||||
public function display($template = null, $cache_id = null, $compile_id = null, $parent = null)
|
public function display($template = null, $cache_id = null, $compile_id = null, $parent = null)
|
||||||
{
|
{
|
||||||
// display template
|
// display template
|
||||||
@@ -363,14 +375,14 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test if cache is valid
|
* test if cache is valid
|
||||||
*
|
*
|
||||||
* @param string|object $template the resource handle of the template file or template object
|
* @param string|object $template the resource handle of the template file or template object
|
||||||
* @param mixed $cache_id cache id to be used with this template
|
* @param mixed $cache_id cache id to be used with this template
|
||||||
* @param mixed $compile_id compile id to be used with this template
|
* @param mixed $compile_id compile id to be used with this template
|
||||||
* @param object $parent next higher level of Smarty variables
|
* @param object $parent next higher level of Smarty variables
|
||||||
* @return boolean cache status
|
* @return boolean cache status
|
||||||
*/
|
*/
|
||||||
public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null)
|
public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null)
|
||||||
{
|
{
|
||||||
if ($template === null && $this instanceof $this->template_class) {
|
if ($template === null && $this instanceof $this->template_class) {
|
||||||
@@ -387,26 +399,26 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates a data object
|
* creates a data object
|
||||||
*
|
*
|
||||||
* @param object $parent next higher level of Smarty variables
|
* @param object $parent next higher level of Smarty variables
|
||||||
* @returns Smarty_Data data object
|
* @returns Smarty_Data data object
|
||||||
*/
|
*/
|
||||||
public function createData($parent = null)
|
public function createData($parent = null)
|
||||||
{
|
{
|
||||||
return new Smarty_Data($parent, $this);
|
return new Smarty_Data($parent, $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers plugin to be used in templates
|
* Registers plugin to be used in templates
|
||||||
*
|
*
|
||||||
* @param string $type plugin type
|
* @param string $type plugin type
|
||||||
* @param string $tag name of template tag
|
* @param string $tag name of template tag
|
||||||
* @param callback $callback PHP callback to register
|
* @param callback $callback PHP callback to register
|
||||||
* @param boolean $cacheable if true (default) this fuction is cachable
|
* @param boolean $cacheable if true (default) this fuction is cachable
|
||||||
* @param array $cache_attr caching attributes if any
|
* @param array $cache_attr caching attributes if any
|
||||||
* @throws SmartyException when the plugin tag is invalid
|
* @throws SmartyException when the plugin tag is invalid
|
||||||
*/
|
*/
|
||||||
public function registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = null)
|
public function registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = null)
|
||||||
{
|
{
|
||||||
if (isset($this->smarty->registered_plugins[$type][$tag])) {
|
if (isset($this->smarty->registered_plugins[$type][$tag])) {
|
||||||
@@ -419,11 +431,11 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregister Plugin
|
* Unregister Plugin
|
||||||
*
|
*
|
||||||
* @param string $type of plugin
|
* @param string $type of plugin
|
||||||
* @param string $tag name of plugin
|
* @param string $tag name of plugin
|
||||||
*/
|
*/
|
||||||
public function unregisterPlugin($type, $tag)
|
public function unregisterPlugin($type, $tag)
|
||||||
{
|
{
|
||||||
if (isset($this->smarty->registered_plugins[$type][$tag])) {
|
if (isset($this->smarty->registered_plugins[$type][$tag])) {
|
||||||
@@ -432,21 +444,21 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a resource to fetch a template
|
* Registers a resource to fetch a template
|
||||||
*
|
*
|
||||||
* @param string $type name of resource type
|
* @param string $type name of resource type
|
||||||
* @param Smarty_Resource|array $callback or instance of Smarty_Resource, or array of callbacks to handle resource (deprecated)
|
* @param Smarty_Resource|array $callback or instance of Smarty_Resource, or array of callbacks to handle resource (deprecated)
|
||||||
*/
|
*/
|
||||||
public function registerResource($type, $callback)
|
public function registerResource($type, $callback)
|
||||||
{
|
{
|
||||||
$this->smarty->registered_resources[$type] = $callback instanceof Smarty_Resource ? $callback : array($callback, false);
|
$this->smarty->registered_resources[$type] = $callback instanceof Smarty_Resource ? $callback : array($callback, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters a resource
|
* Unregisters a resource
|
||||||
*
|
*
|
||||||
* @param string $type name of resource type
|
* @param string $type name of resource type
|
||||||
*/
|
*/
|
||||||
public function unregisterResource($type)
|
public function unregisterResource($type)
|
||||||
{
|
{
|
||||||
if (isset($this->smarty->registered_resources[$type])) {
|
if (isset($this->smarty->registered_resources[$type])) {
|
||||||
@@ -455,21 +467,21 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a cache resource to cache a template's output
|
* Registers a cache resource to cache a template's output
|
||||||
*
|
*
|
||||||
* @param string $type name of cache resource type
|
* @param string $type name of cache resource type
|
||||||
* @param Smarty_CacheResource $callback instance of Smarty_CacheResource to handle output caching
|
* @param Smarty_CacheResource $callback instance of Smarty_CacheResource to handle output caching
|
||||||
*/
|
*/
|
||||||
public function registerCacheResource($type, Smarty_CacheResource $callback)
|
public function registerCacheResource($type, Smarty_CacheResource $callback)
|
||||||
{
|
{
|
||||||
$this->smarty->registered_cache_resources[$type] = $callback;
|
$this->smarty->registered_cache_resources[$type] = $callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters a cache resource
|
* Unregisters a cache resource
|
||||||
*
|
*
|
||||||
* @param string $type name of cache resource type
|
* @param string $type name of cache resource type
|
||||||
*/
|
*/
|
||||||
public function unregisterCacheResource($type)
|
public function unregisterCacheResource($type)
|
||||||
{
|
{
|
||||||
if (isset($this->smarty->registered_cache_resources[$type])) {
|
if (isset($this->smarty->registered_cache_resources[$type])) {
|
||||||
@@ -478,16 +490,16 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers object to be used in templates
|
* Registers object to be used in templates
|
||||||
*
|
*
|
||||||
* @param string $object name of template object
|
* @param string $object name of template object
|
||||||
* @param object $object_impl the referenced PHP object to register
|
* @param object $object_impl the referenced PHP object to register
|
||||||
* @param array $allowed list of allowed methods (empty = all)
|
* @param array $allowed list of allowed methods (empty = all)
|
||||||
* @param boolean $smarty_args smarty argument format, else traditional
|
* @param boolean $smarty_args smarty argument format, else traditional
|
||||||
* @param array $block_methods list of block-methods
|
* @param array $block_methods list of block-methods
|
||||||
* @param array $block_functs list of methods that are block format
|
* @param array $block_functs list of methods that are block format
|
||||||
* @throws SmartyException if any of the methods in $allowed or $block_methods are invalid
|
* @throws SmartyException if any of the methods in $allowed or $block_methods are invalid
|
||||||
*/
|
*/
|
||||||
public function registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
|
public function registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
|
||||||
{
|
{
|
||||||
// test if allowed methodes callable
|
// test if allowed methodes callable
|
||||||
@@ -508,16 +520,16 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
// register the object
|
// register the object
|
||||||
$this->smarty->registered_objects[$object_name] =
|
$this->smarty->registered_objects[$object_name] =
|
||||||
array($object_impl, (array) $allowed, (boolean) $smarty_args, (array) $block_methods);
|
array($object_impl, (array) $allowed, (boolean) $smarty_args, (array) $block_methods);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return a reference to a registered object
|
* return a reference to a registered object
|
||||||
*
|
*
|
||||||
* @param string $name object name
|
* @param string $name object name
|
||||||
* @return object
|
* @return object
|
||||||
* @throws SmartyException if no such object is found
|
* @throws SmartyException if no such object is found
|
||||||
*/
|
*/
|
||||||
public function getRegisteredObject($name)
|
public function getRegisteredObject($name)
|
||||||
{
|
{
|
||||||
if (!isset($this->smarty->registered_objects[$name])) {
|
if (!isset($this->smarty->registered_objects[$name])) {
|
||||||
@@ -530,11 +542,11 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unregister an object
|
* unregister an object
|
||||||
*
|
*
|
||||||
* @param string $name object name
|
* @param string $name object name
|
||||||
* @throws SmartyException if no such object is found
|
* @throws SmartyException if no such object is found
|
||||||
*/
|
*/
|
||||||
public function unregisterObject($name)
|
public function unregisterObject($name)
|
||||||
{
|
{
|
||||||
unset($this->smarty->registered_objects[$name]);
|
unset($this->smarty->registered_objects[$name]);
|
||||||
@@ -542,12 +554,12 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers static classes to be used in templates
|
* Registers static classes to be used in templates
|
||||||
*
|
*
|
||||||
* @param string $class name of template class
|
* @param string $class name of template class
|
||||||
* @param string $class_impl the referenced PHP class to register
|
* @param string $class_impl the referenced PHP class to register
|
||||||
* @throws SmartyException if $class_impl does not refer to an existing class
|
* @throws SmartyException if $class_impl does not refer to an existing class
|
||||||
*/
|
*/
|
||||||
public function registerClass($class_name, $class_impl)
|
public function registerClass($class_name, $class_impl)
|
||||||
{
|
{
|
||||||
// test if exists
|
// test if exists
|
||||||
@@ -559,11 +571,11 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a default plugin handler
|
* Registers a default plugin handler
|
||||||
*
|
*
|
||||||
* @param callable $callback class/method name
|
* @param callable $callback class/method name
|
||||||
* @throws SmartyException if $callback is not callable
|
* @throws SmartyException if $callback is not callable
|
||||||
*/
|
*/
|
||||||
public function registerDefaultPluginHandler($callback)
|
public function registerDefaultPluginHandler($callback)
|
||||||
{
|
{
|
||||||
if (is_callable($callback)) {
|
if (is_callable($callback)) {
|
||||||
@@ -574,11 +586,11 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a default template handler
|
* Registers a default template handler
|
||||||
*
|
*
|
||||||
* @param callable $callback class/method name
|
* @param callable $callback class/method name
|
||||||
* @throws SmartyException if $callback is not callable
|
* @throws SmartyException if $callback is not callable
|
||||||
*/
|
*/
|
||||||
public function registerDefaultTemplateHandler($callback)
|
public function registerDefaultTemplateHandler($callback)
|
||||||
{
|
{
|
||||||
if (is_callable($callback)) {
|
if (is_callable($callback)) {
|
||||||
@@ -589,11 +601,11 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a default template handler
|
* Registers a default template handler
|
||||||
*
|
*
|
||||||
* @param callable $callback class/method name
|
* @param callable $callback class/method name
|
||||||
* @throws SmartyException if $callback is not callable
|
* @throws SmartyException if $callback is not callable
|
||||||
*/
|
*/
|
||||||
public function registerDefaultConfigHandler($callback)
|
public function registerDefaultConfigHandler($callback)
|
||||||
{
|
{
|
||||||
if (is_callable($callback)) {
|
if (is_callable($callback)) {
|
||||||
@@ -604,22 +616,22 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a filter function
|
* Registers a filter function
|
||||||
*
|
*
|
||||||
* @param string $type filter type
|
* @param string $type filter type
|
||||||
* @param callback $callback
|
* @param callback $callback
|
||||||
*/
|
*/
|
||||||
public function registerFilter($type, $callback)
|
public function registerFilter($type, $callback)
|
||||||
{
|
{
|
||||||
$this->smarty->registered_filters[$type][$this->_get_filter_name($callback)] = $callback;
|
$this->smarty->registered_filters[$type][$this->_get_filter_name($callback)] = $callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters a filter function
|
* Unregisters a filter function
|
||||||
*
|
*
|
||||||
* @param string $type filter type
|
* @param string $type filter type
|
||||||
* @param callback $callback
|
* @param callback $callback
|
||||||
*/
|
*/
|
||||||
public function unregisterFilter($type, $callback)
|
public function unregisterFilter($type, $callback)
|
||||||
{
|
{
|
||||||
$name = $this->_get_filter_name($callback);
|
$name = $this->_get_filter_name($callback);
|
||||||
@@ -629,15 +641,15 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return internal filter name
|
* Return internal filter name
|
||||||
*
|
*
|
||||||
* @param callback $function_name
|
* @param callback $function_name
|
||||||
*/
|
*/
|
||||||
public function _get_filter_name($function_name)
|
public function _get_filter_name($function_name)
|
||||||
{
|
{
|
||||||
if (is_array($function_name)) {
|
if (is_array($function_name)) {
|
||||||
$_class_name = (is_object($function_name[0]) ?
|
$_class_name = (is_object($function_name[0]) ?
|
||||||
get_class($function_name[0]) : $function_name[0]);
|
get_class($function_name[0]) : $function_name[0]);
|
||||||
return $_class_name . '_' . $function_name[1];
|
return $_class_name . '_' . $function_name[1];
|
||||||
} else {
|
} else {
|
||||||
return $function_name;
|
return $function_name;
|
||||||
@@ -645,12 +657,12 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* load a filter of specified type and name
|
* load a filter of specified type and name
|
||||||
*
|
*
|
||||||
* @param string $type filter type
|
* @param string $type filter type
|
||||||
* @param string $name filter name
|
* @param string $name filter name
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function loadFilter($type, $name)
|
public function loadFilter($type, $name)
|
||||||
{
|
{
|
||||||
$_plugin = "smarty_{$type}filter_{$name}";
|
$_plugin = "smarty_{$type}filter_{$name}";
|
||||||
@@ -669,12 +681,12 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unload a filter of specified type and name
|
* unload a filter of specified type and name
|
||||||
*
|
*
|
||||||
* @param string $type filter type
|
* @param string $type filter type
|
||||||
* @param string $name filter name
|
* @param string $name filter name
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function unloadFilter($type, $name)
|
public function unloadFilter($type, $name)
|
||||||
{
|
{
|
||||||
$_filter_name = "smarty_{$type}filter_{$name}";
|
$_filter_name = "smarty_{$type}filter_{$name}";
|
||||||
@@ -687,21 +699,21 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* preg_replace callback to convert camelcase getter/setter to underscore property names
|
* preg_replace callback to convert camelcase getter/setter to underscore property names
|
||||||
*
|
*
|
||||||
* @param string $match match string
|
* @param string $match match string
|
||||||
* @return string replacemant
|
* @return string replacemant
|
||||||
*/
|
*/
|
||||||
private function replaceCamelcase($match) {
|
private function replaceCamelcase($match) {
|
||||||
return "_" . strtolower($match[1]);
|
return "_" . strtolower($match[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle unknown class methods
|
* Handle unknown class methods
|
||||||
*
|
*
|
||||||
* @param string $name unknown method-name
|
* @param string $name unknown method-name
|
||||||
* @param array $args argument array
|
* @param array $args argument array
|
||||||
*/
|
*/
|
||||||
public function __call($name, $args)
|
public function __call($name, $args)
|
||||||
{
|
{
|
||||||
static $_prefixes = array('set' => true, 'get' => true);
|
static $_prefixes = array('set' => true, 'get' => true);
|
||||||
@@ -738,14 +750,14 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data {
|
|||||||
}
|
}
|
||||||
if ($_is_this) {
|
if ($_is_this) {
|
||||||
if ($first3 == 'get')
|
if ($first3 == 'get')
|
||||||
return $this->$property_name;
|
return $this->$property_name;
|
||||||
else
|
else
|
||||||
return $this->$property_name = $args[0];
|
return $this->$property_name = $args[0];
|
||||||
} else if ($_is_this === false) {
|
} else if ($_is_this === false) {
|
||||||
if ($first3 == 'get')
|
if ($first3 == 'get')
|
||||||
return $this->smarty->$property_name;
|
return $this->smarty->$property_name;
|
||||||
else
|
else
|
||||||
return $this->smarty->$property_name = $args[0];
|
return $this->smarty->$property_name = $args[0];
|
||||||
} else {
|
} else {
|
||||||
throw new SmartyException("property '$property_name' does not exist.");
|
throw new SmartyException("property '$property_name' does not exist.");
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user