diff options
Diffstat (limited to 'lib/smarty3/sysplugins/smarty_internal_runtime_codeframe.php')
-rw-r--r-- | lib/smarty3/sysplugins/smarty_internal_runtime_codeframe.php | 94 |
1 files changed, 48 insertions, 46 deletions
diff --git a/lib/smarty3/sysplugins/smarty_internal_runtime_codeframe.php b/lib/smarty3/sysplugins/smarty_internal_runtime_codeframe.php index 66faf67..983ca61 100644 --- a/lib/smarty3/sysplugins/smarty_internal_runtime_codeframe.php +++ b/lib/smarty3/sysplugins/smarty_internal_runtime_codeframe.php @@ -25,9 +25,13 @@ class Smarty_Internal_Runtime_CodeFrame * * @return string */ - public function create(Smarty_Internal_Template $_template, $content = '', $functions = '', $cache = false, - Smarty_Internal_TemplateCompilerBase $compiler = null) - { + public function create( + Smarty_Internal_Template $_template, + $content = '', + $functions = '', + $cache = false, + Smarty_Internal_TemplateCompilerBase $compiler = null + ) { // build property code $properties[ 'version' ] = Smarty::SMARTY_VERSION; $properties[ 'unifunc' ] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true)); @@ -35,64 +39,62 @@ class Smarty_Internal_Runtime_CodeFrame $properties[ 'has_nocache_code' ] = $_template->compiled->has_nocache_code; $properties[ 'file_dependency' ] = $_template->compiled->file_dependency; $properties[ 'includes' ] = $_template->compiled->includes; - } else { + } else { $properties[ 'has_nocache_code' ] = $_template->cached->has_nocache_code; $properties[ 'file_dependency' ] = $_template->cached->file_dependency; $properties[ 'cache_lifetime' ] = $_template->cache_lifetime; } $output = "<?php\n"; - $output .= "/* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . - "\n from \"" . $_template->source->filepath . "\" */\n\n"; + $output .= "/* Smarty version {$properties[ 'version' ]}, created on " . strftime("%Y-%m-%d %H:%M:%S") . + "\n from '" . str_replace('*/', '* /', $_template->source->filepath) . "' */\n\n"; $output .= "/* @var Smarty_Internal_Template \$_smarty_tpl */\n"; $dec = "\$_smarty_tpl->_decodeProperties(\$_smarty_tpl, " . var_export($properties, true) . ',' . - ($cache ? 'true' : 'false') . ")"; + ($cache ? 'true' : 'false') . ')'; $output .= "if ({$dec}) {\n"; $output .= "function {$properties['unifunc']} (Smarty_Internal_Template \$_smarty_tpl) {\n"; if (!$cache && !empty($compiler->tpl_function)) { - $output .= "\$_smarty_tpl->ext->_tplFunction->registerTplFunctions(\$_smarty_tpl, " . - var_export($compiler->tpl_function, true) . ");\n"; + $output .= '$_smarty_tpl->smarty->ext->_tplFunction->registerTplFunctions($_smarty_tpl, '; + $output .= var_export($compiler->tpl_function, true); + $output .= ");\n"; } - if ($cache && isset($_template->ext->_tplFunction)) { - $output .= "\$_smarty_tpl->ext->_tplFunction->registerTplFunctions(\$_smarty_tpl, " . - var_export($_template->ext->_tplFunction->getTplFunction(), true) . ");\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}%%*/<?php \$_smarty = \$_smarty_tpl->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"; - } + if ($cache && isset($_template->smarty->ext->_tplFunction)) { + $output .= "\$_smarty_tpl->smarty->ext->_tplFunction->registerTplFunctions(\$_smarty_tpl, " . + var_export($_template->smarty->ext->_tplFunction->getTplFunction($_template), true) . ");\n"; } - $output .= "?>\n"; + $output .= "?>"; $output .= $content; $output .= "<?php }\n?>"; $output .= $functions; $output .= "<?php }\n"; // remove unneeded PHP tags - return preg_replace(array('/\s*\?>[\n]?<\?php\s*/', '/\?>\s*$/'), array("\n", ''), $output); + if (preg_match('/\s*\?>[\n]?<\?php\s*/', $output)) { + $curr_split = preg_split( + '/\s*\?>[\n]?<\?php\s*/', + $output + ); + preg_match_all( + '/\s*\?>[\n]?<\?php\s*/', + $output, + $curr_parts + ); + $output = ''; + foreach ($curr_split as $idx => $curr_output) { + $output .= $curr_output; + if (isset($curr_parts[ 0 ][ $idx ])) { + $output .= "\n"; + } + } + } + if (preg_match('/\?>\s*$/', $output)) { + $curr_split = preg_split( + '/\?>\s*$/', + $output + ); + $output = ''; + foreach ($curr_split as $idx => $curr_output) { + $output .= $curr_output; + } + } + return $output; } -}
\ No newline at end of file +} |