diff options
author | emkael <emkael@tlen.pl> | 2018-10-18 02:40:38 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2018-10-18 02:40:38 +0200 |
commit | eab8a101e7a3fcbb41e01a574985e06c5a3775de (patch) | |
tree | 60f201da5984b0c3638d10da02bba42b61aa3177 /lib/smarty3/sysplugins/smarty_internal_compile_private_php.php | |
parent | 7f38be342c1495aeca418286c15c25c18ac9e142 (diff) |
Updating Smarty
Diffstat (limited to 'lib/smarty3/sysplugins/smarty_internal_compile_private_php.php')
-rw-r--r-- | lib/smarty3/sysplugins/smarty_internal_compile_private_php.php | 129 |
1 files changed, 81 insertions, 48 deletions
diff --git a/lib/smarty3/sysplugins/smarty_internal_compile_private_php.php b/lib/smarty3/sysplugins/smarty_internal_compile_private_php.php index 65d16a9..a3cf0a2 100644 --- a/lib/smarty3/sysplugins/smarty_internal_compile_private_php.php +++ b/lib/smarty3/sysplugins/smarty_internal_compile_private_php.php @@ -16,7 +16,6 @@ */ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase { - /** * Attribute definition: Overwrites base class. * @@ -40,45 +39,57 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase // check and get attributes $_attr = $this->getAttributes($compiler, $args); $compiler->has_code = false; - if ($_attr[ 'type' ] == 'xml') { + if ($_attr[ 'type' ] === 'xml') { $compiler->tag_nocache = true; - $save = $compiler->template->compiled->has_nocache_code; $output = addcslashes($_attr[ 'code' ], "'\\"); - $compiler->parser->current_buffer->append_subtree($compiler->parser, - new Smarty_Internal_ParseTree_Tag($compiler->parser, - $compiler->processNocacheCode("<?php echo '" . - $output . - "';?>", - true))); - $compiler->template->compiled->has_nocache_code = $save; + $compiler->parser->current_buffer->append_subtree( + $compiler->parser, + new Smarty_Internal_ParseTree_Tag( + $compiler->parser, + $compiler->processNocacheCode( + "<?php echo '{$output}';?>", + true + ) + ) + ); return ''; } - if ($_attr[ 'type' ] != 'tag') { - if ($compiler->php_handling == Smarty::PHP_REMOVE) { + if ($_attr[ 'type' ] !== 'tag') { + if ($compiler->php_handling === Smarty::PHP_REMOVE) { return ''; - } elseif ($compiler->php_handling == Smarty::PHP_QUOTE) { + } elseif ($compiler->php_handling === Smarty::PHP_QUOTE) { $output = - preg_replace_callback('#(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)|(\?>)|(%>)|(<\/script>)#i', - array($this, 'quote'), $_attr[ 'code' ]); - $compiler->parser->current_buffer->append_subtree($compiler->parser, - new Smarty_Internal_ParseTree_Text($output)); + preg_replace_callback( + '#(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)|(\?>)|(%>)|(<\/script>)#i', + array($this, 'quote'), + $_attr[ 'code' ] + ); + $compiler->parser->current_buffer->append_subtree( + $compiler->parser, + new Smarty_Internal_ParseTree_Text($output) + ); return ''; - } elseif ($compiler->php_handling == Smarty::PHP_PASSTHRU || $_attr[ 'type' ] == 'unmatched') { + } elseif ($compiler->php_handling === Smarty::PHP_PASSTHRU || $_attr[ 'type' ] === 'unmatched') { $compiler->tag_nocache = true; - $save = $compiler->template->compiled->has_nocache_code; $output = addcslashes($_attr[ 'code' ], "'\\"); - $compiler->parser->current_buffer->append_subtree($compiler->parser, - new Smarty_Internal_ParseTree_Tag($compiler->parser, - $compiler->processNocacheCode("<?php echo '" . - $output . - "';?>", - true))); - $compiler->template->compiled->has_nocache_code = $save; + $compiler->parser->current_buffer->append_subtree( + $compiler->parser, + new Smarty_Internal_ParseTree_Tag( + $compiler->parser, + $compiler->processNocacheCode( + "<?php echo '{$output}';?>", + true + ) + ) + ); return ''; - } elseif ($compiler->php_handling == Smarty::PHP_ALLOW) { + } elseif ($compiler->php_handling === Smarty::PHP_ALLOW) { if (!($compiler->smarty instanceof SmartyBC)) { - $compiler->trigger_template_error('$smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it', - null, true); + $compiler->trigger_template_error( + '$smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it', + null, + true + ); } $compiler->has_code = true; return $_attr[ 'code' ]; @@ -88,21 +99,27 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase } else { $compiler->has_code = true; if (!($compiler->smarty instanceof SmartyBC)) { - $compiler->trigger_template_error('{php}{/php} tags not allowed. Use SmartyBC to enable them', null, - true); + $compiler->trigger_template_error( + '{php}{/php} tags not allowed. Use SmartyBC to enable them', + null, + true + ); } $ldel = preg_quote($compiler->smarty->left_delimiter, '#'); $rdel = preg_quote($compiler->smarty->right_delimiter, '#'); preg_match("#^({$ldel}php\\s*)((.)*?)({$rdel})#", $_attr[ 'code' ], $match); if (!empty($match[ 2 ])) { - if ('nocache' == trim($match[ 2 ])) { + if ('nocache' === trim($match[ 2 ])) { $compiler->tag_nocache = true; } else { - $compiler->trigger_template_error("illegal value of option flag \"{$match[2]}\"", null, true); + $compiler->trigger_template_error("illegal value of option flag '{$match[2]}'", null, true); } } - return preg_replace(array("#^{$ldel}\\s*php\\s*(.)*?{$rdel}#", "#{$ldel}\\s*/\\s*php\\s*{$rdel}$#"), - array('<?php ', '?>'), $_attr[ 'code' ]); + return preg_replace( + array("#^{$ldel}\\s*php\\s*(.)*?{$rdel}#", "#{$ldel}\\s*/\\s*php\\s*{$rdel}$#"), + array('<?php ', '?>'), + $_attr[ 'code' ] + ); } } @@ -111,9 +128,11 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase * * This code has been moved from lexer here fo easier debugging and maintenance * - * @param $lex + * @param Smarty_Internal_Templatelexer $lex + * + * @throws \SmartyCompilerException */ - public function parsePhp($lex) + public function parsePhp(Smarty_Internal_Templatelexer $lex) { $lex->token = Smarty_Internal_Templateparser::TP_PHP; $close = 0; @@ -121,7 +140,7 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase $closeTag = '?>'; if (strpos($lex->value, '<?xml') === 0) { $lex->is_xml = true; - $lex->token = Smarty_Internal_Templateparser::TP_NOCACHE; + $lex->phpType = 'xml'; return; } elseif (strpos($lex->value, '<?') === 0) { $lex->phpType = 'php'; @@ -133,7 +152,7 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase } elseif (strpos($lex->value, '?>') === 0) { if ($lex->is_xml) { $lex->is_xml = false; - $lex->token = Smarty_Internal_Templateparser::TP_NOCACHE; + $lex->phpType = 'xml'; return; } $lex->phpType = 'unmatched'; @@ -146,16 +165,18 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase return; } $closeTag = "{$lex->smarty->left_delimiter}/php{$lex->smarty->right_delimiter}"; - if ($lex->value == $closeTag) { + if ($lex->value === $closeTag) { $lex->compiler->trigger_template_error("unexpected closing tag '{$closeTag}'"); } $lex->phpType = 'tag'; } - if ($lex->phpType == 'unmatched') { + if ($lex->phpType === 'unmatched') { return; } - if (($lex->phpType == 'php' || $lex->phpType == 'asp') && - ($lex->compiler->php_handling == Smarty::PHP_PASSTHRU || $lex->compiler->php_handling == Smarty::PHP_QUOTE) + if (($lex->phpType === 'php' || $lex->phpType === 'asp') + && + ($lex->compiler->php_handling === Smarty::PHP_PASSTHRU || + $lex->compiler->php_handling === Smarty::PHP_QUOTE) ) { return; } @@ -167,15 +188,21 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase $lex->compiler->trigger_template_error("missing closing tag '{$closeTag}'"); } while ($body) { - if (preg_match('~([/][*])|([/][/][^\n]*)|(\'[^\'\\\\]*(?:\\.[^\'\\\\]*)*\')|("[^"\\\\]*(?:\\.[^"\\\\]*)*")~', - $lex->data, $match, PREG_OFFSET_CAPTURE, $start)) { + if (preg_match( + '~([/][*])|([/][/][^\n]*)|(\'[^\'\\\\]*(?:\\.[^\'\\\\]*)*\')|("[^"\\\\]*(?:\\.[^"\\\\]*)*")~', + $lex->data, + $match, + PREG_OFFSET_CAPTURE, + $start + ) + ) { $value = $match[ 0 ][ 0 ]; $from = $pos = $match[ 0 ][ 1 ]; if ($pos > $close) { $body = false; } else { $start = $pos + strlen($value); - $phpCommentStart = $value == '/*'; + $phpCommentStart = $value === '/*'; if ($phpCommentStart) { $phpCommentEnd = preg_match('~([*][/])~', $lex->data, $match, PREG_OFFSET_CAPTURE, $start); if ($phpCommentEnd) { @@ -184,8 +211,14 @@ class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase } } while ($close > $pos && $close < $start) { - if (preg_match('~' . preg_quote($closeTag, '~') . '~i', $lex->data, $match, PREG_OFFSET_CAPTURE, - $from)) { + if (preg_match( + '~' . preg_quote($closeTag, '~') . '~i', + $lex->data, + $match, + PREG_OFFSET_CAPTURE, + $from + ) + ) { $close = $match[ 0 ][ 1 ]; $from = $close + strlen($match[ 0 ][ 0 ]); } else { |