From 53fe73b9cc161103c4dc2ae10cc45f03ca0489bc Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Thu, 1 Dec 2022 21:53:05 +0100 Subject: [PATCH] WIP making compile classes PSR-4 --- src/Compile/Append.php | 2 +- src/Compile/Assign.php | 4 +- src/Compile/Base.php | 212 +++++++++++ src/Compile/Block.php | 96 +++++ src/Compile/Blockclose.php | 101 +++++ src/Compile/BreakTag.php | 121 ++++++ ...rty_internal_compile_call.php => Call.php} | 12 +- src/Compile/Child.php | 82 ++++ src/Compile/ConfigLoad.php | 94 +++++ src/Compile/Debug.php | 44 +++ src/Compile/EvalTag.php | 74 ++++ src/Compile/Include.php | 355 ++++++++++++++++++ src/Compile/Inheritance.php | 2 +- src/Compile/Insert.php | 161 ++++++++ src/Compile/Ldelim.php | 40 ++ src/Compile/PrivateModifier.php | 153 ++++++++ src/Compile/WhileTag.php | 67 ++++ src/Compile/Whileclose.php | 40 ++ ...ile_make_nocache.php => _make_nocache.php} | 8 +- ...k_plugin.php => _private_block_plugin.php} | 12 +- ...ection.php => _private_foreachsection.php} | 4 +- ...lugin.php => _private_function_plugin.php} | 10 +- ...ction.php => _private_object_function.php} | 18 +- ...sion.php => _private_print_expression.php} | 10 +- ...n.php => _private_registered_function.php} | 8 +- ...able.php => _private_special_variable.php} | 10 +- src/Compile/smarty_internal_compile_block.php | 188 ---------- .../smarty_internal_compile_block_child.php | 4 +- .../smarty_internal_compile_block_parent.php | 4 +- src/Compile/smarty_internal_compile_break.php | 117 ------ .../smarty_internal_compile_capture.php | 16 +- src/Compile/smarty_internal_compile_child.php | 79 ---- .../smarty_internal_compile_config_load.php | 96 ----- .../smarty_internal_compile_continue.php | 4 +- src/Compile/smarty_internal_compile_debug.php | 41 -- src/Compile/smarty_internal_compile_eval.php | 70 ---- .../smarty_internal_compile_extends.php | 7 +- src/Compile/smarty_internal_compile_for.php | 18 +- .../smarty_internal_compile_foreach.php | 26 +- .../smarty_internal_compile_function.php | 16 +- src/Compile/smarty_internal_compile_if.php | 17 +- .../smarty_internal_compile_include.php | 347 ----------------- .../smarty_internal_compile_insert.php | 157 -------- .../smarty_internal_compile_ldelim.php | 37 -- .../smarty_internal_compile_nocache.php | 12 +- .../smarty_internal_compile_parent.php | 4 +- ...arty_internal_compile_private_modifier.php | 150 -------- ..._compile_private_object_block_function.php | 2 +- ...ernal_compile_private_registered_block.php | 2 +- .../smarty_internal_compile_rdelim.php | 6 +- .../smarty_internal_compile_section.php | 24 +- .../smarty_internal_compile_setfilter.php | 10 +- src/Compile/smarty_internal_compile_while.php | 102 ----- src/Compile/smarty_internal_compilebase.php | 203 ---------- 54 files changed, 1798 insertions(+), 1701 deletions(-) create mode 100644 src/Compile/Base.php create mode 100644 src/Compile/Block.php create mode 100644 src/Compile/Blockclose.php create mode 100644 src/Compile/BreakTag.php rename src/Compile/{smarty_internal_compile_call.php => Call.php} (91%) create mode 100644 src/Compile/Child.php create mode 100644 src/Compile/ConfigLoad.php create mode 100644 src/Compile/Debug.php create mode 100644 src/Compile/EvalTag.php create mode 100644 src/Compile/Include.php create mode 100644 src/Compile/Insert.php create mode 100644 src/Compile/Ldelim.php create mode 100644 src/Compile/PrivateModifier.php create mode 100644 src/Compile/WhileTag.php create mode 100644 src/Compile/Whileclose.php rename src/Compile/{smarty_internal_compile_make_nocache.php => _make_nocache.php} (87%) rename src/Compile/{smarty_internal_compile_private_block_plugin.php => _private_block_plugin.php} (91%) rename src/Compile/{smarty_internal_compile_private_foreachsection.php => _private_foreachsection.php} (98%) rename src/Compile/{smarty_internal_compile_private_function_plugin.php => _private_function_plugin.php} (91%) rename src/Compile/{smarty_internal_compile_private_object_function.php => _private_object_function.php} (86%) rename src/Compile/{smarty_internal_compile_private_print_expression.php => _private_print_expression.php} (95%) rename src/Compile/{smarty_internal_compile_private_registered_function.php => _private_registered_function.php} (95%) rename src/Compile/{smarty_internal_compile_private_special_variable.php => _private_special_variable.php} (93%) delete mode 100644 src/Compile/smarty_internal_compile_block.php delete mode 100644 src/Compile/smarty_internal_compile_break.php delete mode 100644 src/Compile/smarty_internal_compile_child.php delete mode 100644 src/Compile/smarty_internal_compile_config_load.php delete mode 100644 src/Compile/smarty_internal_compile_debug.php delete mode 100644 src/Compile/smarty_internal_compile_eval.php delete mode 100644 src/Compile/smarty_internal_compile_include.php delete mode 100644 src/Compile/smarty_internal_compile_insert.php delete mode 100644 src/Compile/smarty_internal_compile_ldelim.php delete mode 100644 src/Compile/smarty_internal_compile_private_modifier.php delete mode 100644 src/Compile/smarty_internal_compile_while.php delete mode 100644 src/Compile/smarty_internal_compilebase.php diff --git a/src/Compile/Append.php b/src/Compile/Append.php index 707c9bc1..81dc1c05 100644 --- a/src/Compile/Append.php +++ b/src/Compile/Append.php @@ -29,7 +29,7 @@ class Append extends Assign * @return string compiled code * @throws \SmartyCompilerException */ - public function compile($args, \Smarty_Internal_TemplateCompilerBase $compiler, $parameter) + public function compile($args, Smarty_Internal_TemplateCompilerBase $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 f38c43b3..66421934 100644 --- a/src/Compile/Assign.php +++ b/src/Compile/Assign.php @@ -26,7 +26,7 @@ class Assign extends CompileBase * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $option_flags = array('nocache', 'noscope'); @@ -51,7 +51,7 @@ class Assign extends CompileBase * @return string compiled code * @throws \SmartyCompilerException */ - public function compile($args, \Smarty_Internal_TemplateCompilerBase $compiler, $parameter) + public function compile($args, Smarty_Internal_TemplateCompilerBase $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 new file mode 100644 index 00000000..4b5d864c --- /dev/null +++ b/src/Compile/Base.php @@ -0,0 +1,212 @@ + true, 0 => false, 'true' => true, 'false' => false]; + + /** + * Mapping array with attributes as key + * + * @var array + */ + protected $mapCache = []; + + /** + * This function checks if the attributes passed are valid + * The attributes passed for the tag to compile are checked against the list of required and + * optional attributes. Required attributes must be present. Optional attributes are check against + * the corresponding list. The keyword '_any' specifies that any attribute will be accepted + * as valid + * + * @param object $compiler compiler object + * @param array $attributes attributes applied to the tag + * + * @return array of mapped attributes for further processing + */ + protected function getAttributes($compiler, $attributes) { + $_indexed_attr = []; + if (!isset($this->mapCache['option'])) { + $this->mapCache['option'] = array_fill_keys($this->option_flags, true); + } + foreach ($attributes as $key => $mixed) { + // shorthand ? + if (!is_array($mixed)) { + // option flag ? + if (isset($this->mapCache['option'][trim($mixed, '\'"')])) { + $_indexed_attr[trim($mixed, '\'"')] = true; + // shorthand attribute ? + } elseif (isset($this->shorttag_order[$key])) { + $_indexed_attr[$this->shorttag_order[$key]] = $mixed; + } else { + // too many shorthands + $compiler->trigger_template_error('too many shorthand attributes', null, true); + } + // named attribute + } else { + foreach ($mixed as $k => $v) { + // option flag? + if (isset($this->mapCache['option'][$k])) { + if (is_bool($v)) { + $_indexed_attr[$k] = $v; + } else { + if (is_string($v)) { + $v = trim($v, '\'" '); + } + if (isset($this->optionMap[$v])) { + $_indexed_attr[$k] = $this->optionMap[$v]; + } else { + $compiler->trigger_template_error( + "illegal value '" . var_export($v, true) . + "' for option flag '{$k}'", + null, + true + ); + } + } + // must be named attribute + } else { + $_indexed_attr[$k] = $v; + } + } + } + } + // check if all required attributes present + foreach ($this->required_attributes as $attr) { + if (!isset($_indexed_attr[$attr])) { + $compiler->trigger_template_error("missing '{$attr}' attribute", null, true); + } + } + // check for not allowed attributes + if ($this->optional_attributes !== ['_any']) { + if (!isset($this->mapCache['all'])) { + $this->mapCache['all'] = + array_fill_keys( + array_merge( + $this->required_attributes, + $this->optional_attributes, + $this->option_flags + ), + true + ); + } + foreach ($_indexed_attr as $key => $dummy) { + if (!isset($this->mapCache['all'][$key]) && $key !== 0) { + $compiler->trigger_template_error("unexpected '{$key}' attribute", null, true); + } + } + } + // default 'false' for all option flags not set + foreach ($this->option_flags as $flag) { + if (!isset($_indexed_attr[$flag])) { + $_indexed_attr[$flag] = false; + } + } + if (isset($_indexed_attr['nocache']) && $_indexed_attr['nocache']) { + $compiler->tag_nocache = true; + } + return $_indexed_attr; + } + + /** + * Push opening tag name on stack + * Optionally additional data can be saved on stack + * + * @param object $compiler compiler object + * @param string $openTag the opening tag's name + * @param mixed $data optional data saved + */ + protected function openTag($compiler, $openTag, $data = null) { + array_push($compiler->_tag_stack, [$openTag, $data]); + } + + /** + * Pop closing tag + * Raise an error if this stack-top doesn't match with expected opening tags + * + * @param object $compiler compiler object + * @param array|string $expectedTag the expected opening tag names + * + * @return mixed any type the opening tag's name or saved data + */ + protected function closeTag($compiler, $expectedTag) { + if (count($compiler->_tag_stack) > 0) { + // get stacked info + [$_openTag, $_data] = array_pop($compiler->_tag_stack); + // open tag must match with the expected ones + if (in_array($_openTag, (array)$expectedTag)) { + if (is_null($_data)) { + // return opening tag + return $_openTag; + } else { + // return restored data + return $_data; + } + } + // wrong nesting of tags + $compiler->trigger_template_error("unclosed '{$compiler->smarty->left_delimiter}{$_openTag}{$compiler->smarty->right_delimiter}' tag"); + return; + } + // wrong nesting of tags + $compiler->trigger_template_error('unexpected closing tag', null, true); + } + + /** + * Compiles code for the tag + * + * @param array $args array with attributes from parser + * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object + * @param array $parameter array with compilation parameter + * + * @return string compiled code + * @throws \SmartyCompilerException + */ + abstract public function compile($args, \Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null); +} diff --git a/src/Compile/Block.php b/src/Compile/Block.php new file mode 100644 index 00000000..b6fb3d80 --- /dev/null +++ b/src/Compile/Block.php @@ -0,0 +1,96 @@ + + */ +class Block extends Inheritance { + + /** + * Attribute definition: Overwrites base class. + * + * @var array + * @see Base + */ + public $required_attributes = ['name']; + + /** + * Attribute definition: Overwrites base class. + * + * @var array + * @see Base + */ + public $shorttag_order = ['name']; + + /** + * Attribute definition: Overwrites base class. + * + * @var array + * @see Base + */ + public $option_flags = ['hide', 'nocache']; + + /** + * Attribute definition: Overwrites base class. + * + * @var array + * @see Base + */ + public $optional_attributes = ['assign']; + + /** + * Compiles code for the {block} tag + * + * @param array $args array with attributes from parser + * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object + * @param array $parameter array with compilation parameter + */ + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) + { + if (!isset($compiler->_cache['blockNesting'])) { + $compiler->_cache['blockNesting'] = 0; + } + if ($compiler->_cache['blockNesting'] === 0) { + // make sure that inheritance gets initialized in template code + $this->registerInit($compiler); + $this->option_flags = ['hide', 'nocache', 'append', 'prepend']; + } else { + $this->option_flags = ['hide', 'nocache']; + } + // check and get attributes + $_attr = $this->getAttributes($compiler, $args); + ++$compiler->_cache['blockNesting']; + $_className = 'Block_' . preg_replace('![^\w]+!', '_', uniqid(mt_rand(), true)); + $compiler->_cache['blockName'][$compiler->_cache['blockNesting']] = $_attr['name']; + $compiler->_cache['blockClass'][$compiler->_cache['blockNesting']] = $_className; + $compiler->_cache['blockParams'][$compiler->_cache['blockNesting']] = []; + $compiler->_cache['blockParams'][1]['subBlocks'][trim($_attr['name'], '"\'')][] = $_className; + $this->openTag( + $compiler, + 'block', + [ + $_attr, $compiler->nocache, $compiler->parser->current_buffer, + $compiler->template->compiled->has_nocache_code, + $compiler->template->caching, + ] + ); + $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; + $compiler->parser->current_buffer = new Template(); + $compiler->template->compiled->has_nocache_code = false; + $compiler->suppressNocacheProcessing = true; + } +} diff --git a/src/Compile/Blockclose.php b/src/Compile/Blockclose.php new file mode 100644 index 00000000..b74241f1 --- /dev/null +++ b/src/Compile/Blockclose.php @@ -0,0 +1,101 @@ +closeTag($compiler, ['block']); + // init block parameter + $_block = $compiler->_cache['blockParams'][$compiler->_cache['blockNesting']]; + unset($compiler->_cache['blockParams'][$compiler->_cache['blockNesting']]); + $_name = $_attr['name']; + $_assign = isset($_attr['assign']) ? $_attr['assign'] : null; + unset($_attr['assign'], $_attr['name']); + foreach ($_attr as $name => $stat) { + if ((is_bool($stat) && $stat !== false) || (!is_bool($stat) && $stat !== 'false')) { + $_block[$name] = 'true'; + } + } + $_className = $compiler->_cache['blockClass'][$compiler->_cache['blockNesting']]; + // get compiled block code + $_functionCode = $compiler->parser->current_buffer; + // setup buffer for template function code + $compiler->parser->current_buffer = new Template(); + $output = "cStyleComment(" {block {$_name}} ") . "\n"; + $output .= "class {$_className} extends \\Smarty\\Block\n"; + $output .= "{\n"; + foreach ($_block as $property => $value) { + $output .= "public \${$property} = " . var_export($value, true) . ";\n"; + } + $output .= "public function callBlock(Smarty_Internal_Template \$_smarty_tpl) {\n"; + if ($compiler->template->compiled->has_nocache_code) { + $output .= "\$_smarty_tpl->cached->hashes['{$compiler->template->compiled->nocache_hash}'] = true;\n"; + } + if (isset($_assign)) { + $output .= "ob_start();\n"; + } + $output .= "?>\n"; + $compiler->parser->current_buffer->append_subtree( + $compiler->parser, + new \Smarty\ParseTree\Tag( + $compiler->parser, + $output + ) + ); + $compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode); + $output = "assign({$_assign}, ob_get_clean());\n"; + } + $output .= "}\n"; + $output .= "}\n"; + $output .= $compiler->cStyleComment(" {/block {$_name}} ") . "\n\n"; + $output .= "?>\n"; + $compiler->parser->current_buffer->append_subtree( + $compiler->parser, + new \Smarty\ParseTree\Tag( + $compiler->parser, + $output + ) + ); + $compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser); + $compiler->parser->current_buffer = new Template(); + // restore old status + $compiler->template->compiled->has_nocache_code = $_has_nocache_code; + $compiler->tag_nocache = $compiler->nocache; + $compiler->nocache = $_nocache; + $compiler->parser->current_buffer = $_buffer; + $output = "_cache['blockNesting'] === 1) { + $output .= "\$_smarty_tpl->inheritance->instanceBlock(\$_smarty_tpl, '$_className', $_name);\n"; + } else { + $output .= "\$_smarty_tpl->inheritance->instanceBlock(\$_smarty_tpl, '$_className', $_name, \$this->tplIndex);\n"; + } + $output .= "?>\n"; + --$compiler->_cache['blockNesting']; + if ($compiler->_cache['blockNesting'] === 0) { + unset($compiler->_cache['blockNesting']); + } + $compiler->has_code = true; + $compiler->suppressNocacheProcessing = true; + return $output; + } +} \ No newline at end of file diff --git a/src/Compile/BreakTag.php b/src/Compile/BreakTag.php new file mode 100644 index 00000000..ebf3012d --- /dev/null +++ b/src/Compile/BreakTag.php @@ -0,0 +1,121 @@ +checkLevels($args, $compiler); + $output = " 0 && $this->tag === 'continue') { + $foreachLevels--; + } + if ($foreachLevels > 0) { + /* @var Smarty_Internal_Compile_Foreach $foreachCompiler */ + $foreachCompiler = $compiler->getTagCompiler('foreach'); + $output .= $foreachCompiler->compileRestore($foreachLevels); + } + $output .= "{$this->tag} {$levels};?>"; + return $output; + } + + /** + * check attributes and return array of break and foreach levels + * + * @param array $args array with attributes from parser + * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object + * + * @return array + * @throws \SmartyCompilerException + */ + public function checkLevels($args, Smarty_Internal_TemplateCompilerBase $compiler) { + static $_is_loopy = ['for' => true, 'foreach' => true, 'while' => true, 'section' => true]; + // check and get attributes + $_attr = $this->getAttributes($compiler, $args); + if ($_attr['nocache'] === true) { + $compiler->trigger_template_error('nocache option not allowed', null, true); + } + if (isset($_attr['levels'])) { + if (!is_numeric($_attr['levels'])) { + $compiler->trigger_template_error('level attribute must be a numeric constant', null, true); + } + $levels = $_attr['levels']; + } else { + $levels = 1; + } + $level_count = $levels; + $stack_count = count($compiler->_tag_stack) - 1; + $foreachLevels = 0; + $lastTag = ''; + while ($level_count > 0 && $stack_count >= 0) { + if (isset($_is_loopy[$compiler->_tag_stack[$stack_count][0]])) { + $lastTag = $compiler->_tag_stack[$stack_count][0]; + if ($level_count === 0) { + break; + } + $level_count--; + if ($compiler->_tag_stack[$stack_count][0] === 'foreach') { + $foreachLevels++; + } + } + $stack_count--; + } + if ($level_count !== 0) { + $compiler->trigger_template_error("cannot {$this->tag} {$levels} level(s)", null, true); + } + if ($lastTag === 'foreach' && $this->tag === 'break' && $foreachLevels > 0) { + $foreachLevels--; + } + return [$levels, $foreachLevels]; + } +} diff --git a/src/Compile/smarty_internal_compile_call.php b/src/Compile/Call.php similarity index 91% rename from src/Compile/smarty_internal_compile_call.php rename to src/Compile/Call.php index 445cabc6..5fa15a56 100644 --- a/src/Compile/smarty_internal_compile_call.php +++ b/src/Compile/Call.php @@ -8,19 +8,21 @@ * @author Uwe Tews */ +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Function_Call Class * * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase +class Call extends Base { /** * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $required_attributes = array('name'); @@ -28,7 +30,7 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $shorttag_order = array('name'); @@ -36,7 +38,7 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $optional_attributes = array('_any'); @@ -48,7 +50,7 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase * * @return string compiled code */ - public function compile($args, $compiler) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { // check and get attributes $_attr = $this->getAttributes($compiler, $args); diff --git a/src/Compile/Child.php b/src/Compile/Child.php new file mode 100644 index 00000000..ca6140f3 --- /dev/null +++ b/src/Compile/Child.php @@ -0,0 +1,82 @@ + + */ +class Child extends Base { + + /** + * Attribute definition: Overwrites base class. + * + * @var array + * @see Base + */ + protected $optional_attributes = ['assign']; + + /** + * Tag name + * + * @var string + */ + private $tag = 'child'; + + /** + * Block type + * + * @var string + */ + private $blockType = 'Child'; + + /** + * Compiles code for the {child} tag + * + * @param array $args array with attributes from parser + * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object + * @param array $parameter array with compilation parameter + * + * @return string compiled code + * @throws \SmartyCompilerException + */ + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) { + // check and get attributes + $_attr = $this->getAttributes($compiler, $args); + $tag = isset($parameter[0]) ? "'{$parameter[0]}'" : "'{{$this->tag}}'"; + if (!isset($compiler->_cache['blockNesting'])) { + $compiler->trigger_template_error( + "{$tag} used outside {block} tags ", + $compiler->parser->lex->taglineno + ); + } + $compiler->has_code = true; + $compiler->suppressNocacheProcessing = true; + if ($this->blockType === 'Child') { + $compiler->_cache['blockParams'][$compiler->_cache['blockNesting']]['callsChild'] = 'true'; + } + $_assign = $_attr['assign'] ?? null; + $output = "inheritance->call' . $this->blockType . '($_smarty_tpl, $this' . + ($this->blockType === 'Child' ? '' : ", {$tag}") . ");\n"; + if (isset($_assign)) { + $output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n"; + } + $output .= "?>\n"; + return $output; + } +} diff --git a/src/Compile/ConfigLoad.php b/src/Compile/ConfigLoad.php new file mode 100644 index 00000000..61227b19 --- /dev/null +++ b/src/Compile/ConfigLoad.php @@ -0,0 +1,94 @@ + Smarty::SCOPE_LOCAL, 'parent' => Smarty::SCOPE_PARENT, + 'root' => Smarty::SCOPE_ROOT, 'tpl_root' => Smarty::SCOPE_TPL_ROOT, + 'smarty' => Smarty::SCOPE_SMARTY, 'global' => Smarty::SCOPE_SMARTY, + ]; + + /** + * Compiles code for the {config_load} tag + * + * @param array $args array with attributes from parser + * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object + * + * @return string compiled code + * @throws \SmartyCompilerException + */ + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) { + // check and get attributes + $_attr = $this->getAttributes($compiler, $args); + if ($_attr['nocache'] === true) { + $compiler->trigger_template_error('nocache option not allowed', null, true); + } + // save possible attributes + $conf_file = $_attr['file']; + $section = $_attr['section'] ?? 'null'; + // scope setup + if ($_attr['noscope']) { + $_scope = -1; + } else { + $_scope = $compiler->convertScope($_attr, $this->valid_scopes); + } + // create config object + return "smarty->ext->configLoad->_loadConfigFile(\$_smarty_tpl, {$conf_file}, {$section}, {$_scope});\n?>\n"; + } +} diff --git a/src/Compile/Debug.php b/src/Compile/Debug.php new file mode 100644 index 00000000..d395d751 --- /dev/null +++ b/src/Compile/Debug.php @@ -0,0 +1,44 @@ +getAttributes($compiler, $args); + + // compile always as nocache + $compiler->tag_nocache = true; + // display debug template + $_output = + "display_debug(\$_smarty_tpl);\n"; + $_output .= "unset(\$_smarty_debug);\n?>"; + return $_output; + } +} diff --git a/src/Compile/EvalTag.php b/src/Compile/EvalTag.php new file mode 100644 index 00000000..a01947ce --- /dev/null +++ b/src/Compile/EvalTag.php @@ -0,0 +1,74 @@ +getAttributes($compiler, $args); + if (isset($_attr['assign'])) { + // output will be stored in a smarty variable instead of being displayed + $_assign = $_attr['assign']; + } + // create template object + $_output = + "\$_template = new {$compiler->smarty->template_class}('eval:'.{$_attr[ 'var' ]}, \$_smarty_tpl->smarty, \$_smarty_tpl);"; + //was there an assign attribute? + if (isset($_assign)) { + $_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());"; + } else { + $_output .= 'echo $_template->fetch();'; + } + return ""; + } +} diff --git a/src/Compile/Include.php b/src/Compile/Include.php new file mode 100644 index 00000000..26542721 --- /dev/null +++ b/src/Compile/Include.php @@ -0,0 +1,355 @@ + Smarty::SCOPE_PARENT, 'root' => Smarty::SCOPE_ROOT, + 'global' => Smarty::SCOPE_GLOBAL, 'tpl_root' => Smarty::SCOPE_TPL_ROOT, + 'smarty' => Smarty::SCOPE_SMARTY, + ]; + + /** + * Compiles code for the {include} tag + * + * @param array $args array with attributes from parser + * @param Smarty_Internal_SmartyTemplateCompiler $compiler compiler object + * + * @return string + * @throws \Exception + * @throws \SmartyCompilerException + * @throws \SmartyException + */ + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = [], $tag = null, $function = null) { + $uid = $t_hash = null; + // check and get attributes + $_attr = $this->getAttributes($compiler, $args); + $fullResourceName = $source_resource = $_attr['file']; + $variable_template = false; + $cache_tpl = false; + // parse resource_name + if (preg_match('/^([\'"])(([A-Za-z0-9_\-]{2,})[:])?(([^$()]+)|(.+))\1$/', $source_resource, $match)) { + $type = !empty($match[3]) ? $match[3] : $compiler->template->smarty->default_resource_type; + $name = !empty($match[5]) ? $match[5] : $match[6]; + $handler = Smarty_Resource::load($compiler->smarty, $type); + if ($handler->recompiled || $handler->uncompiled) { + $variable_template = true; + } + if (!$variable_template) { + if ($type !== 'string') { + $fullResourceName = "{$type}:{$name}"; + $compiled = $compiler->parent_compiler->template->compiled; + if (isset($compiled->includes[$fullResourceName])) { + $compiled->includes[$fullResourceName]++; + $cache_tpl = true; + } else { + if ("{$compiler->template->source->type}:{$compiler->template->source->name}" == + $fullResourceName + ) { + // recursive call of current template + $compiled->includes[$fullResourceName] = 2; + $cache_tpl = true; + } else { + $compiled->includes[$fullResourceName] = 1; + } + } + $fullResourceName = $match[1] . $fullResourceName . $match[1]; + } + } + if (empty($match[5])) { + $variable_template = true; + } + } else { + $variable_template = true; + } + // scope setup + $_scope = $compiler->convertScope($_attr, $this->valid_scopes); + // set flag to cache subtemplate object when called within loop or template name is variable. + if ($cache_tpl || $variable_template || $compiler->loopNesting > 0) { + $_cache_tpl = 'true'; + } else { + $_cache_tpl = 'false'; + } + // assume caching is off + $_caching = Smarty::CACHING_OFF; + $call_nocache = $compiler->tag_nocache || $compiler->nocache; + // caching was on and {include} is not in nocache mode + if ($compiler->template->caching && !$compiler->nocache && !$compiler->tag_nocache) { + $_caching = self::CACHING_NOCACHE_CODE; + } + // flag if included template code should be merged into caller + $merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || $_attr['inline'] === true) && + !$compiler->template->source->handler->recompiled; + if ($merge_compiled_includes) { + // variable template name ? + if ($variable_template) { + $merge_compiled_includes = false; + } + // variable compile_id? + if (isset($_attr['compile_id']) && $compiler->isVariable($_attr['compile_id'])) { + $merge_compiled_includes = false; + } + } + /* + * if the {include} tag provides individual parameter for caching or compile_id + * the subtemplate must not be included into the common cache file and is treated like + * a call in nocache mode. + * + */ + if ($_attr['nocache'] !== true && $_attr['caching']) { + $_caching = $_new_caching = (int)$_attr['caching']; + $call_nocache = true; + } else { + $_new_caching = Smarty::CACHING_LIFETIME_CURRENT; + } + if (isset($_attr['cache_lifetime'])) { + $_cache_lifetime = $_attr['cache_lifetime']; + $call_nocache = true; + $_caching = $_new_caching; + } else { + $_cache_lifetime = '$_smarty_tpl->cache_lifetime'; + } + if (isset($_attr['cache_id'])) { + $_cache_id = $_attr['cache_id']; + $call_nocache = true; + $_caching = $_new_caching; + } else { + $_cache_id = '$_smarty_tpl->cache_id'; + } + if (isset($_attr['compile_id'])) { + $_compile_id = $_attr['compile_id']; + } else { + $_compile_id = '$_smarty_tpl->compile_id'; + } + // if subtemplate will be called in nocache mode do not merge + if ($compiler->template->caching && $call_nocache) { + $merge_compiled_includes = false; + } + // assign attribute + if (isset($_attr['assign'])) { + // output will be stored in a smarty variable instead of being displayed + if ($_assign = $compiler->getId($_attr['assign'])) { + $_assign = "'{$_assign}'"; + if ($compiler->tag_nocache || $compiler->nocache || $call_nocache) { + // create nocache var to make it know for further compiling + $compiler->setNocacheInVariable($_attr['assign']); + } + } else { + $_assign = $_attr['assign']; + } + } + $has_compiled_template = false; + if ($merge_compiled_includes) { + $c_id = isset($_attr['compile_id']) ? $_attr['compile_id'] : $compiler->template->compile_id; + // we must observe different compile_id and caching + $t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching')); + $compiler->smarty->allow_ambiguous_resources = true; + /* @var Smarty_Internal_Template $tpl */ + $tpl = new $compiler->smarty->template_class( + trim($fullResourceName, '"\''), + $compiler->smarty, + $compiler->template, + $compiler->template->cache_id, + $c_id, + $_caching + ); + $uid = $tpl->source->type . $tpl->source->uid; + if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash])) { + $has_compiled_template = $this->compileInlineTemplate($compiler, $tpl, $t_hash); + } else { + $has_compiled_template = true; + } + unset($tpl); + } + // delete {include} standard attributes + unset($_attr['file'], $_attr['assign'], $_attr['cache_id'], $_attr['compile_id'], $_attr['cache_lifetime'], $_attr['nocache'], $_attr['caching'], $_attr['scope'], $_attr['inline']); + // remaining attributes must be assigned as smarty variable + $_vars = 'array()'; + if (!empty($_attr)) { + $_pairs = []; + // create variables + foreach ($_attr as $key => $value) { + $_pairs[] = "'$key'=>$value"; + } + $_vars = 'array(' . join(',', $_pairs) . ')'; + } + $update_compile_id = $compiler->template->caching && !$compiler->tag_nocache && !$compiler->nocache && + $_compile_id !== '$_smarty_tpl->compile_id'; + if ($has_compiled_template && !$call_nocache) { + $_output = "makeNocacheCode("\$_compile_id_save[] = \$_smarty_tpl->compile_id;\n\$_smarty_tpl->compile_id = {$_compile_id};\n"); + } + if (!empty($_attr) && $_caching === 9999 && $compiler->template->caching) { + $_vars_nc = "foreach ($_vars as \$ik => \$iv) {\n"; + $_vars_nc .= "\$_smarty_tpl->tpl_vars[\$ik] = new \\Smarty\\Variable(\$iv);\n"; + $_vars_nc .= "}\n"; + $_output .= substr($compiler->processNocacheCode('\n", true), 6, -3); + } + if (isset($_assign)) { + $_output .= "ob_start();\n"; + } + $_output .= "\$_smarty_tpl->_subTemplateRender({$fullResourceName}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_scope}, {$_cache_tpl}, '{$compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['uid']}', '{$compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['func']}');\n"; + if (isset($_assign)) { + $_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n"; + } + if ($update_compile_id) { + $_output .= $compiler->makeNocacheCode("\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n"); + } + $_output .= "?>"; + return $_output; + } + if ($call_nocache) { + $compiler->tag_nocache = true; + } + $_output = "compile_id;\n\$_smarty_tpl->compile_id = {$_compile_id};\n"; + } + // was there an assign attribute + if (isset($_assign)) { + $_output .= "ob_start();\n"; + } + $_output .= "\$_smarty_tpl->_subTemplateRender({$fullResourceName}, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_scope, {$_cache_tpl});\n"; + if (isset($_assign)) { + $_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n"; + } + if ($update_compile_id) { + $_output .= "\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n"; + } + $_output .= "?>"; + return $_output; + } + + /** + * Compile inline sub template + * + * @param \Smarty_Internal_SmartyTemplateCompiler $compiler + * @param \Smarty_Internal_Template $tpl + * @param string $t_hash + * + * @return bool + * @throws \Exception + * @throws \SmartyException + */ + private function compileInlineTemplate( + Smarty_Internal_SmartyTemplateCompiler $compiler, + Smarty_Internal_Template $tpl, + $t_hash + ) { + $uid = $tpl->source->type . $tpl->source->uid; + if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) { + $compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['uid'] = $tpl->source->uid; + if (isset($compiler->template->inheritance)) { + $tpl->inheritance = clone $compiler->template->inheritance; + } + $tpl->compiled = new Smarty_Template_Compiled(); + $tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash; + $tpl->loadCompiler(); + // save unique function name + $compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['func'] = + $tpl->compiled->unifunc = 'content_' . str_replace(['.', ','], '_', uniqid('', true)); + // make sure whole chain gets compiled + $tpl->mustCompile = true; + $compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['nocache_hash'] = + $tpl->compiled->nocache_hash; + if ($tpl->source->type === 'file') { + $sourceInfo = $tpl->source->filepath; + } else { + $basename = $tpl->source->handler->getBasename($tpl->source); + $sourceInfo = $tpl->source->type . ':' . + ($basename ? $basename : $tpl->source->name); + } + // get compiled code + $compiled_code = "cStyleComment(" Start inline template \"{$sourceInfo}\" =============================") . "\n"; + $compiled_code .= "function {$tpl->compiled->unifunc} (Smarty_Internal_Template \$_smarty_tpl) {\n"; + $compiled_code .= "?>\n" . $tpl->compiler->compileTemplateSource($tpl, null, $compiler->parent_compiler); + $compiled_code .= "\n"; + $compiled_code .= $tpl->compiler->postFilter($tpl->compiler->blockOrFunctionCode); + $compiled_code .= "cStyleComment(" End inline template \"{$sourceInfo}\" =============================") . "\n"; + $compiled_code .= '?>'; + unset($tpl->compiler); + if ($tpl->compiled->has_nocache_code) { + // replace nocache_hash + $compiled_code = + str_replace( + "{$tpl->compiled->nocache_hash}", + $compiler->template->compiled->nocache_hash, + $compiled_code + ); + $compiler->template->compiled->has_nocache_code = true; + } + $compiler->parent_compiler->mergedSubTemplatesCode[$tpl->compiled->unifunc] = $compiled_code; + return true; + } else { + return false; + } + } +} diff --git a/src/Compile/Inheritance.php b/src/Compile/Inheritance.php index ba226700..017ba306 100644 --- a/src/Compile/Inheritance.php +++ b/src/Compile/Inheritance.php @@ -17,7 +17,7 @@ namespace Smarty\Compile; * @package Smarty * @subpackage Compiler */ -abstract class Inheritance extends \Smarty_Internal_CompileBase +abstract class Inheritance extends \Smarty\Compile\Base { /** * Compile inheritance initialization code as prefix diff --git a/src/Compile/Insert.php b/src/Compile/Insert.php new file mode 100644 index 00000000..6345ec85 --- /dev/null +++ b/src/Compile/Insert.php @@ -0,0 +1,161 @@ +getAttributes($compiler, $args); + $nocacheParam = $compiler->template->caching && ($compiler->tag_nocache || $compiler->nocache); + if (!$nocacheParam) { + // do not compile as nocache code + $compiler->suppressNocacheProcessing = true; + } + $compiler->tag_nocache = true; + $_smarty_tpl = $compiler->template; + $_name = null; + $_script = null; + $_output = 'template->tpl_vars[$var])) { + $compiler->template->tpl_vars[$var]->nocache = true; + } else { + $compiler->template->tpl_vars[$var] = new Variable(null, true); + } + } + if (isset($_attr['script'])) { + // script which must be included + $_function = "smarty_insert_{$_name}"; + $_smarty_tpl = $compiler->template; + $_filepath = false; + eval('$_script = @' . $_attr['script'] . ';'); + if (!isset($compiler->smarty->security_policy) && file_exists($_script)) { + $_filepath = $_script; + } else { + if (isset($compiler->smarty->security_policy)) { + $_dir = $compiler->smarty->security_policy->trusted_dir; + } else { + $_dir = null; + } + if (!empty($_dir)) { + foreach ((array)$_dir as $_script_dir) { + $_script_dir = rtrim($_script_dir ?? '', '/\\') . DIRECTORY_SEPARATOR; + if (file_exists($_script_dir . $_script)) { + $_filepath = $_script_dir . $_script; + break; + } + } + } + } + if ($_filepath === false) { + $compiler->trigger_template_error("{insert} missing script file '{$_script}'", null, true); + } + // code for script file loading + $_output .= "require_once '{$_filepath}' ;"; + include_once $_filepath; + if (!is_callable($_function)) { + $compiler->trigger_template_error( + " {insert} function '{$_function}' is not callable in script file '{$_script}'", + null, + true + ); + } + } else { + $_filepath = 'null'; + $_function = "insert_{$_name}"; + // function in PHP script ? + if (!is_callable($_function)) { + // try plugin + if (!$_function = $compiler->getPlugin($_name, 'insert')) { + $compiler->trigger_template_error( + "{insert} no function or plugin found for '{$_name}'", + null, + true + ); + } + } + } + // delete {insert} standard attributes + unset($_attr['name'], $_attr['assign'], $_attr['script'], $_attr['nocache']); + // convert attributes into parameter array string + $_paramsArray = []; + foreach ($_attr as $_key => $_value) { + $_paramsArray[] = "'$_key' => $_value"; + } + $_params = 'array(' . implode(", ", $_paramsArray) . ')'; + // call insert + if (isset($_assign)) { + if ($_smarty_tpl->caching && !$nocacheParam) { + $_output .= "echo Smarty_Internal_Nocache_Insert::compile ('{$_function}',{$_params}, \$_smarty_tpl, '{$_filepath}',{$_assign});?>"; + } else { + $_output .= "\$_smarty_tpl->assign({$_assign} , {$_function} ({$_params},\$_smarty_tpl), true);?>"; + } + } else { + if ($_smarty_tpl->caching && !$nocacheParam) { + $_output .= "echo Smarty_Internal_Nocache_Insert::compile ('{$_function}',{$_params}, \$_smarty_tpl, '{$_filepath}');?>"; + } else { + $_output .= "echo {$_function}({$_params},\$_smarty_tpl);?>"; + } + } + $compiler->template->compiled->has_nocache_code = true; + return $_output; + } +} diff --git a/src/Compile/Ldelim.php b/src/Compile/Ldelim.php new file mode 100644 index 00000000..e015d1a0 --- /dev/null +++ b/src/Compile/Ldelim.php @@ -0,0 +1,40 @@ +getAttributes($compiler, $args); + if ($_attr['nocache'] === true) { + $compiler->trigger_template_error('nocache option not allowed', null, true); + } + return $compiler->smarty->left_delimiter; + } +} diff --git a/src/Compile/PrivateModifier.php b/src/Compile/PrivateModifier.php new file mode 100644 index 00000000..05a5995e --- /dev/null +++ b/src/Compile/PrivateModifier.php @@ -0,0 +1,153 @@ +getAttributes($compiler, $args); + $output = $parameter['value']; + // loop over list of modifiers + foreach ($parameter['modifierlist'] as $single_modifier) { + /* @var string $modifier */ + $modifier = $single_modifier[0]; + $single_modifier[0] = $output; + $params = implode(',', $single_modifier); + // check if we know already the type of modifier + if (isset($compiler->known_modifier_type[$modifier])) { + $modifier_types = [$compiler->known_modifier_type[$modifier]]; + } else { + $modifier_types = [1, 2, 3, 4, 5, 6]; + } + foreach ($modifier_types as $type) { + switch ($type) { + case 1: + // registered modifier + if (isset($compiler->smarty->registered_plugins[\Smarty\Smarty::PLUGIN_MODIFIER][$modifier])) { + if (is_callable($compiler->smarty->registered_plugins[\Smarty\Smarty::PLUGIN_MODIFIER][$modifier][0])) { + $output = + sprintf( + 'call_user_func_array($_smarty_tpl->registered_plugins[ \'%s\' ][ %s ][ 0 ], array( %s ))', + \Smarty\Smarty::PLUGIN_MODIFIER, + var_export($modifier, true), + $params + ); + $compiler->known_modifier_type[$modifier] = $type; + break 2; + } + } + break; + case 2: + // registered modifier compiler + if (isset($compiler->smarty->registered_plugins[\Smarty\Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0])) { + $output = + call_user_func( + $compiler->smarty->registered_plugins[\Smarty\Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0], + $single_modifier, + $compiler->smarty + ); + $compiler->known_modifier_type[$modifier] = $type; + break 2; + } + break; + case 3: + // modifiercompiler plugin + // check if modifier allowed + if (!is_object($compiler->smarty->security_policy) + || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) + ) { + $plugin = 'smarty_modifiercompiler_' . $modifier; + $output = $plugin($single_modifier, $compiler); + } + $compiler->known_modifier_type[$modifier] = $type; + break 2; + case 4: + // modifier plugin + if ($function = $compiler->getPlugin($modifier, \Smarty\Smarty::PLUGIN_MODIFIER)) { + // check if modifier allowed + if (!is_object($compiler->smarty->security_policy) + || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) + ) { + $output = "{$function}({$params})"; + } + $compiler->known_modifier_type[$modifier] = $type; + break 2; + } + break; + case 5: + // PHP function + if (is_callable($modifier)) { + // check if modifier allowed + if (!is_object($compiler->smarty->security_policy) + || $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler) + ) { + trigger_error('Using php-function "' . $modifier . '" as a modifier is deprecated and will be ' . + 'removed in a future release. Use Smarty::registerPlugin to explicitly register ' . + 'a custom modifier.', E_USER_DEPRECATED); + $output = "{$modifier}({$params})"; + } + $compiler->known_modifier_type[$modifier] = $type; + break 2; + } + break; + case 6: + // default plugin handler + if (isset($compiler->default_handler_plugins[\Smarty\Smarty::PLUGIN_MODIFIER][$modifier]) + || (is_callable($compiler->smarty->default_plugin_handler_func) + && $compiler->getPluginFromDefaultHandler($modifier, \Smarty\Smarty::PLUGIN_MODIFIER)) + ) { + $function = $compiler->default_handler_plugins[\Smarty\Smarty::PLUGIN_MODIFIER][$modifier][0]; + // check if modifier allowed + if (!is_object($compiler->smarty->security_policy) + || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) + ) { + if (!is_array($function)) { + $output = "{$function}({$params})"; + } else { + if (is_object($function[0])) { + $output = $function[0] . '->' . $function[1] . '(' . $params . ')'; + } else { + $output = $function[0] . '::' . $function[1] . '(' . $params . ')'; + } + } + } + $compiler->known_modifier_type[$modifier] = $type; + break 2; + } + } + } + if (!isset($compiler->known_modifier_type[$modifier])) { + $compiler->trigger_template_error("unknown modifier '{$modifier}'", null, true); + } + } + return $output; + } +} diff --git a/src/Compile/WhileTag.php b/src/Compile/WhileTag.php new file mode 100644 index 00000000..ce6c6aa5 --- /dev/null +++ b/src/Compile/WhileTag.php @@ -0,0 +1,67 @@ +loopNesting++; + // check and get attributes + $_attr = $this->getAttributes($compiler, $args); + $this->openTag($compiler, 'while', $compiler->nocache); + if (!array_key_exists('if condition', $parameter)) { + $compiler->trigger_template_error('missing while condition', null, true); + } + // maybe nocache because of nocache variables + $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; + if (is_array($parameter['if condition'])) { + if ($compiler->nocache) { + // create nocache var to make it know for further compiling + if (is_array($parameter['if condition']['var'])) { + $var = $parameter['if condition']['var']['var']; + } else { + $var = $parameter['if condition']['var']; + } + $compiler->setNocacheInVariable($var); + } + $prefixVar = $compiler->getNewPrefixVariable(); + $assignCompiler = new Assign(); + $assignAttr = []; + $assignAttr[]['value'] = $prefixVar; + if (is_array($parameter['if condition']['var'])) { + $assignAttr[]['var'] = $parameter['if condition']['var']['var']; + $_output = ""; + $_output .= $assignCompiler->compile( + $assignAttr, + $compiler, + ['smarty_internal_index' => $parameter['if condition']['var']['smarty_internal_index']] + ); + } else { + $assignAttr[]['var'] = $parameter['if condition']['var']; + $_output = ""; + $_output .= $assignCompiler->compile($assignAttr, $compiler, []); + } + return $_output; + } else { + return ""; + } + } +} \ No newline at end of file diff --git a/src/Compile/Whileclose.php b/src/Compile/Whileclose.php new file mode 100644 index 00000000..3f17c528 --- /dev/null +++ b/src/Compile/Whileclose.php @@ -0,0 +1,40 @@ +loopNesting--; + // must endblock be nocache? + if ($compiler->nocache) { + $compiler->tag_nocache = true; + } + $compiler->nocache = $this->closeTag($compiler, ['while']); + return "\n"; + } +} diff --git a/src/Compile/smarty_internal_compile_make_nocache.php b/src/Compile/_make_nocache.php similarity index 87% rename from src/Compile/smarty_internal_compile_make_nocache.php rename to src/Compile/_make_nocache.php index 8a34ccd0..e27bfb29 100644 --- a/src/Compile/smarty_internal_compile_make_nocache.php +++ b/src/Compile/_make_nocache.php @@ -8,19 +8,21 @@ * @author Uwe Tews */ +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Make_Nocache Class * * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Make_Nocache extends Smarty_Internal_CompileBase +class _Make_Nocache extends Base { /** * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $option_flags = array(); @@ -46,7 +48,7 @@ class Smarty_Internal_Compile_Make_Nocache extends Smarty_Internal_CompileBase * * @return string compiled code */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { // check and get attributes $_attr = $this->getAttributes($compiler, $args); diff --git a/src/Compile/smarty_internal_compile_private_block_plugin.php b/src/Compile/_private_block_plugin.php similarity index 91% rename from src/Compile/smarty_internal_compile_private_block_plugin.php rename to src/Compile/_private_block_plugin.php index 02b617aa..8b559f8a 100644 --- a/src/Compile/smarty_internal_compile_private_block_plugin.php +++ b/src/Compile/_private_block_plugin.php @@ -8,19 +8,21 @@ * @author Uwe Tews */ +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Block Plugin Class * * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_CompileBase +class _Private_Block_Plugin extends Base { /** * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $optional_attributes = array('_any'); @@ -44,7 +46,7 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi * @throws \SmartyCompilerException * @throws \SmartyException */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function = null) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { if (!isset($tag[ 5 ]) || substr($tag, -5) !== 'close') { // opening tag of block plugin @@ -52,7 +54,7 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi $_attr = $this->getAttributes($compiler, $args); $this->nesting++; unset($_attr[ 'nocache' ]); - list($callback, $_paramsArray, $callable) = $this->setup($compiler, $_attr, $tag, $function); + [$callback, $_paramsArray, $callable] = $this->setup($compiler, $_attr, $tag, $function); $_params = 'array(' . implode(',', $_paramsArray) . ')'; // compile code $output = "tag_nocache = true; } // closing tag of block plugin, restore nocache - list($_params, $compiler->nocache, $callback) = $this->closeTag($compiler, substr($tag, 0, -5)); + [$_params, $compiler->nocache, $callback] = $this->closeTag($compiler, substr($tag, 0, -5)); // compile code if (!isset($parameter[ 'modifier_list' ])) { $mod_pre = $mod_post = $mod_content = ''; diff --git a/src/Compile/smarty_internal_compile_private_foreachsection.php b/src/Compile/_private_foreachsection.php similarity index 98% rename from src/Compile/smarty_internal_compile_private_foreachsection.php rename to src/Compile/_private_foreachsection.php index 64d3e927..8bb1eb48 100644 --- a/src/Compile/smarty_internal_compile_private_foreachsection.php +++ b/src/Compile/_private_foreachsection.php @@ -8,13 +8,15 @@ * @author Uwe Tews */ +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile ForeachSection Class * * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_CompileBase +class _Private_ForeachSection extends Base { /** * Name of this tag diff --git a/src/Compile/smarty_internal_compile_private_function_plugin.php b/src/Compile/_private_function_plugin.php similarity index 91% rename from src/Compile/smarty_internal_compile_private_function_plugin.php rename to src/Compile/_private_function_plugin.php index 05582342..b334dbe1 100644 --- a/src/Compile/smarty_internal_compile_private_function_plugin.php +++ b/src/Compile/_private_function_plugin.php @@ -8,19 +8,21 @@ * @author Uwe Tews */ +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Function Plugin Class * * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_CompileBase +class _Private_Function_Plugin extends Base { /** * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $required_attributes = array(); @@ -28,7 +30,7 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $optional_attributes = array('_any'); @@ -45,7 +47,7 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co * @throws \SmartyCompilerException * @throws \SmartyException */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { // check and get attributes $_attr = $this->getAttributes($compiler, $args); diff --git a/src/Compile/smarty_internal_compile_private_object_function.php b/src/Compile/_private_object_function.php similarity index 86% rename from src/Compile/smarty_internal_compile_private_object_function.php rename to src/Compile/_private_object_function.php index 2a763c6e..05a2160b 100644 --- a/src/Compile/smarty_internal_compile_private_object_function.php +++ b/src/Compile/_private_object_function.php @@ -8,19 +8,21 @@ * @author Uwe Tews */ +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Object Function Class * * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_CompileBase +class _Private_Object_Function extends Base { /** * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $optional_attributes = array('_any'); @@ -31,13 +33,13 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object * @param array $parameter array with compilation parameter * @param string $tag name of function - * @param string $method name of method to call + * @param string $function name of method to call * * @return string compiled code * @throws \SmartyCompilerException * @throws \SmartyException */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $method) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { // check and get attributes $_attr = $this->getAttributes($compiler, $args); @@ -48,7 +50,7 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co unset($_attr[ 'assign' ]); } // method or property ? - if (is_callable(array($compiler->smarty->registered_objects[ $tag ][ 0 ], $method))) { + if (is_callable(array($compiler->smarty->registered_objects[ $tag ][ 0 ], $function))) { // convert attributes into parameter array string if ($compiler->smarty->registered_objects[ $tag ][ 2 ]) { $_paramsArray = array(); @@ -60,14 +62,14 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co } } $_params = 'array(' . implode(',', $_paramsArray) . ')'; - $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params},\$_smarty_tpl)"; + $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$function}({$_params},\$_smarty_tpl)"; } else { $_params = implode(',', $_attr); - $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params})"; + $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$function}({$_params})"; } } else { // object property - $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}"; + $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$function}"; } if (!empty($parameter[ 'modifierlist' ])) { $output = $compiler->compileTag( diff --git a/src/Compile/smarty_internal_compile_private_print_expression.php b/src/Compile/_private_print_expression.php similarity index 95% rename from src/Compile/smarty_internal_compile_private_print_expression.php rename to src/Compile/_private_print_expression.php index c49501d6..150a405c 100644 --- a/src/Compile/smarty_internal_compile_private_print_expression.php +++ b/src/Compile/_private_print_expression.php @@ -8,19 +8,21 @@ * @author Uwe Tews */ +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Print Expression Class * * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_CompileBase +class _Private_Print_Expression extends Base { /** * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $optional_attributes = array('assign'); @@ -28,7 +30,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $option_flags = array('nocache', 'nofilter'); @@ -42,7 +44,7 @@ class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_C * @return string * @throws \SmartyException */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { // check and get attributes $_attr = $this->getAttributes($compiler, $args); diff --git a/src/Compile/smarty_internal_compile_private_registered_function.php b/src/Compile/_private_registered_function.php similarity index 95% rename from src/Compile/smarty_internal_compile_private_registered_function.php rename to src/Compile/_private_registered_function.php index 2c560733..5f80f943 100644 --- a/src/Compile/smarty_internal_compile_private_registered_function.php +++ b/src/Compile/_private_registered_function.php @@ -8,19 +8,21 @@ * @author Uwe Tews */ +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Registered Function Class * * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Internal_CompileBase +class _Private_Registered_Function extends Base { /** * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $optional_attributes = array('_any'); @@ -36,7 +38,7 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna * @throws \SmartyCompilerException * @throws \SmartyException */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { // check and get attributes $_attr = $this->getAttributes($compiler, $args); diff --git a/src/Compile/smarty_internal_compile_private_special_variable.php b/src/Compile/_private_special_variable.php similarity index 93% rename from src/Compile/smarty_internal_compile_private_special_variable.php rename to src/Compile/_private_special_variable.php index 615e5aaa..a74a4e82 100644 --- a/src/Compile/smarty_internal_compile_private_special_variable.php +++ b/src/Compile/_private_special_variable.php @@ -8,13 +8,15 @@ * @author Uwe Tews */ +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile special Smarty Variable Class * * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_CompileBase +class _Private_Special_Variable extends Base { /** * Compiles code for the special $smarty variables @@ -26,7 +28,7 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C * @return string compiled code * @throws \SmartyCompilerException */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { $_index = preg_split("/\]\[/", substr($parameter, 1, strlen($parameter) - 2)); $variable = smarty_strtolower_ascii($compiler->getId($_index[ 0 ])); @@ -49,8 +51,8 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C $_index ); case 'capture': - if (class_exists('Smarty_Internal_Compile_Capture')) { - return Smarty_Internal_Compile_Capture::compileSpecialVariable(array(), $compiler, $_index); + if (class_exists('_Capture')) { + return _Capture::compileSpecialVariable(array(), $compiler, $_index); } return ''; case 'now': diff --git a/src/Compile/smarty_internal_compile_block.php b/src/Compile/smarty_internal_compile_block.php deleted file mode 100644 index 8e4a57c9..00000000 --- a/src/Compile/smarty_internal_compile_block.php +++ /dev/null @@ -1,188 +0,0 @@ - - */ -class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inheritance -{ - /** - * Attribute definition: Overwrites base class. - * - * @var array - * @see Smarty_Internal_CompileBase - */ - public $required_attributes = array('name'); - - /** - * Attribute definition: Overwrites base class. - * - * @var array - * @see Smarty_Internal_CompileBase - */ - public $shorttag_order = array('name'); - - /** - * Attribute definition: Overwrites base class. - * - * @var array - * @see Smarty_Internal_CompileBase - */ - public $option_flags = array('hide', 'nocache'); - - /** - * Attribute definition: Overwrites base class. - * - * @var array - * @see Smarty_Internal_CompileBase - */ - public $optional_attributes = array('assign'); - - /** - * Compiles code for the {block} tag - * - * @param array $args array with attributes from parser - * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object - * @param array $parameter array with compilation parameter - */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) - { - if (!isset($compiler->_cache[ 'blockNesting' ])) { - $compiler->_cache[ 'blockNesting' ] = 0; - } - if ($compiler->_cache[ 'blockNesting' ] === 0) { - // make sure that inheritance gets initialized in template code - $this->registerInit($compiler); - $this->option_flags = array('hide', 'nocache', 'append', 'prepend'); - } else { - $this->option_flags = array('hide', 'nocache'); - } - // check and get attributes - $_attr = $this->getAttributes($compiler, $args); - ++$compiler->_cache[ 'blockNesting' ]; - $_className = 'Block_' . preg_replace('![^\w]+!', '_', uniqid(mt_rand(), true)); - $compiler->_cache[ 'blockName' ][ $compiler->_cache[ 'blockNesting' ] ] = $_attr[ 'name' ]; - $compiler->_cache[ 'blockClass' ][ $compiler->_cache[ 'blockNesting' ] ] = $_className; - $compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ] = array(); - $compiler->_cache[ 'blockParams' ][ 1 ][ 'subBlocks' ][ trim($_attr[ 'name' ], '"\'') ][] = $_className; - $this->openTag( - $compiler, - 'block', - array( - $_attr, $compiler->nocache, $compiler->parser->current_buffer, - $compiler->template->compiled->has_nocache_code, - $compiler->template->caching - ) - ); - $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; - $compiler->parser->current_buffer = new \Smarty\ParseTree\Template(); - $compiler->template->compiled->has_nocache_code = false; - $compiler->suppressNocacheProcessing = true; - } -} - -/** - * Smarty Internal Plugin Compile BlockClose Class - */ -class Smarty_Internal_Compile_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 array $parameter array with compilation parameter - * - * @return bool true - */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) - { - [$_attr, $_nocache, $_buffer, $_has_nocache_code, $_caching] = $this->closeTag($compiler, array('block')); - // init block parameter - $_block = $compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ]; - unset($compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ]); - $_name = $_attr[ 'name' ]; - $_assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : null; - unset($_attr[ 'assign' ], $_attr[ 'name' ]); - foreach ($_attr as $name => $stat) { - if ((is_bool($stat) && $stat !== false) || (!is_bool($stat) && $stat !== 'false')) { - $_block[ $name ] = 'true'; - } - } - $_className = $compiler->_cache[ 'blockClass' ][ $compiler->_cache[ 'blockNesting' ] ]; - // get compiled block code - $_functionCode = $compiler->parser->current_buffer; - // setup buffer for template function code - $compiler->parser->current_buffer = new \Smarty\ParseTree\Template(); - $output = "cStyleComment(" {block {$_name}} ") . "\n"; - $output .= "class {$_className} extends \\Smarty\\Block\n"; - $output .= "{\n"; - foreach ($_block as $property => $value) { - $output .= "public \${$property} = " . var_export($value, true) . ";\n"; - } - $output .= "public function callBlock(Smarty_Internal_Template \$_smarty_tpl) {\n"; - if ($compiler->template->compiled->has_nocache_code) { - $output .= "\$_smarty_tpl->cached->hashes['{$compiler->template->compiled->nocache_hash}'] = true;\n"; - } - if (isset($_assign)) { - $output .= "ob_start();\n"; - } - $output .= "?>\n"; - $compiler->parser->current_buffer->append_subtree( - $compiler->parser, - new \Smarty\ParseTree\Tag( - $compiler->parser, - $output - ) - ); - $compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode); - $output = "assign({$_assign}, ob_get_clean());\n"; - } - $output .= "}\n"; - $output .= "}\n"; - $output .= $compiler->cStyleComment(" {/block {$_name}} ") . "\n\n"; - $output .= "?>\n"; - $compiler->parser->current_buffer->append_subtree( - $compiler->parser, - new \Smarty\ParseTree\Tag( - $compiler->parser, - $output - ) - ); - $compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser); - $compiler->parser->current_buffer = new \Smarty\ParseTree\Template(); - // restore old status - $compiler->template->compiled->has_nocache_code = $_has_nocache_code; - $compiler->tag_nocache = $compiler->nocache; - $compiler->nocache = $_nocache; - $compiler->parser->current_buffer = $_buffer; - $output = "_cache[ 'blockNesting' ] === 1) { - $output .= "\$_smarty_tpl->inheritance->instanceBlock(\$_smarty_tpl, '$_className', $_name);\n"; - } else { - $output .= "\$_smarty_tpl->inheritance->instanceBlock(\$_smarty_tpl, '$_className', $_name, \$this->tplIndex);\n"; - } - $output .= "?>\n"; - --$compiler->_cache[ 'blockNesting' ]; - if ($compiler->_cache[ 'blockNesting' ] === 0) { - unset($compiler->_cache[ 'blockNesting' ]); - } - $compiler->has_code = true; - $compiler->suppressNocacheProcessing = true; - return $output; - } -} diff --git a/src/Compile/smarty_internal_compile_block_child.php b/src/Compile/smarty_internal_compile_block_child.php index 588d1862..54114813 100644 --- a/src/Compile/smarty_internal_compile_block_child.php +++ b/src/Compile/smarty_internal_compile_block_child.php @@ -8,12 +8,14 @@ * file that was distributed with this source code. */ +use Smarty\Compile\Child; + /** * Smarty Internal Plugin Compile Block Child Class * * @author Uwe Tews */ -class Smarty_Internal_Compile_Block_Child extends Smarty_Internal_Compile_Child +class Smarty_Internal_Compile_Block_Child extends Child { /** * Tag name diff --git a/src/Compile/smarty_internal_compile_block_parent.php b/src/Compile/smarty_internal_compile_block_parent.php index 97f11ca4..ab902ff8 100644 --- a/src/Compile/smarty_internal_compile_block_parent.php +++ b/src/Compile/smarty_internal_compile_block_parent.php @@ -8,12 +8,14 @@ * file that was distributed with this source code. */ +use Smarty\Compile\Child; + /** * Smarty Internal Plugin Compile Block Parent Class * * @author Uwe Tews */ -class Smarty_Internal_Compile_Block_Parent extends Smarty_Internal_Compile_Child +class Smarty_Internal_Compile_Block_Parent extends Child { /** * Tag name diff --git a/src/Compile/smarty_internal_compile_break.php b/src/Compile/smarty_internal_compile_break.php deleted file mode 100644 index 1ee8d75d..00000000 --- a/src/Compile/smarty_internal_compile_break.php +++ /dev/null @@ -1,117 +0,0 @@ -checkLevels($args, $compiler); - $output = " 0 && $this->tag === 'continue') { - $foreachLevels--; - } - if ($foreachLevels > 0) { - /* @var Smarty_Internal_Compile_Foreach $foreachCompiler */ - $foreachCompiler = $compiler->getTagCompiler('foreach'); - $output .= $foreachCompiler->compileRestore($foreachLevels); - } - $output .= "{$this->tag} {$levels};?>"; - return $output; - } - - /** - * check attributes and return array of break and foreach levels - * - * @param array $args array with attributes from parser - * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object - * - * @return array - * @throws \SmartyCompilerException - */ - public function checkLevels($args, Smarty_Internal_TemplateCompilerBase $compiler) - { - static $_is_loopy = array('for' => true, 'foreach' => true, 'while' => true, 'section' => true); - // check and get attributes - $_attr = $this->getAttributes($compiler, $args); - if ($_attr[ 'nocache' ] === true) { - $compiler->trigger_template_error('nocache option not allowed', null, true); - } - if (isset($_attr[ 'levels' ])) { - if (!is_numeric($_attr[ 'levels' ])) { - $compiler->trigger_template_error('level attribute must be a numeric constant', null, true); - } - $levels = $_attr[ 'levels' ]; - } else { - $levels = 1; - } - $level_count = $levels; - $stack_count = count($compiler->_tag_stack) - 1; - $foreachLevels = 0; - $lastTag = ''; - while ($level_count > 0 && $stack_count >= 0) { - if (isset($_is_loopy[ $compiler->_tag_stack[ $stack_count ][ 0 ] ])) { - $lastTag = $compiler->_tag_stack[ $stack_count ][ 0 ]; - if ($level_count === 0) { - break; - } - $level_count--; - if ($compiler->_tag_stack[ $stack_count ][ 0 ] === 'foreach') { - $foreachLevels++; - } - } - $stack_count--; - } - if ($level_count !== 0) { - $compiler->trigger_template_error("cannot {$this->tag} {$levels} level(s)", null, true); - } - if ($lastTag === 'foreach' && $this->tag === 'break' && $foreachLevels > 0) { - $foreachLevels--; - } - return array($levels, $foreachLevels); - } -} diff --git a/src/Compile/smarty_internal_compile_capture.php b/src/Compile/smarty_internal_compile_capture.php index a4ffbc9e..b7c1b5cb 100644 --- a/src/Compile/smarty_internal_compile_capture.php +++ b/src/Compile/smarty_internal_compile_capture.php @@ -8,19 +8,21 @@ * @author Uwe Tews */ +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Capture Class * * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase +class _Capture extends Base { /** * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $shorttag_order = array('name'); @@ -28,7 +30,7 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $optional_attributes = array('name', 'assign', 'append'); @@ -59,7 +61,7 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase * * @return string compiled code */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = null) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { // check and get attributes $_attr = $this->getAttributes($compiler, $args, $parameter, 'capture'); @@ -80,7 +82,7 @@ class Smarty_Internal_Compile_Capture extends Smarty_Internal_CompileBase * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase +class _CaptureClose extends Base { /** * Compiles code for the {/capture} tag @@ -91,7 +93,7 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase * * @return string compiled code */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { // check and get attributes $_attr = $this->getAttributes($compiler, $args, $parameter, '/capture'); @@ -99,7 +101,7 @@ class Smarty_Internal_Compile_CaptureClose extends Smarty_Internal_CompileBase if ($compiler->nocache) { $compiler->tag_nocache = true; } - list($compiler->nocache) = array_pop($compiler->_cache[ 'capture_stack' ]); + [$compiler->nocache] = array_pop($compiler->_cache[ 'capture_stack' ]); return "smarty->ext->_capture->close(\$_smarty_tpl);?>"; } } diff --git a/src/Compile/smarty_internal_compile_child.php b/src/Compile/smarty_internal_compile_child.php deleted file mode 100644 index f728c18b..00000000 --- a/src/Compile/smarty_internal_compile_child.php +++ /dev/null @@ -1,79 +0,0 @@ - - */ -class Smarty_Internal_Compile_Child extends Smarty_Internal_CompileBase -{ - /** - * Attribute definition: Overwrites base class. - * - * @var array - * @see Smarty_Internal_CompileBase - */ - public $optional_attributes = array('assign'); - - /** - * Tag name - * - * @var string - */ - public $tag = 'child'; - - /** - * Block type - * - * @var string - */ - public $blockType = 'Child'; - - /** - * Compiles code for the {child} tag - * - * @param array $args array with attributes from parser - * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object - * @param array $parameter array with compilation parameter - * - * @return string compiled code - * @throws \SmartyCompilerException - */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) - { - // check and get attributes - $_attr = $this->getAttributes($compiler, $args); - $tag = isset($parameter[ 0 ]) ? "'{$parameter[0]}'" : "'{{$this->tag}}'"; - if (!isset($compiler->_cache[ 'blockNesting' ])) { - $compiler->trigger_template_error( - "{$tag} used outside {block} tags ", - $compiler->parser->lex->taglineno - ); - } - $compiler->has_code = true; - $compiler->suppressNocacheProcessing = true; - if ($this->blockType === 'Child') { - $compiler->_cache[ 'blockParams' ][ $compiler->_cache[ 'blockNesting' ] ][ 'callsChild' ] = 'true'; - } - $_assign = isset($_attr[ 'assign' ]) ? $_attr[ 'assign' ] : null; - $output = "inheritance->call' . $this->blockType . '($_smarty_tpl, $this' . - ($this->blockType === 'Child' ? '' : ", {$tag}") . ");\n"; - if (isset($_assign)) { - $output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n"; - } - $output .= "?>\n"; - return $output; - } -} diff --git a/src/Compile/smarty_internal_compile_config_load.php b/src/Compile/smarty_internal_compile_config_load.php deleted file mode 100644 index 2a775d56..00000000 --- a/src/Compile/smarty_internal_compile_config_load.php +++ /dev/null @@ -1,96 +0,0 @@ - \Smarty\Smarty::SCOPE_LOCAL, 'parent' => \Smarty\Smarty::SCOPE_PARENT, - 'root' => \Smarty\Smarty::SCOPE_ROOT, 'tpl_root' => \Smarty\Smarty::SCOPE_TPL_ROOT, - 'smarty' => \Smarty\Smarty::SCOPE_SMARTY, 'global' => \Smarty\Smarty::SCOPE_SMARTY - ); - - /** - * Compiles code for the {config_load} tag - * - * @param array $args array with attributes from parser - * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object - * - * @return string compiled code - * @throws \SmartyCompilerException - */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) - { - // check and get attributes - $_attr = $this->getAttributes($compiler, $args); - if ($_attr[ 'nocache' ] === true) { - $compiler->trigger_template_error('nocache option not allowed', null, true); - } - // save possible attributes - $conf_file = $_attr[ 'file' ]; - if (isset($_attr[ 'section' ])) { - $section = $_attr[ 'section' ]; - } else { - $section = 'null'; - } - // scope setup - if ($_attr[ 'noscope' ]) { - $_scope = -1; - } else { - $_scope = $compiler->convertScope($_attr, $this->valid_scopes); - } - // create config object - $_output = - "smarty->ext->configLoad->_loadConfigFile(\$_smarty_tpl, {$conf_file}, {$section}, {$_scope});\n?>\n"; - return $_output; - } -} diff --git a/src/Compile/smarty_internal_compile_continue.php b/src/Compile/smarty_internal_compile_continue.php index e545728e..1eefb7c7 100644 --- a/src/Compile/smarty_internal_compile_continue.php +++ b/src/Compile/smarty_internal_compile_continue.php @@ -8,13 +8,15 @@ * @author Uwe Tews */ +use Smarty\Compile\BreakTag; + /** * Smarty Internal Plugin Compile Continue Class * * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Continue extends Smarty_Internal_Compile_Break +class Smarty_Internal_Compile_Continue extends BreakTag { /** * Tag name diff --git a/src/Compile/smarty_internal_compile_debug.php b/src/Compile/smarty_internal_compile_debug.php deleted file mode 100644 index 16b63939..00000000 --- a/src/Compile/smarty_internal_compile_debug.php +++ /dev/null @@ -1,41 +0,0 @@ -getAttributes($compiler, $args); - - // compile always as nocache - $compiler->tag_nocache = true; - // display debug template - $_output = - "display_debug(\$_smarty_tpl);\n"; - $_output .= "unset(\$_smarty_debug);\n?>"; - return $_output; - } -} diff --git a/src/Compile/smarty_internal_compile_eval.php b/src/Compile/smarty_internal_compile_eval.php deleted file mode 100644 index 8e0174e3..00000000 --- a/src/Compile/smarty_internal_compile_eval.php +++ /dev/null @@ -1,70 +0,0 @@ -getAttributes($compiler, $args); - if (isset($_attr[ 'assign' ])) { - // output will be stored in a smarty variable instead of being displayed - $_assign = $_attr[ 'assign' ]; - } - // create template object - $_output = - "\$_template = new {$compiler->smarty->template_class}('eval:'.{$_attr[ 'var' ]}, \$_smarty_tpl->smarty, \$_smarty_tpl);"; - //was there an assign attribute? - if (isset($_assign)) { - $_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());"; - } else { - $_output .= 'echo $_template->fetch();'; - } - return ""; - } -} diff --git a/src/Compile/smarty_internal_compile_extends.php b/src/Compile/smarty_internal_compile_extends.php index ba874ed8..ba556453 100644 --- a/src/Compile/smarty_internal_compile_extends.php +++ b/src/Compile/smarty_internal_compile_extends.php @@ -9,6 +9,7 @@ */ use Smarty\Compile\Inheritance; +use Smarty\Compile\Base; /** * Smarty Internal Plugin Compile extend Class @@ -22,7 +23,7 @@ class Smarty_Internal_Compile_Extends extends Inheritance * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $required_attributes = array('file'); @@ -38,7 +39,7 @@ class Smarty_Internal_Compile_Extends extends Inheritance * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $shorttag_order = array('file'); @@ -52,7 +53,7 @@ class Smarty_Internal_Compile_Extends extends Inheritance * @throws \SmartyCompilerException * @throws \SmartyException */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { // check and get attributes $_attr = $this->getAttributes($compiler, $args); diff --git a/src/Compile/smarty_internal_compile_for.php b/src/Compile/smarty_internal_compile_for.php index 60ed31c8..9494dd57 100644 --- a/src/Compile/smarty_internal_compile_for.php +++ b/src/Compile/smarty_internal_compile_for.php @@ -8,13 +8,15 @@ * @author Uwe Tews */ +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile For Class * * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase +class _For extends Base { /** * Compiles code for the {for} tag @@ -32,7 +34,7 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase * * @return string compiled code */ - public function compile($args, $compiler, $parameter) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { $compiler->loopNesting++; if ($parameter === 0) { @@ -106,7 +108,7 @@ class Smarty_Internal_Compile_For extends Smarty_Internal_CompileBase * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Forelse extends Smarty_Internal_CompileBase +class _Forelse extends Base { /** * Compiles code for the {forelse} tag @@ -117,11 +119,11 @@ class Smarty_Internal_Compile_Forelse extends Smarty_Internal_CompileBase * * @return string compiled code */ - public function compile($args, $compiler, $parameter) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { // check and get attributes $_attr = $this->getAttributes($compiler, $args); - list($openTag, $nocache) = $this->closeTag($compiler, array('for')); + [$openTag, $nocache] = $this->closeTag($compiler, array('for')); $this->openTag($compiler, 'forelse', array('forelse', $nocache)); return ""; } @@ -133,7 +135,7 @@ class Smarty_Internal_Compile_Forelse extends Smarty_Internal_CompileBase * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase +class _Forclose extends Base { /** * Compiles code for the {/for} tag @@ -144,7 +146,7 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase * * @return string compiled code */ - public function compile($args, $compiler, $parameter) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { $compiler->loopNesting--; // check and get attributes @@ -153,7 +155,7 @@ class Smarty_Internal_Compile_Forclose extends Smarty_Internal_CompileBase if ($compiler->nocache) { $compiler->tag_nocache = true; } - list($openTag, $compiler->nocache) = $this->closeTag($compiler, array('for', 'forelse')); + [$openTag, $compiler->nocache] = $this->closeTag($compiler, array('for', 'forelse')); $output = "loopNesting++; // init @@ -277,7 +279,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase +class _Foreachelse extends Base { /** * Compiles code for the {foreachelse} tag @@ -287,11 +289,11 @@ class Smarty_Internal_Compile_Foreachelse extends Smarty_Internal_CompileBase * * @return string compiled code */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { // check and get attributes $_attr = $this->getAttributes($compiler, $args); - list($openTag, $nocache, $local, $itemVar, $restore) = $this->closeTag($compiler, array('foreach')); + [$openTag, $nocache, $local, $itemVar, $restore] = $this->closeTag($compiler, array('foreach')); $this->openTag($compiler, 'foreachelse', array('foreachelse', $nocache, $local, $itemVar, 0)); $output = "loopNesting--; // must endblock be nocache? if ($compiler->nocache) { $compiler->tag_nocache = true; } - list( + [ $openTag, $compiler->nocache, $local, $itemVar, $restore - ) = $this->closeTag($compiler, array('foreach', 'foreachelse')); + ] = $this->closeTag($compiler, array('foreach', 'foreachelse')); $output = "getAttributes($compiler, $args); @@ -82,7 +84,7 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase +class _Functionclose extends Base { /** * Compiler object @@ -99,7 +101,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase * * @return bool true */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { $this->compiler = $compiler; $saved_data = $this->closeTag($compiler, array('function')); diff --git a/src/Compile/smarty_internal_compile_if.php b/src/Compile/smarty_internal_compile_if.php index e33e316a..948d1c8d 100644 --- a/src/Compile/smarty_internal_compile_if.php +++ b/src/Compile/smarty_internal_compile_if.php @@ -9,6 +9,7 @@ */ use Smarty\Compile\Assign; +use Smarty\Compile\Base; /** * Smarty Internal Plugin Compile If Class @@ -16,7 +17,7 @@ use Smarty\Compile\Assign; * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase +class _If extends Base { /** * Compiles code for the {if} tag @@ -28,7 +29,7 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase * @return string compiled code * @throws \SmartyCompilerException */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { // check and get attributes $_attr = $this->getAttributes($compiler, $args); @@ -78,7 +79,7 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase +class _Else extends Base { /** * Compiles code for the {else} tag @@ -88,7 +89,7 @@ class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase * * @return string compiled code */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { [$nesting, $compiler->tag_nocache] = $this->closeTag($compiler, array('if', 'elseif')); $this->openTag($compiler, 'else', array($nesting, $compiler->tag_nocache)); @@ -102,7 +103,7 @@ class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase +class _Elseif extends Base { /** * Compiles code for the {elseif} tag @@ -114,7 +115,7 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase * @return string compiled code * @throws \SmartyCompilerException */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { // check and get attributes $_attr = $this->getAttributes($compiler, $args); @@ -183,7 +184,7 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase +class _Ifclose extends Base { /** * Compiles code for the {/if} tag @@ -193,7 +194,7 @@ class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase * * @return string compiled code */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { // must endblock be nocache? if ($compiler->nocache) { diff --git a/src/Compile/smarty_internal_compile_include.php b/src/Compile/smarty_internal_compile_include.php deleted file mode 100644 index 763bb245..00000000 --- a/src/Compile/smarty_internal_compile_include.php +++ /dev/null @@ -1,347 +0,0 @@ - \Smarty\Smarty::SCOPE_PARENT, 'root' => \Smarty\Smarty::SCOPE_ROOT, - 'global' => \Smarty\Smarty::SCOPE_GLOBAL, 'tpl_root' => \Smarty\Smarty::SCOPE_TPL_ROOT, - 'smarty' => \Smarty\Smarty::SCOPE_SMARTY - ); - - /** - * Compiles code for the {include} tag - * - * @param array $args array with attributes from parser - * @param Smarty_Internal_SmartyTemplateCompiler $compiler compiler object - * - * @return string - * @throws \Exception - * @throws \SmartyCompilerException - * @throws \SmartyException - */ - public function compile($args, Smarty_Internal_SmartyTemplateCompiler $compiler) - { - $uid = $t_hash = null; - // check and get attributes - $_attr = $this->getAttributes($compiler, $args); - $fullResourceName = $source_resource = $_attr[ 'file' ]; - $variable_template = false; - $cache_tpl = false; - // parse resource_name - if (preg_match('/^([\'"])(([A-Za-z0-9_\-]{2,})[:])?(([^$()]+)|(.+))\1$/', $source_resource, $match)) { - $type = !empty($match[ 3 ]) ? $match[ 3 ] : $compiler->template->smarty->default_resource_type; - $name = !empty($match[ 5 ]) ? $match[ 5 ] : $match[ 6 ]; - $handler = Smarty_Resource::load($compiler->smarty, $type); - if ($handler->recompiled || $handler->uncompiled) { - $variable_template = true; - } - if (!$variable_template) { - if ($type !== 'string') { - $fullResourceName = "{$type}:{$name}"; - $compiled = $compiler->parent_compiler->template->compiled; - if (isset($compiled->includes[ $fullResourceName ])) { - $compiled->includes[ $fullResourceName ]++; - $cache_tpl = true; - } else { - if ("{$compiler->template->source->type}:{$compiler->template->source->name}" == - $fullResourceName - ) { - // recursive call of current template - $compiled->includes[ $fullResourceName ] = 2; - $cache_tpl = true; - } else { - $compiled->includes[ $fullResourceName ] = 1; - } - } - $fullResourceName = $match[ 1 ] . $fullResourceName . $match[ 1 ]; - } - } - if (empty($match[ 5 ])) { - $variable_template = true; - } - } else { - $variable_template = true; - } - // scope setup - $_scope = $compiler->convertScope($_attr, $this->valid_scopes); - // set flag to cache subtemplate object when called within loop or template name is variable. - if ($cache_tpl || $variable_template || $compiler->loopNesting > 0) { - $_cache_tpl = 'true'; - } else { - $_cache_tpl = 'false'; - } - // assume caching is off - $_caching = \Smarty\Smarty::CACHING_OFF; - $call_nocache = $compiler->tag_nocache || $compiler->nocache; - // caching was on and {include} is not in nocache mode - if ($compiler->template->caching && !$compiler->nocache && !$compiler->tag_nocache) { - $_caching = self::CACHING_NOCACHE_CODE; - } - // flag if included template code should be merged into caller - $merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || $_attr[ 'inline' ] === true) && - !$compiler->template->source->handler->recompiled; - if ($merge_compiled_includes) { - // variable template name ? - if ($variable_template) { - $merge_compiled_includes = false; - } - // variable compile_id? - if (isset($_attr[ 'compile_id' ]) && $compiler->isVariable($_attr[ 'compile_id' ])) { - $merge_compiled_includes = false; - } - } - /* - * if the {include} tag provides individual parameter for caching or compile_id - * the subtemplate must not be included into the common cache file and is treated like - * a call in nocache mode. - * - */ - if ($_attr[ 'nocache' ] !== true && $_attr[ 'caching' ]) { - $_caching = $_new_caching = (int)$_attr[ 'caching' ]; - $call_nocache = true; - } else { - $_new_caching = \Smarty\Smarty::CACHING_LIFETIME_CURRENT; - } - if (isset($_attr[ 'cache_lifetime' ])) { - $_cache_lifetime = $_attr[ 'cache_lifetime' ]; - $call_nocache = true; - $_caching = $_new_caching; - } else { - $_cache_lifetime = '$_smarty_tpl->cache_lifetime'; - } - if (isset($_attr[ 'cache_id' ])) { - $_cache_id = $_attr[ 'cache_id' ]; - $call_nocache = true; - $_caching = $_new_caching; - } else { - $_cache_id = '$_smarty_tpl->cache_id'; - } - if (isset($_attr[ 'compile_id' ])) { - $_compile_id = $_attr[ 'compile_id' ]; - } else { - $_compile_id = '$_smarty_tpl->compile_id'; - } - // if subtemplate will be called in nocache mode do not merge - if ($compiler->template->caching && $call_nocache) { - $merge_compiled_includes = false; - } - // assign attribute - if (isset($_attr[ 'assign' ])) { - // output will be stored in a smarty variable instead of being displayed - if ($_assign = $compiler->getId($_attr[ 'assign' ])) { - $_assign = "'{$_assign}'"; - if ($compiler->tag_nocache || $compiler->nocache || $call_nocache) { - // create nocache var to make it know for further compiling - $compiler->setNocacheInVariable($_attr[ 'assign' ]); - } - } else { - $_assign = $_attr[ 'assign' ]; - } - } - $has_compiled_template = false; - if ($merge_compiled_includes) { - $c_id = isset($_attr[ 'compile_id' ]) ? $_attr[ 'compile_id' ] : $compiler->template->compile_id; - // we must observe different compile_id and caching - $t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching')); - $compiler->smarty->allow_ambiguous_resources = true; - /* @var Smarty_Internal_Template $tpl */ - $tpl = new $compiler->smarty->template_class( - trim($fullResourceName, '"\''), - $compiler->smarty, - $compiler->template, - $compiler->template->cache_id, - $c_id, - $_caching - ); - $uid = $tpl->source->type . $tpl->source->uid; - if (!isset($compiler->parent_compiler->mergedSubTemplatesData[ $uid ][ $t_hash ])) { - $has_compiled_template = $this->compileInlineTemplate($compiler, $tpl, $t_hash); - } else { - $has_compiled_template = true; - } - unset($tpl); - } - // delete {include} standard attributes - unset($_attr[ 'file' ], $_attr[ 'assign' ], $_attr[ 'cache_id' ], $_attr[ 'compile_id' ], $_attr[ 'cache_lifetime' ], $_attr[ 'nocache' ], $_attr[ 'caching' ], $_attr[ 'scope' ], $_attr[ 'inline' ]); - // remaining attributes must be assigned as smarty variable - $_vars = 'array()'; - if (!empty($_attr)) { - $_pairs = array(); - // create variables - foreach ($_attr as $key => $value) { - $_pairs[] = "'$key'=>$value"; - } - $_vars = 'array(' . join(',', $_pairs) . ')'; - } - $update_compile_id = $compiler->template->caching && !$compiler->tag_nocache && !$compiler->nocache && - $_compile_id !== '$_smarty_tpl->compile_id'; - if ($has_compiled_template && !$call_nocache) { - $_output = "makeNocacheCode("\$_compile_id_save[] = \$_smarty_tpl->compile_id;\n\$_smarty_tpl->compile_id = {$_compile_id};\n"); - } - if (!empty($_attr) && $_caching === 9999 && $compiler->template->caching) { - $_vars_nc = "foreach ($_vars as \$ik => \$iv) {\n"; - $_vars_nc .= "\$_smarty_tpl->tpl_vars[\$ik] = new \\Smarty\\Variable(\$iv);\n"; - $_vars_nc .= "}\n"; - $_output .= substr($compiler->processNocacheCode('\n", true), 6, -3); - } - if (isset($_assign)) { - $_output .= "ob_start();\n"; - } - $_output .= "\$_smarty_tpl->_subTemplateRender({$fullResourceName}, {$_cache_id}, {$_compile_id}, {$_caching}, {$_cache_lifetime}, {$_vars}, {$_scope}, {$_cache_tpl}, '{$compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['uid']}', '{$compiler->parent_compiler->mergedSubTemplatesData[$uid][$t_hash]['func']}');\n"; - if (isset($_assign)) { - $_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n"; - } - if ($update_compile_id) { - $_output .= $compiler->makeNocacheCode("\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n"); - } - $_output .= "?>"; - return $_output; - } - if ($call_nocache) { - $compiler->tag_nocache = true; - } - $_output = "compile_id;\n\$_smarty_tpl->compile_id = {$_compile_id};\n"; - } - // was there an assign attribute - if (isset($_assign)) { - $_output .= "ob_start();\n"; - } - $_output .= "\$_smarty_tpl->_subTemplateRender({$fullResourceName}, $_cache_id, $_compile_id, $_caching, $_cache_lifetime, $_vars, $_scope, {$_cache_tpl});\n"; - if (isset($_assign)) { - $_output .= "\$_smarty_tpl->assign({$_assign}, ob_get_clean());\n"; - } - if ($update_compile_id) { - $_output .= "\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n"; - } - $_output .= "?>"; - return $_output; - } - - /** - * Compile inline sub template - * - * @param \Smarty_Internal_SmartyTemplateCompiler $compiler - * @param \Smarty_Internal_Template $tpl - * @param string $t_hash - * - * @return bool - * @throws \Exception - * @throws \SmartyException - */ - public function compileInlineTemplate( - Smarty_Internal_SmartyTemplateCompiler $compiler, - Smarty_Internal_Template $tpl, - $t_hash - ) { - $uid = $tpl->source->type . $tpl->source->uid; - if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) { - $compiler->parent_compiler->mergedSubTemplatesData[ $uid ][ $t_hash ][ 'uid' ] = $tpl->source->uid; - if (isset($compiler->template->inheritance)) { - $tpl->inheritance = clone $compiler->template->inheritance; - } - $tpl->compiled = new Smarty_Template_Compiled(); - $tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash; - $tpl->loadCompiler(); - // save unique function name - $compiler->parent_compiler->mergedSubTemplatesData[ $uid ][ $t_hash ][ 'func' ] = - $tpl->compiled->unifunc = 'content_' . str_replace(array('.', ','), '_', uniqid('', true)); - // make sure whole chain gets compiled - $tpl->mustCompile = true; - $compiler->parent_compiler->mergedSubTemplatesData[ $uid ][ $t_hash ][ 'nocache_hash' ] = - $tpl->compiled->nocache_hash; - if ($tpl->source->type === 'file') { - $sourceInfo = $tpl->source->filepath; - } else { - $basename = $tpl->source->handler->getBasename($tpl->source); - $sourceInfo = $tpl->source->type . ':' . - ($basename ? $basename : $tpl->source->name); - } - // get compiled code - $compiled_code = "cStyleComment(" Start inline template \"{$sourceInfo}\" =============================") . "\n"; - $compiled_code .= "function {$tpl->compiled->unifunc} (Smarty_Internal_Template \$_smarty_tpl) {\n"; - $compiled_code .= "?>\n" . $tpl->compiler->compileTemplateSource($tpl, null, $compiler->parent_compiler); - $compiled_code .= "\n"; - $compiled_code .= $tpl->compiler->postFilter($tpl->compiler->blockOrFunctionCode); - $compiled_code .= "cStyleComment(" End inline template \"{$sourceInfo}\" =============================") . "\n"; - $compiled_code .= '?>'; - unset($tpl->compiler); - if ($tpl->compiled->has_nocache_code) { - // replace nocache_hash - $compiled_code = - str_replace( - "{$tpl->compiled->nocache_hash}", - $compiler->template->compiled->nocache_hash, - $compiled_code - ); - $compiler->template->compiled->has_nocache_code = true; - } - $compiler->parent_compiler->mergedSubTemplatesCode[ $tpl->compiled->unifunc ] = $compiled_code; - return true; - } else { - return false; - } - } -} diff --git a/src/Compile/smarty_internal_compile_insert.php b/src/Compile/smarty_internal_compile_insert.php deleted file mode 100644 index e0e2a256..00000000 --- a/src/Compile/smarty_internal_compile_insert.php +++ /dev/null @@ -1,157 +0,0 @@ -getAttributes($compiler, $args); - $nocacheParam = $compiler->template->caching && ($compiler->tag_nocache || $compiler->nocache); - if (!$nocacheParam) { - // do not compile as nocache code - $compiler->suppressNocacheProcessing = true; - } - $compiler->tag_nocache = true; - $_smarty_tpl = $compiler->template; - $_name = null; - $_script = null; - $_output = 'template->tpl_vars[ $var ])) { - $compiler->template->tpl_vars[ $var ]->nocache = true; - } else { - $compiler->template->tpl_vars[ $var ] = new \Smarty\Variable(null, true); - } - } - if (isset($_attr[ 'script' ])) { - // script which must be included - $_function = "smarty_insert_{$_name}"; - $_smarty_tpl = $compiler->template; - $_filepath = false; - eval('$_script = @' . $_attr[ 'script' ] . ';'); - if (!isset($compiler->smarty->security_policy) && file_exists($_script)) { - $_filepath = $_script; - } else { - if (isset($compiler->smarty->security_policy)) { - $_dir = $compiler->smarty->security_policy->trusted_dir; - } else { - $_dir = null; - } - if (!empty($_dir)) { - foreach ((array)$_dir as $_script_dir) { - $_script_dir = rtrim($_script_dir ?? '', '/\\') . DIRECTORY_SEPARATOR; - if (file_exists($_script_dir . $_script)) { - $_filepath = $_script_dir . $_script; - break; - } - } - } - } - if ($_filepath === false) { - $compiler->trigger_template_error("{insert} missing script file '{$_script}'", null, true); - } - // code for script file loading - $_output .= "require_once '{$_filepath}' ;"; - include_once $_filepath; - if (!is_callable($_function)) { - $compiler->trigger_template_error( - " {insert} function '{$_function}' is not callable in script file '{$_script}'", - null, - true - ); - } - } else { - $_filepath = 'null'; - $_function = "insert_{$_name}"; - // function in PHP script ? - if (!is_callable($_function)) { - // try plugin - if (!$_function = $compiler->getPlugin($_name, 'insert')) { - $compiler->trigger_template_error( - "{insert} no function or plugin found for '{$_name}'", - null, - true - ); - } - } - } - // delete {insert} standard attributes - unset($_attr[ 'name' ], $_attr[ 'assign' ], $_attr[ 'script' ], $_attr[ 'nocache' ]); - // convert attributes into parameter array string - $_paramsArray = array(); - foreach ($_attr as $_key => $_value) { - $_paramsArray[] = "'$_key' => $_value"; - } - $_params = 'array(' . implode(", ", $_paramsArray) . ')'; - // call insert - if (isset($_assign)) { - if ($_smarty_tpl->caching && !$nocacheParam) { - $_output .= "echo Smarty_Internal_Nocache_Insert::compile ('{$_function}',{$_params}, \$_smarty_tpl, '{$_filepath}',{$_assign});?>"; - } else { - $_output .= "\$_smarty_tpl->assign({$_assign} , {$_function} ({$_params},\$_smarty_tpl), true);?>"; - } - } else { - if ($_smarty_tpl->caching && !$nocacheParam) { - $_output .= "echo Smarty_Internal_Nocache_Insert::compile ('{$_function}',{$_params}, \$_smarty_tpl, '{$_filepath}');?>"; - } else { - $_output .= "echo {$_function}({$_params},\$_smarty_tpl);?>"; - } - } - $compiler->template->compiled->has_nocache_code = true; - return $_output; - } -} diff --git a/src/Compile/smarty_internal_compile_ldelim.php b/src/Compile/smarty_internal_compile_ldelim.php deleted file mode 100644 index 5493d4ec..00000000 --- a/src/Compile/smarty_internal_compile_ldelim.php +++ /dev/null @@ -1,37 +0,0 @@ -getAttributes($compiler, $args); - if ($_attr[ 'nocache' ] === true) { - $compiler->trigger_template_error('nocache option not allowed', null, true); - } - return $compiler->smarty->left_delimiter; - } -} diff --git a/src/Compile/smarty_internal_compile_nocache.php b/src/Compile/smarty_internal_compile_nocache.php index 12f64ed2..5b063c46 100644 --- a/src/Compile/smarty_internal_compile_nocache.php +++ b/src/Compile/smarty_internal_compile_nocache.php @@ -8,13 +8,15 @@ * @author Uwe Tews */ +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Nocache Class * * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Nocache extends Smarty_Internal_CompileBase +class _Nocache extends Base { /** * Array of names of valid option flags @@ -32,7 +34,7 @@ class Smarty_Internal_Compile_Nocache extends Smarty_Internal_CompileBase * * @return bool */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { $_attr = $this->getAttributes($compiler, $args); $this->openTag($compiler, 'nocache', array($compiler->nocache)); @@ -50,7 +52,7 @@ class Smarty_Internal_Compile_Nocache extends Smarty_Internal_CompileBase * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Nocacheclose extends Smarty_Internal_CompileBase +class _Nocacheclose extends Base { /** * Compiles code for the {/nocache} tag @@ -61,11 +63,11 @@ class Smarty_Internal_Compile_Nocacheclose extends Smarty_Internal_CompileBase * * @return bool */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { $_attr = $this->getAttributes($compiler, $args); // leave nocache mode - list($compiler->nocache) = $this->closeTag($compiler, array('nocache')); + [$compiler->nocache] = $this->closeTag($compiler, array('nocache')); // this tag does not return compiled code $compiler->has_code = false; return true; diff --git a/src/Compile/smarty_internal_compile_parent.php b/src/Compile/smarty_internal_compile_parent.php index ff23edf7..d1148948 100644 --- a/src/Compile/smarty_internal_compile_parent.php +++ b/src/Compile/smarty_internal_compile_parent.php @@ -8,12 +8,14 @@ * file that was distributed with this source code. */ +use Smarty\Compile\Child; + /** * Smarty Internal Plugin Compile Parent Class * * @author Uwe Tews */ -class Smarty_Internal_Compile_Parent extends Smarty_Internal_Compile_Child +class Smarty_Internal_Compile_Parent extends Child { /** * Tag name diff --git a/src/Compile/smarty_internal_compile_private_modifier.php b/src/Compile/smarty_internal_compile_private_modifier.php deleted file mode 100644 index 1f49643c..00000000 --- a/src/Compile/smarty_internal_compile_private_modifier.php +++ /dev/null @@ -1,150 +0,0 @@ -getAttributes($compiler, $args); - $output = $parameter[ 'value' ]; - // loop over list of modifiers - foreach ($parameter[ 'modifierlist' ] as $single_modifier) { - /* @var string $modifier */ - $modifier = $single_modifier[ 0 ]; - $single_modifier[ 0 ] = $output; - $params = implode(',', $single_modifier); - // check if we know already the type of modifier - if (isset($compiler->known_modifier_type[ $modifier ])) { - $modifier_types = array($compiler->known_modifier_type[ $modifier ]); - } else { - $modifier_types = array(1, 2, 3, 4, 5, 6); - } - foreach ($modifier_types as $type) { - switch ($type) { - case 1: - // registered modifier - if (isset($compiler->smarty->registered_plugins[ \Smarty\Smarty::PLUGIN_MODIFIER ][ $modifier ])) { - if (is_callable($compiler->smarty->registered_plugins[ \Smarty\Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ])) { - $output = - sprintf( - 'call_user_func_array($_smarty_tpl->registered_plugins[ \'%s\' ][ %s ][ 0 ], array( %s ))', - \Smarty\Smarty::PLUGIN_MODIFIER, - var_export($modifier, true), - $params - ); - $compiler->known_modifier_type[ $modifier ] = $type; - break 2; - } - } - break; - case 2: - // registered modifier compiler - if (isset($compiler->smarty->registered_plugins[ \Smarty\Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ])) { - $output = - call_user_func( - $compiler->smarty->registered_plugins[ \Smarty\Smarty::PLUGIN_MODIFIERCOMPILER ][ $modifier ][ 0 ], - $single_modifier, - $compiler->smarty - ); - $compiler->known_modifier_type[ $modifier ] = $type; - break 2; - } - break; - case 3: - // modifiercompiler plugin - // check if modifier allowed - if (!is_object($compiler->smarty->security_policy) - || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) - ) { - $plugin = 'smarty_modifiercompiler_' . $modifier; - $output = $plugin($single_modifier, $compiler); - } - $compiler->known_modifier_type[ $modifier ] = $type; - break 2; - case 4: - // modifier plugin - if ($function = $compiler->getPlugin($modifier, \Smarty\Smarty::PLUGIN_MODIFIER)) { - // check if modifier allowed - if (!is_object($compiler->smarty->security_policy) - || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) - ) { - $output = "{$function}({$params})"; - } - $compiler->known_modifier_type[ $modifier ] = $type; - break 2; - } - break; - case 5: - // PHP function - if (is_callable($modifier)) { - // check if modifier allowed - if (!is_object($compiler->smarty->security_policy) - || $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler) - ) { - trigger_error('Using php-function "' . $modifier . '" as a modifier is deprecated and will be ' . - 'removed in a future release. Use Smarty::registerPlugin to explicitly register ' . - 'a custom modifier.', E_USER_DEPRECATED); - $output = "{$modifier}({$params})"; - } - $compiler->known_modifier_type[ $modifier ] = $type; - break 2; - } - break; - case 6: - // default plugin handler - if (isset($compiler->default_handler_plugins[ \Smarty\Smarty::PLUGIN_MODIFIER ][ $modifier ]) - || (is_callable($compiler->smarty->default_plugin_handler_func) - && $compiler->getPluginFromDefaultHandler($modifier, \Smarty\Smarty::PLUGIN_MODIFIER)) - ) { - $function = $compiler->default_handler_plugins[ \Smarty\Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ]; - // check if modifier allowed - if (!is_object($compiler->smarty->security_policy) - || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler) - ) { - if (!is_array($function)) { - $output = "{$function}({$params})"; - } else { - if (is_object($function[ 0 ])) { - $output = $function[ 0 ] . '->' . $function[ 1 ] . '(' . $params . ')'; - } else { - $output = $function[ 0 ] . '::' . $function[ 1 ] . '(' . $params . ')'; - } - } - } - $compiler->known_modifier_type[ $modifier ] = $type; - break 2; - } - } - } - if (!isset($compiler->known_modifier_type[ $modifier ])) { - $compiler->trigger_template_error("unknown modifier '{$modifier}'", null, true); - } - } - return $output; - } -} diff --git a/src/Compile/smarty_internal_compile_private_object_block_function.php b/src/Compile/smarty_internal_compile_private_object_block_function.php index baac51b2..7868b716 100644 --- a/src/Compile/smarty_internal_compile_private_object_block_function.php +++ b/src/Compile/smarty_internal_compile_private_object_block_function.php @@ -14,7 +14,7 @@ * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Internal_Compile_Private_Block_Plugin +class Smarty_Internal_Compile_Private_Object_Block_Function extends _Private_Block_Plugin { /** * Setup callback and parameter array diff --git a/src/Compile/smarty_internal_compile_private_registered_block.php b/src/Compile/smarty_internal_compile_private_registered_block.php index 0f4cee2c..f78c81a0 100644 --- a/src/Compile/smarty_internal_compile_private_registered_block.php +++ b/src/Compile/smarty_internal_compile_private_registered_block.php @@ -14,7 +14,7 @@ * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_Compile_Private_Block_Plugin +class Smarty_Internal_Compile_Private_Registered_Block extends _Private_Block_Plugin { /** * Setup callback, parameter array and nocache mode diff --git a/src/Compile/smarty_internal_compile_rdelim.php b/src/Compile/smarty_internal_compile_rdelim.php index 1cc340c1..1025b5df 100644 --- a/src/Compile/smarty_internal_compile_rdelim.php +++ b/src/Compile/smarty_internal_compile_rdelim.php @@ -8,13 +8,15 @@ * @author Uwe Tews */ +use Smarty\Compile\Ldelim; + /** * Smarty Internal Plugin Compile Rdelim Class * * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Rdelim extends Smarty_Internal_Compile_Ldelim +class Smarty_Internal_Compile_Rdelim extends Ldelim { /** * Compiles code for the {rdelim} tag @@ -26,7 +28,7 @@ class Smarty_Internal_Compile_Rdelim extends Smarty_Internal_Compile_Ldelim * @return string compiled code * @throws \SmartyCompilerException */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { parent::compile($args, $compiler); return $compiler->smarty->right_delimiter; diff --git a/src/Compile/smarty_internal_compile_section.php b/src/Compile/smarty_internal_compile_section.php index 6568da5c..62a84ac5 100644 --- a/src/Compile/smarty_internal_compile_section.php +++ b/src/Compile/smarty_internal_compile_section.php @@ -8,19 +8,21 @@ * @author Uwe Tews */ +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Section Class * * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_ForeachSection +class Smarty_Internal_Compile_Section extends _Private_ForeachSection { /** * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $required_attributes = array('name', 'loop'); @@ -28,7 +30,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $shorttag_order = array('name', 'loop'); @@ -36,7 +38,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo * Attribute definition: Overwrites base class. * * @var array - * @see Smarty_Internal_CompileBase + * @see Base */ public $optional_attributes = array('start', 'step', 'max', 'show', 'properties'); @@ -88,7 +90,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo * @throws \SmartyCompilerException * @throws \SmartyException */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { $compiler->loopNesting++; // check and get attributes @@ -405,7 +407,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Sectionelse extends Smarty_Internal_CompileBase +class _Sectionelse extends Base { /** * Compiles code for the {sectionelse} tag @@ -415,11 +417,11 @@ class Smarty_Internal_Compile_Sectionelse extends Smarty_Internal_CompileBase * * @return string compiled code */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { // check and get attributes $_attr = $this->getAttributes($compiler, $args); - list($openTag, $nocache, $local, $sectionVar) = $this->closeTag($compiler, array('section')); + [$openTag, $nocache, $local, $sectionVar] = $this->closeTag($compiler, array('section')); $this->openTag($compiler, 'sectionelse', array('sectionelse', $nocache, $local, $sectionVar)); return ""; } @@ -431,7 +433,7 @@ class Smarty_Internal_Compile_Sectionelse extends Smarty_Internal_CompileBase * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase +class _Sectionclose extends Base { /** * Compiles code for the {/section} tag @@ -441,14 +443,14 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase * * @return string compiled code */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { $compiler->loopNesting--; // must endblock be nocache? if ($compiler->nocache) { $compiler->tag_nocache = true; } - list($openTag, $compiler->nocache, $local, $sectionVar) = + [$openTag, $compiler->nocache, $local, $sectionVar] = $this->closeTag($compiler, array('section', 'sectionelse')); $output = "variable_filter_stack[] = $compiler->variable_filters; $compiler->variable_filters = $parameter[ 'modifier_list' ]; @@ -41,7 +43,7 @@ class Smarty_Internal_Compile_Setfilter extends Smarty_Internal_CompileBase * @package Smarty * @subpackage Compiler */ -class Smarty_Internal_Compile_Setfilterclose extends Smarty_Internal_CompileBase +class _Setfilterclose extends Base { /** * Compiles code for the {/setfilter} tag @@ -52,7 +54,7 @@ class Smarty_Internal_Compile_Setfilterclose extends Smarty_Internal_CompileBase * * @return string compiled code */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter = array(), $tag = null, $function = null) { $_attr = $this->getAttributes($compiler, $args); // reset variable filter to previous state diff --git a/src/Compile/smarty_internal_compile_while.php b/src/Compile/smarty_internal_compile_while.php deleted file mode 100644 index 3d9e8f48..00000000 --- a/src/Compile/smarty_internal_compile_while.php +++ /dev/null @@ -1,102 +0,0 @@ -loopNesting++; - // check and get attributes - $_attr = $this->getAttributes($compiler, $args); - $this->openTag($compiler, 'while', $compiler->nocache); - if (!array_key_exists('if condition', $parameter)) { - $compiler->trigger_template_error('missing while condition', null, true); - } - // maybe nocache because of nocache variables - $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; - if (is_array($parameter[ 'if condition' ])) { - if ($compiler->nocache) { - // create nocache var to make it know for further compiling - if (is_array($parameter[ 'if condition' ][ 'var' ])) { - $var = $parameter[ 'if condition' ][ 'var' ][ 'var' ]; - } else { - $var = $parameter[ 'if condition' ][ 'var' ]; - } - $compiler->setNocacheInVariable($var); - } - $prefixVar = $compiler->getNewPrefixVariable(); - $assignCompiler = new Assign(); - $assignAttr = array(); - $assignAttr[][ 'value' ] = $prefixVar; - if (is_array($parameter[ 'if condition' ][ 'var' ])) { - $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ]; - $_output = ""; - $_output .= $assignCompiler->compile( - $assignAttr, - $compiler, - array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]) - ); - } else { - $assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ]; - $_output = ""; - $_output .= $assignCompiler->compile($assignAttr, $compiler, array()); - } - return $_output; - } else { - return ""; - } - } -} - -/** - * Smarty Internal Plugin Compile Whileclose Class - * - * @package Smarty - * @subpackage Compiler - */ -class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase -{ - /** - * Compiles code for the {/while} tag - * - * @param array $args array with attributes from parser - * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object - * - * @return string compiled code - */ - public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) - { - $compiler->loopNesting--; - // must endblock be nocache? - if ($compiler->nocache) { - $compiler->tag_nocache = true; - } - $compiler->nocache = $this->closeTag($compiler, array('while')); - return "\n"; - } -} diff --git a/src/Compile/smarty_internal_compilebase.php b/src/Compile/smarty_internal_compilebase.php deleted file mode 100644 index 2a32e437..00000000 --- a/src/Compile/smarty_internal_compilebase.php +++ /dev/null @@ -1,203 +0,0 @@ - true, 0 => false, 'true' => true, 'false' => false); - - /** - * Mapping array with attributes as key - * - * @var array - */ - public $mapCache = array(); - - /** - * This function checks if the attributes passed are valid - * The attributes passed for the tag to compile are checked against the list of required and - * optional attributes. Required attributes must be present. Optional attributes are check against - * the corresponding list. The keyword '_any' specifies that any attribute will be accepted - * as valid - * - * @param object $compiler compiler object - * @param array $attributes attributes applied to the tag - * - * @return array of mapped attributes for further processing - */ - public function getAttributes($compiler, $attributes) - { - $_indexed_attr = array(); - if (!isset($this->mapCache[ 'option' ])) { - $this->mapCache[ 'option' ] = array_fill_keys($this->option_flags, true); - } - foreach ($attributes as $key => $mixed) { - // shorthand ? - if (!is_array($mixed)) { - // option flag ? - if (isset($this->mapCache[ 'option' ][ trim($mixed, '\'"') ])) { - $_indexed_attr[ trim($mixed, '\'"') ] = true; - // shorthand attribute ? - } elseif (isset($this->shorttag_order[ $key ])) { - $_indexed_attr[ $this->shorttag_order[ $key ] ] = $mixed; - } else { - // too many shorthands - $compiler->trigger_template_error('too many shorthand attributes', null, true); - } - // named attribute - } else { - foreach ($mixed as $k => $v) { - // option flag? - if (isset($this->mapCache[ 'option' ][ $k ])) { - if (is_bool($v)) { - $_indexed_attr[ $k ] = $v; - } else { - if (is_string($v)) { - $v = trim($v, '\'" '); - } - if (isset($this->optionMap[ $v ])) { - $_indexed_attr[ $k ] = $this->optionMap[ $v ]; - } else { - $compiler->trigger_template_error( - "illegal value '" . var_export($v, true) . - "' for option flag '{$k}'", - null, - true - ); - } - } - // must be named attribute - } else { - $_indexed_attr[ $k ] = $v; - } - } - } - } - // check if all required attributes present - foreach ($this->required_attributes as $attr) { - if (!isset($_indexed_attr[ $attr ])) { - $compiler->trigger_template_error("missing '{$attr}' attribute", null, true); - } - } - // check for not allowed attributes - if ($this->optional_attributes !== array('_any')) { - if (!isset($this->mapCache[ 'all' ])) { - $this->mapCache[ 'all' ] = - array_fill_keys( - array_merge( - $this->required_attributes, - $this->optional_attributes, - $this->option_flags - ), - true - ); - } - foreach ($_indexed_attr as $key => $dummy) { - if (!isset($this->mapCache[ 'all' ][ $key ]) && $key !== 0) { - $compiler->trigger_template_error("unexpected '{$key}' attribute", null, true); - } - } - } - // default 'false' for all option flags not set - foreach ($this->option_flags as $flag) { - if (!isset($_indexed_attr[ $flag ])) { - $_indexed_attr[ $flag ] = false; - } - } - if (isset($_indexed_attr[ 'nocache' ]) && $_indexed_attr[ 'nocache' ]) { - $compiler->tag_nocache = true; - } - return $_indexed_attr; - } - - /** - * Push opening tag name on stack - * Optionally additional data can be saved on stack - * - * @param object $compiler compiler object - * @param string $openTag the opening tag's name - * @param mixed $data optional data saved - */ - public function openTag($compiler, $openTag, $data = null) - { - array_push($compiler->_tag_stack, array($openTag, $data)); - } - - /** - * Pop closing tag - * Raise an error if this stack-top doesn't match with expected opening tags - * - * @param object $compiler compiler object - * @param array|string $expectedTag the expected opening tag names - * - * @return mixed any type the opening tag's name or saved data - */ - public function closeTag($compiler, $expectedTag) - { - if (count($compiler->_tag_stack) > 0) { - // get stacked info - list($_openTag, $_data) = array_pop($compiler->_tag_stack); - // open tag must match with the expected ones - if (in_array($_openTag, (array)$expectedTag)) { - if (is_null($_data)) { - // return opening tag - return $_openTag; - } else { - // return restored data - return $_data; - } - } - // wrong nesting of tags - $compiler->trigger_template_error("unclosed '{$compiler->smarty->left_delimiter}{$_openTag}{$compiler->smarty->right_delimiter}' tag"); - return; - } - // wrong nesting of tags - $compiler->trigger_template_error('unexpected closing tag', null, true); - return; - } -}