mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
- rework {capture} compiler
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
===== 3.1.28-dev===== (xx.xx.2015)
|
||||
02.08.2015
|
||||
- optimization and code cleanup of {foreach} and {section} compiler
|
||||
- rework {capture} compiler
|
||||
|
||||
01.08.2015
|
||||
- update DateTime object can be instance of DateTimeImmutable since PHP5.5 https://github.com/smarty-php/smarty/pull/75
|
||||
|
@@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '3.1.28-dev/37';
|
||||
const SMARTY_VERSION = '3.1.28-dev/38';
|
||||
|
||||
/**
|
||||
* define variable scopes
|
||||
@@ -688,13 +688,6 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
*/
|
||||
public $escape_html = false;
|
||||
|
||||
/**
|
||||
* global internal smarty vars
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $_smarty_vars = array();
|
||||
|
||||
/**
|
||||
* start time for execution time calculation
|
||||
*
|
||||
|
@@ -23,6 +23,7 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('name');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -35,11 +36,11 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
|
||||
* Compiles code for the {capture} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
@@ -55,6 +56,27 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase
|
||||
|
||||
return $_output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles code for the {$smarty.capture.xxx}
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return string compiled code
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public static function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
// make all lower case
|
||||
$parameter = array_map('strtolower', $parameter);
|
||||
$tag = trim($parameter[0], '"\'');
|
||||
if (!isset($parameter[1]) || false === $name = $compiler->getId($parameter[1])) {
|
||||
$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", $compiler->lex->taglineno);
|
||||
}
|
||||
return "isset(\$_smarty_tpl->_cache['__smarty_capture']['{$name}']) ? \$_smarty_tpl->_cache['__smarty_capture']['{$name}'] : null";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,11 +91,11 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase
|
||||
* Compiles code for the {/capture} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
@@ -88,7 +110,7 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase
|
||||
$_output .= "if (!empty(\$_capture_buffer)) {\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 .= " Smarty::\$_smarty_vars['capture'][\$_capture_buffer]=ob_get_clean();\n";
|
||||
$_output .= "\$_smarty_tpl->_cache['__smarty_capture'][\$_capture_buffer]=ob_get_clean();\n";
|
||||
$_output .= "} else \$_smarty_tpl->capture_error();?>";
|
||||
|
||||
return $_output;
|
||||
|
@@ -41,7 +41,10 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
|
||||
case 'section':
|
||||
return Smarty_Internal_Compile_Private_ForeachSection::compileSpecialVariable(array(), $compiler, $_index);
|
||||
case 'capture':
|
||||
return "Smarty::\$_smarty_vars$parameter";
|
||||
if (class_exists('Smarty_Internal_Compile_Capture')) {
|
||||
return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index);
|
||||
}
|
||||
return '';
|
||||
case 'now':
|
||||
return 'time()';
|
||||
case 'cookies':
|
||||
@@ -116,13 +119,7 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
|
||||
$compiler->trigger_template_error('$smarty.' . trim($_index[0], "'") . ' is invalid');
|
||||
break;
|
||||
}
|
||||
if (isset($_index[1])) {
|
||||
array_shift($_index);
|
||||
foreach ($_index as $_ind) {
|
||||
$compiled_ref = $compiled_ref . "[$_ind]";
|
||||
}
|
||||
}
|
||||
}
|
||||
return $compiled_ref;
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
@@ -305,6 +305,12 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
*/
|
||||
public $cache = array();
|
||||
|
||||
/**
|
||||
* Stack during {capture} compilation
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_capture_stack = array();
|
||||
/**
|
||||
* Strip preg pattern
|
||||
*
|
||||
|
Reference in New Issue
Block a user