diff --git a/plugins/modifiercompiler.escape.php b/plugins/modifiercompiler.escape.php
index 7653ceb6..0fc50774 100644
--- a/plugins/modifiercompiler.escape.php
+++ b/plugins/modifiercompiler.escape.php
@@ -15,12 +15,12 @@
* @author Rodney Rehm
*
* @param array $params parameters
- * @param Smarty_Internal_TemplateCompilerBase $compiler
+ * @param \Smarty\Compiler\Template $compiler
*
* @return string with compiled code
* @throws SmartyException
*/
-function smarty_modifiercompiler_escape($params, Smarty_Internal_TemplateCompilerBase $compiler)
+function smarty_modifiercompiler_escape($params, \Smarty\Compiler\Template $compiler)
{
try {
$esc_type = smarty_literal_compiler_param($params, 1, 'html');
diff --git a/plugins/modifiercompiler.unescape.php b/plugins/modifiercompiler.unescape.php
index e97709f2..ba53e53a 100644
--- a/plugins/modifiercompiler.unescape.php
+++ b/plugins/modifiercompiler.unescape.php
@@ -14,11 +14,11 @@
* @author Rodney Rehm
*
* @param array $params parameters
- * @param Smarty_Internal_TemplateCompilerBase $compiler
+ * @param \Smarty\Compiler\Template $compiler
*
* @return string with compiled code
*/
-function smarty_modifiercompiler_unescape($params, Smarty_Internal_TemplateCompilerBase $compiler)
+function smarty_modifiercompiler_unescape($params, \Smarty\Compiler\Template $compiler)
{
$esc_type = smarty_literal_compiler_param($params, 1, 'html');
diff --git a/plugins/modifiercompiler.wordwrap.php b/plugins/modifiercompiler.wordwrap.php
index a95333ec..4d09b9b5 100644
--- a/plugins/modifiercompiler.wordwrap.php
+++ b/plugins/modifiercompiler.wordwrap.php
@@ -15,12 +15,12 @@
* @author Uwe Tews
*
* @param array $params parameters
- * @param \Smarty_Internal_TemplateCompilerBase $compiler
+ * @param \Smarty\Compiler\Template $compiler
*
* @return string with compiled code
* @throws \SmartyException
*/
-function smarty_modifiercompiler_wordwrap($params, Smarty_Internal_TemplateCompilerBase $compiler)
+function smarty_modifiercompiler_wordwrap($params, \Smarty\Compiler\Template $compiler)
{
if (!isset($params[ 1 ])) {
$params[ 1 ] = 80;
diff --git a/plugins/shared.mb_str_replace.php b/plugins/shared.mb_str_replace.php
index bf40aa54..f1188f30 100644
--- a/plugins/shared.mb_str_replace.php
+++ b/plugins/shared.mb_str_replace.php
@@ -5,83 +5,82 @@
* @package Smarty
* @subpackage PluginsShared
*/
-if (!function_exists('smarty_mb_str_replace')) {
- /**
- * Multibyte string replace
- *
- * @param string|string[] $search the string to be searched
- * @param string|string[] $replace the replacement string
- * @param string $subject the source string
- * @param int &$count number of matches found
- *
- * @return string replaced string
- * @author Rodney Rehm
- */
- function smarty_mb_str_replace($search, $replace, $subject, &$count = 0)
- {
- if (!is_array($search) && is_array($replace)) {
- return false;
+
+/**
+ * Multibyte string replace
+ *
+ * @param string|string[] $search the string to be searched
+ * @param string|string[] $replace the replacement string
+ * @param string $subject the source string
+ * @param int &$count number of matches found
+ *
+ * @return string replaced string
+ * @author Rodney Rehm
+ */
+function smarty_mb_str_replace($search, $replace, $subject, &$count = 0)
+{
+ if (!is_array($search) && is_array($replace)) {
+ return false;
+ }
+ if (is_array($subject)) {
+ // call mb_replace for each single string in $subject
+ foreach ($subject as &$string) {
+ $string = smarty_mb_str_replace($search, $replace, $string, $c);
+ $count += $c;
}
- if (is_array($subject)) {
- // call mb_replace for each single string in $subject
- foreach ($subject as &$string) {
- $string = smarty_mb_str_replace($search, $replace, $string, $c);
+ } elseif (is_array($search)) {
+ if (!is_array($replace)) {
+ foreach ($search as &$string) {
+ $subject = smarty_mb_str_replace($string, $replace, $subject, $c);
$count += $c;
}
- } elseif (is_array($search)) {
- if (!is_array($replace)) {
- foreach ($search as &$string) {
- $subject = smarty_mb_str_replace($string, $replace, $subject, $c);
- $count += $c;
- }
- } else {
- $n = max(count($search), count($replace));
- while ($n--) {
- $subject = smarty_mb_str_replace(current($search), current($replace), $subject, $c);
- $count += $c;
- next($search);
- next($replace);
- }
- }
} else {
- $mb_reg_charset = mb_regex_encoding();
- // Check if mbstring regex is using UTF-8
- $reg_is_unicode = !strcasecmp($mb_reg_charset, "UTF-8");
- if(!$reg_is_unicode) {
- // ...and set to UTF-8 if not
- mb_regex_encoding("UTF-8");
- }
-
- // See if charset used by Smarty is matching one used by regex...
- $current_charset = mb_regex_encoding();
- $convert_result = (bool)strcasecmp(\Smarty\Smarty::$_CHARSET, $current_charset);
- if($convert_result) {
- // ...convert to it if not.
- $subject = mb_convert_encoding($subject, $current_charset, \Smarty\Smarty::$_CHARSET);
- $search = mb_convert_encoding($search, $current_charset, \Smarty\Smarty::$_CHARSET);
- $replace = mb_convert_encoding($replace, $current_charset, \Smarty\Smarty::$_CHARSET);
- }
-
- $parts = mb_split(preg_quote($search), $subject ?? "") ?: array();
- // If original regex encoding was not unicode...
- if(!$reg_is_unicode) {
- // ...restore original regex encoding to avoid breaking the system.
- mb_regex_encoding($mb_reg_charset);
- }
- if($parts === false) {
- // This exception is thrown if call to mb_split failed.
- // Usually it happens, when $search or $replace are not valid for given mb_regex_encoding().
- // There may be other cases for it to fail, please file an issue if you find a reproducible one.
- throw new SmartyException("Source string is not a valid $current_charset sequence (probably)");
- }
-
- $count = count($parts) - 1;
- $subject = implode($replace, $parts);
- // Convert results back to charset used by Smarty, if needed.
- if($convert_result) {
- $subject = mb_convert_encoding($subject, \Smarty\Smarty::$_CHARSET, $current_charset);
+ $n = max(count($search), count($replace));
+ while ($n--) {
+ $subject = smarty_mb_str_replace(current($search), current($replace), $subject, $c);
+ $count += $c;
+ next($search);
+ next($replace);
}
}
- return $subject;
+ } else {
+ $mb_reg_charset = mb_regex_encoding();
+ // Check if mbstring regex is using UTF-8
+ $reg_is_unicode = !strcasecmp($mb_reg_charset, "UTF-8");
+ if(!$reg_is_unicode) {
+ // ...and set to UTF-8 if not
+ mb_regex_encoding("UTF-8");
+ }
+
+ // See if charset used by Smarty is matching one used by regex...
+ $current_charset = mb_regex_encoding();
+ $convert_result = (bool)strcasecmp(\Smarty\Smarty::$_CHARSET, $current_charset);
+ if($convert_result) {
+ // ...convert to it if not.
+ $subject = mb_convert_encoding($subject, $current_charset, \Smarty\Smarty::$_CHARSET);
+ $search = mb_convert_encoding($search, $current_charset, \Smarty\Smarty::$_CHARSET);
+ $replace = mb_convert_encoding($replace, $current_charset, \Smarty\Smarty::$_CHARSET);
+ }
+
+ $parts = mb_split(preg_quote($search), $subject ?? "") ?: array();
+ // If original regex encoding was not unicode...
+ if(!$reg_is_unicode) {
+ // ...restore original regex encoding to avoid breaking the system.
+ mb_regex_encoding($mb_reg_charset);
+ }
+ if($parts === false) {
+ // This exception is thrown if call to mb_split failed.
+ // Usually it happens, when $search or $replace are not valid for given mb_regex_encoding().
+ // There may be other cases for it to fail, please file an issue if you find a reproducible one.
+ throw new SmartyException("Source string is not a valid $current_charset sequence (probably)");
+ }
+
+ $count = count($parts) - 1;
+ $subject = implode($replace, $parts);
+ // Convert results back to charset used by Smarty, if needed.
+ if($convert_result) {
+ $subject = mb_convert_encoding($subject, \Smarty\Smarty::$_CHARSET, $current_charset);
+ }
}
-}
+ return $subject;
+}
\ No newline at end of file
diff --git a/src/Compile/Append.php b/src/Compile/Append.php
index 81dc1c05..187142ec 100644
--- a/src/Compile/Append.php
+++ b/src/Compile/Append.php
@@ -23,13 +23,13 @@ class Append extends Assign
* Compiles code for the {append} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null)
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null)
{
// the following must be assigned at runtime because it will be overwritten in parent class
$this->required_attributes = array('var', 'value');
diff --git a/src/Compile/Assign.php b/src/Compile/Assign.php
index 66421934..2e7eed06 100644
--- a/src/Compile/Assign.php
+++ b/src/Compile/Assign.php
@@ -28,14 +28,14 @@ class Assign extends CompileBase
* @var array
* @see Base
*/
- public $option_flags = array('nocache', 'noscope');
+ protected $option_flags = array('nocache', 'noscope');
/**
* Valid scope names
*
* @var array
*/
- public $valid_scopes = array(
+ protected $valid_scopes = array(
'local' => Smarty::SCOPE_LOCAL, 'parent' => Smarty::SCOPE_PARENT,
'root' => Smarty::SCOPE_ROOT, 'global' => Smarty::SCOPE_GLOBAL,
'tpl_root' => Smarty::SCOPE_TPL_ROOT, 'smarty' => Smarty::SCOPE_SMARTY
@@ -45,13 +45,13 @@ class Assign extends CompileBase
* Compiles code for the {assign} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null)
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null)
{
// the following must be assigned at runtime because it will be overwritten in Append
$this->required_attributes = array('var', 'value');
diff --git a/src/Compile/Base.php b/src/Compile/Base.php
index 4b5d864c..20b9b4fa 100644
--- a/src/Compile/Base.php
+++ b/src/Compile/Base.php
@@ -202,11 +202,11 @@ abstract class Base {
* Compiles code for the tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
- abstract public function compile($args, \Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null);
+ abstract public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null);
}
diff --git a/src/Compile/Block.php b/src/Compile/Block.php
index b6fb3d80..e646084c 100644
--- a/src/Compile/Block.php
+++ b/src/Compile/Block.php
@@ -11,7 +11,6 @@
namespace Smarty\Compile;
use Smarty\ParseTree\Template;
-use Smarty_Internal_TemplateCompilerBase;
/**
* Smarty Internal Plugin Compile Block Class
@@ -42,7 +41,7 @@ class Block extends Inheritance {
* @var array
* @see Base
*/
- public $option_flags = ['hide', 'nocache'];
+ protected $option_flags = ['hide', 'nocache'];
/**
* Attribute definition: Overwrites base class.
@@ -56,10 +55,10 @@ class Block extends Inheritance {
* Compiles code for the {block} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
* @param array $parameter array with compilation parameter
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null)
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null)
{
if (!isset($compiler->_cache['blockNesting'])) {
$compiler->_cache['blockNesting'] = 0;
diff --git a/src/Compile/BlockClose.php b/src/Compile/BlockClose.php
index c62a909c..e4eda84a 100644
--- a/src/Compile/BlockClose.php
+++ b/src/Compile/BlockClose.php
@@ -3,7 +3,7 @@
namespace Smarty\Compile;
use Smarty\ParseTree\Template;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile BlockClose Class
@@ -14,12 +14,12 @@ class BlockClose extends Inheritance {
* Compiles code for the {/block} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return bool true
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null)
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null)
{
[$_attr, $_nocache, $_buffer, $_has_nocache_code, $_caching] = $this->closeTag($compiler, ['block']);
// init block parameter
diff --git a/src/Compile/BreakTag.php b/src/Compile/BreakTag.php
index a4bbf9a6..0354d916 100644
--- a/src/Compile/BreakTag.php
+++ b/src/Compile/BreakTag.php
@@ -10,9 +10,6 @@
namespace Smarty\Compile;
-use Smarty\Compile\ForeachTag;
-use Smarty_Internal_TemplateCompilerBase;
-
/**
* Smarty Internal Plugin Compile Break Class
*
@@ -48,12 +45,12 @@ class BreakTag extends Base {
* Compiles code for the {break} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null)
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null)
{
[$levels, $foreachLevels] = $this->checkLevels($args, $compiler);
$output = " true, 'foreach' => true, 'while' => true, 'section' => true];
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
diff --git a/src/Compile/Call.php b/src/Compile/Call.php
index 5fa15a56..0d10e8a2 100644
--- a/src/Compile/Call.php
+++ b/src/Compile/Call.php
@@ -50,7 +50,7 @@ class Call extends Base
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null)
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
diff --git a/src/Compile/Capture.php b/src/Compile/Capture.php
index 17fe547c..bcee2f48 100644
--- a/src/Compile/Capture.php
+++ b/src/Compile/Capture.php
@@ -2,8 +2,6 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
-
/**
* Smarty Internal Plugin Compile Capture Class
*
@@ -31,13 +29,13 @@ class Capture extends Base {
/**
* Compiles code for the {$smarty.capture.xxx}
*
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
public static function compileSpecialVariable(
- Smarty_Internal_TemplateCompilerBase $compiler,
+ \Smarty\Compiler\Template $compiler,
$parameter = null
) {
return '$_smarty_tpl->smarty->ext->_capture->getBuffer($_smarty_tpl' .
@@ -48,12 +46,12 @@ class Capture extends Base {
* Compiles code for the {capture} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
* @param null $parameter
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args, $parameter, 'capture');
$buffer = $_attr['name'] ?? "'default'";
diff --git a/src/Compile/CaptureClose.php b/src/Compile/CaptureClose.php
index c58bc456..f1dded01 100644
--- a/src/Compile/CaptureClose.php
+++ b/src/Compile/CaptureClose.php
@@ -10,7 +10,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Captureclose Class
@@ -24,12 +24,12 @@ class CaptureClose extends Base {
* Compiles code for the {/capture} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
* @param null $parameter
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args, $parameter, '/capture');
// must endblock be nocache?
diff --git a/src/Compile/Child.php b/src/Compile/Child.php
index 4dd47d89..03083e65 100644
--- a/src/Compile/Child.php
+++ b/src/Compile/Child.php
@@ -10,7 +10,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Child Class
@@ -45,13 +45,13 @@ class Child extends Base {
* Compiles code for the {child} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$tag = isset($parameter[0]) ? "'{$parameter[0]}'" : "'{{$this->tag}}'";
diff --git a/src/Compile/ConfigLoad.php b/src/Compile/ConfigLoad.php
index 61227b19..a98da80c 100644
--- a/src/Compile/ConfigLoad.php
+++ b/src/Compile/ConfigLoad.php
@@ -11,7 +11,7 @@
namespace Smarty\Compile;
use Smarty\Smarty;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Config Load Class
@@ -68,12 +68,12 @@ class ConfigLoad extends Base {
* Compiles code for the {config_load} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
diff --git a/src/Compile/Debug.php b/src/Compile/Debug.php
index d395d751..f0c1dee9 100644
--- a/src/Compile/Debug.php
+++ b/src/Compile/Debug.php
@@ -11,7 +11,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Debug Class
@@ -29,7 +29,7 @@ class Debug extends Base {
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes, may trigger errors
$this->getAttributes($compiler, $args);
diff --git a/src/Compile/ElseIfTag.php b/src/Compile/ElseIfTag.php
index c4938a8a..b038e6c2 100644
--- a/src/Compile/ElseIfTag.php
+++ b/src/Compile/ElseIfTag.php
@@ -2,7 +2,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile ElseIf Class
@@ -16,13 +16,13 @@ class ElseIfTag extends Base {
* Compiles code for the {elseif} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
[$nesting, $compiler->tag_nocache] = $this->closeTag($compiler, ['if', 'elseif']);
diff --git a/src/Compile/ElseTag.php b/src/Compile/ElseTag.php
index 58eb0e46..1da16733 100644
--- a/src/Compile/ElseTag.php
+++ b/src/Compile/ElseTag.php
@@ -2,7 +2,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Else Class
@@ -16,11 +16,11 @@ class ElseTag extends Base {
* Compiles code for the {else} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
[$nesting, $compiler->tag_nocache] = $this->closeTag($compiler, ['if', 'elseif']);
$this->openTag($compiler, 'else', [$nesting, $compiler->tag_nocache]);
return '';
diff --git a/src/Compile/EvalTag.php b/src/Compile/EvalTag.php
index a01947ce..916b6617 100644
--- a/src/Compile/EvalTag.php
+++ b/src/Compile/EvalTag.php
@@ -11,7 +11,7 @@
namespace Smarty\Compile;
use Smarty\Compile\Base;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Eval Class
@@ -53,7 +53,7 @@ class EvalTag extends Base {
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if (isset($_attr['assign'])) {
diff --git a/src/Compile/ExtendsTag.php b/src/Compile/ExtendsTag.php
index 1eb7c57f..5cd0a637 100644
--- a/src/Compile/ExtendsTag.php
+++ b/src/Compile/ExtendsTag.php
@@ -11,7 +11,7 @@
namespace Smarty\Compile;
use Smarty_Internal_Template;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile extend Class
@@ -49,13 +49,13 @@ class ExtendsTag extends Inheritance {
* Compiles code for the {extends} tag extends: resource
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
*
* @return string compiled code
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
@@ -96,13 +96,13 @@ class ExtendsTag extends Inheritance {
/**
* Add code for inheritance endChild() method to end of template
*
- * @param \Smarty_Internal_TemplateCompilerBase $compiler
+ * @param \Smarty\Compiler\Template $compiler
* @param null|string $template optional inheritance parent template
*
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
- private function compileEndChild(Smarty_Internal_TemplateCompilerBase $compiler, $template = null) {
+ private function compileEndChild(\Smarty\Compiler\Template $compiler, $template = null) {
$inlineUids = '';
if (isset($template) && $compiler->smarty->merge_compiled_includes) {
$code = $compiler->compileTag('include', [$template, ['scope' => 'parent']]);
@@ -122,13 +122,13 @@ class ExtendsTag extends Inheritance {
/**
* Add code for including subtemplate to end of template
*
- * @param \Smarty_Internal_TemplateCompilerBase $compiler
+ * @param \Smarty\Compiler\Template $compiler
* @param string $template subtemplate name
*
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
- private function compileInclude(Smarty_Internal_TemplateCompilerBase $compiler, $template) {
+ private function compileInclude(\Smarty\Compiler\Template $compiler, $template) {
$compiler->parser->template_postfix[] = new \Smarty\ParseTree\Tag(
$compiler->parser,
$compiler->compileTag(
diff --git a/src/Compile/ForClose.php b/src/Compile/ForClose.php
index aa5140f0..677731ec 100644
--- a/src/Compile/ForClose.php
+++ b/src/Compile/ForClose.php
@@ -10,7 +10,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Forclose Class
@@ -29,7 +29,7 @@ class ForClose extends Base {
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->loopNesting--;
// check and get attributes
$this->getAttributes($compiler, $args);
diff --git a/src/Compile/ForElse.php b/src/Compile/ForElse.php
index e8148a7a..134f275f 100644
--- a/src/Compile/ForElse.php
+++ b/src/Compile/ForElse.php
@@ -2,7 +2,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Forelse Class
@@ -21,7 +21,7 @@ class ForElse extends Base {
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$this->getAttributes($compiler, $args);
[$openTag, $nocache] = $this->closeTag($compiler, ['for']);
diff --git a/src/Compile/ForTag.php b/src/Compile/ForTag.php
index 5df805d5..6f0cd9d7 100644
--- a/src/Compile/ForTag.php
+++ b/src/Compile/ForTag.php
@@ -2,7 +2,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile For Class
@@ -28,7 +28,7 @@ class ForTag extends Base {
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->loopNesting++;
if ($parameter === 0) {
$this->required_attributes = ['start', 'to'];
diff --git a/src/Compile/ForeachClose.php b/src/Compile/ForeachClose.php
index 79cd78c3..b0e1c906 100644
--- a/src/Compile/ForeachClose.php
+++ b/src/Compile/ForeachClose.php
@@ -11,7 +11,7 @@
namespace Smarty\Compile;
use Smarty_Internal_Compile_Foreach;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Foreachclose Class
@@ -25,12 +25,12 @@ class ForeachClose extends Base {
* Compiles code for the {/foreach} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->loopNesting--;
// must endblock be nocache?
if ($compiler->nocache) {
diff --git a/src/Compile/ForeachElse.php b/src/Compile/ForeachElse.php
index 53a02b1d..7ef3916f 100644
--- a/src/Compile/ForeachElse.php
+++ b/src/Compile/ForeachElse.php
@@ -2,7 +2,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Foreachelse Class
@@ -16,11 +16,11 @@ class ForeachElse extends Base {
* Compiles code for the {foreachelse} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$this->getAttributes($compiler, $args);
[$openTag, $nocache, $local, $itemVar, $restore] = $this->closeTag($compiler, ['foreach']);
diff --git a/src/Compile/ForeachSection.php b/src/Compile/ForeachSection.php
index d8b52856..8c8e8cc9 100644
--- a/src/Compile/ForeachSection.php
+++ b/src/Compile/ForeachSection.php
@@ -10,7 +10,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile ForeachSection Class
@@ -78,11 +78,11 @@ abstract class ForeachSection extends Base {
* Scan sources for used tag attributes
*
* @param array $attributes
- * @param \Smarty_Internal_TemplateCompilerBase $compiler
+ * @param \Smarty\Compiler\Template $compiler
*
* @throws \SmartyException
*/
- protected function scanForProperties($attributes, Smarty_Internal_TemplateCompilerBase $compiler) {
+ protected function scanForProperties($attributes, \Smarty\Compiler\Template $compiler) {
$this->propertyPreg = '~(';
$this->startOffset = 1;
$this->resultOffsets = [];
@@ -151,20 +151,20 @@ abstract class ForeachSection extends Base {
/**
* Find matches in template source
*
- * @param \Smarty_Internal_TemplateCompilerBase $compiler
+ * @param \Smarty\Compiler\Template $compiler
*/
- private function matchTemplateSource(Smarty_Internal_TemplateCompilerBase $compiler) {
+ private function matchTemplateSource(\Smarty\Compiler\Template $compiler) {
$this->matchProperty($compiler->parser->lex->data);
}
/**
* Find matches in all parent template source
*
- * @param \Smarty_Internal_TemplateCompilerBase $compiler
+ * @param \Smarty\Compiler\Template $compiler
*
* @throws \SmartyException
*/
- private function matchParentTemplateSource(Smarty_Internal_TemplateCompilerBase $compiler) {
+ private function matchParentTemplateSource(\Smarty\Compiler\Template $compiler) {
// search parent compiler template source
$nextCompiler = $compiler;
while ($nextCompiler !== $nextCompiler->parent_compiler) {
@@ -190,13 +190,13 @@ abstract class ForeachSection extends Base {
/**
* Compiles code for the {$smarty.foreach.xxx} or {$smarty.section.xxx}tag
*
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
- public function compileSpecialVariable(Smarty_Internal_TemplateCompilerBase $compiler, $parameter) {
+ public function compileSpecialVariable(\Smarty\Compiler\Template $compiler, $parameter) {
$tag = smarty_strtolower_ascii(trim($parameter[0], '"\''));
$name = isset($parameter[1]) ? $compiler->getId($parameter[1]) : false;
if (!$name) {
diff --git a/src/Compile/ForeachTag.php b/src/Compile/ForeachTag.php
index a2949ec0..f1f99112 100644
--- a/src/Compile/ForeachTag.php
+++ b/src/Compile/ForeachTag.php
@@ -2,7 +2,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Foreach Class
@@ -75,13 +75,13 @@ class ForeachTag extends ForeachSection {
* Compiles code for the {foreach} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
*
* @return string compiled code
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->loopNesting++;
// init
$this->isNamed = false;
diff --git a/src/Compile/FunctionClose.php b/src/Compile/FunctionClose.php
index 1ce3d356..add2482d 100644
--- a/src/Compile/FunctionClose.php
+++ b/src/Compile/FunctionClose.php
@@ -10,7 +10,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Functionclose Class
@@ -31,11 +31,11 @@ class FunctionClose extends Base {
* Compiles code for the {/function} tag
*
* @param array $args array with attributes from parser
- * @param object|\Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param object|\Smarty\Compiler\Template $compiler compiler object
*
* @return bool true
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$this->compiler = $compiler;
$saved_data = $this->closeTag($compiler, ['function']);
$_attr = $saved_data[0];
diff --git a/src/Compile/FunctionTag.php b/src/Compile/FunctionTag.php
index 85b54fdb..ce8df2af 100644
--- a/src/Compile/FunctionTag.php
+++ b/src/Compile/FunctionTag.php
@@ -2,7 +2,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Function Class
@@ -40,12 +40,12 @@ class FunctionTag extends Base {
* Compiles code for the {function} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
*
* @return bool true
* @throws \SmartyCompilerException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
diff --git a/src/Compile/IfClose.php b/src/Compile/IfClose.php
index d0804b12..a6423b3b 100644
--- a/src/Compile/IfClose.php
+++ b/src/Compile/IfClose.php
@@ -12,7 +12,7 @@ namespace Smarty\Compile;
use Smarty\Compile\Assign;
use Smarty\Compile\Base;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Ifclose Class
@@ -26,11 +26,11 @@ class IfClose extends Base {
* Compiles code for the {/if} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// must endblock be nocache?
if ($compiler->nocache) {
$compiler->tag_nocache = true;
diff --git a/src/Compile/IfTag.php b/src/Compile/IfTag.php
index bdb54a0a..f1f84335 100644
--- a/src/Compile/IfTag.php
+++ b/src/Compile/IfTag.php
@@ -2,7 +2,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile If Class
@@ -16,13 +16,13 @@ class IfTag extends Base {
* Compiles code for the {if} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$this->openTag($compiler, 'if', [1, $compiler->nocache]);
diff --git a/src/Compile/IncludeTag.php b/src/Compile/IncludeTag.php
index 26542721..d26c5e86 100644
--- a/src/Compile/IncludeTag.php
+++ b/src/Compile/IncludeTag.php
@@ -10,10 +10,10 @@
namespace Smarty\Compile;
+use Smarty\Compiler\Template;
use Smarty\Smarty;
-use Smarty_Internal_SmartyTemplateCompiler;
use Smarty_Internal_Template;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
use Smarty_Resource;
use Smarty_Template_Compiled;
@@ -77,14 +77,14 @@ class IncludeTag extends Base {
* Compiles code for the {include} tag
*
* @param array $args array with attributes from parser
- * @param Smarty_Internal_SmartyTemplateCompiler $compiler compiler object
+ * @param Template $compiler compiler object
*
* @return string
* @throws \Exception
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$uid = $t_hash = null;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
@@ -288,7 +288,7 @@ class IncludeTag extends Base {
/**
* Compile inline sub template
*
- * @param \Smarty_Internal_SmartyTemplateCompiler $compiler
+ * @param \Smarty\Compiler\Template $compiler
* @param \Smarty_Internal_Template $tpl
* @param string $t_hash
*
@@ -297,9 +297,9 @@ class IncludeTag extends Base {
* @throws \SmartyException
*/
private function compileInlineTemplate(
- Smarty_Internal_SmartyTemplateCompiler $compiler,
- Smarty_Internal_Template $tpl,
- $t_hash
+ Template $compiler,
+ Smarty_Internal_Template $tpl,
+ $t_hash
) {
$uid = $tpl->source->type . $tpl->source->uid;
if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) {
diff --git a/src/Compile/Inheritance.php b/src/Compile/Inheritance.php
index 017ba306..2523a180 100644
--- a/src/Compile/Inheritance.php
+++ b/src/Compile/Inheritance.php
@@ -22,10 +22,10 @@ abstract class Inheritance extends \Smarty\Compile\Base
/**
* Compile inheritance initialization code as prefix
*
- * @param \Smarty_Internal_TemplateCompilerBase $compiler
+ * @param \Smarty\Compiler\Template $compiler
* @param bool|false $initChildSequence if true force child template
*/
- public static function postCompile(\Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false)
+ public static function postCompile(\Smarty\Compiler\Template $compiler, $initChildSequence = false)
{
$compiler->prefixCompiledCode .= "_loadInheritance();\n\$_smarty_tpl->inheritance->init(\$_smarty_tpl, " .
var_export($initChildSequence, true) . ");\n?>\n";
@@ -34,10 +34,10 @@ abstract class Inheritance extends \Smarty\Compile\Base
/**
* Register post compile callback to compile inheritance initialization code
*
- * @param \Smarty_Internal_TemplateCompilerBase $compiler
+ * @param \Smarty\Compiler\Template $compiler
* @param bool|false $initChildSequence if true force child template
*/
- public function registerInit(\Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false)
+ public function registerInit(\Smarty\Compiler\Template $compiler, $initChildSequence = false)
{
if ($initChildSequence || !isset($compiler->_cache[ 'inheritanceInit' ])) {
$compiler->registerPostCompileCallback(
diff --git a/src/Compile/Insert.php b/src/Compile/Insert.php
index 6345ec85..5a36eb75 100644
--- a/src/Compile/Insert.php
+++ b/src/Compile/Insert.php
@@ -11,7 +11,7 @@
namespace Smarty\Compile;
use Smarty\Variable;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Insert Class
@@ -49,13 +49,13 @@ class Insert extends Base {
* Compiles code for the {insert} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
*
* @return string compiled code
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$nocacheParam = $compiler->template->caching && ($compiler->tag_nocache || $compiler->nocache);
diff --git a/src/Compile/Ldelim.php b/src/Compile/Ldelim.php
index e015d1a0..13deb4be 100644
--- a/src/Compile/Ldelim.php
+++ b/src/Compile/Ldelim.php
@@ -10,7 +10,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Ldelim Class
@@ -25,12 +25,12 @@ class Ldelim extends Base {
* This tag does output the left delimiter
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$_attr = $this->getAttributes($compiler, $args);
if ($_attr['nocache'] === true) {
$compiler->trigger_template_error('nocache option not allowed', null, true);
diff --git a/src/Compile/MakeNocache.php b/src/Compile/MakeNocache.php
index c1844c8a..47f5d3b8 100644
--- a/src/Compile/MakeNocache.php
+++ b/src/Compile/MakeNocache.php
@@ -11,7 +11,7 @@
namespace Smarty\Compile;
use Smarty\Compile\Base;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Make_Nocache Class
@@ -47,11 +47,11 @@ class MakeNocache extends Base {
* Compiles code for the {make_nocache} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
if ($compiler->template->caching) {
diff --git a/src/Compile/Nocache.php b/src/Compile/Nocache.php
index 7cc14244..e27ba7c3 100644
--- a/src/Compile/Nocache.php
+++ b/src/Compile/Nocache.php
@@ -2,7 +2,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Nocache Class
@@ -17,18 +17,18 @@ class Nocache extends Base {
*
* @var array
*/
- public $option_flags = [];
+ protected $option_flags = [];
/**
* Compiles code for the {nocache} tag
* This tag does not generate compiled output. It only sets a compiler flag.
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
*
* @return bool
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$this->getAttributes($compiler, $args);
$this->openTag($compiler, 'nocache', [$compiler->nocache]);
// enter nocache mode
diff --git a/src/Compile/NocacheClose.php b/src/Compile/NocacheClose.php
index 4d7deeef..20f4d97d 100644
--- a/src/Compile/NocacheClose.php
+++ b/src/Compile/NocacheClose.php
@@ -10,7 +10,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Nocacheclose Class
@@ -25,11 +25,11 @@ class NocacheClose extends Base {
* This tag does not generate compiled output. It only sets a compiler flag.
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
*
* @return bool
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$_attr = $this->getAttributes($compiler, $args);
// leave nocache mode
[$compiler->nocache] = $this->closeTag($compiler, ['nocache']);
diff --git a/src/Compile/PrivateBlockPlugin.php b/src/Compile/PrivateBlockPlugin.php
index 53529bdb..bbb7cd82 100644
--- a/src/Compile/PrivateBlockPlugin.php
+++ b/src/Compile/PrivateBlockPlugin.php
@@ -10,7 +10,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Block Plugin Class
@@ -39,7 +39,7 @@ class PrivateBlockPlugin extends Base {
* Compiles code for the execution of block plugin
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of block plugin
* @param string $function PHP function name
@@ -48,7 +48,7 @@ class PrivateBlockPlugin extends Base {
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
if (!isset($tag[5]) || substr($tag, -5) !== 'close') {
// opening tag of block plugin
// check and get attributes
@@ -104,14 +104,14 @@ class PrivateBlockPlugin extends Base {
/**
* Setup callback and parameter array
*
- * @param \Smarty_Internal_TemplateCompilerBase $compiler
+ * @param \Smarty\Compiler\Template $compiler
* @param array $_attr attributes
* @param string $tag
* @param string $function
*
* @return array
*/
- protected function setup(Smarty_Internal_TemplateCompilerBase $compiler, $_attr, $tag, $function) {
+ protected function setup(\Smarty\Compiler\Template $compiler, $_attr, $tag, $function) {
$_paramsArray = [];
foreach ($_attr as $_key => $_value) {
if (is_int($_key)) {
diff --git a/src/Compile/PrivateFunctionPlugin.php b/src/Compile/PrivateFunctionPlugin.php
index 9fdbee3b..0f56ef7a 100644
--- a/src/Compile/PrivateFunctionPlugin.php
+++ b/src/Compile/PrivateFunctionPlugin.php
@@ -11,7 +11,7 @@
namespace Smarty\Compile;
use Smarty\Compile\Base;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Function Plugin Class
@@ -41,7 +41,7 @@ class PrivateFunctionPlugin extends Base {
* Compiles code for the execution of function plugin
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of function plugin
* @param string $function PHP function name
@@ -50,7 +50,7 @@ class PrivateFunctionPlugin extends Base {
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
unset($_attr['nocache']);
diff --git a/src/Compile/PrivateModifier.php b/src/Compile/PrivateModifier.php
index 05a5995e..175f38f0 100644
--- a/src/Compile/PrivateModifier.php
+++ b/src/Compile/PrivateModifier.php
@@ -10,7 +10,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Modifier Class
@@ -24,14 +24,14 @@ class PrivateModifier extends Base {
* Compiles code for modifier execution
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$output = $parameter['value'];
diff --git a/src/Compile/PrivateObjectBlockFunction.php b/src/Compile/PrivateObjectBlockFunction.php
index 4945cb76..71f54453 100644
--- a/src/Compile/PrivateObjectBlockFunction.php
+++ b/src/Compile/PrivateObjectBlockFunction.php
@@ -10,8 +10,7 @@
namespace Smarty\Compile;
-use Smarty\Compile\PrivateBlockPlugin;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Object Block Function Class
@@ -24,14 +23,14 @@ class PrivateObjectBlockFunction extends PrivateBlockPlugin {
/**
* Setup callback and parameter array
*
- * @param \Smarty_Internal_TemplateCompilerBase $compiler
+ * @param Template $compiler
* @param array $_attr attributes
* @param string $tag
* @param string $function
*
* @return array
*/
- protected function setup(Smarty_Internal_TemplateCompilerBase $compiler, $_attr, $tag, $function) {
+ protected function setup(Template $compiler, $_attr, $tag, $function) {
$_paramsArray = [];
foreach ($_attr as $_key => $_value) {
if (is_int($_key)) {
diff --git a/src/Compile/PrivateObjectFunction.php b/src/Compile/PrivateObjectFunction.php
index ca82b3a9..4798f892 100644
--- a/src/Compile/PrivateObjectFunction.php
+++ b/src/Compile/PrivateObjectFunction.php
@@ -10,7 +10,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Object Function Class
@@ -32,7 +32,7 @@ class PrivateObjectFunction extends Base {
* Compiles code for the execution of function plugin
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of function
* @param string $function name of method to call
@@ -41,7 +41,7 @@ class PrivateObjectFunction extends Base {
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
unset($_attr['nocache']);
diff --git a/src/Compile/PrivatePrintExpression.php b/src/Compile/PrivatePrintExpression.php
index 49aa13e8..18c85273 100644
--- a/src/Compile/PrivatePrintExpression.php
+++ b/src/Compile/PrivatePrintExpression.php
@@ -11,7 +11,7 @@
namespace Smarty\Compile;
use Smarty\Compile\Base;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Print Expression Class
@@ -35,19 +35,19 @@ class PrivatePrintExpression extends Base {
* @var array
* @see Base
*/
- public $option_flags = ['nocache', 'nofilter'];
+ protected $option_flags = ['nocache', 'nofilter'];
/**
* Compiles code for generating output from any expression
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string
* @throws \SmartyException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$output = $parameter['value'];
@@ -133,14 +133,14 @@ class PrivatePrintExpression extends Base {
}
/**
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
* @param string $name name of variable filter
* @param string $output embedded output
*
* @return string
* @throws \SmartyException
*/
- private function compile_variable_filter(Smarty_Internal_TemplateCompilerBase $compiler, $name, $output) {
+ private function compile_variable_filter(\Smarty\Compiler\Template $compiler, $name, $output) {
$function = $compiler->getPlugin($name, 'variablefilter');
if ($function) {
return "{$function}({$output},\$_smarty_tpl)";
diff --git a/src/Compile/PrivateRegisteredFunction.php b/src/Compile/PrivateRegisteredFunction.php
index 06c50ed7..f62b7f77 100644
--- a/src/Compile/PrivateRegisteredFunction.php
+++ b/src/Compile/PrivateRegisteredFunction.php
@@ -10,7 +10,8 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
+use Smarty\Smarty;
/**
* Smarty Internal Plugin Compile Registered Function Class
@@ -32,7 +33,7 @@ class PrivateRegisteredFunction extends Base {
* Compiles code for the execution of a registered function
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param Template $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of function
*
@@ -40,15 +41,15 @@ class PrivateRegisteredFunction extends Base {
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
unset($_attr['nocache']);
- if (isset($compiler->smarty->registered_plugins[\Smarty\Smarty::PLUGIN_FUNCTION][$tag])) {
- $tag_info = $compiler->smarty->registered_plugins[\Smarty\Smarty::PLUGIN_FUNCTION][$tag];
+ if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag])) {
+ $tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION][$tag];
$is_registered = true;
} else {
- $tag_info = $compiler->default_handler_plugins[\Smarty\Smarty::PLUGIN_FUNCTION][$tag];
+ $tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_FUNCTION][$tag];
$is_registered = false;
}
// not cacheable?
diff --git a/src/Compile/PrivateSpecialVariable.php b/src/Compile/PrivateSpecialVariable.php
index 7eea562d..9b7657f1 100644
--- a/src/Compile/PrivateSpecialVariable.php
+++ b/src/Compile/PrivateSpecialVariable.php
@@ -14,7 +14,7 @@ use Smarty\Compile\Capture;
use Smarty\Compile\Base;
use Smarty\Compile\ForeachTag;
use Smarty\Compile\Section;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile special Smarty Variable Class
@@ -28,13 +28,13 @@ class PrivateSpecialVariable extends Base {
* Compiles code for the special $smarty variables
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
* @param $parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2));
$variable = smarty_strtolower_ascii($compiler->getId($_index[0]));
if ($variable === false) {
diff --git a/src/Compile/Rdelim.php b/src/Compile/Rdelim.php
index 765370a9..ce41c054 100644
--- a/src/Compile/Rdelim.php
+++ b/src/Compile/Rdelim.php
@@ -10,7 +10,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Rdelim Class
@@ -25,12 +25,12 @@ class Rdelim extends Ldelim {
* This tag does output the right delimiter.
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
parent::compile($args, $compiler);
return $compiler->smarty->right_delimiter;
}
diff --git a/src/Compile/Section.php b/src/Compile/Section.php
index cab698b5..19bc89e4 100644
--- a/src/Compile/Section.php
+++ b/src/Compile/Section.php
@@ -2,7 +2,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Section Class
@@ -78,13 +78,13 @@ class Section extends ForeachSection {
* Compiles code for the {section} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
*
* @return string compiled code
* @throws \SmartyCompilerException
* @throws \SmartyException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->loopNesting++;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
diff --git a/src/Compile/SectionClose.php b/src/Compile/SectionClose.php
index e855f172..080cc2b2 100644
--- a/src/Compile/SectionClose.php
+++ b/src/Compile/SectionClose.php
@@ -12,7 +12,7 @@ namespace Smarty\Compile;
use Smarty\Compile\ForeachSection;
use Smarty\Compile\Base;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Sectionclose Class
@@ -26,11 +26,11 @@ class SectionClose extends Base {
* Compiles code for the {/section} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->loopNesting--;
// must endblock be nocache?
if ($compiler->nocache) {
diff --git a/src/Compile/SectionElse.php b/src/Compile/SectionElse.php
index 67df3abc..f96f537b 100644
--- a/src/Compile/SectionElse.php
+++ b/src/Compile/SectionElse.php
@@ -2,7 +2,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Sectionelse Class
@@ -16,11 +16,11 @@ class SectionElse extends Base {
* Compiles code for the {sectionelse} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$this->getAttributes($compiler, $args);
[$openTag, $nocache, $local, $sectionVar] = $this->closeTag($compiler, ['section']);
diff --git a/src/Compile/Setfilter.php b/src/Compile/Setfilter.php
index 3dc8e321..352d77ee 100644
--- a/src/Compile/Setfilter.php
+++ b/src/Compile/Setfilter.php
@@ -2,7 +2,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Setfilter Class
@@ -16,12 +16,12 @@ class Setfilter extends Base {
* Compiles code for setfilter tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->variable_filter_stack[] = $compiler->variable_filters;
$compiler->variable_filters = $parameter['modifier_list'];
// this tag does not return compiled code
diff --git a/src/Compile/SetfilterClose.php b/src/Compile/SetfilterClose.php
index 92acdeb2..0aa01d42 100644
--- a/src/Compile/SetfilterClose.php
+++ b/src/Compile/SetfilterClose.php
@@ -10,7 +10,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Setfilterclose Class
@@ -25,11 +25,11 @@ class SetfilterClose extends Base {
* This tag does not generate compiled output. It resets variable filter.
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$this->getAttributes($compiler, $args);
// reset variable filter to previous state
if (count($compiler->variable_filter_stack)) {
diff --git a/src/Compile/WhileClose.php b/src/Compile/WhileClose.php
index 3e7d63b4..cec9e358 100644
--- a/src/Compile/WhileClose.php
+++ b/src/Compile/WhileClose.php
@@ -10,7 +10,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Whileclose Class
@@ -24,11 +24,11 @@ class WhileClose extends Base {
* Compiles code for the {/while} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
*
* @return string compiled code
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->loopNesting--;
// must endblock be nocache?
if ($compiler->nocache) {
diff --git a/src/Compile/WhileTag.php b/src/Compile/WhileTag.php
index ce6c6aa5..3136b718 100644
--- a/src/Compile/WhileTag.php
+++ b/src/Compile/WhileTag.php
@@ -2,7 +2,7 @@
namespace Smarty\Compile;
-use Smarty_Internal_TemplateCompilerBase;
+use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile While Class
@@ -16,13 +16,13 @@ class WhileTag extends Base {
* Compiles code for the {while} tag
*
* @param array $args array with attributes from parser
- * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
+ * @param \Smarty\Compiler\Template $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
- public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) {
+ public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
$compiler->loopNesting++;
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
diff --git a/src/Compiler/ConfigFile.php b/src/Compiler/ConfigFile.php
new file mode 100644
index 00000000..cd8fc484
--- /dev/null
+++ b/src/Compiler/ConfigFile.php
@@ -0,0 +1,208 @@
+smarty = $smarty;
+ // get required plugins
+ $this->lexer_class = $lexer_class;
+ $this->parser_class = $parser_class;
+ $this->smarty = $smarty;
+ $this->config_data['sections'] = [];
+ $this->config_data['vars'] = [];
+ }
+
+ /**
+ * Method to compile Smarty config source.
+ *
+ * @param Smarty_Internal_Template $template
+ *
+ * @return bool true if compiling succeeded, false if it failed
+ * @throws \SmartyException
+ */
+ public function compileTemplate(Smarty_Internal_Template $template) {
+ $this->template = $template;
+ $this->template->compiled->file_dependency[$this->template->source->uid] =
+ [
+ $this->template->source->filepath,
+ $this->template->source->getTimeStamp(),
+ $this->template->source->type,
+ ];
+ if ($this->smarty->debugging) {
+ if (!isset($this->smarty->_debug)) {
+ $this->smarty->_debug = new \Smarty\Debug();
+ }
+ $this->smarty->_debug->start_compile($this->template);
+ }
+ // init the lexer/parser to compile the config file
+ /* @var Smarty_Internal_ConfigFileLexer $this- >lex */
+ $this->lex = new $this->lexer_class(
+ str_replace(
+ [
+ "\r\n",
+ "\r",
+ ],
+ "\n",
+ $template->source->getContent()
+ ) . "\n",
+ $this
+ );
+ /* @var Smarty_Internal_ConfigFileParser $this- >parser */
+ $this->parser = new $this->parser_class($this->lex, $this);
+ if (function_exists('mb_internal_encoding')
+ && function_exists('ini_get')
+ && ((int)ini_get('mbstring.func_overload')) & 2
+ ) {
+ $mbEncoding = mb_internal_encoding();
+ mb_internal_encoding('ASCII');
+ } else {
+ $mbEncoding = null;
+ }
+ if ($this->smarty->_parserdebug) {
+ $this->parser->PrintTrace();
+ }
+ // get tokens from lexer and parse them
+ while ($this->lex->yylex()) {
+ if ($this->smarty->_parserdebug) {
+ echo "
Parsing {$this->parser->yyTokenName[$this->lex->token]} Token {$this->lex->value} Line {$this->lex->line} \n";
+ }
+ $this->parser->doParse($this->lex->token, $this->lex->value);
+ }
+ // finish parsing process
+ $this->parser->doParse(0, 0);
+ if ($mbEncoding) {
+ mb_internal_encoding($mbEncoding);
+ }
+ if ($this->smarty->debugging) {
+ $this->smarty->_debug->end_compile($this->template);
+ }
+ // template header code
+ $template_header = sprintf(
+ "\n",
+ \Smarty\Smarty::SMARTY_VERSION,
+ date("Y-m-d H:i:s"),
+ str_replace('*/', '* /', $this->template->source->filepath)
+ );
+ $code = 'smarty->ext->configLoad->_loadConfigVars($_smarty_tpl, ' .
+ var_export($this->config_data, true) . '); ?>';
+ return $template_header . $this->createCodeFrame($code);
+ }
+
+ /**
+ * display compiler error messages without dying
+ * If parameter $args is empty it is a parser detected syntax error.
+ * 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
+ *
+ * @throws SmartyCompilerException
+ */
+ public function trigger_config_file_error($args = null) {
+ // get config source line which has error
+ $line = $this->lex->line;
+ if (isset($args)) {
+ // $line--;
+ }
+ $match = preg_split("/\n/", $this->lex->data);
+ $error_text =
+ "Syntax error in config file '{$this->template->source->filepath}' on line {$line} '{$match[$line - 1]}' ";
+ if (isset($args)) {
+ // individual error message
+ $error_text .= $args;
+ } else {
+ // expected token from parser
+ foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) {
+ $exp_token = $this->parser->yyTokenName[$token];
+ if (isset($this->lex->smarty_token_names[$exp_token])) {
+ // token type from lexer
+ $expect[] = '"' . $this->lex->smarty_token_names[$exp_token] . '"';
+ } else {
+ // otherwise internal token name
+ $expect[] = $this->parser->yyTokenName[$token];
+ }
+ }
+ // output parser error message
+ $error_text .= ' - Unexpected "' . $this->lex->value . '", expected one of: ' . implode(' , ', $expect);
+ }
+ throw new SmartyCompilerException($error_text);
+ }
+}
diff --git a/src/Compiler/Template.php b/src/Compiler/Template.php
new file mode 100644
index 00000000..a3558cc1
--- /dev/null
+++ b/src/Compiler/Template.php
@@ -0,0 +1,1744 @@
+smarty = $smarty;
+ $this->nocache_hash = str_replace(
+ [
+ '.',
+ ',',
+ ],
+ '_',
+ uniqid(mt_rand(), true)
+ );
+ // get required plugins
+ $this->lexer_class = $lexer_class;
+ $this->parser_class = $parser_class;
+ }
+
+ /**
+ * 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 null|\Smarty\Compiler\Template $parent_compiler
+ *
+ * @return bool true if compiling succeeded, false if it failed
+ * @throws \Exception
+ */
+ public function compileTemplate(
+ Smarty_Internal_Template $template,
+ $nocache = null,
+ \Smarty\Compiler\Template $parent_compiler = null
+ ) {
+ // get code frame of compiled template
+ $_compiled_code = $template->createCodeFrame(
+ $this->compileTemplateSource(
+ $template,
+ $nocache,
+ $parent_compiler
+ ),
+ $this->postFilter($this->blockOrFunctionCode) .
+ join('', $this->mergedSubTemplatesCode),
+ false,
+ $this
+ );
+ return $_compiled_code;
+ }
+
+ /**
+ * Compile template source and run optional post filter
+ *
+ * @param \Smarty_Internal_Template $template
+ * @param null|bool $nocache flag if template must be compiled in nocache mode
+ * @param \Smarty\Compiler\Template $parent_compiler
+ *
+ * @return string
+ * @throws \Exception
+ */
+ public function compileTemplateSource(
+ Smarty_Internal_Template $template,
+ $nocache = null,
+ \Smarty\Compiler\Template $parent_compiler = null
+ ) {
+ try {
+ // save template object in compiler class
+ $this->template = $template;
+ if ($this->smarty->debugging) {
+ if (!isset($this->smarty->_debug)) {
+ $this->smarty->_debug = new \Smarty\Debug();
+ }
+ $this->smarty->_debug->start_compile($this->template);
+ }
+ $this->parent_compiler = $parent_compiler ? $parent_compiler : $this;
+ $nocache = isset($nocache) ? $nocache : false;
+ if (empty($template->compiled->nocache_hash)) {
+ $template->compiled->nocache_hash = $this->nocache_hash;
+ } else {
+ $this->nocache_hash = $template->compiled->nocache_hash;
+ }
+ $this->caching = $template->caching;
+ // flag for nocache sections
+ $this->nocache = $nocache;
+ $this->tag_nocache = false;
+ // reset has nocache code flag
+ $this->template->compiled->has_nocache_code = false;
+ $this->has_variable_string = false;
+ $this->prefix_code = [];
+ // 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] =
+ [
+ $this->template->source->filepath,
+ $this->template->source->getTimeStamp(),
+ $this->template->source->type,
+ ];
+ }
+ $this->smarty->_current_file = $this->template->source->filepath;
+ // get template source
+ if (!empty($this->template->source->components)) {
+ // we have array of inheritance templates by extends: resource
+ // generate corresponding source code sequence
+ $_content =
+ ExtendsTag::extendsSourceArrayCode($this->template);
+ } else {
+ // get template source
+ $_content = $this->template->source->getContent();
+ }
+ $_compiled_code = $this->postFilter($this->doCompile($this->preFilter($_content), true));
+ } catch (Exception $e) {
+ if ($this->smarty->debugging) {
+ $this->smarty->_debug->end_compile($this->template);
+ }
+ $this->_tag_stack = [];
+ // free memory
+ $this->parent_compiler = null;
+ $this->template = null;
+ $this->parser = null;
+ throw $e;
+ }
+ if ($this->smarty->debugging) {
+ $this->smarty->_debug->end_compile($this->template);
+ }
+ $this->parent_compiler = null;
+ $this->parser = null;
+ return $_compiled_code;
+ }
+
+ /**
+ * Optionally process compiled code by post filter
+ *
+ * @param string $code compiled code
+ *
+ * @return string
+ * @throws \SmartyException
+ */
+ public function postFilter($code) {
+ // run post filter if on code
+ if (!empty($code) && isset($this->smarty->registered_filters['post'])) {
+ return $this->smarty->ext->_filterHandler->runFilter('post', $code, $this->template);
+ } else {
+ return $code;
+ }
+ }
+
+ /**
+ * Run optional prefilter
+ *
+ * @param string $_content template source
+ *
+ * @return string
+ * @throws \SmartyException
+ */
+ public function preFilter($_content) {
+ // run pre filter if required
+ if ($_content !== '' && isset($this->smarty->registered_filters['pre'])) {
+ return $this->smarty->ext->_filterHandler->runFilter('pre', $_content, $this->template);
+ } else {
+ return $_content;
+ }
+ }
+
+ /**
+ * Compile Tag
+ * This is a call back from the lexer/parser
+ *
+ * Save current prefix code
+ * Compile tag
+ * 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
+ *
+ * @return string compiled code
+ * @throws SmartyException
+ * @throws SmartyCompilerException
+ */
+ public function compileTag($tag, $args, $parameter = []) {
+ $this->prefixCodeStack[] = $this->prefix_code;
+ $this->prefix_code = [];
+ $result = $this->compileTag2($tag, $args, $parameter);
+ $this->prefix_code = array_merge($this->prefix_code, array_pop($this->prefixCodeStack));
+ return $result;
+ }
+
+ /**
+ * compile variable
+ *
+ * @param string $variable
+ *
+ * @return string
+ */
+ public function compileVariable($variable) {
+ if (!strpos($variable, '(')) {
+ // 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;
+ // todo $this->template->compiled->properties['variables'][$var] = $this->tag_nocache | $this->nocache;
+ }
+ return '$_smarty_tpl->tpl_vars[' . $variable . ']->value';
+ }
+
+ /**
+ * compile config variable
+ *
+ * @param string $variable
+ *
+ * @return string
+ */
+ public function compileConfigVariable($variable) {
+ // return '$_smarty_tpl->config_vars[' . $variable . ']';
+ return '$_smarty_tpl->smarty->ext->configLoad->_getConfigVariable($_smarty_tpl, ' . $variable . ')';
+ }
+
+ /**
+ * compile PHP function call
+ *
+ * @param string $name
+ * @param array $parameter
+ *
+ * @return string
+ * @throws \SmartyCompilerException
+ */
+ 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)
+ ) {
+ $func_name = smarty_strtolower_ascii($name);
+
+ if ($func_name === 'isset') {
+ if (count($parameter) === 0) {
+ $this->trigger_template_error('Illegal number of parameter in "isset()"');
+ }
+
+ $pa = [];
+ foreach ($parameter as $p) {
+ $pa[] = $this->syntaxMatchesVariable($p) ? 'isset(' . $p . ')' : '(' . $p . ' !== null )';
+ }
+ return '(' . implode(' && ', $pa) . ')';
+
+ } elseif (in_array(
+ $func_name,
+ [
+ 'empty',
+ 'reset',
+ 'current',
+ 'end',
+ 'prev',
+ 'next',
+ ]
+ )
+ ) {
+ if (count($parameter) !== 1) {
+ $this->trigger_template_error("Illegal number of parameter in '{$func_name()}'");
+ }
+ if ($func_name === 'empty') {
+ return $func_name . '(' .
+ str_replace("')->value", "',null,true,false)->value", $parameter[0]) . ')';
+ } else {
+ return $func_name . '(' . $parameter[0] . ')';
+ }
+ } else {
+ return $name . '(' . implode(',', $parameter) . ')';
+ }
+ } else {
+ $this->trigger_template_error("unknown function '{$name}'");
+ }
+ }
+ }
+
+ /**
+ * Determines whether the passed string represents a valid (PHP) variable.
+ * This is important, because `isset()` only works on variables and `empty()` can only be passed
+ * a variable prior to php5.5
+ *
+ * @param $string
+ *
+ * @return bool
+ */
+ private function syntaxMatchesVariable($string) {
+ static $regex_pattern = '/^\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*((->)[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*|\[.*]*\])*$/';
+ return 1 === preg_match($regex_pattern, trim($string));
+ }
+
+ /**
+ * This method is called from parser to process a text content section if strip is enabled
+ * - remove text from inheritance child templates as they may generate output
+ *
+ * @param string $text
+ *
+ * @return string
+ */
+ public function processText($text) {
+
+ if (strpos($text, '<') === false) {
+ return preg_replace($this->stripRegEx, '', $text);
+ }
+
+ $store = [];
+ $_store = 0;
+
+ // capture html elements not to be messed with
+ $_offset = 0;
+ if (preg_match_all(
+ '#(]*>)|(]*>)|(
]*>.*?]*>)#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++; + } + } + $expressions = [// replace multiple spaces between tags by a single space + '#(:SMARTY@!@|>)[\040\011]+(?=@!@SMARTY:|<)#s' => '\1 \2', + // remove newline between tags + '#(:SMARTY@!@|>)[\040\011]*[\n]\s*(?=@!@SMARTY:|<)#s' => '\1\2', + // remove multiple spaces between attributes (but not in attribute values!) + '#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5', + '#>[\040\011]+$#Ss' => '> ', + '#>[\040\011]*[\n]\s*$#Ss' => '>', + $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 + ) + ) { + 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++; + } + } + return $text; + } + + /** + * lazy loads internal compile plugin for tag and calls the compile method + * compile objects cached for reuse. + * 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 + * + * @return bool|string compiled code or false + * @throws \SmartyCompilerException + */ + private function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null) { + /* @var Base $tagCompiler */ + $tagCompiler = $this->getTagCompiler($tag); + // compile this tag + return $tagCompiler === false ? false : $tagCompiler->compile($args, $this, $param1, $param2, $param3); + } + + /** + * lazy loads internal compile plugin for tag compile objects cached for reuse. + * + * class name format: \Smarty\Compile\TagName + * + * @param string $tag tag name + * + * @return bool|Base tag compiler object or false if not found or untrusted by security policy + */ + public function getTagCompiler($tag) { + + if (isset($this->smarty->security_policy) && !$this->smarty->security_policy->isTrustedTag($tag, $this)) { + return false; + } + + switch ($tag) { + case 'append': + return new \Smarty\Compile\Append(); + case 'assign': + return new \Smarty\Compile\Assign(); + case 'block': + return new \Smarty\Compile\Block(); + case 'blockclose': + return new \Smarty\Compile\BlockClose(); + case 'break': + return new \Smarty\Compile\BreakTag(); + case 'call': + return new \Smarty\Compile\Call(); + case 'capture': + return new \Smarty\Compile\Capture(); + case 'captureclose': + return new \Smarty\Compile\CaptureClose(); + case 'child': + return new \Smarty\Compile\Child(); + case 'block_child': + return new \Smarty\Compile\BlockChild(); + case 'block_parent': + return new \Smarty\Compile\BlockParent(); + case 'config_load': + return new \Smarty\Compile\ConfigLoad(); + case 'continue': + return new \Smarty\Compile\ContinueTag(); + case 'debug': + return new \Smarty\Compile\Debug(); + case 'eval': + return new \Smarty\Compile\EvalTag(); + case 'extends': + return new \Smarty\Compile\ExtendsTag(); + case 'for': + return new \Smarty\Compile\ForTag(); + case 'foreach': + return new \Smarty\Compile\ForeachTag(); + case 'foreachelse': + return new \Smarty\Compile\ForeachElse(); + case 'foreachclose': + return new \Smarty\Compile\ForeachClose(); + case 'forelse': + return new \Smarty\Compile\ForElse(); + case 'forclose': + return new \Smarty\Compile\ForClose(); + case 'function': + return new \Smarty\Compile\FunctionTag(); + case 'functionclose': + return new \Smarty\Compile\FunctionClose(); + case 'if': + return new \Smarty\Compile\IfTag(); + case 'else': + return new \Smarty\Compile\ElseTag(); + case 'elseif': + return new \Smarty\Compile\ElseIfTag(); + case 'ifclose': + return new \Smarty\Compile\IfClose(); + case 'include': + return new \Smarty\Compile\IncludeTag(); + case 'insert': + return new \Smarty\Compile\Inser(); + case 'ldelim': + return new \Smarty\Compile\Ldelim(); + case 'rdelim': + return new \Smarty\Compile\Rdelim(); + case 'make_nocache': + return new \Smarty\Compile\MakeNocache(); + case 'nocache': + return new \Smarty\Compile\Nocache(); + case 'nocacheclose': + return new \Smarty\Compile\NocacheClose(); + case 'parent': + return new \Smarty\Compile\ParentTag(); + case 'private_block_plugin': + return new \Smarty\Compile\PrivateBlockPlugin(); + case 'private_function_plugin': + return new \Smarty\Compile\PrivateFunctionPlugin(); + case 'private_modifier': + return new \Smarty\Compile\PrivateModifier(); + case 'private_object_function': + return new \Smarty\Compile\PrivateObjectFunction(); + case 'private_object_block_function': + return new \Smarty\Compile\PrivateObjectBlockFunction(); + case 'private_print_expression': + return new \Smarty\Compile\PrivatePrintExpression(); + case 'private_registered_function': + return new \Smarty\Compile\PrivateRegisteredFunction(); + case 'private_special_variable': + return new \Smarty\Compile\PrivateSpecialVariable(); + case 'section': + return new \Smarty\Compile\Section(); + case 'sectionelse': + return new \Smarty\Compile\SectionElse(); + case 'sectionclose': + return new \Smarty\Compile\SectionClose(); + case 'setfilter': + return new \Smarty\Compile\Setfilter(); + case 'setfilterclose': + return new \Smarty\Compile\SetfilterClose(); + case 'while': + return new \Smarty\Compile\WhileTag(); + case 'whileclose': + return new \Smarty\Compile\WhileClose(); + } + + return false; + } + + /** + * Check for plugins and return function name + * + * @param $plugin_name + * @param string $plugin_type type of plugin + * + * @return string call name of function + */ + public function getPlugin($plugin_name, $plugin_type) { + // loop through plugin dirs and find the plugin + $function = 'smarty_' . $plugin_type . '_' . $plugin_name; + if ($plugin_type === 'modifier') { + $this->modifier_plugins[$plugin_name] = true; + } + return $function; + } + + /** + * Check for plugins by default plugin handler + * + * @param string $tag name of tag + * @param string $plugin_type type of plugin + * + * @return bool true if found + * @throws \SmartyCompilerException + */ + public function getPluginFromDefaultHandler($tag, $plugin_type) { + $callback = null; + $script = null; + $cacheable = true; + $result = call_user_func_array( + $this->smarty->default_plugin_handler_func, + [ + $tag, + $plugin_type, + $this->template, + &$callback, + &$script, + &$cacheable, + ] + ); + if ($result) { + $this->tag_nocache = $this->tag_nocache || !$cacheable; + if ($script !== null) { + if (is_file($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] = [ + $callback, + true, + [], + ]; + return true; + } else { + $this->trigger_template_error("Default plugin handler: Returned callback for '{$tag}' not callable"); + } + } + return false; + } + + /** + * Append code segments and remove unneeded ?> \s?$/D', $left) && preg_match('/^<\?php\s+/', $right)) { + $left = preg_replace('/\s*\?>\s?$/D', "\n", $left); + $left .= preg_replace('/^<\?php\s+/', '', $right); + } else { + $left .= $right; + } + return $left; + } + + /** + * Inject inline code for nocache template sections + * This method gets the content of each template element from the parser. + * 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 + * + * @return string content + */ + public function processNocacheCode($content, $is_code) { + // 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) + ) { + $this->template->compiled->has_nocache_code = true; + $_output = addcslashes($content, '\'\\'); + $_output = str_replace('^#^', '\'', $_output); + $_output = + "nocache_hash}%%*/{$_output}/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n"; + } else { + $_output = $content; + } + } else { + $_output = $content; + } + $this->modifier_plugins = []; + $this->suppressNocacheProcessing = false; + $this->tag_nocache = false; + return $_output; + } + + /** + * Get Id + * + * @param string $input + * + * @return bool|string + */ + public function getId($input) { + if (preg_match('~^([\'"]*)([0-9]*[a-zA-Z_]\w*)\1$~', $input, $match)) { + return $match[2]; + } + return false; + } + + /** + * Get variable name from string + * + * @param string $input + * + * @return bool|string + */ + public function getVariableName($input) { + if (preg_match('~^[$]_smarty_tpl->tpl_vars\[[\'"]*([0-9]*[a-zA-Z_]\w*)[\'"]*\]->value$~', $input, $match)) { + return $match[1]; + } + return false; + } + + /** + * Set nocache flag in variable or create new variable + * + * @param string $varName + */ + public function setNocacheInVariable($varName) { + // create nocache var to make it know for further compiling + if ($_var = $this->getId($varName)) { + if (isset($this->template->tpl_vars[$_var])) { + $this->template->tpl_vars[$_var] = clone $this->template->tpl_vars[$_var]; + $this->template->tpl_vars[$_var]->nocache = true; + } else { + $this->template->tpl_vars[$_var] = new \Smarty\Variable(null, true); + } + } + } + + /** + * @param array $_attr tag attributes + * @param array $validScopes + * + * @return int|string + * @throws \SmartyCompilerException + */ + public function convertScope($_attr, $validScopes) { + $_scope = 0; + if (isset($_attr['scope'])) { + $_scopeName = trim($_attr['scope'], '\'"'); + if (is_numeric($_scopeName) && in_array($_scopeName, $validScopes)) { + $_scope = $_scopeName; + } elseif (is_string($_scopeName)) { + $_scopeName = trim($_scopeName, '\'"'); + $_scope = isset($validScopes[$_scopeName]) ? $validScopes[$_scopeName] : false; + } else { + $_scope = false; + } + if ($_scope === false) { + $err = var_export($_scopeName, true); + $this->trigger_template_error("illegal value '{$err}' for \"scope\" attribute", null, true); + } + } + return $_scope; + } + + /** + * Generate nocache code string + * + * @param string $code PHP code + * + * @return string + */ + public function makeNocacheCode($code) { + return "echo '/*%%SmartyNocache:{$this->nocache_hash}%%*//*/%%SmartyNocache:{$this->nocache_hash}%%*/';\n"; + } + + /** + * display compiler error messages without dying + * If parameter $args is empty it is a parser detected syntax error. + * 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 null|bool $tagline if true the line number of last tag + * + * @throws \SmartyCompilerException when an unexpected token is found + */ + public function trigger_template_error($args = null, $line = null, $tagline = null) { + $lex = $this->parser->lex; + if ($tagline === true) { + // get line number of Tag + $line = $lex->taglineno; + } elseif (!isset($line)) { + // get template source line which has error + $line = $lex->line; + } else { + $line = (int)$line; + } + if (in_array( + $this->template->source->type, + [ + '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; + } + // $line += $this->trace_line_offset; + $match = preg_split("/\n/", $lex->data); + $error_text = + 'Syntax error in template "' . (empty($this->trace_filepath) ? $templateName : $this->trace_filepath) . + '" on line ' . ($line + $this->trace_line_offset) . ' "' . + trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1])) . '" '; + if (isset($args)) { + // individual error message + $error_text .= $args; + } else { + $expect = []; + // expected token from parser + $error_text .= ' - Unexpected "' . $lex->value . '"'; + if (count($this->parser->yy_get_expected_tokens($this->parser->yymajor)) <= 4) { + foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) { + $exp_token = $this->parser->yyTokenName[$token]; + if (isset($lex->smarty_token_names[$exp_token])) { + // token type from lexer + $expect[] = '"' . $lex->smarty_token_names[$exp_token] . '"'; + } else { + // otherwise internal token name + $expect[] = $this->parser->yyTokenName[$token]; + } + } + $error_text .= ', expected one of: ' . implode(' , ', $expect); + } + } + if ($this->smarty->_parserdebug) { + $this->parser->errorRunDown(); + echo ob_get_clean(); + flush(); + } + $e = new SmartyCompilerException( + $error_text, + 0, + $this->template->source->filepath, + $line + ); + $e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[$line - 1])); + $e->desc = $args; + $e->template = $this->template->source->filepath; + throw $e; + } + + /** + * Return var_export() value with all white spaces removed + * + * @param mixed $value + * + * @return string + */ + public function getVarExport($value) { + return preg_replace('/\s/', '', var_export($value, true)); + } + + /** + * enter double quoted string + * - save tag stack count + */ + public function enterDoubleQuote() { + array_push($this->_tag_stack_count, $this->getTagStackCount()); + } + + /** + * Return tag stack count + * + * @return int + */ + public function getTagStackCount() { + return count($this->_tag_stack); + } + + /** + * @param $lexerPreg + * + * @return mixed + */ + public function replaceDelimiter($lexerPreg) { + return str_replace( + ['SMARTYldel', 'SMARTYliteral', 'SMARTYrdel', 'SMARTYautoliteral', 'SMARTYal'], + [ + $this->ldelPreg, $this->literalPreg, $this->rdelPreg, + $this->smarty->getAutoLiteral() ? '{1,}' : '{9}', + $this->smarty->getAutoLiteral() ? '' : '\\s*', + ], + $lexerPreg + ); + } + + /** + * Build lexer regular expressions for left and right delimiter and user defined literals + */ + public function initDelimiterPreg() { + $ldel = $this->smarty->getLeftDelimiter(); + $this->ldelLength = strlen($ldel); + $this->ldelPreg = ''; + foreach (str_split($ldel, 1) as $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 .= '[' . preg_quote($chr, '/') . ']'; + } + $literals = $this->smarty->getLiterals(); + if (!empty($literals)) { + foreach ($literals as $key => $literal) { + $literalPreg = ''; + foreach (str_split($literal, 1) as $chr) { + $literalPreg .= '[' . preg_quote($chr, '/') . ']'; + } + $literals[$key] = $literalPreg; + } + $this->literalPreg = '|' . implode('|', $literals); + } else { + $this->literalPreg = ''; + } + } + + /** + * leave double quoted string + * - throw exception if block in string was not closed + * + * @throws \SmartyCompilerException + */ + public function leaveDoubleQuote() { + if (array_pop($this->_tag_stack_count) !== $this->getTagStackCount()) { + $tag = $this->getOpenBlockTag(); + $this->trigger_template_error( + "unclosed '{{$tag}}' in doubled quoted string", + null, + true + ); + } + } + + /** + * Get left delimiter preg + * + * @return string + */ + public function getLdelPreg() { + return $this->ldelPreg; + } + + /** + * Get right delimiter preg + * + * @return string + */ + public function getRdelPreg() { + return $this->rdelPreg; + } + + /** + * Get length of left delimiter + * + * @return int + */ + public function getLdelLength() { + return $this->ldelLength; + } + + /** + * Get length of right delimiter + * + * @return int + */ + public function getRdelLength() { + return $this->rdelLength; + } + + /** + * Get name of current open block tag + * + * @return string|boolean + */ + public function getOpenBlockTag() { + $tagCount = $this->getTagStackCount(); + if ($tagCount) { + return $this->_tag_stack[$tagCount - 1][0]; + } else { + return false; + } + } + + /** + * Check if $value contains variable elements + * + * @param mixed $value + * + * @return bool|int + */ + public function isVariable($value) { + if (is_string($value)) { + return preg_match('/[$(]/', $value); + } + if (is_bool($value) || is_numeric($value)) { + return false; + } + if (is_array($value)) { + foreach ($value as $k => $v) { + if ($this->isVariable($k) || $this->isVariable($v)) { + return true; + } + } + return false; + } + return false; + } + + /** + * Get new prefix variable name + * + * @return string + */ + public function getNewPrefixVariable() { + ++self::$prefixVariableNumber; + return $this->getPrefixVariable(); + } + + /** + * Get current prefix variable name + * + * @return string + */ + public function getPrefixVariable() { + return '$_prefixVariable' . self::$prefixVariableNumber; + } + + /** + * append code to prefix buffer + * + * @param string $code + */ + public function appendPrefixCode($code) { + $this->prefix_code[] = $code; + } + + /** + * get prefix code string + * + * @return string + */ + public function getPrefixCode() { + $code = ''; + $prefixArray = array_merge($this->prefix_code, array_pop($this->prefixCodeStack)); + $this->prefixCodeStack[] = []; + foreach ($prefixArray as $c) { + $code = $this->appendCode($code, $c); + } + $this->prefix_code = []; + return $code; + } + + public function cStyleComment($string) { + return '/*' . str_replace('*/', '* /', $string) . '*/'; + } + + /** + * Compile Tag + * + * @param string $tag tag name + * @param array $args array with tag attributes + * @param array $parameter array with compilation parameter + * + * @return string compiled code + * @throws SmartyException + * @throws SmartyCompilerException + */ + private function compileTag2($tag, $args, $parameter) { + $plugin_type = ''; + // $args contains the attributes parsed and compiled by the lexer/parser + // assume that tag does compile into code, but creates no HTML output + $this->has_code = true; + + // check nocache option flag + foreach ($args as $arg) { + if (!is_array($arg)) { + if ($arg === "'nocache'" || $arg === 'nocache') { + $this->tag_nocache = true; + } + } else { + foreach ($arg as $k => $v) { + if (($k === "'nocache'" || $k === 'nocache') && (trim($v, "'\" ") === 'true')) { + $this->tag_nocache = true; + } + } + } + } + // 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) + ) { + // template defined by {template} tag + $args['_attr']['name'] = "'{$tag}'"; + $_output = $this->callTagCompiler('call', $args, $parameter); + } + } + if ($_output !== false) { + if ($_output !== true) { + // did we get compiled code + if ($this->has_code) { + // return compiled code + return $_output; + } + } + // tag did not produce compiled code + return null; + } else { + // map_named attributes + if (isset($args['_attr'])) { + foreach ($args['_attr'] as $key => $attribute) { + if (is_array($attribute)) { + $args = array_merge($args, $attribute); + } + } + } + // not an internal compiler tag + if (strlen($tag) < 6 || substr($tag, -5) !== 'close') { + // 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])) + ) { + return $this->callTagCompiler('private_object_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 + ); + } + } + // check if tag is registered + foreach ([ + \Smarty\Smarty::PLUGIN_COMPILER, + \Smarty\Smarty::PLUGIN_FUNCTION, + \Smarty\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\Smarty::PLUGIN_COMPILER) { + $new_args = []; + foreach ($args as $key => $mixed) { + if (is_array($mixed)) { + $new_args = array_merge($new_args, $mixed); + } else { + $new_args[$key] = $mixed; + } + } + 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], + [ + $new_args, + $this, + ] + ); + } + // compile registered function or block function + if ($plugin_type === \Smarty\Smarty::PLUGIN_FUNCTION || $plugin_type === \Smarty\Smarty::PLUGIN_BLOCK) { + 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\Smarty::PLUGIN_COMPILER + && (!isset($this->smarty->security_policy) + || $this->smarty->security_policy->isTrustedTag($tag, $this)) + ) { + $plugin = 'smarty_compiler_' . $tag; + if (is_callable($plugin)) { + // convert arguments format for old compiler plugins + $new_args = []; + foreach ($args as $key => $mixed) { + if (is_array($mixed)) { + $new_args = array_merge($new_args, $mixed); + } else { + $new_args[$key] = $mixed; + } + } + return $plugin($new_args, $this->smarty); + } + if (class_exists($plugin, false)) { + $plugin_object = new $plugin; + if (method_exists($plugin_object, 'compile')) { + return $plugin_object->compile($args, $this); + } + } + 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) + ) { + return $this->callTagCompiler( + 'private_' . $plugin_type . '_plugin', + $args, + $parameter, + $tag, + $function + ); + } + } + } + } + if (is_callable($this->smarty->default_plugin_handler_func)) { + $found = false; + // look for already resolved tags + foreach ($this->plugin_search_order as $plugin_type) { + if (isset($this->default_handler_plugins[$plugin_type][$tag])) { + $found = true; + break; + } + } + if (!$found) { + // call default handler + foreach ($this->plugin_search_order as $plugin_type) { + if ($this->getPluginFromDefaultHandler($tag, $plugin_type)) { + $found = true; + break; + } + } + } + if ($found) { + // if compiler function plugin call it now + if ($plugin_type === \Smarty\Smarty::PLUGIN_COMPILER) { + $new_args = []; + foreach ($args as $key => $mixed) { + if (is_array($mixed)) { + $new_args = array_merge($new_args, $mixed); + } else { + $new_args[$key] = $mixed; + } + } + return call_user_func_array( + $this->default_handler_plugins[$plugin_type][$tag][0], + [ + $new_args, + $this, + ] + ); + } else { + return $this->callTagCompiler( + 'private_registered_' . $plugin_type, + $args, + $parameter, + $tag + ); + } + } + } + } else { + // compile closing tag of block function + $base_tag = substr($tag, 0, -5); + // check if closing tag is a registered object + 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 + ); + } else { + // throw exception + $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\Smarty::PLUGIN_BLOCK][$base_tag]) + || isset($this->default_handler_plugins[\Smarty\Smarty::PLUGIN_BLOCK][$base_tag]) + ) { + return $this->callTagCompiler('private_registered_block', $args, $parameter, $tag); + } + // registered function tag ? + if (isset($this->smarty->registered_plugins[\Smarty\Smarty::PLUGIN_FUNCTION][$tag])) { + return $this->callTagCompiler('private_registered_function', $args, $parameter, $tag); + } + // block plugin? + if ($function = $this->getPlugin($base_tag, \Smarty\Smarty::PLUGIN_BLOCK)) { + return $this->callTagCompiler('private_block_plugin', $args, $parameter, $tag, $function); + } + // function plugin? + if ($function = $this->getPlugin($tag, \Smarty\Smarty::PLUGIN_FUNCTION)) { + if (!isset($this->smarty->security_policy) + || $this->smarty->security_policy->isTrustedTag($tag, $this) + ) { + return $this->callTagCompiler('private_function_plugin', $args, $parameter, $tag, $function); + } + } + // registered compiler plugin ? + if (isset($this->smarty->registered_plugins[\Smarty\Smarty::PLUGIN_COMPILER][$tag])) { + // if compiler function plugin call it now + $args = []; + if (!$this->smarty->registered_plugins[\Smarty\Smarty::PLUGIN_COMPILER][$tag][1]) { + $this->tag_nocache = true; + } + return call_user_func_array( + $this->smarty->registered_plugins[\Smarty\Smarty::PLUGIN_COMPILER][$tag][0], + [ + $args, + $this, + ] + ); + } + $plugin = 'smarty_compiler_' . $tag; + if (is_callable($plugin)) { + return $plugin($args, $this->smarty); + } + if (class_exists($plugin, false)) { + $plugin_object = new $plugin; + if (method_exists($plugin_object, 'compile')) { + return $plugin_object->compile($args, $this); + } + } + throw new SmartyException("Plugin '{$tag}' not callable"); + } + $this->trigger_template_error("unknown tag '{$tag}'", null, true); + } + } + + /** + * method to compile a Smarty template + * + * @param mixed $_content template source + * @param bool $isTemplateSource + * + * @return bool true if compiling succeeded, false if it failed + * @throws \SmartyCompilerException + */ + protected function doCompile($_content, $isTemplateSource = false) { + /* here is where the compiling takes place. Smarty + tags in the templates are replaces with PHP code, + then written to compiled files. */ + // init the lexer/parser to compile the template + $this->parser = + new $this->parser_class( + new $this->lexer_class( + str_replace( + [ + "\r\n", + "\r", + ], + "\n", + $_content + ), + $this + ), + $this + ); + if ($isTemplateSource && $this->template->caching) { + $this->parser->insertPhpCode("compiled->nocache_hash = '{$this->nocache_hash}';\n?>\n"); + } + if (function_exists('mb_internal_encoding') + && function_exists('ini_get') + && ((int)ini_get('mbstring.func_overload')) & 2 + ) { + $mbEncoding = mb_internal_encoding(); + mb_internal_encoding('ASCII'); + } else { + $mbEncoding = null; + } + if ($this->smarty->_parserdebug) { + $this->parser->PrintTrace(); + $this->parser->lex->PrintTrace(); + } + // get tokens from lexer and parse them + while ($this->parser->lex->yylex()) { + if ($this->smarty->_parserdebug) { + echo "
Line {$this->parser->lex->line} Parsing {$this->parser->yyTokenName[$this->parser->lex->token]} Token " . + htmlentities($this->parser->lex->value) . ""; + } + $this->parser->doParse($this->parser->lex->token, $this->parser->lex->value); + } + // finish parsing process + $this->parser->doParse(0, 0); + if ($mbEncoding) { + mb_internal_encoding($mbEncoding); + } + // check for unclosed tags + if (count($this->_tag_stack) > 0) { + // get stacked info + [$openTag, $_data] = array_pop($this->_tag_stack); + $this->trigger_template_error( + "unclosed {$this->smarty->left_delimiter}" . $openTag . + "{$this->smarty->right_delimiter} tag" + ); + } + // call post compile callbacks + foreach ($this->postCompileCallbacks as $cb) { + $parameter = $cb; + $parameter[0] = $this; + call_user_func_array($cb[0], $parameter); + } + // return compiled code + return $this->prefixCompiledCode . $this->parser->retvalue . $this->postfixCompiledCode; + } + + /** + * Register a post compile callback + * - when the callback is called after template compiling the compiler object will be inserted as first parameter + * + * @param callback $callback + * @param array $parameter optional parameter array + * @param string $key optional key for callback + * @param bool $replace if true replace existing keyed callback + */ + public function registerPostCompileCallback($callback, $parameter = [], $key = null, $replace = false) { + array_unshift($parameter, $callback); + if (isset($key)) { + if ($replace || !isset($this->postCompileCallbacks[$key])) { + $this->postCompileCallbacks[$key] = $parameter; + } + } else { + $this->postCompileCallbacks[] = $parameter; + } + } + + /** + * Remove a post compile callback + * + * @param string $key callback key + */ + public function unregisterPostCompileCallback($key) { + unset($this->postCompileCallbacks[$key]); + } +} diff --git a/src/Compiler/smarty_internal_config_file_compiler.php b/src/Compiler/smarty_internal_config_file_compiler.php deleted file mode 100644 index 668f5093..00000000 --- a/src/Compiler/smarty_internal_config_file_compiler.php +++ /dev/null @@ -1,211 +0,0 @@ -smarty = $smarty; - // get required plugins - $this->lexer_class = $lexer_class; - $this->parser_class = $parser_class; - $this->smarty = $smarty; - $this->config_data[ 'sections' ] = array(); - $this->config_data[ 'vars' ] = array(); - } - - /** - * Method to compile Smarty config source. - * - * @param Smarty_Internal_Template $template - * - * @return bool true if compiling succeeded, false if it failed - * @throws \SmartyException - */ - public function compileTemplate(Smarty_Internal_Template $template) - { - $this->template = $template; - $this->template->compiled->file_dependency[ $this->template->source->uid ] = - array( - $this->template->source->filepath, - $this->template->source->getTimeStamp(), - $this->template->source->type - ); - if ($this->smarty->debugging) { - if (!isset($this->smarty->_debug)) { - $this->smarty->_debug = new \Smarty\Debug(); - } - $this->smarty->_debug->start_compile($this->template); - } - // init the lexer/parser to compile the config file - /* @var Smarty_Internal_ConfigFileLexer $this->lex */ - $this->lex = new $this->lexer_class( - str_replace( - array( - "\r\n", - "\r" - ), - "\n", - $template->source->getContent() - ) . "\n", - $this - ); - /* @var Smarty_Internal_ConfigFileParser $this->parser */ - $this->parser = new $this->parser_class($this->lex, $this); - if (function_exists('mb_internal_encoding') - && function_exists('ini_get') - && ((int)ini_get('mbstring.func_overload')) & 2 - ) { - $mbEncoding = mb_internal_encoding(); - mb_internal_encoding('ASCII'); - } else { - $mbEncoding = null; - } - if ($this->smarty->_parserdebug) { - $this->parser->PrintTrace(); - } - // get tokens from lexer and parse them - while ($this->lex->yylex()) { - if ($this->smarty->_parserdebug) { - echo "
Line {$this->parser->lex->line} Parsing {$this->parser->yyTokenName[$this->parser->lex->token]} Token " . - htmlentities($this->parser->lex->value) . ""; - } - $this->parser->doParse($this->parser->lex->token, $this->parser->lex->value); - } - // finish parsing process - $this->parser->doParse(0, 0); - if ($mbEncoding) { - mb_internal_encoding($mbEncoding); - } - // check for unclosed tags - if (count($this->_tag_stack) > 0) { - // get stacked info - list($openTag, $_data) = array_pop($this->_tag_stack); - $this->trigger_template_error( - "unclosed {$this->smarty->left_delimiter}" . $openTag . - "{$this->smarty->right_delimiter} tag" - ); - } - // call post compile callbacks - foreach ($this->postCompileCallbacks as $cb) { - $parameter = $cb; - $parameter[ 0 ] = $this; - call_user_func_array($cb[ 0 ], $parameter); - } - // return compiled code - return $this->prefixCompiledCode . $this->parser->retvalue . $this->postfixCompiledCode; - } - - /** - * Register a post compile callback - * - when the callback is called after template compiling the compiler object will be inserted as first parameter - * - * @param callback $callback - * @param array $parameter optional parameter array - * @param string $key optional key for callback - * @param bool $replace if true replace existing keyed callback - */ - public function registerPostCompileCallback($callback, $parameter = array(), $key = null, $replace = false) - { - array_unshift($parameter, $callback); - if (isset($key)) { - if ($replace || !isset($this->postCompileCallbacks[ $key ])) { - $this->postCompileCallbacks[ $key ] = $parameter; - } - } else { - $this->postCompileCallbacks[] = $parameter; - } - } - - /** - * Remove a post compile callback - * - * @param string $key callback key - */ - public function unregisterPostCompileCallback($key) - { - unset($this->postCompileCallbacks[ $key ]); - } -} diff --git a/src/Compiler/smarty_internal_templatecompilerbase.php b/src/Compiler/smarty_internal_templatecompilerbase.php deleted file mode 100644 index e46896aa..00000000 --- a/src/Compiler/smarty_internal_templatecompilerbase.php +++ /dev/null @@ -1,1600 +0,0 @@ -smarty = $smarty; - $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 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 - ) { - // get code frame of compiled template - $_compiled_code = $template->createCodeFrame( - $this->compileTemplateSource( - $template, - $nocache, - $parent_compiler - ), - $this->postFilter($this->blockOrFunctionCode) . - join('', $this->mergedSubTemplatesCode), - false, - $this - ); - return $_compiled_code; - } - - /** - * Compile template source and run optional post filter - * - * @param \Smarty_Internal_Template $template - * @param null|bool $nocache flag if template must be compiled in nocache mode - * @param \Smarty_Internal_TemplateCompilerBase $parent_compiler - * - * @return string - * @throws \Exception - */ - 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; - if ($this->smarty->debugging) { - if (!isset($this->smarty->_debug)) { - $this->smarty->_debug = new \Smarty\Debug(); - } - $this->smarty->_debug->start_compile($this->template); - } - $this->parent_compiler = $parent_compiler ? $parent_compiler : $this; - $nocache = isset($nocache) ? $nocache : false; - if (empty($template->compiled->nocache_hash)) { - $template->compiled->nocache_hash = $this->nocache_hash; - } else { - $this->nocache_hash = $template->compiled->nocache_hash; - } - $this->caching = $template->caching; - // flag for nocache sections - $this->nocache = $nocache; - $this->tag_nocache = false; - // reset has nocache code flag - $this->template->compiled->has_nocache_code = false; - $this->has_variable_string = false; - $this->prefix_code = array(); - // 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, - ); - } - $this->smarty->_current_file = $this->template->source->filepath; - // get template source - if (!empty($this->template->source->components)) { - // we have array of inheritance templates by extends: resource - // generate corresponding source code sequence - $_content = - Smarty_Internal_Compile_Extends::extendsSourceArrayCode($this->template); - } else { - // get template source - $_content = $this->template->source->getContent(); - } - $_compiled_code = $this->postFilter($this->doCompile($this->preFilter($_content), true)); - } catch (Exception $e) { - if ($this->smarty->debugging) { - $this->smarty->_debug->end_compile($this->template); - } - $this->_tag_stack = array(); - // free memory - $this->parent_compiler = null; - $this->template = null; - $this->parser = null; - throw $e; - } - if ($this->smarty->debugging) { - $this->smarty->_debug->end_compile($this->template); - } - $this->parent_compiler = null; - $this->parser = null; - return $_compiled_code; - } - - /** - * Optionally process compiled code by post filter - * - * @param string $code compiled code - * - * @return string - * @throws \SmartyException - */ - public function postFilter($code) - { - // run post filter if on code - if (!empty($code) && isset($this->smarty->registered_filters[ 'post' ])) { - return $this->smarty->ext->_filterHandler->runFilter('post', $code, $this->template); - } else { - return $code; - } - } - - /** - * Run optional prefilter - * - * @param string $_content template source - * - * @return string - * @throws \SmartyException - */ - public function preFilter($_content) - { - // run pre filter if required - if ($_content !== '' && isset($this->smarty->registered_filters[ 'pre' ])) { - return $this->smarty->ext->_filterHandler->runFilter('pre', $_content, $this->template); - } else { - return $_content; - } - } - - /** - * Compile Tag - * This is a call back from the lexer/parser - * - * Save current prefix code - * Compile tag - * 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 - * - * @throws SmartyCompilerException - * @throws SmartyException - * @return string compiled code - */ - public function compileTag($tag, $args, $parameter = array()) - { - $this->prefixCodeStack[] = $this->prefix_code; - $this->prefix_code = array(); - $result = $this->compileTag2($tag, $args, $parameter); - $this->prefix_code = array_merge($this->prefix_code, array_pop($this->prefixCodeStack)); - return $result; - } - - /** - * compile variable - * - * @param string $variable - * - * @return string - */ - public function compileVariable($variable) - { - if (!strpos($variable, '(')) { - // 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; - // todo $this->template->compiled->properties['variables'][$var] = $this->tag_nocache | $this->nocache; - } - return '$_smarty_tpl->tpl_vars[' . $variable . ']->value'; - } - - /** - * compile config variable - * - * @param string $variable - * - * @return string - */ - public function compileConfigVariable($variable) - { - // return '$_smarty_tpl->config_vars[' . $variable . ']'; - return '$_smarty_tpl->smarty->ext->configLoad->_getConfigVariable($_smarty_tpl, ' . $variable . ')'; - } - - /** - * compile PHP function call - * - * @param string $name - * @param array $parameter - * - * @return string - * @throws \SmartyCompilerException - */ - 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) - ) { - $func_name = smarty_strtolower_ascii($name); - - if ($func_name === 'isset') { - if (count($parameter) === 0) { - $this->trigger_template_error('Illegal number of parameter in "isset()"'); - } - - $pa = array(); - foreach ($parameter as $p) { - $pa[] = $this->syntaxMatchesVariable($p) ? 'isset(' . $p . ')' : '(' . $p . ' !== null )'; - } - return '(' . implode(' && ', $pa) . ')'; - - } 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()}'"); - } - if ($func_name === 'empty') { - return $func_name . '(' . - str_replace("')->value", "',null,true,false)->value", $parameter[ 0 ]) . ')'; - } else { - return $func_name . '(' . $parameter[ 0 ] . ')'; - } - } else { - return $name . '(' . implode(',', $parameter) . ')'; - } - } else { - $this->trigger_template_error("unknown function '{$name}'"); - } - } - } - - /** - * Determines whether the passed string represents a valid (PHP) variable. - * This is important, because `isset()` only works on variables and `empty()` can only be passed - * a variable prior to php5.5 - * @param $string - * @return bool - */ - private function syntaxMatchesVariable($string) { - static $regex_pattern = '/^\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*((->)[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*|\[.*]*\])*$/'; - return 1 === preg_match($regex_pattern, trim($string)); - } - - /** - * This method is called from parser to process a text content section if strip is enabled - * - remove text from inheritance child templates as they may generate output - * - * @param string $text - * - * @return string - */ - public function processText($text) - { - - if (strpos($text, '<') === false) { - return preg_replace($this->stripRegEx, '', $text); - } - - $store = array(); - $_store = 0; - - // capture html elements not to be messed with - $_offset = 0; - if (preg_match_all( - '#(]*>)|(]*>)|(
]*>.*?]*>)#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++; - } - } - $expressions = array(// replace multiple spaces between tags by a single space - '#(:SMARTY@!@|>)[\040\011]+(?=@!@SMARTY:|<)#s' => '\1 \2', - // remove newline between tags - '#(:SMARTY@!@|>)[\040\011]*[\n]\s*(?=@!@SMARTY:|<)#s' => '\1\2', - // remove multiple spaces between attributes (but not in attribute values!) - '#(([a-z0-9]\s*=\s*("[^"]*?")|(\'[^\']*?\'))|<[a-z0-9_]+)\s+([a-z/>])#is' => '\1 \5', - '#>[\040\011]+$#Ss' => '> ', - '#>[\040\011]*[\n]\s*$#Ss' => '>', - $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 - ) - ) { - 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++; - } - } - return $text; - } - - /** - * lazy loads internal compile plugin for tag and calls the compile method - * compile objects cached for reuse. - * 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 - * - * @return bool|string compiled code or false - * @throws \SmartyCompilerException - */ - private function callTagCompiler($tag, $args, $param1 = null, $param2 = null, $param3 = null) - { - /* @var Base $tagCompiler */ - $tagCompiler = $this->getTagCompiler($tag); - // compile this tag - return $tagCompiler === false ? false : $tagCompiler->compile($args, $this, $param1, $param2, $param3); - } - - /** - * lazy loads internal compile plugin for tag compile objects cached for reuse. - * - * class name format: \Smarty\Compile\TagName - * - * @param string $tag tag name - * - * @return bool|Base tag compiler object or false if not found or untrusted by security policy - */ - public function getTagCompiler($tag) - { - - if (isset($this->smarty->security_policy) && !$this->smarty->security_policy->isTrustedTag($tag, $this)) { - return false; - } - - switch ($tag) { - case 'append': return new \Smarty\Compile\Append(); - case 'assign': return new \Smarty\Compile\Assign(); - case 'block': return new \Smarty\Compile\Block(); - case 'blockclose': return new \Smarty\Compile\Blockclose(); - case 'break': return new \Smarty\Compile\BreakTag(); - case 'call': return new \Smarty\Compile\Call(); - case 'child': return new \Smarty\Compile\Child(); - case 'config_load': return new \Smarty\Compile\ConfigLoad(); - case 'continue': return new \Smarty\Compile\ContinueTag(); - case 'debug': return new \Smarty\Compile\Debug(); - case 'eval': return new \Smarty\Compile\EvalTag(); - case 'include': return new \Smarty\Compile\IncludeTag(); - case 'insert': return new \Smarty\Compile\Inser(); - case 'ldelim': return new \Smarty\Compile\Ldelim(); - case 'make_nocache': return new \Smarty\Compile\MakeNocache(); - case 'private_block_plugin': return new \Smarty\Compile\PrivateBlockPlugin(); - case 'private_function_plugin': return new \Smarty\Compile\PrivateFunctionPlugin(); - case 'private_modifier': return new \Smarty\Compile\PrivateModifier(); - case 'private_object_function': return new \Smarty\Compile\PrivateObjectFunction(); - case 'private_object_block_function': return new \Smarty\Compile\PrivateObjectBlockFunction(); - case 'private_print_expression': return new \Smarty\Compile\PrivatePrintExpression(); - case 'private_registered_function': return new \Smarty\Compile\PrivateRegisteredFunction(); - case 'private_special_variable': return new \Smarty\Compile\PrivateSpecialVariable(); - case 'while': return new \Smarty\Compile\WhileTag(); - case 'whileclose': return new \Smarty\Compile\Whileclose(); - } - - return false; - } - - /** - * Check for plugins and return function name - * - * @param $plugin_name - * @param string $plugin_type type of plugin - * - * @return string call name of function - */ - public function getPlugin($plugin_name, $plugin_type) - { - // loop through plugin dirs and find the plugin - $function = 'smarty_' . $plugin_type . '_' . $plugin_name; - if ($plugin_type === 'modifier') { - $this->modifier_plugins[ $plugin_name ] = true; - } - return $function; - } - - /** - * Check for plugins by default plugin handler - * - * @param string $tag name of tag - * @param string $plugin_type type of plugin - * - * @return bool true if found - * @throws \SmartyCompilerException - */ - public function getPluginFromDefaultHandler($tag, $plugin_type) - { - $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, - ) - ); - if ($result) { - $this->tag_nocache = $this->tag_nocache || !$cacheable; - if ($script !== null) { - if (is_file($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() - ); - return true; - } else { - $this->trigger_template_error("Default plugin handler: Returned callback for '{$tag}' not callable"); - } - } - return false; - } - - /** - * Append code segments and remove unneeded ?> \s?$/D', $left) && preg_match('/^<\?php\s+/', $right)) { - $left = preg_replace('/\s*\?>\s?$/D', "\n", $left); - $left .= preg_replace('/^<\?php\s+/', '', $right); - } else { - $left .= $right; - } - return $left; - } - - /** - * Inject inline code for nocache template sections - * This method gets the content of each template element from the parser. - * 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 - * - * @return string content - */ - public function processNocacheCode($content, $is_code) - { - // 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) - ) { - $this->template->compiled->has_nocache_code = true; - $_output = addcslashes($content, '\'\\'); - $_output = str_replace('^#^', '\'', $_output); - $_output = - "nocache_hash}%%*/{$_output}/*/%%SmartyNocache:{$this->nocache_hash}%%*/';?>\n"; - } else { - $_output = $content; - } - } else { - $_output = $content; - } - $this->modifier_plugins = array(); - $this->suppressNocacheProcessing = false; - $this->tag_nocache = false; - return $_output; - } - - /** - * Get Id - * - * @param string $input - * - * @return bool|string - */ - public function getId($input) - { - if (preg_match('~^([\'"]*)([0-9]*[a-zA-Z_]\w*)\1$~', $input, $match)) { - return $match[ 2 ]; - } - return false; - } - - /** - * Get variable name from string - * - * @param string $input - * - * @return bool|string - */ - public function getVariableName($input) - { - if (preg_match('~^[$]_smarty_tpl->tpl_vars\[[\'"]*([0-9]*[a-zA-Z_]\w*)[\'"]*\]->value$~', $input, $match)) { - return $match[ 1 ]; - } - return false; - } - - /** - * Set nocache flag in variable or create new variable - * - * @param string $varName - */ - public function setNocacheInVariable($varName) - { - // create nocache var to make it know for further compiling - if ($_var = $this->getId($varName)) { - if (isset($this->template->tpl_vars[ $_var ])) { - $this->template->tpl_vars[ $_var ] = clone $this->template->tpl_vars[ $_var ]; - $this->template->tpl_vars[ $_var ]->nocache = true; - } else { - $this->template->tpl_vars[ $_var ] = new \Smarty\Variable(null, true); - } - } - } - - /** - * @param array $_attr tag attributes - * @param array $validScopes - * - * @return int|string - * @throws \SmartyCompilerException - */ - public function convertScope($_attr, $validScopes) - { - $_scope = 0; - if (isset($_attr[ 'scope' ])) { - $_scopeName = trim($_attr[ 'scope' ], '\'"'); - if (is_numeric($_scopeName) && in_array($_scopeName, $validScopes)) { - $_scope = $_scopeName; - } elseif (is_string($_scopeName)) { - $_scopeName = trim($_scopeName, '\'"'); - $_scope = isset($validScopes[ $_scopeName ]) ? $validScopes[ $_scopeName ] : false; - } else { - $_scope = false; - } - if ($_scope === false) { - $err = var_export($_scopeName, true); - $this->trigger_template_error("illegal value '{$err}' for \"scope\" attribute", null, true); - } - } - return $_scope; - } - - /** - * Generate nocache code string - * - * @param string $code PHP code - * - * @return string - */ - public function makeNocacheCode($code) - { - return "echo '/*%%SmartyNocache:{$this->nocache_hash}%%*//*/%%SmartyNocache:{$this->nocache_hash}%%*/';\n"; - } - - /** - * display compiler error messages without dying - * If parameter $args is empty it is a parser detected syntax error. - * 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 null|bool $tagline if true the line number of last tag - * - * @throws \SmartyCompilerException when an unexpected token is found - */ - public function trigger_template_error($args = null, $line = null, $tagline = null) - { - $lex = $this->parser->lex; - if ($tagline === true) { - // get line number of Tag - $line = $lex->taglineno; - } 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 - ) - ); - } else { - $templateName = $this->template->source->type . ':' . $this->template->source->filepath; - } - // $line += $this->trace_line_offset; - $match = preg_split("/\n/", $lex->data); - $error_text = - 'Syntax error in template "' . (empty($this->trace_filepath) ? $templateName : $this->trace_filepath) . - '" on line ' . ($line + $this->trace_line_offset) . ' "' . - trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ])) . '" '; - if (isset($args)) { - // individual error message - $error_text .= $args; - } else { - $expect = array(); - // expected token from parser - $error_text .= ' - Unexpected "' . $lex->value . '"'; - if (count($this->parser->yy_get_expected_tokens($this->parser->yymajor)) <= 4) { - foreach ($this->parser->yy_get_expected_tokens($this->parser->yymajor) as $token) { - $exp_token = $this->parser->yyTokenName[ $token ]; - if (isset($lex->smarty_token_names[ $exp_token ])) { - // token type from lexer - $expect[] = '"' . $lex->smarty_token_names[ $exp_token ] . '"'; - } else { - // otherwise internal token name - $expect[] = $this->parser->yyTokenName[ $token ]; - } - } - $error_text .= ', expected one of: ' . implode(' , ', $expect); - } - } - if ($this->smarty->_parserdebug) { - $this->parser->errorRunDown(); - echo ob_get_clean(); - flush(); - } - $e = new SmartyCompilerException( - $error_text, - 0, - $this->template->source->filepath, - $line - ); - $e->source = trim(preg_replace('![\t\r\n]+!', ' ', $match[ $line - 1 ])); - $e->desc = $args; - $e->template = $this->template->source->filepath; - throw $e; - } - - /** - * Return var_export() value with all white spaces removed - * - * @param mixed $value - * - * @return string - */ - public function getVarExport($value) - { - return preg_replace('/\s/', '', var_export($value, true)); - } - - /** - * enter double quoted string - * - save tag stack count - */ - public function enterDoubleQuote() - { - array_push($this->_tag_stack_count, $this->getTagStackCount()); - } - - /** - * Return tag stack count - * - * @return int - */ - public function getTagStackCount() - { - return count($this->_tag_stack); - } - - /** - * @param $lexerPreg - * - * @return mixed - */ - 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 - ); - } - - /** - * Build lexer regular expressions for left and right delimiter and user defined literals - */ - public function initDelimiterPreg() - { - $ldel = $this->smarty->getLeftDelimiter(); - $this->ldelLength = strlen($ldel); - $this->ldelPreg = ''; - foreach (str_split($ldel, 1) as $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 .= '[' . preg_quote($chr,'/') . ']'; - } - $literals = $this->smarty->getLiterals(); - if (!empty($literals)) { - foreach ($literals as $key => $literal) { - $literalPreg = ''; - foreach (str_split($literal, 1) as $chr) { - $literalPreg .= '[' . preg_quote($chr,'/') . ']'; - } - $literals[ $key ] = $literalPreg; - } - $this->literalPreg = '|' . implode('|', $literals); - } else { - $this->literalPreg = ''; - } - } - - /** - * leave double quoted string - * - throw exception if block in string was not closed - * - * @throws \SmartyCompilerException - */ - public function leaveDoubleQuote() - { - if (array_pop($this->_tag_stack_count) !== $this->getTagStackCount()) { - $tag = $this->getOpenBlockTag(); - $this->trigger_template_error( - "unclosed '{{$tag}}' in doubled quoted string", - null, - true - ); - } - } - - /** - * Get left delimiter preg - * - * @return string - */ - public function getLdelPreg() - { - return $this->ldelPreg; - } - - /** - * Get right delimiter preg - * - * @return string - */ - public function getRdelPreg() - { - return $this->rdelPreg; - } - - /** - * Get length of left delimiter - * - * @return int - */ - public function getLdelLength() - { - return $this->ldelLength; - } - - /** - * Get length of right delimiter - * - * @return int - */ - public function getRdelLength() - { - return $this->rdelLength; - } - - /** - * Get name of current open block tag - * - * @return string|boolean - */ - public function getOpenBlockTag() - { - $tagCount = $this->getTagStackCount(); - if ($tagCount) { - return $this->_tag_stack[ $tagCount - 1 ][ 0 ]; - } else { - return false; - } - } - - /** - * Check if $value contains variable elements - * - * @param mixed $value - * - * @return bool|int - */ - public function isVariable($value) - { - if (is_string($value)) { - return preg_match('/[$(]/', $value); - } - if (is_bool($value) || is_numeric($value)) { - return false; - } - if (is_array($value)) { - foreach ($value as $k => $v) { - if ($this->isVariable($k) || $this->isVariable($v)) { - return true; - } - } - return false; - } - return false; - } - - /** - * Get new prefix variable name - * - * @return string - */ - public function getNewPrefixVariable() - { - ++self::$prefixVariableNumber; - return $this->getPrefixVariable(); - } - - /** - * Get current prefix variable name - * - * @return string - */ - public function getPrefixVariable() - { - return '$_prefixVariable' . self::$prefixVariableNumber; - } - - /** - * append code to prefix buffer - * - * @param string $code - */ - public function appendPrefixCode($code) - { - $this->prefix_code[] = $code; - } - - /** - * get prefix code string - * - * @return string - */ - public function getPrefixCode() - { - $code = ''; - $prefixArray = array_merge($this->prefix_code, array_pop($this->prefixCodeStack)); - $this->prefixCodeStack[] = array(); - foreach ($prefixArray as $c) { - $code = $this->appendCode($code, $c); - } - $this->prefix_code = array(); - return $code; - } - - /** - * method to compile a Smarty template - * - * @param mixed $_content template source - * @param bool $isTemplateSource - * - * @return bool true if compiling succeeded, false if it failed - */ - abstract protected function doCompile($_content, $isTemplateSource = false); - - public function cStyleComment($string) { - return '/*' . str_replace('*/', '* /' , $string) . '*/'; - } - - /** - * Compile Tag - * - * @param string $tag tag name - * @param array $args array with tag attributes - * @param array $parameter array with compilation parameter - * - * @throws SmartyCompilerException - * @throws SmartyException - * @return string compiled code - */ - private function compileTag2($tag, $args, $parameter) - { - $plugin_type = ''; - // $args contains the attributes parsed and compiled by the lexer/parser - // assume that tag does compile into code, but creates no HTML output - $this->has_code = true; - - // check nocache option flag - foreach ($args as $arg) { - if (!is_array($arg)) { - if ($arg === "'nocache'" || $arg === 'nocache') { - $this->tag_nocache = true; - } - } else { - foreach ($arg as $k => $v) { - if (($k === "'nocache'" || $k === 'nocache') && (trim($v, "'\" ") === 'true')) { - $this->tag_nocache = true; - } - } - } - } - // 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) - ) { - // template defined by {template} tag - $args[ '_attr' ][ 'name' ] = "'{$tag}'"; - $_output = $this->callTagCompiler('call', $args, $parameter); - } - } - if ($_output !== false) { - if ($_output !== true) { - // did we get compiled code - if ($this->has_code) { - // return compiled code - return $_output; - } - } - // tag did not produce compiled code - return null; - } else { - // map_named attributes - if (isset($args[ '_attr' ])) { - foreach ($args[ '_attr' ] as $key => $attribute) { - if (is_array($attribute)) { - $args = array_merge($args, $attribute); - } - } - } - // not an internal compiler tag - if (strlen($tag) < 6 || substr($tag, -5) !== 'close') { - // 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 ])) - ) { - return $this->callTagCompiler('private_object_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 - ); - } - } - // check if tag is registered - foreach (array( - \Smarty\Smarty::PLUGIN_COMPILER, - \Smarty\Smarty::PLUGIN_FUNCTION, - \Smarty\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\Smarty::PLUGIN_COMPILER) { - $new_args = array(); - foreach ($args as $key => $mixed) { - if (is_array($mixed)) { - $new_args = array_merge($new_args, $mixed); - } else { - $new_args[ $key ] = $mixed; - } - } - 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 - ) - ); - } - // compile registered function or block function - if ($plugin_type === \Smarty\Smarty::PLUGIN_FUNCTION || $plugin_type === \Smarty\Smarty::PLUGIN_BLOCK) { - 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\Smarty::PLUGIN_COMPILER - && (!isset($this->smarty->security_policy) - || $this->smarty->security_policy->isTrustedTag($tag, $this)) - ) { - $plugin = 'smarty_compiler_' . $tag; - if (is_callable($plugin)) { - // convert arguments format for old compiler plugins - $new_args = array(); - foreach ($args as $key => $mixed) { - if (is_array($mixed)) { - $new_args = array_merge($new_args, $mixed); - } else { - $new_args[ $key ] = $mixed; - } - } - return $plugin($new_args, $this->smarty); - } - if (class_exists($plugin, false)) { - $plugin_object = new $plugin; - if (method_exists($plugin_object, 'compile')) { - return $plugin_object->compile($args, $this); - } - } - 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) - ) { - return $this->callTagCompiler( - 'private_' . $plugin_type . '_plugin', - $args, - $parameter, - $tag, - $function - ); - } - } - } - } - if (is_callable($this->smarty->default_plugin_handler_func)) { - $found = false; - // look for already resolved tags - foreach ($this->plugin_search_order as $plugin_type) { - if (isset($this->default_handler_plugins[ $plugin_type ][ $tag ])) { - $found = true; - break; - } - } - if (!$found) { - // call default handler - foreach ($this->plugin_search_order as $plugin_type) { - if ($this->getPluginFromDefaultHandler($tag, $plugin_type)) { - $found = true; - break; - } - } - } - if ($found) { - // if compiler function plugin call it now - if ($plugin_type === \Smarty\Smarty::PLUGIN_COMPILER) { - $new_args = array(); - foreach ($args as $key => $mixed) { - if (is_array($mixed)) { - $new_args = array_merge($new_args, $mixed); - } else { - $new_args[ $key ] = $mixed; - } - } - 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 - ); - } - } - } - } else { - // compile closing tag of block function - $base_tag = substr($tag, 0, -5); - // check if closing tag is a registered object - 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 - ); - } else { - // throw exception - $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\Smarty::PLUGIN_BLOCK ][ $base_tag ]) - || isset($this->default_handler_plugins[ \Smarty\Smarty::PLUGIN_BLOCK ][ $base_tag ]) - ) { - return $this->callTagCompiler('private_registered_block', $args, $parameter, $tag); - } - // registered function tag ? - if (isset($this->smarty->registered_plugins[ \Smarty\Smarty::PLUGIN_FUNCTION ][ $tag ])) { - return $this->callTagCompiler('private_registered_function', $args, $parameter, $tag); - } - // block plugin? - if ($function = $this->getPlugin($base_tag, \Smarty\Smarty::PLUGIN_BLOCK)) { - return $this->callTagCompiler('private_block_plugin', $args, $parameter, $tag, $function); - } - // function plugin? - if ($function = $this->getPlugin($tag, \Smarty\Smarty::PLUGIN_FUNCTION)) { - if (!isset($this->smarty->security_policy) - || $this->smarty->security_policy->isTrustedTag($tag, $this) - ) { - return $this->callTagCompiler('private_function_plugin', $args, $parameter, $tag, $function); - } - } - // registered compiler plugin ? - if (isset($this->smarty->registered_plugins[ \Smarty\Smarty::PLUGIN_COMPILER ][ $tag ])) { - // if compiler function plugin call it now - $args = array(); - if (!$this->smarty->registered_plugins[ \Smarty\Smarty::PLUGIN_COMPILER ][ $tag ][ 1 ]) { - $this->tag_nocache = true; - } - return call_user_func_array( - $this->smarty->registered_plugins[ \Smarty\Smarty::PLUGIN_COMPILER ][ $tag ][ 0 ], - array( - $args, - $this - ) - ); - } - $plugin = 'smarty_compiler_' . $tag; - if (is_callable($plugin)) { - return $plugin($args, $this->smarty); - } - if (class_exists($plugin, false)) { - $plugin_object = new $plugin; - if (method_exists($plugin_object, 'compile')) { - return $plugin_object->compile($args, $this); - } - } - throw new SmartyException("Plugin '{$tag}' not callable"); - } - $this->trigger_template_error("unknown tag '{$tag}'", null, true); - } - } -} diff --git a/src/Lexer/smarty_internal_configfilelexer.plex b/src/Lexer/smarty_internal_configfilelexer.plex index 7a86fadc..2b2d9ae6 100644 --- a/src/Lexer/smarty_internal_configfilelexer.plex +++ b/src/Lexer/smarty_internal_configfilelexer.plex @@ -70,7 +70,7 @@ class Smarty_Internal_Configfilelexer /** * compiler object * - * @var Smarty_Internal_Config_File_Compiler + * @var Smarty\Compiler\ConfigFile */ private $compiler = null; /** @@ -122,9 +122,9 @@ class Smarty_Internal_Configfilelexer * constructor * * @param string $data template source - * @param Smarty_Internal_Config_File_Compiler $compiler + * @param Smarty\Compiler\ConfigFile $compiler */ - public function __construct($data, Smarty_Internal_Config_File_Compiler $compiler) + public function __construct($data, Smarty\Compiler\ConfigFile $compiler) { $this->data = $data . "\n"; //now all lines are \n-terminated $this->dataLength = strlen($data); diff --git a/src/Lexer/smarty_internal_templatelexer.plex b/src/Lexer/smarty_internal_templatelexer.plex index 63fad5e3..a5f21f8e 100644 --- a/src/Lexer/smarty_internal_templatelexer.plex +++ b/src/Lexer/smarty_internal_templatelexer.plex @@ -84,7 +84,7 @@ class Smarty_Internal_Templatelexer /** * compiler object * - * @var Smarty_Internal_TemplateCompilerBase + * @var \Smarty\Compiler\Template */ public $compiler = null; @@ -219,9 +219,9 @@ class Smarty_Internal_Templatelexer * constructor * * @param string $source template source - * @param Smarty_Internal_TemplateCompilerBase $compiler + * @param \Smarty\Compiler\Template $compiler */ - public function __construct($source, Smarty_Internal_TemplateCompilerBase $compiler) + public function __construct($source, \Smarty\Compiler\Template $compiler) { $this->data = $source; $this->dataLength = strlen($this->data); diff --git a/src/Parser/smarty_internal_configfileparser.y b/src/Parser/smarty_internal_configfileparser.y index 3996676c..213d7ebc 100644 --- a/src/Parser/smarty_internal_configfileparser.y +++ b/src/Parser/smarty_internal_configfileparser.y @@ -59,7 +59,7 @@ class Configfile /** * compiler object * - * @var Smarty_Internal_Config_File_Compiler + * @var Smarty\Compiler\ConfigFile */ public $compiler = null; /** @@ -92,9 +92,9 @@ class Configfile * constructor * * @param Lexer $lex - * @param Smarty_Internal_Config_File_Compiler $compiler + * @param Smarty\Compiler\ConfigFile $compiler */ - public function __construct(Lexer $lex, Smarty_Internal_Config_File_Compiler $compiler) + public function __construct(Lexer $lex, Smarty\Compiler\ConfigFile $compiler) { $this->lex = $lex; $this->smarty = $compiler->smarty; diff --git a/src/Parser/smarty_internal_templateparser.y b/src/Parser/smarty_internal_templateparser.y index dff453ec..65649200 100644 --- a/src/Parser/smarty_internal_templateparser.y +++ b/src/Parser/smarty_internal_templateparser.y @@ -94,7 +94,7 @@ class Smarty_Internal_Templateparser /** * compiler object * - * @var Smarty_Internal_TemplateCompilerBase + * @var \Smarty\Compiler\Template */ public $compiler = null; @@ -144,9 +144,9 @@ class Smarty_Internal_Templateparser * constructor * * @param Smarty_Internal_Templatelexer $lex - * @param Smarty_Internal_TemplateCompilerBase $compiler + * @param \Smarty\Compiler\Template $compiler */ - public function __construct(Smarty_Internal_Templatelexer $lex, Smarty_Internal_TemplateCompilerBase $compiler) + public function __construct(Smarty_Internal_Templatelexer $lex, \Smarty\Compiler\Template $compiler) { $this->lex = $lex; $this->compiler = $compiler; diff --git a/src/Template/CodeFrame.php b/src/Template/CodeFrame.php index 1ccf7f5f..974ead50 100644 --- a/src/Template/CodeFrame.php +++ b/src/Template/CodeFrame.php @@ -24,7 +24,7 @@ class CodeFrame * @param string $content optional template content * @param string $functions compiled template function and block code * @param bool $cache flag for cache file - * @param \Smarty_Internal_TemplateCompilerBase $compiler + * @param \Smarty\Compiler\Template $compiler * * @return string */ @@ -33,7 +33,7 @@ class CodeFrame $content = '', $functions = '', $cache = false, - \Smarty_Internal_TemplateCompilerBase $compiler = null + \Smarty\Compiler\Template $compiler = null ) { // build property code $properties[ 'version' ] = \Smarty::SMARTY_VERSION; diff --git a/src/Template/smarty_template_config.php b/src/Template/smarty_template_config.php index 850ae32e..d5cac3eb 100644 --- a/src/Template/smarty_template_config.php +++ b/src/Template/smarty_template_config.php @@ -43,7 +43,7 @@ class Smarty_Template_Config extends Smarty_Template_Source * * @var string */ - public $compiler_class = 'Smarty_Internal_Config_File_Compiler'; + public $compiler_class = 'Smarty\Compiler\ConfigFile'; /** * Name of the Class to tokenize this resource's contents with diff --git a/src/Template/smarty_template_source.php b/src/Template/smarty_template_source.php index a86e4feb..8ad039db 100644 --- a/src/Template/smarty_template_source.php +++ b/src/Template/smarty_template_source.php @@ -106,7 +106,7 @@ class Smarty_Template_Source * * @var string */ - public $compiler_class = 'Smarty_Internal_SmartyTemplateCompiler'; + public $compiler_class = 'Smarty\Compiler\Template'; /** * Name of the Class to tokenize this resource's contents with diff --git a/src/smarty_internal_template.php b/src/smarty_internal_template.php index 894d55c8..25f2e06e 100644 --- a/src/smarty_internal_template.php +++ b/src/smarty_internal_template.php @@ -16,7 +16,7 @@ * * @property Smarty_Template_Compiled $compiled * @property Smarty_Template_Cached $cached - * @property Smarty_Internal_TemplateCompilerBase $compiler + * @property \Smarty\Compiler\Template $compiler * @property mixed|\Smarty_Template_Cached registered_plugins * * The following methods will be dynamically loaded by the extension handler when they are called. @@ -624,11 +624,11 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase * @param string $content optional template content * @param string $functions compiled template function and block code * @param bool $cache flag for cache file - * @param \Smarty_Internal_TemplateCompilerBase $compiler + * @param \Smarty\Compiler\Template $compiler * * @return string */ - public function createCodeFrame($content = '', $functions = '', $cache = false, Smarty_Internal_TemplateCompilerBase $compiler = null) { + public function createCodeFrame($content = '', $functions = '', $cache = false, \Smarty\Compiler\Template $compiler = null) { return \Smarty\Template\CodeFrame::create($this, $content, $functions, $cache, $compiler); }