| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  | <?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 | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-12-08 23:41:42 +01:00
										 |  |  |      * @param Smarty_Internal_Template              $_template | 
					
						
							| 
									
										
										
										
											2015-12-23 00:44:51 +01:00
										 |  |  |      * @param string                                $content   optional template content | 
					
						
							| 
									
										
										
										
											2015-12-08 23:41:42 +01:00
										 |  |  |      * @param string                                $functions compiled template function and block code | 
					
						
							| 
									
										
										
										
											2015-12-23 00:44:51 +01:00
										 |  |  |      * @param bool                                  $cache     flag for cache file | 
					
						
							| 
									
										
										
										
											2015-12-08 23:41:42 +01:00
										 |  |  |      * @param \Smarty_Internal_TemplateCompilerBase $compiler | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return string | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-12-08 23:41:42 +01:00
										 |  |  |     public function create(Smarty_Internal_Template $_template, $content = '', $functions = '', $cache = false, | 
					
						
							|  |  |  |                            Smarty_Internal_TemplateCompilerBase $compiler = null) | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         // build property code
 | 
					
						
							| 
									
										
										
										
											2015-12-08 23:41:42 +01:00
										 |  |  |         $properties[ 'version' ] = Smarty::SMARTY_VERSION; | 
					
						
							|  |  |  |         $properties[ 'unifunc' ] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true)); | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |         if (!$cache) { | 
					
						
							| 
									
										
										
										
											2016-01-27 00:35:04 +01:00
										 |  |  |             $properties[ 'has_nocache_code' ] = $_template->compiled->has_nocache_code; | 
					
						
							| 
									
										
										
										
											2015-12-08 23:41:42 +01:00
										 |  |  |             $properties[ 'file_dependency' ] = $_template->compiled->file_dependency; | 
					
						
							|  |  |  |             $properties[ 'includes' ] = $_template->compiled->includes; | 
					
						
							| 
									
										
										
										
											2016-08-07 15:31:01 +02:00
										 |  |  |          } else { | 
					
						
							| 
									
										
										
										
											2016-01-27 00:35:04 +01:00
										 |  |  |             $properties[ 'has_nocache_code' ] = $_template->cached->has_nocache_code; | 
					
						
							| 
									
										
										
										
											2015-12-08 23:41:42 +01:00
										 |  |  |             $properties[ 'file_dependency' ] = $_template->cached->file_dependency; | 
					
						
							|  |  |  |             $properties[ 'cache_lifetime' ] = $_template->cache_lifetime; | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         $output = "<?php\n"; | 
					
						
							|  |  |  |         $output .= "/* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                    "\n  from \"" . $_template->source->filepath . "\" */\n\n"; | 
					
						
							| 
									
										
										
										
											2016-02-05 17:41:11 +01:00
										 |  |  |         $output .= "/* @var Smarty_Internal_Template \$_smarty_tpl */\n"; | 
					
						
							| 
									
										
										
										
											2015-12-23 00:44:51 +01:00
										 |  |  |         $dec = "\$_smarty_tpl->_decodeProperties(\$_smarty_tpl, " . var_export($properties, true) . ',' . | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                ($cache ? 'true' : 'false') . ")"; | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |         $output .= "if ({$dec}) {\n"; | 
					
						
							| 
									
										
										
										
											2016-02-05 17:41:11 +01:00
										 |  |  |         $output .= "function {$properties['unifunc']} (Smarty_Internal_Template \$_smarty_tpl) {\n"; | 
					
						
							| 
									
										
										
										
											2016-08-07 15:31:01 +02:00
										 |  |  |         if (!$cache && !empty($compiler->tpl_function)) { | 
					
						
							|  |  |  |             $output .= "\$_smarty_tpl->ext->_tplFunction->registerTplFunctions(\$_smarty_tpl, " . | 
					
						
							|  |  |  |                        var_export($compiler->tpl_function, true) . ");\n"; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if ($cache && isset($_template->ext->_tplFunction)) { | 
					
						
							|  |  |  |             $output .= "\$_smarty_tpl->ext->_tplFunction->registerTplFunctions(\$_smarty_tpl, " . | 
					
						
							|  |  |  |                        var_export($_template->ext->_tplFunction->getTplFunction(), true) . ");\n"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |         // include code for plugins
 | 
					
						
							|  |  |  |         if (!$cache) { | 
					
						
							| 
									
										
										
										
											2015-12-08 23:41:42 +01:00
										 |  |  |             if (!empty($_template->compiled->required_plugins[ 'compiled' ])) { | 
					
						
							|  |  |  |                 foreach ($_template->compiled->required_plugins[ 'compiled' ] as $tmp) { | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |                     foreach ($tmp as $data) { | 
					
						
							| 
									
										
										
										
											2015-12-08 23:41:42 +01:00
										 |  |  |                         $file = addslashes($data[ 'file' ]); | 
					
						
							|  |  |  |                         if (is_array($data[ 'function' ])) { | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |                             $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"; | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-12-08 23:41:42 +01:00
										 |  |  |             if ($_template->caching && !empty($_template->compiled->required_plugins[ 'nocache' ])) { | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |                 $_template->compiled->has_nocache_code = true; | 
					
						
							|  |  |  |                 $output .= "echo '/*%%SmartyNocache:{$_template->compiled->nocache_hash}%%*/<?php \$_smarty = \$_smarty_tpl->smarty; "; | 
					
						
							| 
									
										
										
										
											2015-12-08 23:41:42 +01:00
										 |  |  |                 foreach ($_template->compiled->required_plugins[ 'nocache' ] as $tmp) { | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |                     foreach ($tmp as $data) { | 
					
						
							| 
									
										
										
										
											2015-12-08 23:41:42 +01:00
										 |  |  |                         $file = addslashes($data[ 'file' ]); | 
					
						
							| 
									
										
										
										
											2016-03-09 04:03:37 +01:00
										 |  |  |                         if (is_array($data[ 'function' ])) { | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |                             $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
 | 
					
						
							| 
									
										
										
										
											2015-12-19 21:37:46 +01:00
										 |  |  |         return preg_replace(array('/\s*\?>[\n]?<\?php\s*/', '/\?>\s*$/'), array("\n", ''), $output); | 
					
						
							| 
									
										
										
										
											2015-10-24 05:02:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } |