| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: |
|
| 10: |
|
| 11: | |
| 12: | |
| 13: | |
| 14: |
|
| 15: | class Smarty_Internal_Runtime_CodeFrame
|
| 16: | {
|
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: |
|
| 28: | public function create(
|
| 29: | Smarty_Internal_Template $_template,
|
| 30: | $content = '',
|
| 31: | $functions = '',
|
| 32: | $cache = false,
|
| 33: | Smarty_Internal_TemplateCompilerBase $compiler = null
|
| 34: | ) {
|
| 35: |
|
| 36: | $properties[ 'version' ] = Smarty::SMARTY_VERSION;
|
| 37: | $properties[ 'unifunc' ] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
|
| 38: | if (!$cache) {
|
| 39: | $properties[ 'has_nocache_code' ] = $_template->compiled->has_nocache_code;
|
| 40: | $properties[ 'file_dependency' ] = $_template->compiled->file_dependency;
|
| 41: | $properties[ 'includes' ] = $_template->compiled->includes;
|
| 42: | } else {
|
| 43: | $properties[ 'has_nocache_code' ] = $_template->cached->has_nocache_code;
|
| 44: | $properties[ 'file_dependency' ] = $_template->cached->file_dependency;
|
| 45: | $properties[ 'cache_lifetime' ] = $_template->cache_lifetime;
|
| 46: | }
|
| 47: | $output = sprintf(
|
| 48: | "<?php\n/* Smarty version %s, created on %s\n from '%s' */\n\n",
|
| 49: | $properties[ 'version' ],
|
| 50: | date("Y-m-d H:i:s"),
|
| 51: | str_replace('*/', '* /', $_template->source->filepath)
|
| 52: | );
|
| 53: | $output .= "/* @var Smarty_Internal_Template \$_smarty_tpl */\n";
|
| 54: | $dec = "\$_smarty_tpl->_decodeProperties(\$_smarty_tpl, " . var_export($properties, true) . ',' .
|
| 55: | ($cache ? 'true' : 'false') . ')';
|
| 56: | $output .= "if ({$dec}) {\n";
|
| 57: | $output .= "function {$properties['unifunc']} (Smarty_Internal_Template \$_smarty_tpl) {\n";
|
| 58: | if (!$cache && !empty($compiler->tpl_function)) {
|
| 59: | $output .= '$_smarty_tpl->smarty->ext->_tplFunction->registerTplFunctions($_smarty_tpl, ';
|
| 60: | $output .= var_export($compiler->tpl_function, true);
|
| 61: | $output .= ");\n";
|
| 62: | }
|
| 63: | if ($cache && isset($_template->smarty->ext->_tplFunction)) {
|
| 64: | $output .= "\$_smarty_tpl->smarty->ext->_tplFunction->registerTplFunctions(\$_smarty_tpl, " .
|
| 65: | var_export($_template->smarty->ext->_tplFunction->getTplFunction($_template), true) . ");\n";
|
| 66: | }
|
| 67: | $output .= "?>";
|
| 68: | $output .= $content;
|
| 69: | $output .= "<?php }\n?>";
|
| 70: | $output .= $functions;
|
| 71: | $output .= "<?php }\n";
|
| 72: |
|
| 73: | if (preg_match('/\s*\?>[\n]?<\?php\s*/', $output)) {
|
| 74: | $curr_split = preg_split(
|
| 75: | '/\s*\?>[\n]?<\?php\s*/',
|
| 76: | $output
|
| 77: | );
|
| 78: | preg_match_all(
|
| 79: | '/\s*\?>[\n]?<\?php\s*/',
|
| 80: | $output,
|
| 81: | $curr_parts
|
| 82: | );
|
| 83: | $output = '';
|
| 84: | foreach ($curr_split as $idx => $curr_output) {
|
| 85: | $output .= $curr_output;
|
| 86: | if (isset($curr_parts[ 0 ][ $idx ])) {
|
| 87: | $output .= "\n";
|
| 88: | }
|
| 89: | }
|
| 90: | }
|
| 91: | if (preg_match('/\?>\s*$/', $output)) {
|
| 92: | $curr_split = preg_split(
|
| 93: | '/\?>\s*$/',
|
| 94: | $output
|
| 95: | );
|
| 96: | $output = '';
|
| 97: | foreach ($curr_split as $idx => $curr_output) {
|
| 98: | $output .= $curr_output;
|
| 99: | }
|
| 100: | }
|
| 101: | return $output;
|
| 102: | }
|
| 103: | }
|
| 104: | |