Add makefile, PSR-4 ModifierCompilers

This commit is contained in:
Simon Wisselink
2022-12-23 14:03:05 +01:00
parent 4d66910e7f
commit 57cff64869
134 changed files with 1048 additions and 1084 deletions

4
.gitignore vendored
View File

@@ -11,3 +11,7 @@ phpunit*
.phpunit.result.cache
vendor/*
composer.lock
/src/Lexer/ConfigfileLexer.php
/src/Lexer/TemplateLexer.php
/src/Parser/ConfigfileParser.php
/src/Parser/TemplateParser.php

19
Makefile Normal file
View File

@@ -0,0 +1,19 @@
all: lexers parsers
lexers: src/Lexer/ConfigfileLexer.php src/Lexer/TemplateLexer.php
parsers: src/Parser/ConfigfileParser.php src/Parser/TemplateParser.php
src/Lexer/ConfigfileLexer.php: src/Lexer/ConfigfileLexer.plex
php ./utilities/make-lexer.php src/Lexer/ConfigfileLexer.plex src/Lexer/ConfigfileLexer.php
src/Lexer/TemplateLexer.php: src/Lexer/TemplateLexer.plex
php ./utilities/make-lexer.php src/Lexer/TemplateLexer.plex src/Lexer/TemplateLexer.php
src/Parser/ConfigfileParser.php: src/Parser/ConfigfileParser.y
php ./utilities/make-parser.php src/Parser/ConfigfileParser.y src/Parser/ConfigfileParser.php
src/Parser/TemplateParser.php: src/Parser/TemplateParser.y
php ./utilities/make-parser.php src/Parser/TemplateParser.y src/Parser/TemplateParser.php
clean:
rm -f src/Lexer/ConfigfileLexer.php src/Lexer/TemplateLexer.php src/Parser/ConfigfileParser.php src/Parser/TemplateParser.php

View File

@@ -1,9 +1,7 @@
- [ ] \Smarty\Cacheresource\Base::load generates classnames that are now invalid
- [ ] \Smarty\Resource\BasePlugin::load generates classnames that are now invalid
- [ ] consistent ConfigFile Configfile
## Data, TemplateBase, Smarty, Template, Debug, DataObject mess:
- [ ] review usages of ->_getSmartyObj and ->smarty: maybe change this so we can hide more
- [ ] ->_objType and ->objMap
- [ ] refactor _isTplObj, _isDataObj
- [ ] remove `require_once` calls from tests/*, especially where they load files from the demo dir
- [ ] look for and remove @method and @property phpdoc tags
- [ ] remove `require_once` calls from tests/*, especially where they load files from the demo dir

View File

@@ -36,7 +36,10 @@
"autoload": {
"psr-4" : {
"Smarty\\" : "src/"
}
},
"files": [
"src/functions.php"
]
},
"extra": {
"branch-alias": {
@@ -45,6 +48,12 @@
},
"require-dev": {
"phpunit/phpunit": "^8.5 || ^7.5",
"smarty/smarty-lexer": "^3.1"
}
"smarty/smarty-lexer": "@dev"
},
"repositories": [
{
"type": "path",
"url": "../smarty-lexer/"
}
]
}

View File

@@ -1,28 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty count_characters modifier plugin
* Type: modifier
* Name: count_characters
* Purpose: count the number of characters in a text
*
* @link https://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online
* manual)
* @author Uwe Tews
*
* @param array $params parameters
*
* @return string with compiled code
*/
function smarty_modifiercompiler_count_characters($params)
{
if (!isset($params[ 1 ]) || $params[ 1 ] !== 'true') {
return 'preg_match_all(\'/[^\s]/' . \Smarty\Smarty::$_UTF8_MODIFIER . '\',' . $params[ 0 ] . ', $tmp)';
}
return 'mb_strlen(' . $params[ 0 ] . ', \'' . addslashes(\Smarty\Smarty::$_CHARSET) . '\')';
}

View File

@@ -1,26 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty count_paragraphs modifier plugin
* Type: modifier
* Name: count_paragraphs
* Purpose: count the number of paragraphs in a text
*
* @link https://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
* count_paragraphs (Smarty online manual)
* @author Uwe Tews
*
* @param array $params parameters
*
* @return string with compiled code
*/
function smarty_modifiercompiler_count_paragraphs($params)
{
// count \r or \n characters
return '(preg_match_all(\'#[\r\n]+#\', ' . $params[ 0 ] . ', $tmp)+1)';
}

View File

@@ -1,26 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty count_sentences modifier plugin
* Type: modifier
* Name: count_sentences
* Purpose: count the number of sentences in a text
*
* @link https://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
* count_sentences (Smarty online manual)
* @author Uwe Tews
*
* @param array $params parameters
*
* @return string with compiled code
*/
function smarty_modifiercompiler_count_sentences($params)
{
// find periods, question marks, exclamation marks with a word before but not after.
return 'preg_match_all("#\w[\.\?\!](\W|$)#S' . \Smarty\Smarty::$_UTF8_MODIFIER . '", ' . $params[ 0 ] . ', $tmp)';
}

View File

@@ -1,26 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty count_words modifier plugin
* Type: modifier
* Name: count_words
* Purpose: count the number of words in a text
*
* @link https://www.smarty.net/manual/en/language.modifier.count.words.php count_words (Smarty online manual)
* @author Uwe Tews
*
* @param array $params parameters
*
* @return string with compiled code
*/
function smarty_modifiercompiler_count_words($params)
{
// expression taken from http://de.php.net/manual/en/function.str-word-count.php#85592
return 'preg_match_all(\'/\p{L}[\p{L}\p{Mn}\p{Pd}\\\'\x{2019}]*/' . \Smarty\Smarty::$_UTF8_MODIFIER . '\', ' .
$params[ 0 ] . ', $tmp)';
}

View File

@@ -1,32 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty default modifier plugin
* Type: modifier
* Name: default
* Purpose: designate default value for empty variables
*
* @link https://www.smarty.net/manual/en/language.modifier.default.php default (Smarty online manual)
* @author Uwe Tews
*
* @param array $params parameters
*
* @return string with compiled code
*/
function smarty_modifiercompiler_default($params)
{
$output = $params[ 0 ];
if (!isset($params[ 1 ])) {
$params[ 1 ] = "''";
}
array_shift($params);
foreach ($params as $param) {
$output = '(($tmp = ' . $output . ' ?? null)===null||$tmp===\'\' ? ' . $param . ' ?? null : $tmp)';
}
return $output;
}

View File

@@ -1,63 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
use Smarty\Exception;
/**
* Smarty escape modifier plugin
* Type: modifier
* Name: escape
* Purpose: escape string for output
*
* @link https://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual)
* @author Rodney Rehm
*
* @param array $params parameters
* @param \Smarty\Compiler\Template $compiler
*
* @return string with compiled code
* @throws Exception
*/
function smarty_modifiercompiler_escape($params, \Smarty\Compiler\Template $compiler)
{
try {
$esc_type = smarty_literal_compiler_param($params, 1, 'html');
$char_set = smarty_literal_compiler_param($params, 2, \Smarty\Smarty::$_CHARSET);
$double_encode = smarty_literal_compiler_param($params, 3, true);
if (!$char_set) {
$char_set = \Smarty\Smarty::$_CHARSET;
}
switch ($esc_type) {
case 'html':
return 'htmlspecialchars((string)' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' .
var_export($double_encode, true) . ')';
// no break
case 'htmlall':
return 'htmlentities(mb_convert_encoding((string)' . $params[ 0 ] . ', \'UTF-8\', ' .
var_export($char_set, true) . '), ENT_QUOTES, \'UTF-8\', ' .
var_export($double_encode, true) . ')';
// no break
case 'url':
return 'rawurlencode((string)' . $params[ 0 ] . ')';
case 'urlpathinfo':
return 'str_replace("%2F", "/", rawurlencode((string)' . $params[ 0 ] . '))';
case 'quotes':
// escape unescaped single quotes
return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'", (string)' . $params[ 0 ] . ')';
case 'javascript':
// escape quotes and backslashes, newlines, etc.
// see https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements
return 'strtr((string)' .
$params[ 0 ] .
', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/", "<!--" => "<\!--", "<s" => "<\s", "<S" => "<\S" ))';
}
} catch (Exception $e) {
// pass through to regular plugin fallback
}
return 'smarty_modifier_escape(' . join(', ', $params) . ')';
}

View File

@@ -1,26 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty from_charset modifier plugin
* Type: modifier
* Name: from_charset
* Purpose: convert character encoding from $charset to internal encoding
*
* @author Rodney Rehm
*
* @param array $params parameters
*
* @return string with compiled code
*/
function smarty_modifiercompiler_from_charset($params)
{
if (!isset($params[ 1 ])) {
$params[ 1 ] = '"ISO-8859-1"';
}
return 'mb_convert_encoding(' . $params[ 0 ] . ', "' . addslashes(\Smarty\Smarty::$_CHARSET) . '", ' . $params[ 1 ] . ')';
}

View File

@@ -1,30 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty indent modifier plugin
* Type: modifier
* Name: indent
* Purpose: indent lines of text
*
* @link https://www.smarty.net/manual/en/language.modifier.indent.php indent (Smarty online manual)
* @author Uwe Tews
*
* @param array $params parameters
*
* @return string with compiled code
*/
function smarty_modifiercompiler_indent($params)
{
if (!isset($params[ 1 ])) {
$params[ 1 ] = 4;
}
if (!isset($params[ 2 ])) {
$params[ 2 ] = "' '";
}
return 'preg_replace(\'!^!m\',str_repeat(' . $params[ 2 ] . ',' . $params[ 1 ] . '),' . $params[ 0 ] . ')';
}

View File

@@ -1,25 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty lower modifier plugin
* Type: modifier
* Name: lower
* Purpose: convert string to lowercase
*
* @link https://www.smarty.net/manual/en/language.modifier.lower.php lower (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @author Uwe Tews
*
* @param array $params parameters
*
* @return string with compiled code
*/
function smarty_modifiercompiler_lower($params)
{
return 'mb_strtolower(' . $params[ 0 ] . ', \'' . addslashes(\Smarty\Smarty::$_CHARSET) . '\')';
}

View File

@@ -1,23 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty nl2br modifier plugin
* Type: modifier
* Name: nl2br
* Purpose: insert HTML line breaks before all newlines in a string
*
* @link https://www.smarty.net/docs/en/language.modifier.nl2br.tpl nl2br (Smarty online manual)
*
* @param array $params parameters
*
* @return string with compiled code
*/
function smarty_modifiercompiler_nl2br($params) {
return 'nl2br((string) ' . $params[0] . ', (bool) ' . ($params[1] ?? true) . ')';
}

View File

@@ -1,20 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty noprint modifier plugin
* Type: modifier
* Name: noprint
* Purpose: return an empty string
*
* @author Uwe Tews
* @return string with compiled code
*/
function smarty_modifiercompiler_noprint()
{
return "''";
}

View File

@@ -1,23 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty round modifier plugin
* Type: modifier
* Name: round
* Purpose: Returns the rounded value of num to specified precision (number of digits after the decimal point)
*
* @link https://www.smarty.net/docs/en/language.modifier.round.tpl round (Smarty online manual)
*
* @param array $params parameters
*
* @return string with compiled code
*/
function smarty_modifiercompiler_round($params) {
return 'round((float) ' . $params[0] . ', (int) ' . ($params[1] ?? 0) . ', (int) ' . ($params[2] ?? PHP_ROUND_HALF_UP) . ')';
}

View File

@@ -1,23 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty str_repeat modifier plugin
* Type: modifier
* Name: str_repeat
* Purpose: returns string repeated times times
*
* @link https://www.smarty.net/docs/en/language.modifier.str_repeat.tpl str_repeat (Smarty online manual)
*
* @param array $params parameters
*
* @return string with compiled code
*/
function smarty_modifiercompiler_str_repeat($params) {
return 'str_repeat((string) ' . $params[0] . ', (int) ' . $params[1] . ')';
}

View File

@@ -1,24 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty string_format modifier plugin
* Type: modifier
* Name: string_format
* Purpose: format strings via sprintf
*
* @link https://www.smarty.net/manual/en/language.modifier.string.format.php string_format (Smarty online manual)
* @author Uwe Tews
*
* @param array $params parameters
*
* @return string with compiled code
*/
function smarty_modifiercompiler_string_format($params)
{
return 'sprintf(' . $params[ 1 ] . ',' . $params[ 0 ] . ')';
}

View File

@@ -1,28 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty strip_tags modifier plugin
* Type: modifier
* Name: strip_tags
* Purpose: strip html tags from text
*
* @link https://www.smarty.net/docs/en/language.modifier.strip.tags.tpl strip_tags (Smarty online manual)
* @author Uwe Tews
*
* @param array $params parameters
*
* @return string with compiled code
*/
function smarty_modifiercompiler_strip_tags($params)
{
if (!isset($params[ 1 ]) || $params[ 1 ] === true || trim($params[ 1 ], '"') === 'true') {
return "preg_replace('!<[^>]*?>!', ' ', {$params[0]} ?: '')";
} else {
return 'strip_tags((string) ' . $params[ 0 ] . ')';
}
}

View File

@@ -1,23 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty strlen modifier plugin
* Type: modifier
* Name: strlen
* Purpose: return the length of the given string
*
* @link https://www.smarty.net/docs/en/language.modifier.strlen.tpl strlen (Smarty online manual)
*
* @param array $params parameters
*
* @return string with compiled code
*/
function smarty_modifiercompiler_strlen($params) {
return 'strlen((string) ' . $params[0] . ')';
}

View File

@@ -1,26 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty to_charset modifier plugin
* Type: modifier
* Name: to_charset
* Purpose: convert character encoding from internal encoding to $charset
*
* @author Rodney Rehm
*
* @param array $params parameters
*
* @return string with compiled code
*/
function smarty_modifiercompiler_to_charset($params)
{
if (!isset($params[ 1 ])) {
$params[ 1 ] = '"ISO-8859-1"';
}
return 'mb_convert_encoding(' . $params[ 0 ] . ', ' . $params[ 1 ] . ', "' . addslashes(\Smarty\Smarty::$_CHARSET) . '")';
}

View File

@@ -1,40 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty unescape modifier plugin
* Type: modifier
* Name: unescape
* Purpose: unescape html entities
*
* @author Rodney Rehm
*
* @param array $params parameters
* @param \Smarty\Compiler\Template $compiler
*
* @return string with compiled code
*/
function smarty_modifiercompiler_unescape($params, \Smarty\Compiler\Template $compiler)
{
$esc_type = smarty_literal_compiler_param($params, 1, 'html');
if (!isset($params[ 2 ])) {
$params[ 2 ] = '\'' . addslashes(\Smarty\Smarty::$_CHARSET) . '\'';
}
switch ($esc_type) {
case 'entity':
case 'htmlall':
return 'html_entity_decode(mb_convert_encoding(' . $params[ 0 ] . ', ' . $params[ 2 ] . ', \'UTF-8\'), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, ' . $params[ 2 ] . ')';
case 'html':
return 'htmlspecialchars_decode(' . $params[ 0 ] . ', ENT_QUOTES)';
case 'url':
return 'rawurldecode(' . $params[ 0 ] . ')';
default:
return $params[ 0 ];
}
}

View File

@@ -1,24 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty upper modifier plugin
* Type: modifier
* Name: lower
* Purpose: convert string to uppercase
*
* @link https://www.smarty.net/manual/en/language.modifier.upper.php lower (Smarty online manual)
* @author Uwe Tews
*
* @param array $params parameters
*
* @return string with compiled code
*/
function smarty_modifiercompiler_upper($params)
{
return 'mb_strtoupper(' . $params[ 0 ] . ' ?? \'\', \'' . addslashes(\Smarty\Smarty::$_CHARSET) . '\')';
}

View File

@@ -1,36 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
/**
* Smarty wordwrap modifier plugin
* Type: modifier
* Name: wordwrap
* Purpose: wrap a string of text at a given length
*
* @link https://www.smarty.net/manual/en/language.modifier.wordwrap.php wordwrap (Smarty online manual)
* @author Uwe Tews
*
* @param array $params parameters
* @param \Smarty\Compiler\Template $compiler
*
* @return string with compiled code
* @throws \Smarty\Exception
*/
function smarty_modifiercompiler_wordwrap($params, \Smarty\Compiler\Template $compiler)
{
if (!isset($params[ 1 ])) {
$params[ 1 ] = 80;
}
if (!isset($params[ 2 ])) {
$params[ 2 ] = '"\n"';
}
if (!isset($params[ 3 ])) {
$params[ 3 ] = 'false';
}
$function = $compiler->getPlugin('mb_wordwrap', 'modifier');
return $function . '(' . $params[ 0 ] . ',' . $params[ 1 ] . ',' . $params[ 2 ] . ',' . $params[ 3 ] . ')';
}

View File

@@ -1,38 +0,0 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsShared
*/
use Smarty\Exception;
/**
* evaluate compiler parameter
*
* @param array $params parameter array as given to the compiler function
* @param integer $index array index of the parameter to convert
* @param mixed $default value to be returned if the parameter is not present
*
* @return mixed evaluated value of parameter or $default
* @throws Exception if parameter is not a literal (but an expression, variable, …)
* @author Rodney Rehm
*/
function smarty_literal_compiler_param($params, $index, $default = null)
{
// not set, go default
if (!isset($params[ $index ])) {
return $default;
}
// test if param is a literal
if (!preg_match('/^([\'"]?)[a-zA-Z0-9-]+(\\1)$/', $params[ $index ])) {
throw new Exception(
'$param[' . $index .
'] is not a literal and is thus not evaluatable at compile time'
);
}
$t = null;
eval("\$t = " . $params[ $index ] . ";");
return $t;
}

View File

@@ -27,7 +27,7 @@ abstract class Base
*
* @var array
*/
protected static $sysplugins = array('file' => 'File.php',);
protected static $sysplugins = ['file' => \Smarty\Cacheresource\File::class];
/**
* populate Cached Object with meta data from Resource
@@ -211,7 +211,7 @@ abstract class Base
}
// try sysplugins dir
if (isset(self::$sysplugins[ $type ])) {
$cache_resource_class = 'Smarty_Internal_CacheResource_' . \smarty_ucfirst_ascii($type);
$cache_resource_class = self::$sysplugins[ $type ];
return $smarty->_cacheresource_handlers[ $type ] = new $cache_resource_class();
}
// try plugins dir

View File

@@ -1,91 +0,0 @@
<?php
/**
* Smarty Internal Plugin Compile Function_Call
* Compiles the calls of user defined tags defined by {function}
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Function_Call Class
*
* @package Smarty
* @subpackage Compiler
*/
class Call extends Base
{
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Base
*/
public $required_attributes = array('name');
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Base
*/
public $shorttag_order = array('name');
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Base
*/
public $optional_attributes = array('_any');
/**
* Compiles the calls of user defined tags defined by {function}
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = array(), $tag = null, $function = null)
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
// save possible attributes
if (isset($_attr[ 'assign' ])) {
// output will be stored in a smarty variable instead of being displayed
$_assign = $_attr[ 'assign' ];
}
//$_name = trim($_attr['name'], "''");
$_name = $_attr[ 'name' ];
unset($_attr[ 'name' ], $_attr[ 'assign' ], $_attr[ 'nocache' ]);
// set flag (compiled code of {function} must be included in cache file
if (!$compiler->template->caching || $compiler->nocache || $compiler->tag_nocache) {
$_nocache = 'true';
} else {
$_nocache = 'false';
}
$_paramsArray = array();
foreach ($_attr as $_key => $_value) {
if (is_int($_key)) {
$_paramsArray[] = "$_key=>$_value";
} else {
$_paramsArray[] = "'$_key'=>$_value";
}
}
$_params = 'array(' . implode(',', $_paramsArray) . ')';
//$compiler->suppressNocacheProcessing = true;
// was there an assign attribute
if (isset($_assign)) {
$_output =
"<?php ob_start();\n\$_smarty_tpl->smarty->getRuntime('TplFunction')->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});\n\$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
} else {
$_output =
"<?php \$_smarty_tpl->smarty->getRuntime('TplFunction')->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});?>\n";
}
return $_output;
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Smarty\Compile\Modifier;
use Smarty\Exception;
abstract class Base {
/**
* Compiles code for the modifier
*
* @param array $params array with attributes from parser
* @param \Smarty\Compiler\Template $compiler compiler object
*
* @return string compiled code
* @throws \Smarty\CompilerException
*/
abstract public function compile($params, \Smarty\Compiler\Template $compiler);
/**
* evaluate compiler parameter
*
* @param array $params parameter array as given to the compiler function
* @param integer $index array index of the parameter to convert
* @param mixed $default value to be returned if the parameter is not present
*
* @return mixed evaluated value of parameter or $default
* @throws Exception if parameter is not a literal (but an expression, variable, …)
* @author Rodney Rehm
*/
protected function literal_compiler_param($params, $index, $default = null)
{
// not set, go default
if (!isset($params[ $index ])) {
return $default;
}
// test if param is a literal
if (!preg_match('/^([\'"]?)[a-zA-Z0-9-]+(\\1)$/', $params[ $index ])) {
throw new Exception(
'$param[' . $index .
'] is not a literal and is thus not evaluatable at compile time'
);
}
$t = null;
eval("\$t = " . $params[ $index ] . ";");
return $t;
}
}

View File

@@ -1,10 +1,7 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
namespace Smarty\Compile\Modifier;
/**
* Smarty cat modifier plugin
* Type: modifier
@@ -17,12 +14,14 @@
* @link https://www.smarty.net/manual/en/language.modifier.cat.php cat
* (Smarty online manual)
* @author Uwe Tews
*
* @param array $params parameters
*
* @return string with compiled code
*/
function smarty_modifiercompiler_cat($params)
{
return '(' . implode(').(', $params) . ')';
class CatModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
return '(' . implode(').(', $params) . ')';
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Smarty\Compile\Modifier;
/**
* Smarty count_characters modifier plugin
* Type: modifier
* Name: count_characters
* Purpose: count the number of characters in a text
*
* @link https://www.smarty.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online
* manual)
* @author Uwe Tews
*/
class CountCharactersModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
if (!isset($params[ 1 ]) || $params[ 1 ] !== 'true') {
return 'preg_match_all(\'/[^\s]/' . \Smarty\Smarty::$_UTF8_MODIFIER . '\',' . $params[ 0 ] . ', $tmp)';
}
return 'mb_strlen(' . $params[ 0 ] . ', \'' . addslashes(\Smarty\Smarty::$_CHARSET) . '\')';
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Smarty\Compile\Modifier;
/**
* Smarty count_paragraphs modifier plugin
* Type: modifier
* Name: count_paragraphs
* Purpose: count the number of paragraphs in a text
*
* @link https://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
* count_paragraphs (Smarty online manual)
* @author Uwe Tews
*/
class CountParagraphsModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
// count \r or \n characters
return '(preg_match_all(\'#[\r\n]+#\', ' . $params[ 0 ] . ', $tmp)+1)';
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Smarty\Compile\Modifier;
/**
* Smarty count_sentences modifier plugin
* Type: modifier
* Name: count_sentences
* Purpose: count the number of sentences in a text
*
* @link https://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
* count_sentences (Smarty online manual)
* @author Uwe Tews
*/
class CountSentencesModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
// find periods, question marks, exclamation marks with a word before but not after.
return 'preg_match_all("#\w[\.\?\!](\W|$)#S' . \Smarty\Smarty::$_UTF8_MODIFIER . '", ' . $params[ 0 ] . ', $tmp)';
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Smarty\Compile\Modifier;
/**
* Smarty count_words modifier plugin
* Type: modifier
* Name: count_words
* Purpose: count the number of words in a text
*
* @link https://www.smarty.net/manual/en/language.modifier.count.words.php count_words (Smarty online manual)
* @author Uwe Tews
*/
class CountWordsModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
// expression taken from http://de.php.net/manual/en/function.str-word-count.php#85592
return 'preg_match_all(\'/\p{L}[\p{L}\p{Mn}\p{Pd}\\\'\x{2019}]*/' . \Smarty\Smarty::$_UTF8_MODIFIER . '\', ' .
$params[ 0 ] . ', $tmp)';
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Smarty\Compile\Modifier;
/**
* Smarty default modifier plugin
* Type: modifier
* Name: default
* Purpose: designate default value for empty variables
*
* @link https://www.smarty.net/manual/en/language.modifier.default.php default (Smarty online manual)
* @author Uwe Tews
*/
class DefaultModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
$output = $params[ 0 ];
if (!isset($params[ 1 ])) {
$params[ 1 ] = "''";
}
array_shift($params);
foreach ($params as $param) {
$output = '(($tmp = ' . $output . ' ?? null)===null||$tmp===\'\' ? ' . $param . ' ?? null : $tmp)';
}
return $output;
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace Smarty\Compile\Modifier;
use Smarty\Exception;
/**
* Smarty escape modifier plugin
* Type: modifier
* Name: escape
* Purpose: escape string for output
*
* @link https://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual)
* @author Rodney Rehm
*/
class EscapeModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
try {
$esc_type = $this->literal_compiler_param($params, 1, 'html');
$char_set = $this->literal_compiler_param($params, 2, \Smarty\Smarty::$_CHARSET);
$double_encode = $this->literal_compiler_param($params, 3, true);
if (!$char_set) {
$char_set = \Smarty\Smarty::$_CHARSET;
}
switch ($esc_type) {
case 'html':
return 'htmlspecialchars((string)' . $params[ 0 ] . ', ENT_QUOTES, ' . var_export($char_set, true) . ', ' .
var_export($double_encode, true) . ')';
// no break
case 'htmlall':
return 'htmlentities(mb_convert_encoding((string)' . $params[ 0 ] . ', \'UTF-8\', ' .
var_export($char_set, true) . '), ENT_QUOTES, \'UTF-8\', ' .
var_export($double_encode, true) . ')';
// no break
case 'url':
return 'rawurlencode((string)' . $params[ 0 ] . ')';
case 'urlpathinfo':
return 'str_replace("%2F", "/", rawurlencode((string)' . $params[ 0 ] . '))';
case 'quotes':
// escape unescaped single quotes
return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'", (string)' . $params[ 0 ] . ')';
case 'javascript':
// escape quotes and backslashes, newlines, etc.
// see https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements
return 'strtr((string)' .
$params[ 0 ] .
', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/", "<!--" => "<\!--", "<s" => "<\s", "<S" => "<\S" ))';
}
} catch (Exception $e) {
// pass through to regular plugin fallback
}
return 'smarty_modifier_escape(' . join(', ', $params) . ')';
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Smarty\Compile\Modifier;
/**
* Smarty from_charset modifier plugin
* Type: modifier
* Name: from_charset
* Purpose: convert character encoding from $charset to internal encoding
*
* @author Rodney Rehm
*/
class FromCharsetModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
if (!isset($params[ 1 ])) {
$params[ 1 ] = '"ISO-8859-1"';
}
return 'mb_convert_encoding(' . $params[ 0 ] . ', "' . addslashes(\Smarty\Smarty::$_CHARSET) . '", ' . $params[ 1 ] . ')';
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Smarty\Compile\Modifier;
/**
* Smarty indent modifier plugin
* Type: modifier
* Name: indent
* Purpose: indent lines of text
*
* @link https://www.smarty.net/manual/en/language.modifier.indent.php indent (Smarty online manual)
* @author Uwe Tews
*/
class IndentModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
if (!isset($params[ 1 ])) {
$params[ 1 ] = 4;
}
if (!isset($params[ 2 ])) {
$params[ 2 ] = "' '";
}
return 'preg_replace(\'!^!m\',str_repeat(' . $params[ 2 ] . ',' . $params[ 1 ] . '),' . $params[ 0 ] . ')';
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Smarty\Compile\Modifier;
/**
* Smarty lower modifier plugin
* Type: modifier
* Name: lower
* Purpose: convert string to lowercase
*
* @link https://www.smarty.net/manual/en/language.modifier.lower.php lower (Smarty online manual)
* @author Monte Ohrt <monte at ohrt dot com>
* @author Uwe Tews
*/
class LowerModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
return 'mb_strtolower(' . $params[ 0 ] . ', \'' . addslashes(\Smarty\Smarty::$_CHARSET) . '\')';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Smarty\Compile\Modifier;
/**
* Smarty nl2br modifier plugin
* Type: modifier
* Name: nl2br
* Purpose: insert HTML line breaks before all newlines in a string
*
* @link https://www.smarty.net/docs/en/language.modifier.nl2br.tpl nl2br (Smarty online manual)
*/
class Nl2brModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
return 'nl2br((string) ' . $params[0] . ', (bool) ' . ($params[1] ?? true) . ')';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Smarty\Compile\Modifier;
/**
* Smarty noprint modifier plugin
* Type: modifier
* Name: noprint
* Purpose: return an empty string
*
* @author Uwe Tews
*/
class NoPrintModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
return "''";
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Smarty\Compile\Modifier;
/**
* Smarty round modifier plugin
* Type: modifier
* Name: round
* Purpose: Returns the rounded value of num to specified precision (number of digits after the decimal point)
*
* @link https://www.smarty.net/docs/en/language.modifier.round.tpl round (Smarty online manual)
*/
class RoundModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
return 'round((float) ' . $params[0] . ', (int) ' . ($params[1] ?? 0) . ', (int) ' . ($params[2] ?? PHP_ROUND_HALF_UP) . ')';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Smarty\Compile\Modifier;
/**
* Smarty str_repeat modifier plugin
* Type: modifier
* Name: str_repeat
* Purpose: returns string repeated times times
*
* @link https://www.smarty.net/docs/en/language.modifier.str_repeat.tpl str_repeat (Smarty online manual)
*/
class StrRepeatModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
return 'str_repeat((string) ' . $params[0] . ', (int) ' . $params[1] . ')';
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Smarty\Compile\Modifier;
/**
* Smarty string_format modifier plugin
* Type: modifier
* Name: string_format
* Purpose: format strings via sprintf
*
* @link https://www.smarty.net/manual/en/language.modifier.string.format.php string_format (Smarty online manual)
* @author Uwe Tews
*/
class StringFormatModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
return 'sprintf(' . $params[ 1 ] . ',' . $params[ 0 ] . ')';
}
}

View File

@@ -1,10 +1,5 @@
<?php
/**
* Smarty plugin
*
* @package Smarty
* @subpackage PluginsModifierCompiler
*/
namespace Smarty\Compile\Modifier;
/**
* Smarty strip modifier plugin
* Type: modifier
@@ -16,15 +11,15 @@
*
* @link https://www.smarty.net/manual/en/language.modifier.strip.php strip (Smarty online manual)
* @author Uwe Tews
*
* @param array $params parameters
*
* @return string with compiled code
*/
function smarty_modifiercompiler_strip($params)
{
if (!isset($params[ 1 ])) {
$params[ 1 ] = "' '";
}
return "preg_replace('!\s+!" . \Smarty\Smarty::$_UTF8_MODIFIER . "', {$params[1]},{$params[0]})";
class StripModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
if (!isset($params[ 1 ])) {
$params[ 1 ] = "' '";
}
return "preg_replace('!\s+!" . \Smarty\Smarty::$_UTF8_MODIFIER . "', {$params[1]},{$params[0]})";
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Smarty\Compile\Modifier;
/**
* Smarty strip_tags modifier plugin
* Type: modifier
* Name: strip_tags
* Purpose: strip html tags from text
*
* @link https://www.smarty.net/docs/en/language.modifier.strip.tags.tpl strip_tags (Smarty online manual)
* @author Uwe Tews
*/
class StripTagsModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
if (!isset($params[ 1 ]) || $params[ 1 ] === true || trim($params[ 1 ], '"') === 'true') {
return "preg_replace('!<[^>]*?>!', ' ', {$params[0]} ?: '')";
} else {
return 'strip_tags((string) ' . $params[ 0 ] . ')';
}
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Smarty\Compile\Modifier;
/**
* Smarty strlen modifier plugin
* Type: modifier
* Name: strlen
* Purpose: return the length of the given string
*
* @link https://www.smarty.net/docs/en/language.modifier.strlen.tpl strlen (Smarty online manual)
*/
class StrlenModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
return 'strlen((string) ' . $params[0] . ')';
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace Smarty\Compile\Modifier;
/**
* Smarty to_charset modifier plugin
* Type: modifier
* Name: to_charset
* Purpose: convert character encoding from internal encoding to $charset
*
* @author Rodney Rehm
*/
class ToCharsetModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
if (!isset($params[ 1 ])) {
$params[ 1 ] = '"ISO-8859-1"';
}
return 'mb_convert_encoding(' . $params[ 0 ] . ', ' . $params[ 1 ] . ', "' . addslashes(\Smarty\Smarty::$_CHARSET) . '")';
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Smarty\Compile\Modifier;
/**
* Smarty unescape modifier plugin
* Type: modifier
* Name: unescape
* Purpose: unescape html entities
*
* @author Rodney Rehm
*/
class UnescapeModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
$esc_type = $this->literal_compiler_param($params, 1, 'html');
if (!isset($params[ 2 ])) {
$params[ 2 ] = '\'' . addslashes(\Smarty\Smarty::$_CHARSET) . '\'';
}
switch ($esc_type) {
case 'entity':
case 'htmlall':
return 'html_entity_decode(mb_convert_encoding(' . $params[ 0 ] . ', ' . $params[ 2 ] . ', \'UTF-8\'), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, ' . $params[ 2 ] . ')';
case 'html':
return 'htmlspecialchars_decode(' . $params[ 0 ] . ', ENT_QUOTES)';
case 'url':
return 'rawurldecode(' . $params[ 0 ] . ')';
default:
return $params[ 0 ];
}
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Smarty\Compile\Modifier;
/**
* Smarty upper modifier plugin
* Type: modifier
* Name: lower
* Purpose: convert string to uppercase
*
* @link https://www.smarty.net/manual/en/language.modifier.upper.php lower (Smarty online manual)
* @author Uwe Tews
*/
class UpperModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
return 'mb_strtoupper(' . $params[ 0 ] . ' ?? \'\', \'' . addslashes(\Smarty\Smarty::$_CHARSET) . '\')';
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace Smarty\Compile\Modifier;
/**
* Smarty wordwrap modifier plugin
* Type: modifier
* Name: wordwrap
* Purpose: wrap a string of text at a given length
*
* @link https://www.smarty.net/manual/en/language.modifier.wordwrap.php wordwrap (Smarty online manual)
* @author Uwe Tews
*/
class WordWrapModifierCompiler extends Base {
public function compile($params, \Smarty\Compiler\Template $compiler) {
if (!isset($params[ 1 ])) {
$params[ 1 ] = 80;
}
if (!isset($params[ 2 ])) {
$params[ 2 ] = '"\n"';
}
if (!isset($params[ 3 ])) {
$params[ 3 ] = 'false';
}
$function = $compiler->getPlugin('mb_wordwrap', 'modifier');
return $function . '(' . $params[ 0 ] . ',' . $params[ 1 ] . ',' . $params[ 2 ] . ',' . $params[ 3 ] . ')';
}
}

View File

@@ -1,6 +1,6 @@
<?php
namespace Smarty\Compile;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Append

View File

@@ -1,8 +1,7 @@
<?php
namespace Smarty\Compile;
namespace Smarty\Compile\Tag;
use Smarty\CompileBase;
use Smarty\Smarty;
/**
@@ -20,7 +19,7 @@ use Smarty\Smarty;
* @package Smarty
* @subpackage Compiler
*/
class Assign extends CompileBase
class Assign extends Base
{
/**
* Attribute definition: Overwrites base class.

View File

@@ -1,13 +1,9 @@
<?php
/**
* Smarty Internal Plugin CompileBase
*
* @package Smarty
* @subpackage Compiler
* Smarty Internal Compile Plugin Base
* @author Uwe Tews
*/
namespace Smarty\Compile;
namespace Smarty\Compile\Tag;
/**
* This class does extend all internal compile plugins
*

View File

@@ -8,7 +8,7 @@
* file that was distributed with this source code.
*/
namespace Smarty\Compile;
namespace Smarty\Compile\Tag;
use Smarty\ParseTree\Template;

View File

@@ -8,7 +8,7 @@
* file that was distributed with this source code.
*/
namespace Smarty\Compile;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Block Child Class

View File

@@ -1,6 +1,6 @@
<?php
namespace Smarty\Compile;
namespace Smarty\Compile\Tag;
use Smarty\ParseTree\Template;

View File

@@ -8,7 +8,7 @@
* file that was distributed with this source code.
*/
namespace Smarty\Compile;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Block Parent Class

View File

@@ -8,7 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Break Class

90
src/Compile/Tag/Call.php Normal file
View File

@@ -0,0 +1,90 @@
<?php
/**
* Smarty Internal Plugin Compile Function_Call
* Compiles the calls of user defined tags defined by {function}
*
* @package Smarty
* @subpackage Compiler
* @author Uwe Tews
*/
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Function_Call Class
*
* @package Smarty
* @subpackage Compiler
*/
class Call extends Base {
/**
* 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 $optional_attributes = ['_any'];
/**
* Compiles the calls of user defined tags defined by {function}
*
* @param array $args array with attributes from parser
* @param object $compiler compiler object
*
* @return string compiled code
*/
public function compile($args, \Smarty\Compiler\Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
// save possible attributes
if (isset($_attr['assign'])) {
// output will be stored in a smarty variable instead of being displayed
$_assign = $_attr['assign'];
}
//$_name = trim($_attr['name'], "''");
$_name = $_attr['name'];
unset($_attr['name'], $_attr['assign'], $_attr['nocache']);
// set flag (compiled code of {function} must be included in cache file
if (!$compiler->template->caching || $compiler->nocache || $compiler->tag_nocache) {
$_nocache = 'true';
} else {
$_nocache = 'false';
}
$_paramsArray = [];
foreach ($_attr as $_key => $_value) {
if (is_int($_key)) {
$_paramsArray[] = "$_key=>$_value";
} else {
$_paramsArray[] = "'$_key'=>$_value";
}
}
$_params = 'array(' . implode(',', $_paramsArray) . ')';
//$compiler->suppressNocacheProcessing = true;
// was there an assign attribute
if (isset($_assign)) {
$_output =
"<?php ob_start();\n\$_smarty_tpl->smarty->getRuntime('TplFunction')->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});\n\$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
} else {
$_output =
"<?php \$_smarty_tpl->smarty->getRuntime('TplFunction')->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});?>\n";
}
return $_output;
}
}

View File

@@ -1,6 +1,6 @@
<?php
namespace Smarty\Compile;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Capture Class

View File

@@ -8,9 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Captureclose Class

View File

@@ -8,9 +8,7 @@
* file that was distributed with this source code.
*/
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Child Class

View File

@@ -8,10 +8,9 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
namespace Smarty\Compile\Tag;
use Smarty\Smarty;
use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Config Load Class
@@ -89,6 +88,6 @@ class ConfigLoad extends Base {
$_scope = $compiler->convertScope($_attr, $this->valid_scopes);
}
// create config object
return "<?php\n\$_smarty_tpl->_loadConfigFile({$conf_file}, {$section}, {$_scope});\n?>\n";
return "<?php\n\$_smarty_tpl->_loadConfigfile({$conf_file}, {$section}, {$_scope});\n?>\n";
}
}

View File

@@ -8,9 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
use Smarty\Compile\BreakTag;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Continue Class

View File

@@ -9,9 +9,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Debug Class

View File

@@ -1,8 +1,6 @@
<?php
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile ElseIf Class

View File

@@ -1,8 +1,6 @@
<?php
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Else Class

View File

@@ -8,10 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
use Smarty\Compile\Base;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Eval Class

View File

@@ -8,9 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile extend Class

View File

@@ -8,9 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Forclose Class

View File

@@ -1,8 +1,6 @@
<?php
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Forelse Class

View File

@@ -1,8 +1,6 @@
<?php
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile For Class

View File

@@ -8,7 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Foreachclose Class
@@ -41,7 +41,7 @@ class ForeachClose extends Base {
$output .= "{$itemVar} = {$local}saved;\n";
}
$output .= "}\n";
/* @var \Smarty\Compile\ForeachTag $foreachCompiler */
/* @var \Smarty\Compile\Tag\ForeachTag $foreachCompiler */
$foreachCompiler = $compiler->getTagCompiler('foreach');
$output .= $foreachCompiler->compileRestore(1);
$output .= "?>";

View File

@@ -1,8 +1,6 @@
<?php
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Foreachelse Class

View File

@@ -8,9 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile ForeachSection Class

View File

@@ -1,8 +1,6 @@
<?php
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Foreach Class

View File

@@ -8,9 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Functionclose Class
@@ -64,7 +62,7 @@ class FunctionClose extends Base {
// setup buffer for template function code
$compiler->parser->current_buffer = new \Smarty\ParseTree\Template();
$_funcName = "smarty_template_function_{$_name}_{$compiler->template->compiled->nocache_hash}";
$_funcNameCaching = $_funcName . 'Smarty\Compile\Nocache';
$_funcNameCaching = $_funcName . 'Smarty\Compile\Tag\Nocache';
if ($compiler->template->compiled->has_nocache_code) {
$compiler->parent_compiler->tpl_function[$_name]['call_name_caching'] = $_funcNameCaching;
$output = "<?php\n";

View File

@@ -1,8 +1,6 @@
<?php
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Function Class

View File

@@ -8,11 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
use Smarty\Compile\Assign;
use Smarty\Compile\Base;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Ifclose Class

View File

@@ -1,8 +1,6 @@
<?php
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile If Class

View File

@@ -8,11 +8,10 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
namespace Smarty\Compile\Tag;
use Smarty\Compiler\Template;
use Smarty\Smarty;
use Smarty\Compile\Base;
use Smarty\Template\Compiled;
/**

View File

@@ -1,6 +1,6 @@
<?php
namespace Smarty\Compile;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Shared Inheritance
@@ -17,7 +17,7 @@ namespace Smarty\Compile;
* @package Smarty
* @subpackage Compiler
*/
abstract class Inheritance extends \Smarty\Compile\Base
abstract class Inheritance extends Base
{
/**
* Compile inheritance initialization code as prefix

View File

@@ -8,10 +8,9 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
namespace Smarty\Compile\Tag;
use Smarty\Variable;
use Smarty\Compiler\Template;
/**
* Smarty Internal Plugin Compile Insert Class

View File

@@ -8,9 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Ldelim Class

View File

@@ -8,10 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
use Smarty\Compile\Base;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Make_Nocache Class

View File

@@ -1,8 +1,6 @@
<?php
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Nocache Class

View File

@@ -8,9 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Nocacheclose Class

View File

@@ -8,7 +8,7 @@
* file that was distributed with this source code.
*/
namespace Smarty\Compile;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Parent Class

View File

@@ -8,9 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Block Plugin Class

View File

@@ -8,10 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
use Smarty\Compile\Base;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Function Plugin Class

View File

@@ -8,9 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Modifier Class
@@ -81,11 +79,8 @@ class PrivateModifier extends Base {
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);
if ($compiler->getModifierCompiler($modifier)) {
$output = $compiler->compileModifier($modifier, $single_modifier);
}
$compiler->known_modifier_type[$modifier] = $type;
break 2;

View File

@@ -8,7 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
namespace Smarty\Compile\Tag;
use Smarty\Compiler\Template;

View File

@@ -8,9 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Object Function Class

View File

@@ -8,10 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
use Smarty\Compile\Base;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Print Expression Class

View File

@@ -8,7 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
namespace Smarty\Compile\Tag;
use Smarty\Compiler\Template;
use Smarty\Smarty;

View File

@@ -8,13 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
use Smarty\Compile\Capture;
use Smarty\Compile\Base;
use Smarty\Compile\ForeachTag;
use Smarty\Compile\Section;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile special Smarty Variable Class

View File

@@ -8,9 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Rdelim Class

View File

@@ -1,8 +1,6 @@
<?php
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Section Class

View File

@@ -8,11 +8,7 @@
* @author Uwe Tews
*/
namespace Smarty\Compile;
use Smarty\Compile\ForeachSection;
use Smarty\Compile\Base;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Sectionclose Class

View File

@@ -1,8 +1,6 @@
<?php
namespace Smarty\Compile;
use Smarty\Compiler\Template;
namespace Smarty\Compile\Tag;
/**
* Smarty Internal Plugin Compile Sectionelse Class

Some files were not shown because too many files have changed in this diff Show More