diff --git a/lexer/smarty_internal_templateparser.y b/lexer/smarty_internal_templateparser.y index f0b262b8..03fa4967 100644 --- a/lexer/smarty_internal_templateparser.y +++ b/lexer/smarty_internal_templateparser.y @@ -903,19 +903,19 @@ variable(res) ::= object(o). { // config variable variable(res) ::= HATCH ID(i) HATCH. { - res = '$_smarty_tpl->_getConfigVariable( \''. i .'\')'; + res = '$_smarty_tpl->smarty->ext->_config->_getConfigVariable($_smarty_tpl, \''. i .'\')'; } variable(res) ::= HATCH ID(i) HATCH arrayindex(a). { - res = '(is_array($tmp = $_smarty_tpl->_getConfigVariable( \''. i .'\')) ? $tmp'.a.' :null)'; + res = '(is_array($tmp = $_smarty_tpl->smarty->ext->_config->_getConfigVariable($_smarty_tpl, \''. i .'\')) ? $tmp'.a.' :null)'; } variable(res) ::= HATCH variable(v) HATCH. { - res = '$_smarty_tpl->_getConfigVariable( '. v .')'; + res = '$_smarty_tpl->smarty->ext->_config->_getConfigVariable($_smarty_tpl, '. v .')'; } variable(res) ::= HATCH variable(v) HATCH arrayindex(a). { - res = '(is_array($tmp = $_smarty_tpl->_getConfigVariable( '. v .')) ? $tmp'.a.' : null)'; + res = '(is_array($tmp = $_smarty_tpl->smarty->ext->_config->_getConfigVariable($_smarty_tpl, '. v .')) ? $tmp'.a.' : null)'; } varindexed(res) ::= DOLLARID(i) arrayindex(a). { @@ -1106,7 +1106,7 @@ function(res) ::= ns1(f) OPENP params(p) CLOSEP. { $this->compiler->trigger_template_error ('Illegal number of paramer in "isset()"'); } $par = implode(',',p); - if (strncasecmp($par,'$_smarty_tpl->_getConfigVariable',strlen('$_smarty_tpl->_getConfigVariable')) === 0) { + if (strncasecmp($par,'$_smarty_tpl->smarty->ext->_config->_getConfigVariable',strlen('$_smarty_tpl->smarty->ext->_config->_getConfigVariable')) === 0) { self::$prefix_number++; $this->compiler->prefix_code[] = ''; $isset_par = '$_tmp'.self::$prefix_number; diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index b543e2cb..b23220c9 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -91,6 +91,7 @@ if (!class_exists('Smarty_Autoloader', false)) { if (!class_exists('Smarty_Internal_Data', false)) { require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_data.php'; } +require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_extension_handler.php'; require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_templatebase.php'; require_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_template.php'; require_once SMARTY_SYSPLUGINS_DIR . 'smarty_resource.php'; @@ -119,7 +120,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.28-dev/68'; + const SMARTY_VERSION = '3.1.28-dev/70'; /** * define variable scopes @@ -689,6 +690,7 @@ class Smarty extends Smarty_Internal_TemplateBase */ public function __construct() { + parent::__construct(); if (is_callable('mb_internal_encoding')) { mb_internal_encoding(Smarty::$_CHARSET); } @@ -1105,7 +1107,7 @@ class Smarty extends Smarty_Internal_TemplateBase */ public function loadPlugin($plugin_name, $check = true) { - return Smarty_Internal_Extension_LoadPlugin::loadPlugin($this, $plugin_name, $check); + return $this->ext->loadPlugin->loadPlugin($this, $plugin_name, $check); } /** diff --git a/libs/sysplugins/smarty_data.php b/libs/sysplugins/smarty_data.php index ecd88c11..cc5f6c84 100644 --- a/libs/sysplugins/smarty_data.php +++ b/libs/sysplugins/smarty_data.php @@ -56,6 +56,7 @@ class Smarty_Data extends Smarty_Internal_Data */ public function __construct($_parent = null, $smarty = null, $name = null) { + parent::__construct(); self::$count ++; $this->dataObjectName = 'Data_object ' . (isset($name) ? "'{$name}'" : self::$count); $this->smarty = $smarty; diff --git a/libs/sysplugins/smarty_internal_cacheresource_file.php b/libs/sysplugins/smarty_internal_cacheresource_file.php index dc9a314a..1f38b719 100644 --- a/libs/sysplugins/smarty_internal_cacheresource_file.php +++ b/libs/sysplugins/smarty_internal_cacheresource_file.php @@ -96,8 +96,9 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource * used in included file */ $_smarty_tpl = $_template; + $_template->cached->valid = false; if ($update && strpos(phpversion(), 'hhvm') !== false) { - return Smarty_Internal_Extension_Hhvm::includeHhvm($_template, $_template->cached->filepath); + return $_template->smarty->ext->_hhvm->includeHhvm($_template, $_template->cached->filepath); } else { return @include $_template->cached->filepath; } @@ -113,8 +114,7 @@ class Smarty_Internal_CacheResource_File extends Smarty_CacheResource */ public function writeCachedContent(Smarty_Internal_Template $_template, $content) { - $obj = new Smarty_Internal_Write_File(); - if ($obj->writeFile($_template->cached->filepath, $content, $_template->smarty) === true) { + if ($_template->smarty->ext->_writeFile->writeFile($_template->cached->filepath, $content, $_template->smarty) === true) { if (function_exists('opcache_invalidate')) { opcache_invalidate($_template->cached->filepath); } diff --git a/libs/sysplugins/smarty_internal_compile_assign.php b/libs/sysplugins/smarty_internal_compile_assign.php index b9caa37d..50eaafe9 100644 --- a/libs/sysplugins/smarty_internal_compile_assign.php +++ b/libs/sysplugins/smarty_internal_compile_assign.php @@ -61,7 +61,7 @@ class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase } // compiled output if (isset($parameter['smarty_internal_index'])) { - $output = "_var->createLocalArrayVariable(\$_smarty_tpl, $_attr[var], $_nocache, $_scope);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];"; + $output = "smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, $_attr[var], $_nocache, $_scope);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$parameter[smarty_internal_index] = $_attr[value];"; } else { // implement Smarty2's behaviour of variables assigned by reference if ($compiler->template->smarty instanceof SmartyBC) { diff --git a/libs/sysplugins/smarty_internal_compile_block.php b/libs/sysplugins/smarty_internal_compile_block.php index 775a608d..52a541eb 100644 --- a/libs/sysplugins/smarty_internal_compile_block.php +++ b/libs/sysplugins/smarty_internal_compile_block.php @@ -122,7 +122,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher $compiler->has_code = true; $compiler->suppressNocacheProcessing = true; $compiler->_cache['blockParams'][$compiler->_cache['blockNesting']][1] = true; - $output = "_inheritance->processBlock(\$_smarty_tpl, 2, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, null, \$_blockParentStack);\n?>\n"; + $output = "ext->_inheritance->processBlock(\$_smarty_tpl, 2, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, null, \$_blockParentStack);\n?>\n"; return $output; } @@ -142,7 +142,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_Compile_Shared_Inher } $compiler->suppressNocacheProcessing = true; $compiler->has_code = true; - $output = "_inheritance->processBlock(\$_smarty_tpl, 3, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, null, \$_blockParentStack);\n?>\n"; + $output = "ext->_inheritance->processBlock(\$_smarty_tpl, 3, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, null, \$_blockParentStack);\n?>\n"; return $output; } } @@ -259,10 +259,10 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_Compile_Shared_ $compiler->parser->current_buffer = $_buffer; $output = "_cache['blockNesting'] == 1) { - $output .= "\$_smarty_tpl->_inheritance->processBlock(\$_smarty_tpl, 0, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, " . + $output .= "\$_smarty_tpl->ext->_inheritance->processBlock(\$_smarty_tpl, 0, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, " . var_export($_block, true) . ");\n"; } else { - $output .= "\$_smarty_tpl->_inheritance->processBlock(\$_smarty_tpl, 0, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, " . + $output .= "\$_smarty_tpl->ext->_inheritance->processBlock(\$_smarty_tpl, 0, {$compiler->_cache['blockName'][$compiler->_cache['blockNesting']]}, " . var_export($_block, true) . ", \$_blockParentStack);\n"; } diff --git a/libs/sysplugins/smarty_internal_compile_call.php b/libs/sysplugins/smarty_internal_compile_call.php index 2970f0b2..b7204bec 100644 --- a/libs/sysplugins/smarty_internal_compile_call.php +++ b/libs/sysplugins/smarty_internal_compile_call.php @@ -79,10 +79,10 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase // was there an assign attribute if (isset($_assign)) { $_output = - "_tplfunc->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});\n\$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n"; + "smarty->ext->_tplFunction->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});\n\$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n"; } else { $_output = - "_tplfunc->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});?>\n"; + "smarty->ext->_tplFunction->callTemplateFunction(\$_smarty_tpl, {$_name}, {$_params}, {$_nocache});?>\n"; } return $_output; } diff --git a/libs/sysplugins/smarty_internal_compile_extends.php b/libs/sysplugins/smarty_internal_compile_extends.php index d1b26a86..7ce3dcf6 100644 --- a/libs/sysplugins/smarty_internal_compile_extends.php +++ b/libs/sysplugins/smarty_internal_compile_extends.php @@ -99,7 +99,7 @@ class Smarty_Internal_Compile_Extends extends Smarty_Internal_Compile_Shared_Inh private function compileEndChild(Smarty_Internal_TemplateCompilerBase $compiler) { $compiler->parser->template_postfix[] = new Smarty_Internal_ParseTree_Tag($compiler->parser, - "_inheritance->endChild(\$_smarty_tpl);\n?>\n"); + "ext->_inheritance->endChild(\$_smarty_tpl);\n?>\n"); } /** diff --git a/libs/sysplugins/smarty_internal_compile_foreach.php b/libs/sysplugins/smarty_internal_compile_foreach.php index c582d41b..876ed026 100644 --- a/libs/sysplugins/smarty_internal_compile_foreach.php +++ b/libs/sysplugins/smarty_internal_compile_foreach.php @@ -184,7 +184,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo $output .= "{$local}{$k} = {$code}\n"; } $output .= "{$itemVar} = new Smarty_Variable();\n"; - $output .= "{$local}total = \$_smarty_tpl->_foreach->count(\$_from);\n"; + $output .= "{$local}total = \$_smarty_tpl->smarty->ext->_foreach->count(\$_from);\n"; if (isset($itemAttr['show'])) { $output .= "{$itemVar}->show = ({$local}total > 0);\n"; } diff --git a/libs/sysplugins/smarty_internal_compile_if.php b/libs/sysplugins/smarty_internal_compile_if.php index 11017d1a..541e2181 100644 --- a/libs/sysplugins/smarty_internal_compile_if.php +++ b/libs/sysplugins/smarty_internal_compile_if.php @@ -58,7 +58,7 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase if (is_array($parameter['if condition']['var'])) { $_output = "tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . - "]->value)) \$_smarty_tpl->_var->createLocalArrayVariable(\$_smarty_tpl, " . $parameter['if condition']['var']['var'] . + "]->value)) \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, " . $parameter['if condition']['var']['var'] . "$_nocache);\n"; $_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . @@ -162,7 +162,7 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase $_output = "tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . - "]->value)) \$_smarty_tpl->_var->createLocalArrayVariable(\$_smarty_tpl, " . + "]->value)) \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, " . $parameter['if condition']['var']['var'] . "$_nocache);\n"; $_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . @@ -195,7 +195,7 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . - "]->value)) \$_smarty_tpl->_var->createLocalArrayVariable(\$_smarty_tpl, " . + "]->value)) \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, " . $parameter['if condition']['var']['var'] . "$_nocache);\n"); $_output .= "if (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . diff --git a/libs/sysplugins/smarty_internal_compile_private_foreachsection.php b/libs/sysplugins/smarty_internal_compile_private_foreachsection.php index 6989223d..25b35e86 100644 --- a/libs/sysplugins/smarty_internal_compile_private_foreachsection.php +++ b/libs/sysplugins/smarty_internal_compile_private_foreachsection.php @@ -176,7 +176,7 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com // run pre filter if required if ((isset($nextCompiler->smarty->autoload_filters['pre']) || isset($nextCompiler->smarty->registered_filters['pre']))) { - $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $nextCompiler->template); + $_content = $nextCompiler->smarty->ext->_filter_Handler->runFilter('pre', $_content, $nextCompiler->template); } $this->matchProperty($_content); } diff --git a/libs/sysplugins/smarty_internal_compile_private_special_variable.php b/libs/sysplugins/smarty_internal_compile_private_special_variable.php index 5b814dca..5a8c54fa 100644 --- a/libs/sysplugins/smarty_internal_compile_private_special_variable.php +++ b/libs/sysplugins/smarty_internal_compile_private_special_variable.php @@ -99,9 +99,9 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C case 'config': if (isset($_index[2])) { - return "(is_array(\$tmp = \$_smarty_tpl->_getConfigVariable($_index[1])) ? \$tmp[$_index[2]] : null)"; + return "(is_array(\$tmp = \$_smarty_tpl->smarty->ext->_config->_getConfigVariable(\$_smarty_tpl, $_index[1])) ? \$tmp[$_index[2]] : null)"; } else { - return "\$_smarty_tpl->_getConfigVariable($_index[1])"; + return "\$_smarty_tpl->smarty->ext->_config->_getConfigVariable(\$_smarty_tpl, $_index[1])"; } case 'ldelim': $_ldelim = $compiler->smarty->left_delimiter; diff --git a/libs/sysplugins/smarty_internal_compile_shared_inheritance.php b/libs/sysplugins/smarty_internal_compile_shared_inheritance.php index 445ad7ae..c7bf1f8f 100644 --- a/libs/sysplugins/smarty_internal_compile_shared_inheritance.php +++ b/libs/sysplugins/smarty_internal_compile_shared_inheritance.php @@ -40,7 +40,7 @@ class Smarty_Internal_Compile_Shared_Inheritance extends Smarty_Internal_Compile */ static function postCompile(Smarty_Internal_TemplateCompilerBase $compiler, $initChildSequence = false) { - $compiler->prefixCompiledCode .= "_inheritance->init(\$_smarty_tpl, " . + $compiler->prefixCompiledCode .= "ext->_inheritance->init(\$_smarty_tpl, " . var_export($initChildSequence, true) . ");\n?>\n"; } } \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_compile_while.php b/libs/sysplugins/smarty_internal_compile_while.php index 119a163e..bd31f667 100644 --- a/libs/sysplugins/smarty_internal_compile_while.php +++ b/libs/sysplugins/smarty_internal_compile_while.php @@ -60,7 +60,7 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase if (is_array($parameter['if condition']['var'])) { $_output .= "if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . - "]->value)) \$_smarty_tpl->_var->createLocalArrayVariable(\$_smarty_tpl, " . $parameter['if condition']['var']['var'] . + "]->value)) \$_smarty_tpl->smarty->ext->_var->createLocalArrayVariable(\$_smarty_tpl, " . $parameter['if condition']['var']['var'] . "$_nocache);\n"; $_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" . $parameter['if condition']['var']['smarty_internal_index'] . " = " . diff --git a/libs/sysplugins/smarty_internal_config_file_compiler.php b/libs/sysplugins/smarty_internal_config_file_compiler.php index bfeb8df3..4cf3a0c3 100644 --- a/libs/sysplugins/smarty_internal_config_file_compiler.php +++ b/libs/sysplugins/smarty_internal_config_file_compiler.php @@ -145,7 +145,7 @@ class Smarty_Internal_Config_File_Compiler $code = 'config_data, true) . '); ?>'; - return $template_header . Smarty_Internal_Extension_CodeFrame::create($this->template, $code); + return $template_header . $this->template->smarty->ext->_codeFrame->create($this->template, $code); } /** diff --git a/libs/sysplugins/smarty_internal_data.php b/libs/sysplugins/smarty_internal_data.php index 6d849e3c..303d8c1e 100644 --- a/libs/sysplugins/smarty_internal_data.php +++ b/libs/sysplugins/smarty_internal_data.php @@ -14,12 +14,11 @@ * @package Smarty * @subpackage Template * - * @method mixed getConfigVars(string $varname = null, bool $search_parents = true) + * @method mixed getConfigVars(string $varName = null, bool $searchParents = true) * @method mixed getStreamVariable(string $variable) - * @local_method mixed getTemplateVars(string $varname = null, Smarty_Internal_Data $_ptr = null, bool $search_parents = true) * @method Smarty_Internal_Data clearAssign(mixed $tpl_var) * @method Smarty_Internal_Data clearAllAssign() - * @method Smarty_Internal_Data clearConfig(string $varname = null) + * @method Smarty_Internal_Data clearConfig(string $varName = null) * @method Smarty_Internal_Data configLoad(string $config_file, mixed $sections = null, string $scope = 'local') * @property int $_objType */ @@ -54,14 +53,21 @@ class Smarty_Internal_Data public $config_vars = array(); /** - * Cache for property information from generic getter/setter - * Preloaded with names which should not use with generic getter/setter + * extension handler * - * @var array + * @var Smarty_Internal_Extension_Handler */ - private $_property_info = array('AutoloadFilters' => 0, 'DefaultModifiers' => 0, 'ConfigVars' => 0, - 'DebugTemplate' => 0, 'RegisteredObject' => 0, 'StreamVariable' => 0, - 'TemplateVars' => 0,); + public $ext = null; + + /** + * Smarty_Internal_Data constructor. + * + * Install extension handler + */ + public function __construct() + { + $this->ext = new Smarty_Internal_Extension_Handler(); + } /** * assigns a Smarty variable @@ -106,63 +112,22 @@ class Smarty_Internal_Data */ public function append($tpl_var, $value = null, $merge = false, $nocache = false) { - if (is_array($tpl_var)) { - // $tpl_var is an array, ignore $value - foreach ($tpl_var as $_key => $_val) { - if ($_key != '') { - $this->append($_key, $_val, $merge, $nocache); - } - } - } else { - if ($tpl_var != '' && isset($value)) { - if (!isset($this->tpl_vars[$tpl_var])) { - $tpl_var_inst = $this->_getVariable($tpl_var, null, true, false); - if ($tpl_var_inst instanceof Smarty_Undefined_Variable) { - $this->tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache); - } else { - $this->tpl_vars[$tpl_var] = clone $tpl_var_inst; - } - } - if (!(is_array($this->tpl_vars[$tpl_var]->value) || - $this->tpl_vars[$tpl_var]->value instanceof ArrayAccess) - ) { - settype($this->tpl_vars[$tpl_var]->value, 'array'); - } - if ($merge && is_array($value)) { - foreach ($value as $_mkey => $_mval) { - $this->tpl_vars[$tpl_var]->value[$_mkey] = $_mval; - } - } else { - $this->tpl_vars[$tpl_var]->value[] = $value; - } - } - } - - return $this; + return $this->ext->append->append($this, $tpl_var, $value, $merge, $nocache); } /** * assigns a global Smarty variable * - * @param string $varname the global variable name + * @param string $varName the global variable name * @param mixed $value the value to assign * @param boolean $nocache if true any output of this variable will be not cached * - * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for - * chaining + * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty */ - public function assignGlobal($varname, $value = null, $nocache = false) + public function assignGlobal($varName, $value = null, $nocache = false) { - if ($varname != '') { - Smarty::$global_tpl_vars[$varname] = new Smarty_Variable($value, $nocache); - $ptr = $this; - while ($ptr->_objType == 2) { - $ptr->tpl_vars[$varname] = clone Smarty::$global_tpl_vars[$varname]; - $ptr = $ptr->parent; - } - } - return $this; - } + return $this->ext->assignGlobal->assignGlobal($this, $varName, $value, $nocache); + } /** * appends values to template variables by reference @@ -171,13 +136,11 @@ class Smarty_Internal_Data * @param mixed &$value the referenced value to append * @param boolean $merge flag if array elements shall be merged * - * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for - * chaining + * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty */ public function appendByRef($tpl_var, &$value, $merge = false) { - Smarty_Internal_Method_AppendByRef::appendByRef($this, $tpl_var, $value, $merge); - return $this; + return $this->ext->appendByRef->appendByRef($this, $tpl_var, $value, $merge); } /** @@ -187,17 +150,11 @@ class Smarty_Internal_Data * @param $value * @param boolean $nocache if true any output of this variable will be not cached * - * @return Smarty_Internal_Data current Smarty_Internal_Data (or Smarty or Smarty_Internal_Template) instance for - * chaining + * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty */ public function assignByRef($tpl_var, &$value, $nocache = false) { - if ($tpl_var != '') { - $this->tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache); - $this->tpl_vars[$tpl_var]->value = &$value; - } - - return $this; + return $this->ext->assignByRef->assignByRef($this, $tpl_var, $value, $nocache); } /** @@ -206,116 +163,15 @@ class Smarty_Internal_Data * @api Smarty::getTemplateVars() * @link http://www.smarty.net/docs/en/api.get.template.vars.tpl * - * @param string $varname variable name or null + * @param string $varName variable name or null * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object - * @param bool $search_parents include parent templates? + * @param bool $searchParents include parent templates? * * @return mixed variable value or or array of variables */ - public function getTemplateVars($varname = null, Smarty_Internal_Data $_ptr = null, $search_parents = true) + public function getTemplateVars($varName = null, Smarty_Internal_Data $_ptr = null, $searchParents = true) { - if (isset($varname)) { - $_var = $this->_getVariable($varname, $_ptr, $search_parents, false); - if (is_object($_var)) { - return $_var->value; - } else { - return null; - } - } else { - $_result = array(); - if ($_ptr === null) { - $_ptr = $this; - } - while ($_ptr !== null) { - foreach ($_ptr->tpl_vars AS $key => $var) { - if (!array_key_exists($key, $_result)) { - $_result[$key] = $var->value; - } - } - // not found, try at parent - if ($search_parents) { - $_ptr = $_ptr->parent; - } else { - $_ptr = null; - } - } - if ($search_parents && isset(Smarty::$global_tpl_vars)) { - foreach (Smarty::$global_tpl_vars AS $key => $var) { - if (!array_key_exists($key, $_result)) { - $_result[$key] = $var->value; - } - } - } - return $_result; - } - } - /** - * gets the object of a Smarty variable - * - * @param string $variable the name of the Smarty variable - * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object - * @param bool $search_parents search also in parent data - * @param bool $error_enable - * - * @return \Smarty_Variable - */ - public function _getVariable($variable, Smarty_Internal_Data $_ptr = null, $search_parents = true, $error_enable = true) - { - if ($_ptr === null) { - $_ptr = $this; - } - while ($_ptr !== null) { - if (isset($_ptr->tpl_vars[$variable])) { - // found it, return it - return $_ptr->tpl_vars[$variable]; - } - // not found, try at parent - if ($search_parents) { - $_ptr = $_ptr->parent; - } else { - $_ptr = null; - } - } - if (isset(Smarty::$global_tpl_vars[$variable])) { - // found it, return it - return Smarty::$global_tpl_vars[$variable]; - } - /* @var \Smarty $smarty */ - $smarty = isset($this->smarty) ? $this->smarty : $this; - if ($smarty->error_unassigned && $error_enable) { - // force a notice - $x = $$variable; - } - - return new Smarty_Undefined_Variable; - } - - /** - * gets a config variable value - * - * @param string $variable the name of the config variable - * @param bool $error_enable - * - * @return mixed the value of the config variable - */ - public function _getConfigVariable($variable, $error_enable = true) - { - $_ptr = $this; - while ($_ptr !== null) { - if (isset($_ptr->config_vars[$variable])) { - // found it, return it - return $_ptr->config_vars[$variable]; - } - // not found, try at parent - $_ptr = $_ptr->parent; - } - /* @var \Smarty $smarty */ - $smarty = isset($this->smarty) ? $this->smarty : $this; - if ($smarty->error_unassigned && $error_enable) { - // force a notice - $x = $$variable; - } - return null; + return $this->ext->getTemplateVars->getTemplateVars($this, $varName, $_ptr, $searchParents); } /** @@ -329,42 +185,6 @@ class Smarty_Internal_Data */ public function __call($name, $args) { - $smarty = $this->_objType == 1 ? $this : $this->smarty; - if (!isset($smarty->_cache['extObjCache'][$name])) { - - $class = 'Smarty_Internal_Method_' . ucfirst($name); - if (preg_match('/^(set|get)([A-Z].*)$/', $name, $match)) { - if (!isset($this->_property_info[$prop = $match[2]])) { - if (!isset($this->_property_info[$prop])) { - // convert camel case to underscored name - $smarty->_cache['resolvedProp'][$prop] = $pn = strtolower(join('_', preg_split('/([A-Z][^A-Z]*)/', $prop, - 1, PREG_SPLIT_NO_EMPTY | - PREG_SPLIT_DELIM_CAPTURE))); - $this->_property_info[$prop] = property_exists($this, $pn) ? 1 : ($this->_objType == 2 && - property_exists($smarty, $pn) ? 2 : 0); - } - } - if ($this->_property_info[$prop]) { - $pn = $smarty->_cache['resolvedProp'][$prop]; - if ($match[1] == 'get') { - return $this->_property_info[$prop] == 1 ? $this->$pn : $this->smarty->$pn; - } else { - return $this->_property_info[$prop] == - 1 ? $this->$pn = $args[0] : $this->smarty->$pn = $args[0]; - } - } elseif (!class_exists($class)) { - throw new SmartyException("property '$pn' does not exist."); - } - } - if (class_exists($class)) { - $callback = array($smarty->_cache['extObjCache'][$name] = new $class(), $name); - } - } else { - $callback = array($smarty->_cache['extObjCache'][$name], $name); - } - if (isset($callback) && $callback[0]->objMap | $this->_objType) { - array_unshift($args, $this); - return call_user_func_array($callback, $args); - } - throw new SmartyException("method '$name' does not exist."); + return $this->ext->_callExternalMethod($this, $name, $args); } } diff --git a/libs/sysplugins/smarty_internal_extension_handler.php b/libs/sysplugins/smarty_internal_extension_handler.php new file mode 100644 index 00000000..5d2dd782 --- /dev/null +++ b/libs/sysplugins/smarty_internal_extension_handler.php @@ -0,0 +1,151 @@ + 0, 'DefaultModifiers' => 0, 'ConfigVars' => 0, + 'DebugTemplate' => 0, 'RegisteredObject' => 0, 'StreamVariable' => 0, + 'TemplateVars' => 0,);# + + private $resolvedProperties = array(); + + + + /** + * Call external Method + * + * @param \Smarty_Internal_Data $data + * @param string $name external method names + * @param array $args argument array + * + * @return mixed + * @throws SmartyException + */ + public function _callExternalMethod(Smarty_Internal_Data $data, $name, $args) { + /* @var Smarty $data->smarty */ + $smarty = isset($data->smarty) ? $data->smarty : $data; + if (!isset($smarty->ext->$name)) { + $class = 'Smarty_Internal_Method_' . ucfirst($name); + if (preg_match('/^(set|get)([A-Z].*)$/', $name, $match)) { + if (!isset($this->_property_info[$prop = $match[2]])) { + // convert camel case to underscored name + $this->resolvedProperties[$prop] = $pn = strtolower(join('_', preg_split('/([A-Z][^A-Z]*)/', $prop, - 1, PREG_SPLIT_NO_EMPTY | + PREG_SPLIT_DELIM_CAPTURE))); + $this->_property_info[$prop] = property_exists($data, $pn) ? 1 : ($data->_objType == 2 && + property_exists($smarty, $pn) ? 2 : 0); + } + if ($this->_property_info[$prop]) { + $pn = $this->resolvedProperties[$prop]; + if ($match[1] == 'get') { + return $this->_property_info[$prop] == 1 ? $data->$pn : $data->smarty->$pn; + } else { + return $this->_property_info[$prop] == + 1 ? $data->$pn = $args[0] : $data->smarty->$pn = $args[0]; + } + } elseif (!class_exists($class)) { + throw new SmartyException("property '$pn' does not exist."); + } + } + if (class_exists($class)) { + $callback = array($smarty->ext->$name = new $class(), $name); + } + } else { + $callback = array($smarty->ext->$name, $name); + } + array_unshift($args, $data); + if (isset($callback) && $callback[0]->objMap | $data->_objType) { + return call_user_func_array($callback, $args); + } + return call_user_func_array(array(new Smarty_Internal_Undefined(), $name), $args); + } + + /** + * set extension property + * + * @param string $property_name property name + * @param mixed $value value + * + * @throws SmartyException + */ + public function __set($property_name, $value) + { + $this->$property_name = $value; + } + + /** + * get extension object + * + * @param string $property_name property name + * + * @return mixed|Smarty_Template_Cached + * @throws SmartyException + */ + public function __get($property_name) + { + // object properties of runtime template extensions will start with '_' + if ($property_name[0] == '_') { + $class = 'Smarty_Internal_Runtime_' . ucfirst(substr($property_name, 1)); + } else { + $class = 'Smarty_Internal_Method_' . ucfirst($property_name); + + } + if (class_exists($class)) { + return $this->$property_name = new $class(); + } + return $this; + } + + /** + * Call error handler for undefined method + * + * @param string $name unknown method-name + * @param array $args argument array + * + * @return mixed + * @throws SmartyException + */ + public function __call($name, $args) + { + return call_user_func_array(array(new Smarty_Internal_Undefined(), $name), $args); + } + +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_append.php b/libs/sysplugins/smarty_internal_method_append.php index 82b741cc..7bc320b1 100644 --- a/libs/sysplugins/smarty_internal_method_append.php +++ b/libs/sysplugins/smarty_internal_method_append.php @@ -45,7 +45,7 @@ class Smarty_Internal_Method_Append } else { if ($tpl_var != '' && isset($value)) { if (!isset($data->tpl_vars[$tpl_var])) { - $tpl_var_inst = $data->_getVariable($tpl_var, null, true, false); + $tpl_var_inst = $data->ext->getTemplateVars->_getVariable($data, $tpl_var, null, true, false); if ($tpl_var_inst instanceof Smarty_Undefined_Variable) { $data->tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache); } else { @@ -66,7 +66,6 @@ class Smarty_Internal_Method_Append } } } - return $data; } } \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_appendbyref.php b/libs/sysplugins/smarty_internal_method_appendbyref.php index 5a55e972..d2ee9651 100644 --- a/libs/sysplugins/smarty_internal_method_appendbyref.php +++ b/libs/sysplugins/smarty_internal_method_appendbyref.php @@ -42,7 +42,6 @@ class Smarty_Internal_Method_AppendByRef $data->tpl_vars[$tpl_var]->value[] = &$value; } } - return $data; } } \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_assignbyref.php b/libs/sysplugins/smarty_internal_method_assignbyref.php new file mode 100644 index 00000000..cfa44939 --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_assignbyref.php @@ -0,0 +1,34 @@ +tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache); + $data->tpl_vars[$tpl_var]->value = &$value; + } + + return $data; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_assignglobal.php b/libs/sysplugins/smarty_internal_method_assignglobal.php new file mode 100644 index 00000000..23b13b3a --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_assignglobal.php @@ -0,0 +1,43 @@ +_objType == 2) { + $ptr->tpl_vars[$varName] = clone Smarty::$global_tpl_vars[$varName]; + $ptr = $ptr->parent; + } + } + return $data; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_gettemplatevars.php b/libs/sysplugins/smarty_internal_method_gettemplatevars.php index 9c963074..235bece4 100644 --- a/libs/sysplugins/smarty_internal_method_gettemplatevars.php +++ b/libs/sysplugins/smarty_internal_method_gettemplatevars.php @@ -25,16 +25,16 @@ class Smarty_Internal_Method_GetTemplateVars * @link http://www.smarty.net/docs/en/api.get.template.vars.tpl * * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data - * @param string $varname variable name or null + * @param string $varName variable name or null * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object - * @param bool $search_parents include parent templates? + * @param bool $searchParents include parent templates? * * @return mixed variable value or or array of variables */ - public function getTemplateVars(Smarty_Internal_Data $data, $varname = null, Smarty_Internal_Data $_ptr = null, $search_parents = true) + public function getTemplateVars(Smarty_Internal_Data $data, $varName = null, Smarty_Internal_Data $_ptr = null, $searchParents = true) { - if (isset($varname)) { - $_var = $data->_getVariable($varname, $_ptr, $search_parents, false); + if (isset($varName)) { + $_var = $this->_getVariable($data, $varName, $_ptr, $searchParents, false); if (is_object($_var)) { return $_var->value; } else { @@ -52,13 +52,13 @@ class Smarty_Internal_Method_GetTemplateVars } } // not found, try at parent - if ($search_parents) { + if ($searchParents) { $_ptr = $_ptr->parent; } else { $_ptr = null; } } - if ($search_parents && isset(Smarty::$global_tpl_vars)) { + if ($searchParents && isset(Smarty::$global_tpl_vars)) { foreach (Smarty::$global_tpl_vars AS $key => $var) { if (!array_key_exists($key, $_result)) { $_result[$key] = $var->value; @@ -68,4 +68,47 @@ class Smarty_Internal_Method_GetTemplateVars return $_result; } } + + /** + * gets the object of a Smarty variable + * + * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data + * @param string $varName the name of the Smarty variable + * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $_ptr optional pointer to data object + * @param bool $searchParents search also in parent data + * @param bool $errorEnable + * + * @return \Smarty_Variable + */ + public function _getVariable(Smarty_Internal_Data $data, $varName, Smarty_Internal_Data $_ptr = null, $searchParents = true, $errorEnable = true) + { + if ($_ptr === null) { + $_ptr = $data; + } + while ($_ptr !== null) { + if (isset($_ptr->tpl_vars[$varName])) { + // found it, return it + return $_ptr->tpl_vars[$varName]; + } + // not found, try at parent + if ($searchParents) { + $_ptr = $_ptr->parent; + } else { + $_ptr = null; + } + } + if (isset(Smarty::$global_tpl_vars[$varName])) { + // found it, return it + return Smarty::$global_tpl_vars[$varName]; + } + /* @var \Smarty $smarty */ + $smarty = isset($data->smarty) ? $data->smarty : $data; + if ($smarty->error_unassigned && $errorEnable) { + // force a notice + $x = $$varName; + } + + return new Smarty_Undefined_Variable; + } + } \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_method_loadplugin.php b/libs/sysplugins/smarty_internal_method_loadplugin.php new file mode 100644 index 00000000..c153f55f --- /dev/null +++ b/libs/sysplugins/smarty_internal_method_loadplugin.php @@ -0,0 +1,111 @@ +loadPlugin() method + * + * @package Smarty + * @subpackage PluginsInternal + * @author Uwe Tews + */ +class Smarty_Internal_Method_LoadPlugin +{ + /** + * Cache of searched plugin files + * + * @var array + */ + public $plugin_files = array(); + + /** + * Takes unknown classes and loads plugin files for them + * class name format: Smarty_PluginType_PluginName + * plugin filename format: plugintype.pluginname.php + * + * @param \Smarty $smarty + * @param string $plugin_name class plugin name to load + * @param bool $check check if already loaded + * + * @return bool|string + * @throws \SmartyException + */ + public function loadPlugin(Smarty $smarty, $plugin_name, $check) + { + // if function or class exists, exit silently (already loaded) + if ($check && (is_callable($plugin_name) || class_exists($plugin_name, false))) { + return true; + } + if (!preg_match('#^smarty_((internal)|([^_]+))_(.+)$#i', $plugin_name, $match)) { + throw new SmartyException("plugin {$plugin_name} is not a valid name format"); + } + if (!empty($match[2])) { + $file = SMARTY_SYSPLUGINS_DIR . strtolower($plugin_name) . '.php'; + if (isset($this->plugin_files[$file])) { + if ($this->plugin_files[$file] !== false) { + return $this->plugin_files[$file]; + } else { + return false; + } + } else { + if (is_file($file)) { + $this->plugin_files[$file] = $file; + require_once($file); + return $file; + } else { + $this->plugin_files[$file] = false; + return false; + } + } + } + // plugin filename is expected to be: [type].[name].php + $_plugin_filename = "{$match[1]}.{$match[4]}.php"; + $_lower_filename = strtolower($_plugin_filename); + if (isset($this->plugin_files)) { + if (isset($this->plugin_files['plugins_dir'][$_lower_filename])) { + if (!$smarty->use_include_path || $this->plugin_files['plugins_dir'][$_lower_filename] !== false) { + return $this->plugin_files['plugins_dir'][$_lower_filename]; + } + } + if (!$smarty->use_include_path || $smarty->ext->_getIncludePath->isNewIncludePath($smarty)) { + unset($this->plugin_files['include_path']); + } else { + if (isset($this->plugin_files['include_path'][$_lower_filename])) { + return $this->plugin_files['include_path'][$_lower_filename]; + } + } + } + $_file_names = array($_plugin_filename); + if ($_lower_filename != $_plugin_filename) { + $_file_names[] = $_lower_filename; + } + $_p_dirs = $smarty->getPluginsDir(); + if (!isset($this->plugin_files['plugins_dir'][$_lower_filename])) { + // loop through plugin dirs and find the plugin + foreach ($_p_dirs as $_plugin_dir) { + foreach ($_file_names as $name) { + $file = $_plugin_dir . $name; + if (is_file($file)) { + $this->plugin_files['plugins_dir'][$_lower_filename] = $file; + require_once($file); + return $file; + } + $this->plugin_files['plugins_dir'][$_lower_filename] = false; + } + } + } + if ($smarty->use_include_path) { + foreach ($_file_names as $_file_name) { + // try PHP include_path + $file = $smarty->ext->_getIncludePath->getIncludePath($_p_dirs, $_file_name, $smarty); + $this->plugin_files['include_path'][$_lower_filename] = $file; + if ($file !== false) { + require_once($file); + return $file; + } + } + } + // no plugin loaded + return false; + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_resource_file.php b/libs/sysplugins/smarty_internal_resource_file.php index 0b7055a7..b15e3cc6 100644 --- a/libs/sysplugins/smarty_internal_resource_file.php +++ b/libs/sysplugins/smarty_internal_resource_file.php @@ -103,7 +103,7 @@ class Smarty_Internal_Resource_File extends Smarty_Resource } // Use include path ? if ($source->smarty->use_include_path) { - return Smarty_Internal_Get_Include_Path::getIncludePath($_directories, $file, $source->smarty); + return $source->smarty->ext->_getIncludePath->getIncludePath($_directories, $file, $source->smarty); } return false; } diff --git a/libs/sysplugins/smarty_internal_runtime_codeframe.php b/libs/sysplugins/smarty_internal_runtime_codeframe.php new file mode 100644 index 00000000..a3be60d4 --- /dev/null +++ b/libs/sysplugins/smarty_internal_runtime_codeframe.php @@ -0,0 +1,88 @@ +compiled->has_nocache_code; + $properties['version'] = Smarty::SMARTY_VERSION; + $properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true)); + if (!empty($_template->tpl_function)) { + $properties['tpl_function'] = $_template->tpl_function; + } + if (!$cache) { + $properties['file_dependency'] = $_template->compiled->file_dependency; + $properties['includes'] = $_template->compiled->includes; + } else { + $properties['file_dependency'] = $_template->cached->file_dependency; + $properties['cache_lifetime'] = $_template->cache_lifetime; + } + $output = "source->filepath . "\" */\n\n"; + + $dec = "\$_smarty_tpl->smarty->ext->_validateCompiled->decodeProperties(\$_smarty_tpl, " . var_export($properties, true) . ',' . + ($cache ? 'true' : 'false') . ")"; + $output .= "if ({$dec}) {\n"; + $output .= "function {$properties['unifunc']} (\$_smarty_tpl) {\n"; + // include code for plugins + if (!$cache) { + if (!empty($_template->compiled->required_plugins['compiled'])) { + foreach ($_template->compiled->required_plugins['compiled'] as $tmp) { + foreach ($tmp as $data) { + $file = addslashes($data['file']); + if (is_array($data['function'])) { + $output .= "if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) require_once '{$file}';\n"; + } else { + $output .= "if (!is_callable('{$data['function']}')) require_once '{$file}';\n"; + } + } + } + } + if ($_template->caching && !empty($_template->compiled->required_plugins['nocache'])) { + $_template->compiled->has_nocache_code = true; + $output .= "echo '/*%%SmartyNocache:{$_template->compiled->nocache_hash}%%*/smarty; "; + foreach ($_template->compiled->required_plugins['nocache'] as $tmp) { + foreach ($tmp as $data) { + $file = addslashes($data['file']); + if (is_Array($data['function'])) { + $output .= addslashes("if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) require_once '{$file}';\n"); + } else { + $output .= addslashes("if (!is_callable('{$data['function']}')) require_once '{$file}';\n"); + } + } + } + $output .= "?>/*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%*/';\n"; + } + } + $output .= "?>\n"; + $output .= $content; + $output .= ""; + $output .= $functions; + $output .= "[\n]?<\?php\s*/', "\n", $output); + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_internal_runtime_config.php b/libs/sysplugins/smarty_internal_runtime_config.php new file mode 100644 index 00000000..895dae1a --- /dev/null +++ b/libs/sysplugins/smarty_internal_runtime_config.php @@ -0,0 +1,39 @@ +config_vars[$varName])) { + // found it, return it + return $_ptr->config_vars[$varName]; + } + // not found, try at parent + $_ptr = $_ptr->parent; + } + if ($tpl->smarty->error_unassigned && $errorEnable) { + // force a notice + $x = $$varName; + } + return null; + } +} diff --git a/libs/sysplugins/smarty_internal_runtime_filterhandler.php b/libs/sysplugins/smarty_internal_runtime_filterhandler.php new file mode 100644 index 00000000..9af26675 --- /dev/null +++ b/libs/sysplugins/smarty_internal_runtime_filterhandler.php @@ -0,0 +1,69 @@ +smarty->autoload_filters[$type])) { + foreach ((array) $template->smarty->autoload_filters[$type] as $name) { + $plugin_name = "Smarty_{$type}filter_{$name}"; + if (function_exists($plugin_name)) { + $callback = $plugin_name; + } elseif (class_exists($plugin_name, false) && is_callable(array($plugin_name, 'execute'))) { + $callback = array($plugin_name, 'execute'); + } elseif ($template->smarty->loadPlugin($plugin_name, false)) { + if (function_exists($plugin_name)) { + // use loaded Smarty2 style plugin + $callback = $plugin_name; + } elseif (class_exists($plugin_name, false) && is_callable(array($plugin_name, 'execute'))) { + // loaded class of filter plugin + $callback = array($plugin_name, 'execute'); + } else { + throw new SmartyException("Auto load {$type}-filter plugin method \"{$plugin_name}::execute\" not callable"); + } + } else { + // nothing found, throw exception + throw new SmartyException("Unable to auto load {$type}-filter plugin \"{$plugin_name}\""); + } + $content = call_user_func($callback, $content, $template); + } + } + // loop over registered filters of specified type + if (!empty($template->smarty->registered_filters[$type])) { + foreach ($template->smarty->registered_filters[$type] as $key => $name) { + $content = call_user_func($template->smarty->registered_filters[$type][$key], $content, $template); + } + } + // return filtered output + return $content; + } +} diff --git a/libs/sysplugins/smarty_internal_runtime_getincludepath.php b/libs/sysplugins/smarty_internal_runtime_getincludepath.php new file mode 100644 index 00000000..965c95f8 --- /dev/null +++ b/libs/sysplugins/smarty_internal_runtime_getincludepath.php @@ -0,0 +1,183 @@ +_include_path != $_i_path) { + $this->_include_dirs = array(); + $this->_include_path = $_i_path; + $_dirs = (array) explode(PATH_SEPARATOR, $_i_path); + foreach ($_dirs as $_path) { + if ($_path[0] != '/' && isset($dir[1]) && $dir[1] != ':') { + $_path = $smarty->_realpath($_path . DS, true); + } + if (is_dir($_path)) { + $this->_include_dirs[] = $smarty->_realpath($_path . DS, true); + } + } + return true; + } + return false; + } + + /** + * return array with include path directories + * + * @param \Smarty $smarty + * + * @return array + */ + public function getIncludePathDirs(Smarty $smarty) + { + $this->isNewIncludePath($smarty); + return $this->_include_dirs; + } + + /** + * Return full file path from PHP include_path + * + * @param string[] $dirs + * @param string $file + * @param \Smarty $smarty + * + * @return bool|string full filepath or false + * + */ + public function getIncludePath($dirs, $file, Smarty $smarty) + { + //if (!(isset($this->_has_stream_include) ? $this->_has_stream_include : $this->_has_stream_include = false)) { + if (!(isset($this->_has_stream_include) ? $this->_has_stream_include : $this->_has_stream_include = function_exists('stream_resolve_include_path'))) { + $this->isNewIncludePath($smarty); + } + // try PHP include_path + foreach ($dirs as $dir) { + $dir_n = isset($this->number[$dir]) ? $this->number[$dir] : $this->number[$dir] = $this->counter ++; + if (isset($this->isFile[$dir_n][$file])) { + if ($this->isFile[$dir_n][$file]) { + return $this->isFile[$dir_n][$file]; + } else { + continue; + } + } + if (isset($this->_user_dirs[$dir_n])) { + if (false === $this->_user_dirs[$dir_n]) { + continue; + } else { + $dir = $this->_user_dirs[$dir_n]; + } + } else { + if ($dir[0] == '/' || $dir[1] == ':') { + $dir = str_ireplace(getcwd(), '.', $dir); + if ($dir[0] == '/' || $dir[1] == ':') { + $this->_user_dirs[$dir_n] = false; + continue; + } + } + $dir = substr($dir, 2); + $this->_user_dirs[$dir_n] = $dir; + } + if ($this->_has_stream_include) { + $path = stream_resolve_include_path($dir . (isset($file) ? $file : '')); + if ($path) { + return $this->isFile[$dir_n][$file] = $path; + } + } else { + foreach ($this->_include_dirs as $key => $_i_path) { + $path = isset($this->isPath[$key][$dir_n]) ? $this->isPath[$key][$dir_n] : $this->isPath[$key][$dir_n] = is_dir($_dir_path = $_i_path . + $dir) ? $_dir_path : false; + if ($path === false) { + continue; + } + if (isset($file)) { + $_file = $this->isFile[$dir_n][$file] = (is_file($path . $file)) ? $path . $file : false; + if ($_file) { + return $_file; + } + } else { + // no file was given return directory path + return $path; + } + } + } + } + return false; + } +} diff --git a/libs/sysplugins/smarty_internal_runtime_hhvm.php b/libs/sysplugins/smarty_internal_runtime_hhvm.php new file mode 100644 index 00000000..117cd816 --- /dev/null +++ b/libs/sysplugins/smarty_internal_runtime_hhvm.php @@ -0,0 +1,30 @@ +blockNesting || $this->state == 3)) { - $tpl->_inheritance = new Smarty_Internal_Runtime_Inheritance(); - $tpl->_inheritance->init($tpl, $initChild, $blockNames); + $tpl->ext->_inheritance = new Smarty_Internal_Runtime_Inheritance(); + $tpl->ext->_inheritance->init($tpl, $initChild, $blockNames); return; } // start of child sub template(s) @@ -118,11 +118,16 @@ class Smarty_Internal_Runtime_Inheritance * if found call it, otherwise call current block * - ignored for outer level blocks in child templates * - * $type 1 = {$smarty.block.child}: + * $type 1 = {block}: + * - nested {block} + * - search in inheritance template hierarchy for child blocks + * if found call it, otherwise call current block + * + * $type 2 = {$smarty.block.child}: * - search in inheritance template hierarchy for child blocks * if found call it, otherwise ignore * - * $type 2 = {$smarty.block.parent}: + * $type 3 = {$smarty.block.parent}: * - get block id from parent stack and call parent block * * @param \Smarty_Internal_Template $tpl template object of caller diff --git a/libs/sysplugins/smarty_internal_runtime_tplfunction.php b/libs/sysplugins/smarty_internal_runtime_tplfunction.php new file mode 100644 index 00000000..8d72ebcd --- /dev/null +++ b/libs/sysplugins/smarty_internal_runtime_tplfunction.php @@ -0,0 +1,97 @@ +tpl_function[$name])) { + if (!$tpl->caching || ($tpl->caching && $nocache)) { + $function = $tpl->tpl_function[$name]['call_name']; + } else { + if (isset($tpl->tpl_function[$name]['call_name_caching'])) { + $function = $tpl->tpl_function[$name]['call_name_caching']; + } else { + $function = $tpl->tpl_function[$name]['call_name']; + } + } + if (function_exists($function)) { + $function ($tpl, $params); + return; + } + // try to load template function dynamically + if ($this->addTplFuncToCache($tpl, $name, $function)) { + $function ($tpl, $params); + return; + } + } + throw new SmartyException("Unable to find template function '{$name}'"); + } + + /** + * + * Add template function to cache file for nocache calls + * + * @param Smarty_Internal_Template $tpl + * @param string $_name template function name + * @param string $_function PHP function name + * + * @return bool + */ + public function addTplFuncToCache(Smarty_Internal_Template $tpl, $_name, $_function) + { + $funcParam = $tpl->tpl_function[$_name]; + if (is_file($funcParam['compiled_filepath'])) { + // read compiled file + $code = file_get_contents($funcParam['compiled_filepath']); + // grab template function + if (preg_match("/\/\* {$_function} \*\/([\S\s]*?)\/\*\/ {$_function} \*\//", $code, $match)) { + // grab source info from file dependency + preg_match("/\s*'{$funcParam['uid']}'([\S\s]*?)\),/", $code, $match1); + unset($code); + // make PHP function known + eval($match[0]); + if (function_exists($_function)) { + // search cache file template + $tplPtr = $tpl; + while (!isset($tplPtr->cached) && isset($tplPtr->parent)) { + $tplPtr = $tplPtr->parent; + } + // add template function code to cache file + if (isset($tplPtr->cached)) { + $cache = $tplPtr->cached; + $content = $cache->read($tplPtr); + if ($content) { + // check if we must update file dependency + if (!preg_match("/'{$funcParam['uid']}'(.*?)'nocache_hash'/", $content, $match2)) { + $content = preg_replace("/('file_dependency'(.*?)\()/", "\\1{$match1[0]}", $content); + } + $cache->write($tplPtr, preg_replace('/\s*\?>\s*$/', "\n", $content) . "\n" . + preg_replace(array('/^\s*<\?php\s+/', '/\s*\?>\s*$/'), "\n", + $match[0])); + } + } + return true; + } + } + } + return false; + } +} diff --git a/libs/sysplugins/smarty_internal_runtime_validatecompiled.php b/libs/sysplugins/smarty_internal_runtime_validatecompiled.php new file mode 100644 index 00000000..6624eb0b --- /dev/null +++ b/libs/sysplugins/smarty_internal_runtime_validatecompiled.php @@ -0,0 +1,81 @@ +smarty->compile_check) || $tpl->smarty->compile_check == 1) + ) { + // check file dependencies at compiled code + foreach ($properties['file_dependency'] as $_file_to_check) { + if ($_file_to_check[2] == 'file' || $_file_to_check[2] == 'extends' || $_file_to_check[2] == 'php') { + if ($tpl->source->filepath == $_file_to_check[0]) { + // do not recheck current template + continue; + //$mtime = $tpl->source->getTimeStamp(); + } else { + // file and php types can be checked without loading the respective resource handlers + $mtime = is_file($_file_to_check[0]) ? filemtime($_file_to_check[0]) : false; + } + } elseif ($_file_to_check[2] == 'string') { + continue; + } else { + $source = Smarty_Template_Source::load(null, $tpl->smarty, $_file_to_check[0]); + $mtime = $source->getTimeStamp(); + } + if (!$mtime || $mtime > $_file_to_check[1]) { + $is_valid = false; + break; + } + } + } + if ($cache) { + // CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc + if ($tpl->caching === Smarty::CACHING_LIFETIME_SAVED && $properties['cache_lifetime'] >= 0 && + (time() > ($tpl->cached->timestamp + $properties['cache_lifetime'])) + ) { + $is_valid = false; + } + $tpl->cached->cache_lifetime = $properties['cache_lifetime']; + $tpl->cached->valid = $is_valid; + $resource = $tpl->cached; + } else { + $tpl->mustCompile = !$is_valid; + $resource = $tpl->compiled; + $resource->includes = isset($properties['includes']) ? $properties['includes'] : array(); + } + if ($is_valid) { + $resource->unifunc = $properties['unifunc']; + $resource->has_nocache_code = $properties['has_nocache_code']; + // $tpl->compiled->nocache_hash = $properties['nocache_hash']; + $resource->file_dependency = $properties['file_dependency']; + if (isset($properties['tpl_function'])) { + $tpl->tpl_function = $properties['tpl_function']; + } + } + return $is_valid && !function_exists($properties['unifunc']); + } +} diff --git a/libs/sysplugins/smarty_internal_runtime_var.php b/libs/sysplugins/smarty_internal_runtime_var.php index f4f1c997..a8f6818f 100644 --- a/libs/sysplugins/smarty_internal_runtime_var.php +++ b/libs/sysplugins/smarty_internal_runtime_var.php @@ -14,24 +14,24 @@ class Smarty_Internal_Runtime_Var * Template code runtime function to create a local Smarty variable for array assignments * * @param \Smarty_Internal_Template $tpl template object - * @param string $tpl_var template variable name + * @param string $varName template variable name * @param bool $nocache cache mode of variable * @param int $scope scope of variable */ - public function createLocalArrayVariable(\Smarty_Internal_Template $tpl, $tpl_var, $nocache = false, + public function createLocalArrayVariable(\Smarty_Internal_Template $tpl, $varName, $nocache = false, $scope = Smarty::SCOPE_LOCAL) { - if (!isset($tpl->tpl_vars[$tpl_var])) { - $tpl->tpl_vars[$tpl_var] = new Smarty_Variable(array(), $nocache, $scope); + if (!isset($tpl->tpl_vars[$varName])) { + $tpl->tpl_vars[$varName] = new Smarty_Variable(array(), $nocache, $scope); } else { - $tpl->tpl_vars[$tpl_var] = clone $tpl->tpl_vars[$tpl_var]; + $tpl->tpl_vars[$varName] = clone $tpl->tpl_vars[$varName]; if ($scope != Smarty::SCOPE_LOCAL) { - $tpl->tpl_vars[$tpl_var]->scope = $scope; + $tpl->tpl_vars[$varName]->scope = $scope; } - if (!(is_array($tpl->tpl_vars[$tpl_var]->value) || - $tpl->tpl_vars[$tpl_var]->value instanceof ArrayAccess) + if (!(is_array($tpl->tpl_vars[$varName]->value) || + $tpl->tpl_vars[$varName]->value instanceof ArrayAccess) ) { - settype($tpl->tpl_vars[$tpl_var]->value, 'array'); + settype($tpl->tpl_vars[$varName]->value, 'array'); } } } diff --git a/libs/sysplugins/smarty_internal_runtime_writefile.php b/libs/sysplugins/smarty_internal_runtime_writefile.php new file mode 100644 index 00000000..05c97378 --- /dev/null +++ b/libs/sysplugins/smarty_internal_runtime_writefile.php @@ -0,0 +1,90 @@ +_file_perms : 0644; + $_dir_perms = property_exists($smarty, '_dir_perms') ? (isset($smarty->_dir_perms) ? $smarty->_dir_perms : 0777) : 0771; + if ($_file_perms !== null) { + $old_umask = umask(0); + } + + $_dirpath = dirname($_filepath); + // if subdirs, create dir structure + if ($_dirpath !== '.' && !file_exists($_dirpath)) { + mkdir($_dirpath, $_dir_perms, true); + } + + // write to tmp file, then move to overt file lock race condition + $_tmp_file = $_dirpath . DS . str_replace(array('.', ','), '_', uniqid('wrt', true)); + if (!file_put_contents($_tmp_file, $_contents)) { + error_reporting($_error_reporting); + throw new SmartyException("unable to write file {$_tmp_file}"); + } + + /* + * Windows' rename() fails if the destination exists, + * Linux' rename() properly handles the overwrite. + * Simply unlink()ing a file might cause other processes + * currently reading that file to fail, but linux' rename() + * seems to be smart enough to handle that for us. + */ + if (Smarty::$_IS_WINDOWS) { + // remove original file + if (is_file($_filepath)) { + @unlink($_filepath); + } + // rename tmp file + $success = @rename($_tmp_file, $_filepath); + } else { + // rename tmp file + $success = @rename($_tmp_file, $_filepath); + if (!$success) { + // remove original file + if (is_file($_filepath)) { + @unlink($_filepath); + } + // rename tmp file + $success = @rename($_tmp_file, $_filepath); + } + } + if (!$success) { + error_reporting($_error_reporting); + throw new SmartyException("unable to write file {$_filepath}"); + } + if ($_file_perms !== null) { + // set file permissions + chmod($_filepath, $_file_perms); + umask($old_umask); + } + error_reporting($_error_reporting); + + return true; + } +} diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index 32b65f89..33939ad9 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -202,7 +202,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase !$no_output_filter && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output'])) ) { - echo Smarty_Internal_Filter_Handler::runFilter('output', ob_get_clean(), $this); + echo $this->smarty->ext->_filterHandler->runFilter('output', ob_get_clean(), $this); } else { ob_end_flush(); flush(); @@ -247,7 +247,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase (!$this->caching || $this->cached->has_nocache_code || $this->source->handler->recompiled) && (isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output'])) ) { - return Smarty_Internal_Filter_Handler::runFilter('output', ob_get_clean(), $this); + return $this->smarty->ext->_filterHandler->runFilter('output', ob_get_clean(), $this); } // return cache content return null; @@ -286,75 +286,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase $this->smarty->_getTemplateId($this->template_resource, $this->cache_id, $this->compile_id); } - /** - * This function is executed automatically when a compiled or cached template file is included - * - Decode saved properties from compiled template and cache files - * - Check if compiled or cache file is valid - * - * @param array $properties special template properties - * @param bool $cache flag if called from cache file - * - * @return bool flag if compiled or cache file is valid - */ - public function decodeProperties($properties, $cache = false) - { - $is_valid = true; - if (Smarty::SMARTY_VERSION != $properties['version']) { - // new version must rebuild - $is_valid = false; - } elseif (!empty($properties['file_dependency']) && - ((!$cache && $this->smarty->compile_check) || $this->smarty->compile_check == 1) - ) { - // check file dependencies at compiled code - foreach ($properties['file_dependency'] as $_file_to_check) { - if ($_file_to_check[2] == 'file' || $_file_to_check[2] == 'extends' || $_file_to_check[2] == 'php') { - if ($this->source->filepath == $_file_to_check[0]) { - // do not recheck current template - continue; - //$mtime = $this->source->getTimeStamp(); - } else { - // file and php types can be checked without loading the respective resource handlers - $mtime = is_file($_file_to_check[0]) ? filemtime($_file_to_check[0]) : false; - } - } elseif ($_file_to_check[2] == 'string') { - continue; - } else { - $source = Smarty_Template_Source::load(null, $this->smarty, $_file_to_check[0]); - $mtime = $source->getTimeStamp(); - } - if (!$mtime || $mtime > $_file_to_check[1]) { - $is_valid = false; - break; - } - } - } - if ($cache) { - // CACHING_LIFETIME_SAVED cache expiry has to be validated here since otherwise we'd define the unifunc - if ($this->caching === Smarty::CACHING_LIFETIME_SAVED && $properties['cache_lifetime'] >= 0 && - (time() > ($this->cached->timestamp + $properties['cache_lifetime'])) - ) { - $is_valid = false; - } - $this->cached->cache_lifetime = $properties['cache_lifetime']; - $this->cached->valid = $is_valid; - $resource = $this->cached; - } else { - $this->mustCompile = !$is_valid; - $resource = $this->compiled; - $resource->includes = isset($properties['includes']) ? $properties['includes'] : array(); - } - if ($is_valid) { - $resource->unifunc = $properties['unifunc']; - $resource->has_nocache_code = $properties['has_nocache_code']; - // $this->compiled->nocache_hash = $properties['nocache_hash']; - $resource->file_dependency = $properties['file_dependency']; - if (isset($properties['tpl_function'])) { - $this->tpl_function = $properties['tpl_function']; - } - } - return $is_valid; - } - /** * runtime error not matching capture tags */ diff --git a/libs/sysplugins/smarty_internal_templatebase.php b/libs/sysplugins/smarty_internal_templatebase.php index 33d9a778..d6ef0f89 100644 --- a/libs/sysplugins/smarty_internal_templatebase.php +++ b/libs/sysplugins/smarty_internal_templatebase.php @@ -150,7 +150,7 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data */ private function _execute($template, $cache_id, $compile_id, $parent, $function) { - /* @var Smarty $smarty */ + /* @var Smarty $this ->smarty */ $smarty = $this->_objType == 1 ? $this : $this->smarty; if ($template === null) { if ($this->_objType != 2) { @@ -207,7 +207,6 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data /** * Registers plugin to be used in templates - * NOTE: this method can be safely removed for dynamic loading * * @api Smarty::registerPlugin() * @link http://www.smarty.net/docs/en/api.register.plugin.tpl @@ -223,21 +222,11 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data */ public function registerPlugin($type, $name, $callback, $cacheable = true, $cache_attr = null) { - /* @var Smarty $smarty */ - $smarty = isset($this->smarty) ? $this->smarty : $this; - if (isset($smarty->registered_plugins[$type][$name])) { - throw new SmartyException("Plugin tag \"{$name}\" already registered"); - } elseif (!is_callable($callback)) { - throw new SmartyException("Plugin \"{$name}\" not callable"); - } else { - $smarty->registered_plugins[$type][$name] = array($callback, (bool) $cacheable, (array) $cache_attr); - } - return $this; + return $this->ext->registerPlugin->registerPlugin($this, $type, $name, $callback, $cacheable, $cache_attr); } /** * load a filter of specified type and name - * NOTE: this method can be safely removed for dynamic loading * * @api Smarty::loadFilter() * @link http://www.smarty.net/docs/en/api.load.filter.tpl @@ -250,32 +239,11 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data */ public function loadFilter($type, $name) { - /* @var Smarty $smarty */ - $smarty = isset($this->smarty) ? $this->smarty : $this; - if (!in_array($type, array('pre', 'post', 'output', 'variable'))) { - throw new SmartyException("Illegal filter type \"{$type}\""); - } - $_plugin = "smarty_{$type}filter_{$name}"; - $_filter_name = $_plugin; - if (is_callable($_plugin)) { - $smarty->registered_filters[$type][$_filter_name] = $_plugin; - return true; - } - if ($smarty->loadPlugin($_plugin)) { - if (class_exists($_plugin, false)) { - $_plugin = array($_plugin, 'execute'); - } - if (is_callable($_plugin)) { - $smarty->registered_filters[$type][$_filter_name] = $_plugin; - return true; - } - } - throw new SmartyException("{$type}filter \"{$name}\" not found or callable"); + return $this->ext->loadFilter->loadFilter($this, $type, $name); } /** * Registers a filter function - * NOTE: this method can be safely removed for dynamic loading * * @api Smarty::registerFilter() * @link http://www.smarty.net/docs/en/api.register.filter.tpl @@ -289,42 +257,11 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data */ public function registerFilter($type, $callback, $name = null) { - /* @var Smarty $smarty */ - $smarty = isset($this->smarty) ? $this->smarty : $this; - if (!in_array($type, array('pre', 'post', 'output', 'variable'))) { - throw new SmartyException("Illegal filter type \"{$type}\""); - } - $name = isset($name) ? $name : $this->_getFilterName($callback); - if (!is_callable($callback)) { - throw new SmartyException("{$type}filter \"{$name}\" not callable"); - } - $smarty->registered_filters[$type][$name] = $callback; - return $this; - } - - /** - * Return internal filter name - * - * @param callback $function_name - * - * @return string internal filter name - */ - public function _getFilterName($function_name) - { - if (is_array($function_name)) { - $_class_name = (is_object($function_name[0]) ? get_class($function_name[0]) : $function_name[0]); - - return $_class_name . '_' . $function_name[1]; - } elseif (is_string($function_name)) { - return $function_name; - } else { - return 'closure'; - } + return $this->ext->registerFilter->registerFilter($this, $type, $callback, $name); } /** * Registers object to be used in templates - * NOTE: this method can be safely removed for dynamic loading * * @api Smarty::registerObject() * @link http://www.smarty.net/docs/en/api.register.object.tpl @@ -341,28 +278,8 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data public function registerObject($object_name, $object, $allowed_methods_properties = array(), $format = true, $block_methods = array()) { - /* @var Smarty $smarty */ - $smarty = isset($this->smarty) ? $this->smarty : $this; - // test if allowed methods callable - if (!empty($allowed_methods_properties)) { - foreach ((array) $allowed_methods_properties as $method) { - if (!is_callable(array($object, $method)) && !property_exists($object, $method)) { - throw new SmartyException("Undefined method or property '$method' in registered object"); - } - } - } - // test if block methods callable - if (!empty($block_methods)) { - foreach ((array) $block_methods as $method) { - if (!is_callable(array($object, $method))) { - throw new SmartyException("Undefined method '$method' in registered object"); - } - } - } - // register the object - $smarty->registered_objects[$object_name] = - array($object, (array) $allowed_methods_properties, (boolean) $format, (array) $block_methods); - return $this; + return $this->ext->registerObject->registerObject($this, $object_name, $object, $allowed_methods_properties, + $format, $block_methods); } /** diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index 9125b43f..ed3bb280 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -317,10 +317,7 @@ abstract class Smarty_Internal_TemplateCompilerBase Smarty_Internal_TemplateCompilerBase $parent_compiler = null) { // get code frame of compiled template - $_compiled_code = - "source->filepath . "\" */ ?>\n" . - Smarty_Internal_Extension_CodeFrame::create($template, $this->compileTemplateSource($template, $nocache, + $_compiled_code = $template->smarty->ext->_codeFrame->create($template, $this->compileTemplateSource($template, $nocache, $parent_compiler), $this->postFilter($this->blockOrFunctionCode) . join('', $this->mergedSubTemplatesCode)); @@ -420,7 +417,7 @@ abstract class Smarty_Internal_TemplateCompilerBase if (!empty($code) && (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) ) { - return Smarty_Internal_Filter_Handler::runFilter('post', $code, $this->template); + return $this->smarty->ext->_filterHandler->runFilter('post', $code, $this->template); } else { return $code; } @@ -440,7 +437,7 @@ abstract class Smarty_Internal_TemplateCompilerBase if ($_content != '' && ((isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre']))) ) { - return Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $this->template); + return $this->smarty->ext->_filterHandler->runFilter('pre', $_content, $this->template); } else { return $_content; } @@ -747,7 +744,7 @@ abstract class Smarty_Internal_TemplateCompilerBase if (strpos($variable, '(') == 0) { // not a variable variable $var = trim($variable, '\''); - $this->tag_nocache = $this->tag_nocache | $this->template->_getVariable($var, null, true, false)->nocache; + $this->tag_nocache = $this->tag_nocache | $this->template->ext->getTemplateVars->_getVariable($this->template, $var, null, true, false)->nocache; // todo $this->template->compiled->properties['variables'][$var] = $this->tag_nocache | $this->nocache; } return '$_smarty_tpl->tpl_vars[' . $variable . ']->value'; diff --git a/libs/sysplugins/smarty_internal_templateparser.php b/libs/sysplugins/smarty_internal_templateparser.php index 5992ec9c..98833973 100644 --- a/libs/sysplugins/smarty_internal_templateparser.php +++ b/libs/sysplugins/smarty_internal_templateparser.php @@ -2197,29 +2197,31 @@ class Smarty_Internal_Templateparser #line 905 "../smarty/lexer/smarty_internal_templateparser.y" function yy_r118() { - $this->_retvalue = '$_smarty_tpl->_getConfigVariable( \'' . $this->yystack[$this->yyidx + - 1]->minor . '\')'; + $this->_retvalue = '$_smarty_tpl->smarty->ext->_config->_getConfigVariable($_smarty_tpl, \'' . + $this->yystack[$this->yyidx + - 1]->minor . '\')'; } #line 909 "../smarty/lexer/smarty_internal_templateparser.y" function yy_r119() { - $this->_retvalue = - '(is_array($tmp = $_smarty_tpl->_getConfigVariable( \'' . $this->yystack[$this->yyidx + - 2]->minor . - '\')) ? $tmp' . $this->yystack[$this->yyidx + 0]->minor . ' :null)'; + $this->_retvalue = '(is_array($tmp = $_smarty_tpl->smarty->ext->_config->_getConfigVariable($_smarty_tpl, \'' . + $this->yystack[$this->yyidx + - 2]->minor . '\')) ? $tmp' . $this->yystack[$this->yyidx + 0]->minor . + ' :null)'; } #line 913 "../smarty/lexer/smarty_internal_templateparser.y" function yy_r120() { - $this->_retvalue = '$_smarty_tpl->_getConfigVariable( ' . $this->yystack[$this->yyidx + - 1]->minor . ')'; + $this->_retvalue = '$_smarty_tpl->smarty->ext->_config->_getConfigVariable($_smarty_tpl, ' . + $this->yystack[$this->yyidx + - 1]->minor . ')'; } #line 917 "../smarty/lexer/smarty_internal_templateparser.y" function yy_r121() { - $this->_retvalue = - '(is_array($tmp = $_smarty_tpl->_getConfigVariable( ' . $this->yystack[$this->yyidx + - 2]->minor . - ')) ? $tmp' . $this->yystack[$this->yyidx + 0]->minor . ' : null)'; + $this->_retvalue = '(is_array($tmp = $_smarty_tpl->smarty->ext->_config->_getConfigVariable($_smarty_tpl, ' . + $this->yystack[$this->yyidx + - 2]->minor . ')) ? $tmp' . $this->yystack[$this->yyidx + 0]->minor . + ' : null)'; } #line 921 "../smarty/lexer/smarty_internal_templateparser.y" @@ -2449,8 +2451,8 @@ class Smarty_Internal_Templateparser $this->compiler->trigger_template_error('Illegal number of paramer in "isset()"'); } $par = implode(',', $this->yystack[$this->yyidx + - 1]->minor); - if (strncasecmp($par, '$_smarty_tpl->_getConfigVariable', - strlen('$_smarty_tpl->_getConfigVariable')) === 0 + if (strncasecmp($par, '$_smarty_tpl->smarty->ext->_config->_getConfigVariable', + strlen('$_smarty_tpl->smarty->ext->_config->_getConfigVariable')) === 0 ) { self::$prefix_number ++; $this->compiler->prefix_code[] = diff --git a/libs/sysplugins/smarty_internal_undefined.php b/libs/sysplugins/smarty_internal_undefined.php new file mode 100644 index 00000000..93fca8ec --- /dev/null +++ b/libs/sysplugins/smarty_internal_undefined.php @@ -0,0 +1,48 @@ +cached->valid = false; + } else { + $tpl->mustCompile = true; + } + return false; + } + + /** + * Call error handler for undefined method + * + * @param string $name unknown method-name + * @param array $args argument array + * + * @return mixed + * @throws SmartyException + */ + public function __call($name, $args) + { + throw new SmartyException(get_class($args[0]) . "->{$name}() undefined method"); + } +} \ No newline at end of file diff --git a/libs/sysplugins/smarty_security.php b/libs/sysplugins/smarty_security.php index 6a2731e2..9d48bcb2 100644 --- a/libs/sysplugins/smarty_security.php +++ b/libs/sysplugins/smarty_security.php @@ -514,7 +514,7 @@ class Smarty_Security } if ($this->smarty->use_include_path) { $this->_include_dir = array(); - $_dirs = Smarty_Internal_Get_Include_Path::getIncludePathDirs($this->smarty); + $_dirs = $this->smarty->ext->_getIncludePath->getIncludePathDirs($this->smarty); foreach ($_dirs as $directory) { $this->_include_dir[] = $directory; $this->_resource_dir[$directory] = true; diff --git a/libs/sysplugins/smarty_template_cached.php b/libs/sysplugins/smarty_template_cached.php index 7b902b0f..4292ab80 100644 --- a/libs/sysplugins/smarty_template_cached.php +++ b/libs/sysplugins/smarty_template_cached.php @@ -344,7 +344,7 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base (isset($_template->smarty->autoload_filters['output']) || isset($_template->smarty->registered_filters['output'])) ) { - $content = Smarty_Internal_Filter_Handler::runFilter('output', $content, $_template); + $content = $_template->smarty->ext->_filterHandler->runFilter('output', $content, $_template); } // write cache file content $this->writeCachedContent($_template, $content); @@ -366,7 +366,7 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base // don't write cache file return false; } - $content = Smarty_Internal_Extension_CodeFrame::create($_template, $content, '', true); + $content = $_template->smarty->ext->_codeFrame->create($_template, $content, '', true); if (!empty($_template->cached->tpl_function)) { foreach ($_template->cached->tpl_function as $funcParam) { if (is_file($funcParam['compiled_filepath'])) {