diff options
author | plegall <plg@piwigo.org> | 2015-12-30 16:21:32 +0100 |
---|---|---|
committer | plegall <plg@piwigo.org> | 2015-12-30 16:21:32 +0100 |
commit | 3ec3cbe6cec5968d29cb11af139123191f4cb4ee (patch) | |
tree | 34aecd51071d63f8df1862a1a11898d8c43fe68a /include/smarty/libs/sysplugins/smarty_internal_runtime_codeframe.php | |
parent | 6ba0148e646b2a193dc4111bb0a443d8c193e646 (diff) | |
parent | 1681b02ee98c2deb740d394280a2a685170bc72e (diff) |
Merge branch 'bug/385-php7'
Diffstat (limited to '')
-rw-r--r-- | include/smarty/libs/sysplugins/smarty_internal_runtime_codeframe.php | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/include/smarty/libs/sysplugins/smarty_internal_runtime_codeframe.php b/include/smarty/libs/sysplugins/smarty_internal_runtime_codeframe.php new file mode 100644 index 000000000..21e6e5221 --- /dev/null +++ b/include/smarty/libs/sysplugins/smarty_internal_runtime_codeframe.php @@ -0,0 +1,94 @@ +<?php +/** + * Smarty Internal Extension + * This file contains the Smarty template extension to create a code frame + * + * @package Smarty + * @subpackage Template + * @author Uwe Tews + */ + +/** + * Class Smarty_Internal_Extension_CodeFrame + * Create code frame for compiled and cached templates + */ +class Smarty_Internal_Runtime_CodeFrame +{ + /** + * Create code frame for compiled and cached templates + * + * @param Smarty_Internal_Template $_template + * @param string $content optional template content + * @param string $functions compiled template function and block code + * @param bool $cache flag for cache file + * @param \Smarty_Internal_TemplateCompilerBase $compiler + * + * @return string + */ + public function create(Smarty_Internal_Template $_template, $content = '', $functions = '', $cache = false, + Smarty_Internal_TemplateCompilerBase $compiler = null) + { + // build property code + $properties[ 'has_nocache_code' ] = $_template->compiled->has_nocache_code; + $properties[ 'version' ] = Smarty::SMARTY_VERSION; + $properties[ 'unifunc' ] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true)); + if (!$cache) { + $properties[ 'file_dependency' ] = $_template->compiled->file_dependency; + $properties[ 'includes' ] = $_template->compiled->includes; + if (!empty($compiler->tpl_function)) { + $properties[ 'tpl_function' ] = $compiler->tpl_function; + } + } else { + $properties[ 'file_dependency' ] = $_template->cached->file_dependency; + $properties[ 'cache_lifetime' ] = $_template->cache_lifetime; + if (!empty($_template->tpl_function)) { + $properties[ 'tpl_function' ] = $_template->tpl_function; + } + } + $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"; + + $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}%%*/<?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"; + } + } + $output .= "?>\n"; + $output .= $content; + $output .= "<?php }\n?>"; + $output .= $functions; + $output .= "<?php }\n"; + // remove unneeded PHP tags + return preg_replace('/\s*\?>[\n]?<\?php\s*/', "\n", $output); + } +}
\ No newline at end of file |