diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 078986ea..335e50f2 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -88,6 +88,7 @@ if (SMARTY_SPL_AUTOLOAD && set_include_path(get_include_path() . PATH_SEPARATOR /** * Load always needed external class files */ +/** include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_data.php'; include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_templatebase.php'; include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_template.php'; @@ -95,6 +96,7 @@ include_once SMARTY_SYSPLUGINS_DIR . 'smarty_resource.php'; include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_resource_file.php'; include_once SMARTY_SYSPLUGINS_DIR . 'smarty_cacheresource.php'; include_once SMARTY_SYSPLUGINS_DIR . 'smarty_internal_cacheresource_file.php'; + * / /** * This is the main Smarty class @@ -110,7 +112,7 @@ class Smarty extends Smarty_Internal_TemplateBase /** * smarty version */ - const SMARTY_VERSION = '3.1.22-dev/2'; + const SMARTY_VERSION = '3.1.22-dev/3'; /** * define variable scopes diff --git a/libs/sysplugins/smarty_internal_compile_function.php b/libs/sysplugins/smarty_internal_compile_function.php index 0b6566a4..50c2a6ca 100644 --- a/libs/sysplugins/smarty_internal_compile_function.php +++ b/libs/sysplugins/smarty_internal_compile_function.php @@ -96,7 +96,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase * * @return boolean true */ - public function compile($args, $compiler, $parameter) + public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter) { $this->compiler = $compiler; $saved_data = $this->closeTag($compiler, array('function')); @@ -106,6 +106,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase $compiler->compiles_template_function = false; $compiler->parent_compiler->templateProperties['tpl_function']['param'][$_name]['called_functions'] = $compiler->called_functions; $compiler->parent_compiler->templateProperties['tpl_function']['param'][$_name]['compiled_filepath'] = $compiler->parent_compiler->template->compiled->filepath; + $compiler->parent_compiler->templateProperties['tpl_function']['param'][$_name]['source_uid'] = $compiler->template->source->uid; $compiler->called_functions = array(); $_parameter = $_attr; unset($_parameter['name']); @@ -120,11 +121,11 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase } if (!empty($_paramsArray)) { $_params = 'array(' . implode(",", $_paramsArray) . ')'; - $_paramsCode = "\$params = array_merge(($_params), \$params);\n"; + $_paramsCode = "\$params = array_merge($_params, \$params);\n"; } else { $_paramsCode = ''; } - $_functionCode = $compiler->parser->current_buffer->to_smarty_php(); + $_functionCode = $compiler->parser->current_buffer; // setup buffer for template function code $compiler->parser->current_buffer = new _smarty_template_buffer($compiler->parser); @@ -153,19 +154,27 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase } $output .= "?>/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/';\n"; } - $output .= "\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\n"; - $output .= $_paramsCode; - $output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);\n}\n"; - $output .= "ob_start();\n?>"; + //$output .= "\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\n"; + $output .= "ob_start();\n"; + $output .= $_paramsCode; + $output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);\n}"; + $output .= "\$params = var_export(\$params, true);\n"; + $output .= "echo \"/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/tpl_vars;\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_variable(\\\$value);\n}\n?>"; + $output .= "/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/\n\";?>"; + // $output .= $compiler->makeNocacheCode("\$saved_tpl_vars = \$_smarty_tpl->tpl_vars;\nforeach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);\n}\n"); + // $output .= substr($compiler->processNocacheCode('tpl_vars;\n" . $_paramsCode . "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);\n}\n" . "? >\n", true), 6); $compiler->parser->current_buffer->append_subtree(new _smarty_tag($compiler->parser, $output)); - $compiler->parser->current_buffer->append_subtree(new _smarty_tag($compiler->parser, $_functionCode)); - $output = "template->properties['nocache_hash']}', \"{\$_smarty_tpl->properties['nocache_hash']}\", ob_get_clean());\n"; - $output .= "\$_smarty_tpl->tpl_vars = \$saved_tpl_vars; -foreach (Smarty::\$global_tpl_vars as \$key => \$value) if(!isset(\$_smarty_tpl->tpl_vars[\$key])) \$_smarty_tpl->tpl_vars[\$key] = \$value;\n}\n}\n"; - $output .= "/*/ {$_funcName}_nocache */\n"; + $compiler->parser->current_buffer->append_subtree( $_functionCode); + $output = "template->properties['nocache_hash']}%%*/tpl_vars = \\\$saved_tpl_vars;\n"; + $output .= "foreach (Smarty::\\\$global_tpl_vars as \\\$key => \\\$value) if(!isset(\\\$_smarty_tpl->tpl_vars[\\\$key])) \\\$_smarty_tpl->tpl_vars[\\\$key] = \\\$value;?>"; + $output .= "/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/\";\n?>"; + $output .= "template->properties['nocache_hash']}', \$_smarty_tpl->properties['nocache_hash'], ob_get_clean());\n}\n}\n"; + $output .= "/*/ {$_funcName}_nocache */\n\n"; $output .= "?>\n"; $compiler->parser->current_buffer->append_subtree(new _smarty_tag($compiler->parser, $output)); - $_functionCode = preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/';(\?>\n)?)/", array($this, 'removeNocache'), $_functionCode); + $_functionCode = preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/';(\?>\n)?)/", array($this, 'removeNocache'), $_functionCode->to_smarty_php()); } $compiler->parent_compiler->templateProperties['tpl_function']['param'][$_name]['call_name'] = $_funcName; $output = " \$value) if(!isset(\$_smarty_tpl- $output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);\n}?>"; $compiler->parser->current_buffer->append_subtree(new _smarty_tag($compiler->parser, $output)); $compiler->parser->current_buffer->append_subtree(new _smarty_tag($compiler->parser, $_functionCode)); - $output = "tpl_vars = \$saved_tpl_vars; -foreach (Smarty::\$global_tpl_vars as \$key => \$value) if(!isset(\$_smarty_tpl->tpl_vars[\$key])) \$_smarty_tpl->tpl_vars[\$key] = \$value;\n}\n}\n"; - $output .= "/*/ {$_funcName} */\n"; + $output = "tpl_vars = \$saved_tpl_vars;\n"; + $output .= "foreach (Smarty::\$global_tpl_vars as \$key => \$value) if(!isset(\$_smarty_tpl->tpl_vars[\$key])) \$_smarty_tpl->tpl_vars[\$key] = \$value;\n}\n}\n"; + $output .= "/*/ {$_funcName} */\n\n"; $output .= "?>\n"; $compiler->parser->current_buffer->append_subtree(new _smarty_tag($compiler->parser, $output)); $compiler->parent_compiler->templateFunctionCode .= $compiler->parser->current_buffer->to_smarty_php(); diff --git a/libs/sysplugins/smarty_internal_function_call_handler.php b/libs/sysplugins/smarty_internal_function_call_handler.php index 7d835990..be769903 100644 --- a/libs/sysplugins/smarty_internal_function_call_handler.php +++ b/libs/sysplugins/smarty_internal_function_call_handler.php @@ -38,13 +38,12 @@ class Smarty_Internal_Function_Call_Handler $code = file_get_contents($funcParam['compiled_filepath']); // grab template function if (preg_match("/\/\* {$_function} \*\/([\S\s]*?)\/\*\/ {$_function} \*\//", $code, $match)) { - $code = "\n"; - $code .= $match[0]; - $code .= "?>\n"; - unset($match); + // grab source info from file dependency + preg_match("/\s*'{$funcParam['source_uid']}'([\S\s]*?)\),/", $code, $match1); + unset($code); $output = ''; // make PHP function known - eval($code); + eval($match[0]); if (function_exists($_function)) { // call template function $_function ($_smarty_tpl, $_params); @@ -58,7 +57,11 @@ class Smarty_Internal_Function_Call_Handler $cache = $tplPtr->cached; $content = $cache->read($tplPtr); if ($content) { - $cache->write($tplPtr, $content . "write($tplPtr, $content . "\n"); } } return true; diff --git a/libs/sysplugins/smarty_internal_parsetree.php b/libs/sysplugins/smarty_internal_parsetree.php index f93d0970..7ed2b33d 100644 --- a/libs/sysplugins/smarty_internal_parsetree.php +++ b/libs/sysplugins/smarty_internal_parsetree.php @@ -271,7 +271,9 @@ class _smarty_template_buffer extends _smarty_parsetree */ public function append_subtree(_smarty_parsetree $subtree) { - if ($subtree->data !== '') { + if (!empty($subtree->subtrees)) { + $this->subtrees = array_merge($this->subtrees, $subtree->subtrees); + } else if ($subtree->data !== '') { $this->subtrees[] = $subtree; } } diff --git a/libs/sysplugins/smarty_internal_templatecompilerbase.php b/libs/sysplugins/smarty_internal_templatecompilerbase.php index f86c46fc..0041a9d1 100644 --- a/libs/sysplugins/smarty_internal_templatecompilerbase.php +++ b/libs/sysplugins/smarty_internal_templatecompilerbase.php @@ -282,9 +282,7 @@ abstract class Smarty_Internal_TemplateCompilerBase Smarty_Internal_Debug::start_compile($this->template); } $no_sources = count($this->sources); - if ($loop || $no_sources) { - $this->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->filepath, $this->template->source->timestamp, $this->template->source->type); - } + $this->parent_compiler->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->filepath, $this->template->source->timestamp, $this->template->source->type); $loop ++; if ($no_sources) { $this->inheritance_child = true;