]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_runtime_codeframe.php
Merge pull request #4233 from MrPetovan/task/4116-move-smarty-to-composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_runtime_codeframe.php
1 <?php
2 /**
3  * Smarty Internal Extension
4  * This file contains the Smarty template extension to create a code frame
5  *
6  * @package    Smarty
7  * @subpackage Template
8  * @author     Uwe Tews
9  */
10
11 /**
12  * Class Smarty_Internal_Extension_CodeFrame
13  * Create code frame for compiled and cached templates
14  */
15 class Smarty_Internal_Runtime_CodeFrame
16 {
17     /**
18      * Create code frame for compiled and cached templates
19      *
20      * @param Smarty_Internal_Template              $_template
21      * @param string                                $content   optional template content
22      * @param string                                $functions compiled template function and block code
23      * @param bool                                  $cache     flag for cache file
24      * @param \Smarty_Internal_TemplateCompilerBase $compiler
25      *
26      * @return string
27      */
28     public function create(Smarty_Internal_Template $_template, $content = '', $functions = '', $cache = false,
29                            Smarty_Internal_TemplateCompilerBase $compiler = null)
30     {
31         // build property code
32         $properties[ 'version' ] = Smarty::SMARTY_VERSION;
33         $properties[ 'unifunc' ] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
34         if (!$cache) {
35             $properties[ 'has_nocache_code' ] = $_template->compiled->has_nocache_code;
36             $properties[ 'file_dependency' ] = $_template->compiled->file_dependency;
37             $properties[ 'includes' ] = $_template->compiled->includes;
38          } else {
39             $properties[ 'has_nocache_code' ] = $_template->cached->has_nocache_code;
40             $properties[ 'file_dependency' ] = $_template->cached->file_dependency;
41             $properties[ 'cache_lifetime' ] = $_template->cache_lifetime;
42         }
43         $output = "<?php\n";
44         $output .= "/* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") .
45                    "\n  from \"" . $_template->source->filepath . "\" */\n\n";
46         $output .= "/* @var Smarty_Internal_Template \$_smarty_tpl */\n";
47         $dec = "\$_smarty_tpl->_decodeProperties(\$_smarty_tpl, " . var_export($properties, true) . ',' .
48                ($cache ? 'true' : 'false') . ")";
49         $output .= "if ({$dec}) {\n";
50         $output .= "function {$properties['unifunc']} (Smarty_Internal_Template \$_smarty_tpl) {\n";
51         if (!$cache && !empty($compiler->tpl_function)) {
52             $output .= "\$_smarty_tpl->smarty->ext->_tplFunction->registerTplFunctions(\$_smarty_tpl, " .
53                        var_export($compiler->tpl_function, true) . ");\n";
54         }
55         if ($cache && isset($_template->smarty->ext->_tplFunction)) {
56             $output .= "\$_smarty_tpl->smarty->ext->_tplFunction->registerTplFunctions(\$_smarty_tpl, " .
57                        var_export($_template->smarty->ext->_tplFunction->getTplFunction($_template), true) . ");\n";
58
59         }
60         // include code for plugins
61         if (!$cache) {
62             if (!empty($_template->compiled->required_plugins[ 'compiled' ])) {
63                 foreach ($_template->compiled->required_plugins[ 'compiled' ] as $tmp) {
64                     foreach ($tmp as $data) {
65                         $file = addslashes($data[ 'file' ]);
66                         if (is_array($data[ 'function' ])) {
67                             $output .= "if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) require_once '{$file}';\n";
68                         } else {
69                             $output .= "if (!is_callable('{$data['function']}')) require_once '{$file}';\n";
70                         }
71                     }
72                 }
73             }
74             if ($_template->caching && !empty($_template->compiled->required_plugins[ 'nocache' ])) {
75                 $_template->compiled->has_nocache_code = true;
76                 $output .= "echo '/*%%SmartyNocache:{$_template->compiled->nocache_hash}%%*/<?php \$_smarty = \$_smarty_tpl->smarty; ";
77                 foreach ($_template->compiled->required_plugins[ 'nocache' ] as $tmp) {
78                     foreach ($tmp as $data) {
79                         $file = addslashes($data[ 'file' ]);
80                         if (is_array($data[ 'function' ])) {
81                             $output .= addslashes("if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) require_once '{$file}';\n");
82                         } else {
83                             $output .= addslashes("if (!is_callable('{$data['function']}')) require_once '{$file}';\n");
84                         }
85                     }
86                 }
87                 $output .= "?>/*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%*/';\n";
88             }
89         }
90         $output .= "?>\n";
91         $output .= $content;
92         $output .= "<?php }\n?>";
93         $output .= $functions;
94         $output .= "<?php }\n";
95         // remove unneeded PHP tags
96         return preg_replace(array('/\s*\?>[\n]?<\?php\s*/', '/\?>\s*$/'), array("\n", ''), $output);
97     }
98 }