aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php')
-rw-r--r--vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php505
1 files changed, 315 insertions, 190 deletions
diff --git a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php
index 0d7284a0a..a72f3a4ab 100644
--- a/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php
+++ b/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php
@@ -16,8 +16,8 @@
*
* @property Smarty_Internal_SmartyTemplateCompiler $prefixCompiledCode = ''
* @property Smarty_Internal_SmartyTemplateCompiler $postfixCompiledCode = ''
- * @method registerPostCompileCallback($callback, $parameter = array(), $key = null, $replace = false)
- * @method unregisterPostCompileCallback($key)
+ * @method registerPostCompileCallback($callback, $parameter = array(), $key = null, $replace = false)
+ * @method unregisterPostCompileCallback($key)
*/
abstract class Smarty_Internal_TemplateCompilerBase
{
@@ -26,31 +26,36 @@ abstract class Smarty_Internal_TemplateCompilerBase
*
* @var array
*/
- static $_tag_objects = array();
+ public static $_tag_objects = array();
+
/**
* counter for prefix variable number
*
* @var int
*/
public static $prefixVariableNumber = 0;
+
/**
* Smarty object
*
* @var Smarty
*/
public $smarty = null;
+
/**
* Parser object
*
* @var Smarty_Internal_Templateparser
*/
public $parser = null;
+
/**
* hash for nocache sections
*
* @var mixed
*/
public $nocache_hash = null;
+
/**
* suppress generation of nocache code
*
@@ -71,174 +76,203 @@ abstract class Smarty_Internal_TemplateCompilerBase
* @var array
*/
public $_tag_stack = array();
+
/**
* tag stack count
*
* @var array
*/
public $_tag_stack_count = array();
+
/**
* Plugins used by template
*
* @var array
*/
public $required_plugins = array('compiled' => array(), 'nocache' => array());
+
/**
* Required plugins stack
*
* @var array
*/
public $required_plugins_stack = array();
+
/**
* current template
*
* @var Smarty_Internal_Template
*/
public $template = null;
+
/**
* merged included sub template data
*
* @var array
*/
public $mergedSubTemplatesData = array();
+
/**
* merged sub template code
*
* @var array
*/
public $mergedSubTemplatesCode = array();
+
/**
* collected template properties during compilation
*
* @var array
*/
public $templateProperties = array();
+
/**
* source line offset for error messages
*
* @var int
*/
public $trace_line_offset = 0;
+
/**
* trace uid
*
* @var string
*/
public $trace_uid = '';
+
/**
* trace file path
*
* @var string
*/
public $trace_filepath = '';
+
/**
* stack for tracing file and line of nested {block} tags
*
* @var array
*/
public $trace_stack = array();
+
/**
* plugins loaded by default plugin handler
*
* @var array
*/
public $default_handler_plugins = array();
+
/**
* saved preprocessed modifier list
*
* @var mixed
*/
public $default_modifier_list = null;
+
/**
* force compilation of complete template as nocache
*
* @var boolean
*/
public $forceNocache = false;
+
/**
* flag if compiled template file shall we written
*
* @var bool
*/
public $write_compiled_code = true;
+
/**
* Template functions
*
* @var array
*/
public $tpl_function = array();
+
/**
* called sub functions from template function
*
* @var array
*/
public $called_functions = array();
+
/**
* compiled template or block function code
*
* @var string
*/
public $blockOrFunctionCode = '';
+
/**
* php_handling setting either from Smarty or security
*
* @var int
*/
public $php_handling = 0;
+
/**
* flags for used modifier plugins
*
* @var array
*/
public $modifier_plugins = array();
+
/**
* type of already compiled modifier
*
* @var array
*/
public $known_modifier_type = array();
+
/**
* parent compiler object for merged subtemplates and template functions
*
* @var Smarty_Internal_TemplateCompilerBase
*/
public $parent_compiler = null;
+
/**
* Flag true when compiling nocache section
*
* @var bool
*/
public $nocache = false;
+
/**
* Flag true when tag is compiled as nocache
*
* @var bool
*/
public $tag_nocache = false;
+
/**
* Compiled tag prefix code
*
* @var array
*/
public $prefix_code = array();
+
/**
* used prefix variables by current compiled tag
*
* @var array
*/
public $usedPrefixVariables = array();
+
/**
* Prefix code stack
*
* @var array
*/
public $prefixCodeStack = array();
+
/**
* Tag has compiled code
*
* @var bool
*/
public $has_code = false;
+
/**
* A variable string was compiled
*
@@ -252,63 +286,75 @@ abstract class Smarty_Internal_TemplateCompilerBase
* @var array
*/
public $variable_filter_stack = array();
+
/**
* variable filters for {setfilter} {/setfilter}
*
* @var array
*/
public $variable_filters = array();
+
/**
* Nesting count of looping tags like {foreach}, {for}, {section}, {while}
*
* @var int
*/
public $loopNesting = 0;
+
/**
* Strip preg pattern
*
* @var string
*/
public $stripRegEx = '![\t ]*[\r\n]+[\t ]*!';
+
/**
* plugin search order
*
* @var array
*/
- public $plugin_search_order = array('function',
- 'block',
- 'compiler',
- 'class');
+ public $plugin_search_order = array(
+ 'function',
+ 'block',
+ 'compiler',
+ 'class'
+ );
+
/**
* General storage area for tag compiler plugins
*
* @var array
*/
public $_cache = array();
+
/**
* Lexer preg pattern for left delimiter
*
* @var string
*/
private $ldelPreg = '[{]';
+
/**
* Lexer preg pattern for right delimiter
*
* @var string
*/
private $rdelPreg = '[}]';
+
/**
* Length of right delimiter
*
* @var int
*/
private $rdelLength = 0;
+
/**
* Length of left delimiter
*
* @var int
*/
private $ldelLength = 0;
+
/**
* Lexer preg pattern for user literals
*
@@ -324,35 +370,44 @@ abstract class Smarty_Internal_TemplateCompilerBase
public function __construct(Smarty $smarty)
{
$this->smarty = $smarty;
- $this->nocache_hash = str_replace(array('.',
- ','),
- '_',
- uniqid(rand(), true));
+ $this->nocache_hash = str_replace(
+ array(
+ '.',
+ ','
+ ),
+ '_',
+ uniqid(mt_rand(), true)
+ );
}
/**
* Method to compile a Smarty template
*
- * @param Smarty_Internal_Template $template template object to compile
- * @param bool $nocache true is shall be compiled in nocache mode
+ * @param Smarty_Internal_Template $template template object to compile
+ * @param bool $nocache true is shall be compiled in nocache mode
* @param null|Smarty_Internal_TemplateCompilerBase $parent_compiler
*
* @return bool true if compiling succeeded, false if it failed
* @throws \Exception
*/
- public function compileTemplate(Smarty_Internal_Template $template,
- $nocache = null,
- Smarty_Internal_TemplateCompilerBase $parent_compiler = null)
- {
+ public function compileTemplate(
+ Smarty_Internal_Template $template,
+ $nocache = null,
+ Smarty_Internal_TemplateCompilerBase $parent_compiler = null
+ ) {
// get code frame of compiled template
- $_compiled_code = $template->smarty->ext->_codeFrame->create($template,
- $this->compileTemplateSource($template,
- $nocache,
- $parent_compiler),
- $this->postFilter($this->blockOrFunctionCode) .
- join('', $this->mergedSubTemplatesCode),
- false,
- $this);
+ $_compiled_code = $template->smarty->ext->_codeFrame->create(
+ $template,
+ $this->compileTemplateSource(
+ $template,
+ $nocache,
+ $parent_compiler
+ ),
+ $this->postFilter($this->blockOrFunctionCode) .
+ join('', $this->mergedSubTemplatesCode),
+ false,
+ $this
+ );
return $_compiled_code;
}
@@ -366,10 +421,11 @@ abstract class Smarty_Internal_TemplateCompilerBase
* @return string
* @throws \Exception
*/
- public function compileTemplateSource(Smarty_Internal_Template $template,
- $nocache = null,
- Smarty_Internal_TemplateCompilerBase $parent_compiler = null)
- {
+ public function compileTemplateSource(
+ Smarty_Internal_Template $template,
+ $nocache = null,
+ Smarty_Internal_TemplateCompilerBase $parent_compiler = null
+ ) {
try {
// save template object in compiler class
$this->template = $template;
@@ -405,9 +461,11 @@ abstract class Smarty_Internal_TemplateCompilerBase
// add file dependency
if ($this->smarty->merge_compiled_includes || $this->template->source->handler->checkTimestamps()) {
$this->parent_compiler->template->compiled->file_dependency[ $this->template->source->uid ] =
- array($this->template->source->filepath,
- $this->template->source->getTimeStamp(),
- $this->template->source->type,);
+ array(
+ $this->template->source->filepath,
+ $this->template->source->getTimeStamp(),
+ $this->template->source->type,
+ );
}
$this->smarty->_current_file = $this->template->source->filepath;
// get template source
@@ -421,8 +479,10 @@ abstract class Smarty_Internal_TemplateCompilerBase
$_content = $this->template->source->getContent();
}
$_compiled_code = $this->postFilter($this->doCompile($this->preFilter($_content), true));
- }
- catch (Exception $e) {
+ if (!empty($this->required_plugins[ 'compiled' ]) || !empty($this->required_plugins[ 'nocache' ])) {
+ $_compiled_code = '<?php ' . $this->compileRequiredPlugins() . "?>\n" . $_compiled_code;
+ }
+ } catch (Exception $e) {
if ($this->smarty->debugging) {
$this->smarty->_debug->end_compile($this->template);
}
@@ -452,8 +512,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
public function postFilter($code)
{
// run post filter if on code
- if (!empty($code) &&
- (isset($this->smarty->autoload_filters[ 'post' ]) || isset($this->smarty->registered_filters[ 'post' ]))
+ if (!empty($code)
+ && (isset($this->smarty->autoload_filters[ 'post' ]) || isset($this->smarty->registered_filters[ 'post' ]))
) {
return $this->smarty->ext->_filterHandler->runFilter('post', $code, $this->template);
} else {
@@ -472,8 +532,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
public function preFilter($_content)
{
// run pre filter if required
- if ($_content !== '' &&
- ((isset($this->smarty->autoload_filters[ 'pre' ]) || isset($this->smarty->registered_filters[ 'pre' ])))
+ if ($_content !== ''
+ && ((isset($this->smarty->autoload_filters[ 'pre' ]) || isset($this->smarty->registered_filters[ 'pre' ])))
) {
return $this->smarty->ext->_filterHandler->runFilter('pre', $_content, $this->template);
} else {
@@ -490,9 +550,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
* Merge tag prefix code with saved one
* (required nested tags in attributes)
*
- * @param string $tag tag name
- * @param array $args array with tag attributes
- * @param array $parameter array with compilation parameter
+ * @param string $tag tag name
+ * @param array $args array with tag attributes
+ * @param array $parameter array with compilation parameter
*
* @throws SmartyCompilerException
* @throws SmartyException
@@ -520,11 +580,13 @@ abstract class Smarty_Internal_TemplateCompilerBase
// not a variable variable
$var = trim($variable, '\'');
$this->tag_nocache = $this->tag_nocache |
- $this->template->ext->getTemplateVars->_getVariable($this->template,
- $var,
- null,
- true,
- false)->nocache;
+ $this->template->ext->getTemplateVars->_getVariable(
+ $this->template,
+ $var,
+ null,
+ true,
+ false
+ )->nocache;
// todo $this->template->compiled->properties['variables'][$var] = $this->tag_nocache | $this->nocache;
}
return '$_smarty_tpl->tpl_vars[' . $variable . ']->value';
@@ -546,8 +608,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
/**
* compile PHP function call
*
- * @param string $name
- * @param array $parameter
+ * @param string $name
+ * @param array $parameter
*
* @return string
* @throws \SmartyCompilerException
@@ -555,8 +617,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
public function compilePHPFunctionCall($name, $parameter)
{
if (!$this->smarty->security_policy || $this->smarty->security_policy->isTrustedPhpFunction($name, $this)) {
- if (strcasecmp($name, 'isset') === 0 || strcasecmp($name, 'empty') === 0 ||
- strcasecmp($name, 'array') === 0 || is_callable($name)
+ if (strcasecmp($name, 'isset') === 0 || strcasecmp($name, 'empty') === 0
+ || strcasecmp($name, 'array') === 0 || is_callable($name)
) {
$func_name = strtolower($name);
$par = implode(',', $parameter);
@@ -575,13 +637,18 @@ abstract class Smarty_Internal_TemplateCompilerBase
$isset_par = str_replace("')->value", "',null,true,false)->value", $par);
}
return $name . '(' . $isset_par . ')';
- } else if (in_array($func_name,
- array('empty',
- 'reset',
- 'current',
- 'end',
- 'prev',
- 'next'))) {
+ } elseif (in_array(
+ $func_name,
+ array(
+ 'empty',
+ 'reset',
+ 'current',
+ 'end',
+ 'prev',
+ 'next'
+ )
+ )
+ ) {
if (count($parameter) !== 1) {
$this->trigger_template_error("Illegal number of parameter in '{$func_name()}'");
}
@@ -615,24 +682,27 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/
public function processText($text)
{
- if ((string)$text !== '') {
+ if ((string)$text != '') {
$store = array();
$_store = 0;
if ($this->parser->strip) {
if (strpos($text, '<') !== false) {
// capture html elements not to be messed with
$_offset = 0;
- if (preg_match_all('#(<script[^>]*>.*?</script[^>]*>)|(<textarea[^>]*>.*?</textarea[^>]*>)|(<pre[^>]*>.*?</pre[^>]*>)#is',
- $text,
- $matches,
- PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
+ if (preg_match_all(
+ '#(<script[^>]*>.*?</script[^>]*>)|(<textarea[^>]*>.*?</textarea[^>]*>)|(<pre[^>]*>.*?</pre[^>]*>)#is',
+ $text,
+ $matches,
+ PREG_OFFSET_CAPTURE | PREG_SET_ORDER
+ )
+ ) {
foreach ($matches as $match) {
$store[] = $match[ 0 ][ 0 ];
$_length = strlen($match[ 0 ][ 0 ]);
$replace = '@!@SMARTY:' . $_store . ':SMARTY@!@';
$text = substr_replace($text, $replace, $match[ 0 ][ 1 ] - $_offset, $_length);
$_offset += $_length - strlen($replace);
- ++$_store;
+ $_store++;
}
}
$expressions = array(// replace multiple spaces between tags by a single space
@@ -643,19 +713,23 @@ abstract class Smarty_Internal_TemplateCompilerBase
'#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5',
'#>[\040\011]+$#Ss' => '> ',
'#>[\040\011]*[\n]\s*$#Ss' => '>',
- $this->stripRegEx => '',);
+ $this->stripRegEx => '',
+ );
$text = preg_replace(array_keys($expressions), array_values($expressions), $text);
$_offset = 0;
- if (preg_match_all('#@!@SMARTY:([0-9]+):SMARTY@!@#is',
- $text,
- $matches,
- PREG_OFFSET_CAPTURE | PREG_SET_ORDER)) {
+ if (preg_match_all(
+ '#@!@SMARTY:([0-9]+):SMARTY@!@#is',
+ $text,
+ $matches,
+ PREG_OFFSET_CAPTURE | PREG_SET_ORDER
+ )
+ ) {
foreach ($matches as $match) {
$_length = strlen($match[ 0 ][ 0 ]);
$replace = $store[ $match[ 1 ][ 0 ] ];
$text = substr_replace($text, $replace, $match[ 0 ][ 1 ] + $_offset, $_length);
$_offset += strlen($replace) - $_length;
- ++$_store;
+ $_store++;
}
}
} else {
@@ -673,11 +747,11 @@ abstract class Smarty_Internal_TemplateCompilerBase
* class name format: Smarty_Internal_Compile_TagName
* plugin filename format: Smarty_Internal_TagName.php
*
- * @param string $tag tag name
- * @param array $args list of tag attributes
- * @param mixed $param1 optional parameter
- * @param mixed $param2 optional parameter
- * @param mixed $param3 optional parameter
+ * @param string $tag tag name
+ * @param array $args list of tag attributes
+ * @param mixed $param1 optional parameter
+ * @param mixed $param2 optional parameter
+ * @param mixed $param3 optional parameter
*
* @return bool|string compiled code or false
* @throws \SmartyCompilerException
@@ -696,10 +770,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
* class name format: Smarty_Internal_Compile_TagName
* plugin filename format: Smarty_Internal_TagName.php
*
- * @param string $tag tag name
+ * @param string $tag tag name
*
* @return bool|\Smarty_Internal_CompileBase tag compiler object or false if not found
- * @throws \SmartyCompilerException
*/
public function getTagCompiler($tag)
{
@@ -709,8 +782,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
$_tag = explode('_', $tag);
$_tag = array_map('ucfirst', $_tag);
$class_name = 'Smarty_Internal_Compile_' . implode('_', $_tag);
- if (class_exists($class_name) &&
- (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this))
+ if (class_exists($class_name)
+ && (!isset($this->smarty->security_policy) || $this->smarty->security_policy->isTrustedTag($tag, $this))
) {
self::$_tag_objects[ $tag ] = new $class_name;
} else {
@@ -723,8 +796,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
/**
* Check for plugins and return function name
*
- * @param $plugin_name
- * @param string $plugin_type type of plugin
+ * @param $plugin_name
+ * @param string $plugin_type type of plugin
*
* @return string call name of function
* @throws \SmartyException
@@ -736,7 +809,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
if (isset($this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) {
$function =
$this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ][ 'function' ];
- } else if (isset($this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) {
+ } elseif (isset($this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) {
$this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ] =
$this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ];
$function =
@@ -746,7 +819,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
if (isset($this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ])) {
$function =
$this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ][ 'function' ];
- } else if (isset($this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) {
+ } elseif (isset($this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ])) {
$this->required_plugins[ 'compiled' ][ $plugin_name ][ $plugin_type ] =
$this->required_plugins[ 'nocache' ][ $plugin_name ][ $plugin_type ];
$function =
@@ -789,8 +862,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
/**
* Check for plugins by default plugin handler
*
- * @param string $tag name of tag
- * @param string $plugin_type type of plugin
+ * @param string $tag name of tag
+ * @param string $plugin_type type of plugin
*
* @return bool true if found
* @throws \SmartyCompilerException
@@ -800,13 +873,17 @@ abstract class Smarty_Internal_TemplateCompilerBase
$callback = null;
$script = null;
$cacheable = true;
- $result = call_user_func_array($this->smarty->default_plugin_handler_func,
- array($tag,
- $plugin_type,
- $this->template,
- &$callback,
- &$script,
- &$cacheable,));
+ $result = call_user_func_array(
+ $this->smarty->default_plugin_handler_func,
+ array(
+ $tag,
+ $plugin_type,
+ $this->template,
+ &$callback,
+ &$script,
+ &$cacheable,
+ )
+ );
if ($result) {
$this->tag_nocache = $this->tag_nocache || !$cacheable;
if ($script !== null) {
@@ -822,15 +899,17 @@ abstract class Smarty_Internal_TemplateCompilerBase
$this->required_plugins[ 'compiled' ][ $tag ][ $plugin_type ][ 'function' ] =
$callback;
}
- require_once $script;
+ include_once $script;
} else {
$this->trigger_template_error("Default plugin handler: Returned script file '{$script}' for '{$tag}' not found");
}
}
if (is_callable($callback)) {
- $this->default_handler_plugins[ $plugin_type ][ $tag ] = array($callback,
- true,
- array());
+ $this->default_handler_plugins[ $plugin_type ][ $tag ] = array(
+ $callback,
+ true,
+ array()
+ );
return true;
} else {
$this->trigger_template_error("Default plugin handler: Returned callback for '{$tag}' not callable");
@@ -864,8 +943,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
* If the content is compiled code and it should be not cached the code is injected
* into the rendered output.
*
- * @param string $content content of template element
- * @param boolean $is_code true if content is compiled code
+ * @param string $content content of template element
+ * @param boolean $is_code true if content is compiled code
*
* @return string content
*/
@@ -874,13 +953,14 @@ abstract class Smarty_Internal_TemplateCompilerBase
// If the template is not evaluated and we have a nocache section and or a nocache tag
if ($is_code && !empty($content)) {
// generate replacement code
- if ((!($this->template->source->handler->recompiled) || $this->forceNocache) && $this->caching &&
- !$this->suppressNocacheProcessing && ($this->nocache || $this->tag_nocache)
+ if ((!($this->template->source->handler->recompiled) || $this->forceNocache) && $this->caching
+ && !$this->suppressNocacheProcessing && ($this->nocache || $this->tag_nocache)
) {
$this->template->compiled->has_nocache_code = true;
$_output = addcslashes($content, '\'\\');
$_output = str_replace('^#^', '\'', $_output);
- $_output = "<?php echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/{$_output}/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n";
+ $_output =
+ "<?php echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/{$_output}/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n";
// make sure we include modifier plugins for nocache code
foreach ($this->modifier_plugins as $plugin_name => $dummy) {
if (isset($this->required_plugins[ 'compiled' ][ $plugin_name ][ 'modifier' ])) {
@@ -962,7 +1042,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
$_scopeName = trim($_attr[ 'scope' ], '\'"');
if (is_numeric($_scopeName) && in_array($_scopeName, $validScopes)) {
$_scope = $_scopeName;
- } else if (is_string($_scopeName)) {
+ } elseif (is_string($_scopeName)) {
$_scopeName = trim($_scopeName, '\'"');
$_scope = isset($validScopes[ $_scopeName ]) ? $validScopes[ $_scopeName ] : false;
} else {
@@ -996,8 +1076,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
* In this case the parser is called to obtain information about expected tokens.
* If parameter $args contains a string this is used as error message
*
- * @param string $args individual error message or null
- * @param string $line line-number
+ * @param string $args individual error message or null
+ * @param string $line line-number
* @param null|bool $tagline if true the line number of last tag
*
* @throws \SmartyCompilerException when an unexpected token is found
@@ -1008,20 +1088,29 @@ abstract class Smarty_Internal_TemplateCompilerBase
if ($tagline === true) {
// get line number of Tag
$line = $lex->taglineno;
- } else if (!isset($line)) {
+ } elseif (!isset($line)) {
// get template source line which has error
$line = $lex->line;
} else {
$line = (int)$line;
}
- if (in_array($this->template->source->type,
- array('eval',
- 'string'))) {
- $templateName = $this->template->source->type . ':' . trim(preg_replace('![\t\r\n]+!',
- ' ',
- strlen($lex->data) > 40 ?
- substr($lex->data, 0, 40) .
- '...' : $lex->data));
+ if (in_array(
+ $this->template->source->type,
+ array(
+ 'eval',
+ 'string'
+ )
+ )
+ ) {
+ $templateName = $this->template->source->type . ':' . trim(
+ preg_replace(
+ '![\t\r\n]+!',
+ ' ',
+ strlen($lex->data) > 40 ?
+ substr($lex->data, 0, 40) .
+ '...' : $lex->data
+ )
+ );
} else {
$templateName = $this->template->source->type . ':' . $this->template->source->filepath;
}
@@ -1068,7 +1157,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
/**
* Return var_export() value with all white spaces removed
*
- * @param mixed $value
+ * @param mixed $value
*
* @return string
*/
@@ -1103,11 +1192,15 @@ abstract class Smarty_Internal_TemplateCompilerBase
*/
public function replaceDelimiter($lexerPreg)
{
- return str_replace(array('SMARTYldel', 'SMARTYliteral', 'SMARTYrdel', 'SMARTYautoliteral', 'SMARTYal'),
- array($this->ldelPreg, $this->literalPreg, $this->rdelPreg,
- $this->smarty->getAutoLiteral() ? '{1,}' : '{9}',
- $this->smarty->getAutoLiteral() ? '' : '\\s*'),
- $lexerPreg);
+ return str_replace(
+ array('SMARTYldel', 'SMARTYliteral', 'SMARTYrdel', 'SMARTYautoliteral', 'SMARTYal'),
+ array(
+ $this->ldelPreg, $this->literalPreg, $this->rdelPreg,
+ $this->smarty->getAutoLiteral() ? '{1,}' : '{9}',
+ $this->smarty->getAutoLiteral() ? '' : '\\s*'
+ ),
+ $lexerPreg
+ );
}
/**
@@ -1119,20 +1212,20 @@ abstract class Smarty_Internal_TemplateCompilerBase
$this->ldelLength = strlen($ldel);
$this->ldelPreg = '';
foreach (str_split($ldel, 1) as $chr) {
- $this->ldelPreg .= '[' . ($chr === '\\' ? '\\' : '') . $chr . ']';
+ $this->ldelPreg .= '[' . preg_quote($chr,'/') . ']';
}
$rdel = $this->smarty->getRightDelimiter();
$this->rdelLength = strlen($rdel);
$this->rdelPreg = '';
foreach (str_split($rdel, 1) as $chr) {
- $this->rdelPreg .= '[' . ($chr === '\\' ? '\\' : '') . $chr . ']';
+ $this->rdelPreg .= '[' . preg_quote($chr,'/') . ']';
}
$literals = $this->smarty->getLiterals();
if (!empty($literals)) {
foreach ($literals as $key => $literal) {
$literalPreg = '';
foreach (str_split($literal, 1) as $chr) {
- $literalPreg .= '[' . ($chr === '\\' ? '\\' : '') . $chr . ']';
+ $literalPreg .= '[' . preg_quote($chr,'/') . ']';
}
$literals[ $key ] = $literalPreg;
}
@@ -1152,9 +1245,11 @@ abstract class Smarty_Internal_TemplateCompilerBase
{
if (array_pop($this->_tag_stack_count) !== $this->getTagStackCount()) {
$tag = $this->getOpenBlockTag();
- $this->trigger_template_error("unclosed '{{$tag}}' in doubled quoted string",
- null,
- true);
+ $this->trigger_template_error(
+ "unclosed '{{$tag}}' in doubled quoted string",
+ null,
+ true
+ );
}
}
@@ -1292,7 +1387,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
*
* @param bool $init if true init required plugins
*/
- public function saveRequiredPlugins($init=false)
+ public function saveRequiredPlugins($init = false)
{
$this->required_plugins_stack[] = $this->required_plugins;
if ($init) {
@@ -1359,9 +1454,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
/**
* Compile Tag
*
- * @param string $tag tag name
- * @param array $args array with tag attributes
- * @param array $parameter array with compilation parameter
+ * @param string $tag tag name
+ * @param array $args array with tag attributes
+ * @param array $parameter array with compilation parameter
*
* @throws SmartyCompilerException
* @throws SmartyException
@@ -1375,8 +1470,10 @@ abstract class Smarty_Internal_TemplateCompilerBase
$this->has_code = true;
// log tag/attributes
if (isset($this->smarty->_cache[ 'get_used_tags' ])) {
- $this->template->_cache[ 'used_tags' ][] = array($tag,
- $args);
+ $this->template->_cache[ 'used_tags' ][] = array(
+ $tag,
+ $args
+ );
}
// check nocache option flag
foreach ($args as $arg) {
@@ -1394,9 +1491,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
}
// compile the smarty tag (required compile classes to compile the tag are auto loaded)
if (($_output = $this->callTagCompiler($tag, $args, $parameter)) === false) {
- if (isset($this->parent_compiler->tpl_function[ $tag ]) ||
- (isset ($this->template->smarty->ext->_tplFunction) &&
- $this->template->smarty->ext->_tplFunction->getTplFunction($this->template, $tag) !== false)
+ if (isset($this->parent_compiler->tpl_function[ $tag ])
+ || (isset($this->template->smarty->ext->_tplFunction)
+ && $this->template->smarty->ext->_tplFunction->getTplFunction($this->template, $tag) !== false)
) {
// template defined by {template} tag
$args[ '_attr' ][ 'name' ] = "'{$tag}'";
@@ -1427,29 +1524,35 @@ abstract class Smarty_Internal_TemplateCompilerBase
// check if tag is a registered object
if (isset($this->smarty->registered_objects[ $tag ]) && isset($parameter[ 'object_method' ])) {
$method = $parameter[ 'object_method' ];
- if (!in_array($method, $this->smarty->registered_objects[ $tag ][ 3 ]) &&
- (empty($this->smarty->registered_objects[ $tag ][ 1 ]) ||
- in_array($method, $this->smarty->registered_objects[ $tag ][ 1 ]))
+ if (!in_array($method, $this->smarty->registered_objects[ $tag ][ 3 ])
+ && (empty($this->smarty->registered_objects[ $tag ][ 1 ])
+ || in_array($method, $this->smarty->registered_objects[ $tag ][ 1 ]))
) {
return $this->callTagCompiler('private_object_function', $args, $parameter, $tag, $method);
- } else if (in_array($method, $this->smarty->registered_objects[ $tag ][ 3 ])) {
- return $this->callTagCompiler('private_object_block_function',
- $args,
- $parameter,
- $tag,
- $method);
+ } elseif (in_array($method, $this->smarty->registered_objects[ $tag ][ 3 ])) {
+ return $this->callTagCompiler(
+ 'private_object_block_function',
+ $args,
+ $parameter,
+ $tag,
+ $method
+ );
} else {
// throw exception
- $this->trigger_template_error('not allowed method "' . $method . '" in registered object "' .
- $tag . '"',
- null,
- true);
+ $this->trigger_template_error(
+ 'not allowed method "' . $method . '" in registered object "' .
+ $tag . '"',
+ null,
+ true
+ );
}
}
// check if tag is registered
- foreach (array(Smarty::PLUGIN_COMPILER,
- Smarty::PLUGIN_FUNCTION,
- Smarty::PLUGIN_BLOCK,) as $plugin_type) {
+ foreach (array(
+ Smarty::PLUGIN_COMPILER,
+ Smarty::PLUGIN_FUNCTION,
+ Smarty::PLUGIN_BLOCK,
+ ) as $plugin_type) {
if (isset($this->smarty->registered_plugins[ $plugin_type ][ $tag ])) {
// if compiler function plugin call it now
if ($plugin_type === Smarty::PLUGIN_COMPILER) {
@@ -1464,25 +1567,31 @@ abstract class Smarty_Internal_TemplateCompilerBase
if (!$this->smarty->registered_plugins[ $plugin_type ][ $tag ][ 1 ]) {
$this->tag_nocache = true;
}
- return call_user_func_array($this->smarty->registered_plugins[ $plugin_type ][ $tag ][ 0 ],
- array($new_args,
- $this));
+ return call_user_func_array(
+ $this->smarty->registered_plugins[ $plugin_type ][ $tag ][ 0 ],
+ array(
+ $new_args,
+ $this
+ )
+ );
}
// compile registered function or block function
if ($plugin_type === Smarty::PLUGIN_FUNCTION || $plugin_type === Smarty::PLUGIN_BLOCK) {
- return $this->callTagCompiler('private_registered_' . $plugin_type,
- $args,
- $parameter,
- $tag);
+ return $this->callTagCompiler(
+ 'private_registered_' . $plugin_type,
+ $args,
+ $parameter,
+ $tag
+ );
}
}
}
// check plugins from plugins folder
foreach ($this->plugin_search_order as $plugin_type) {
- if ($plugin_type === Smarty::PLUGIN_COMPILER &&
- $this->smarty->loadPlugin('smarty_compiler_' . $tag) &&
- (!isset($this->smarty->security_policy) ||
- $this->smarty->security_policy->isTrustedTag($tag, $this))
+ if ($plugin_type === Smarty::PLUGIN_COMPILER
+ && $this->smarty->loadPlugin('smarty_compiler_' . $tag)
+ && (!isset($this->smarty->security_policy)
+ || $this->smarty->security_policy->isTrustedTag($tag, $this))
) {
$plugin = 'smarty_compiler_' . $tag;
if (is_callable($plugin)) {
@@ -1506,14 +1615,16 @@ abstract class Smarty_Internal_TemplateCompilerBase
throw new SmartyException("Plugin '{$tag}' not callable");
} else {
if ($function = $this->getPlugin($tag, $plugin_type)) {
- if (!isset($this->smarty->security_policy) ||
- $this->smarty->security_policy->isTrustedTag($tag, $this)
+ if (!isset($this->smarty->security_policy)
+ || $this->smarty->security_policy->isTrustedTag($tag, $this)
) {
- return $this->callTagCompiler('private_' . $plugin_type . '_plugin',
- $args,
- $parameter,
- $tag,
- $function);
+ return $this->callTagCompiler(
+ 'private_' . $plugin_type . '_plugin',
+ $args,
+ $parameter,
+ $tag,
+ $function
+ );
}
}
}
@@ -1547,14 +1658,20 @@ abstract class Smarty_Internal_TemplateCompilerBase
$new_args[ $key ] = $mixed;
}
}
- return call_user_func_array($this->default_handler_plugins[ $plugin_type ][ $tag ][ 0 ],
- array($new_args,
- $this));
+ return call_user_func_array(
+ $this->default_handler_plugins[ $plugin_type ][ $tag ][ 0 ],
+ array(
+ $new_args,
+ $this
+ )
+ );
} else {
- return $this->callTagCompiler('private_registered_' . $plugin_type,
- $args,
- $parameter,
- $tag);
+ return $this->callTagCompiler(
+ 'private_registered_' . $plugin_type,
+ $args,
+ $parameter,
+ $tag
+ );
}
}
}
@@ -1565,22 +1682,26 @@ abstract class Smarty_Internal_TemplateCompilerBase
if (isset($this->smarty->registered_objects[ $base_tag ]) && isset($parameter[ 'object_method' ])) {
$method = $parameter[ 'object_method' ];
if (in_array($method, $this->smarty->registered_objects[ $base_tag ][ 3 ])) {
- return $this->callTagCompiler('private_object_block_function',
- $args,
- $parameter,
- $tag,
- $method);
+ return $this->callTagCompiler(
+ 'private_object_block_function',
+ $args,
+ $parameter,
+ $tag,
+ $method
+ );
} else {
// throw exception
- $this->trigger_template_error('not allowed closing tag method "' . $method .
- '" in registered object "' . $base_tag . '"',
- null,
- true);
+ $this->trigger_template_error(
+ 'not allowed closing tag method "' . $method .
+ '" in registered object "' . $base_tag . '"',
+ null,
+ true
+ );
}
}
// registered block tag ?
- if (isset($this->smarty->registered_plugins[ Smarty::PLUGIN_BLOCK ][ $base_tag ]) ||
- isset($this->default_handler_plugins[ Smarty::PLUGIN_BLOCK ][ $base_tag ])
+ if (isset($this->smarty->registered_plugins[ Smarty::PLUGIN_BLOCK ][ $base_tag ])
+ || isset($this->default_handler_plugins[ Smarty::PLUGIN_BLOCK ][ $base_tag ])
) {
return $this->callTagCompiler('private_registered_block', $args, $parameter, $tag);
}
@@ -1594,8 +1715,8 @@ abstract class Smarty_Internal_TemplateCompilerBase
}
// function plugin?
if ($function = $this->getPlugin($tag, Smarty::PLUGIN_FUNCTION)) {
- if (!isset($this->smarty->security_policy) ||
- $this->smarty->security_policy->isTrustedTag($tag, $this)
+ if (!isset($this->smarty->security_policy)
+ || $this->smarty->security_policy->isTrustedTag($tag, $this)
) {
return $this->callTagCompiler('private_function_plugin', $args, $parameter, $tag, $function);
}
@@ -1607,9 +1728,13 @@ abstract class Smarty_Internal_TemplateCompilerBase
if (!$this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ][ 1 ]) {
$this->tag_nocache = true;
}
- return call_user_func_array($this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ][ 0 ],
- array($args,
- $this));
+ return call_user_func_array(
+ $this->smarty->registered_plugins[ Smarty::PLUGIN_COMPILER ][ $tag ][ 0 ],
+ array(
+ $args,
+ $this
+ )
+ );
}
if ($this->smarty->loadPlugin('smarty_compiler_' . $tag)) {
$plugin = 'smarty_compiler_' . $tag;