includes/classes/smarty/sysplugins/smarty_internal_runtime_codeframe.php line 48

Open in your IDE?
  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.  * Class Smarty_Internal_Extension_CodeFrame
  12.  * Create code frame for compiled and cached templates
  13.  */
  14. class Smarty_Internal_Runtime_CodeFrame
  15. {
  16.     /**
  17.      * Create code frame for compiled and cached templates
  18.      *
  19.      * @param Smarty_Internal_Template              $_template
  20.      * @param string                                $content   optional template content
  21.      * @param string                                $functions compiled template function and block code
  22.      * @param bool                                  $cache     flag for cache file
  23.      * @param \Smarty_Internal_TemplateCompilerBase $compiler
  24.      *
  25.      * @return string
  26.      */
  27.     public function create(
  28.         Smarty_Internal_Template $_template,
  29.         $content '',
  30.         $functions '',
  31.         $cache false,
  32.         Smarty_Internal_TemplateCompilerBase $compiler null
  33.     ) {
  34.         // build property code
  35.         $properties'version' ] = Smarty::SMARTY_VERSION;
  36.         $properties'unifunc' ] = 'content_' str_replace(array('.'','), '_'uniqid(''true));
  37.         if (!$cache) {
  38.             $properties'has_nocache_code' ] = $_template->compiled->has_nocache_code;
  39.             $properties'file_dependency' ] = $_template->compiled->file_dependency;
  40.             $properties'includes' ] = $_template->compiled->includes;
  41.         } else {
  42.             $properties'has_nocache_code' ] = $_template->cached->has_nocache_code;
  43.             $properties'file_dependency' ] = $_template->cached->file_dependency;
  44.             $properties'cache_lifetime' ] = $_template->cache_lifetime;
  45.         }
  46.         $output "<?php\n";
  47.         $output .= "/* Smarty version {$properties'version' ]}, created on " strftime("%Y-%m-%d %H:%M:%S") .
  48.                    "\n  from '" str_replace('*/''* /'$_template->source->filepath) . "' */\n\n";
  49.         $output .= "/* @var Smarty_Internal_Template \$_smarty_tpl */\n";
  50.         $dec "\$_smarty_tpl->_decodeProperties(\$_smarty_tpl, " var_export($propertiestrue) . ',' .
  51.                ($cache 'true' 'false') . ')';
  52.         $output .= "if ({$dec}) {\n";
  53.         $output .= "function {$properties['unifunc']} (Smarty_Internal_Template \$_smarty_tpl) {\n";
  54.         if (!$cache && !empty($compiler->tpl_function)) {
  55.             $output .= '$_smarty_tpl->smarty->ext->_tplFunction->registerTplFunctions($_smarty_tpl, ';
  56.             $output .= var_export($compiler->tpl_functiontrue);
  57.             $output .= ");\n";
  58.         }
  59.         if ($cache && isset($_template->smarty->ext->_tplFunction)) {
  60.             $output .= "\$_smarty_tpl->smarty->ext->_tplFunction->registerTplFunctions(\$_smarty_tpl, " .
  61.                        var_export($_template->smarty->ext->_tplFunction->getTplFunction($_template), true) . ");\n";
  62.         }
  63.         $output .= "?>";
  64.         $output .= $content;
  65.         $output .= "<?php }\n?>";
  66.         $output .= $functions;
  67.         $output .= "<?php }\n";
  68.         // remove unneeded PHP tags
  69.         if (preg_match('/\s*\?>[\n]?<\?php\s*/'$output)) {
  70.             $curr_split preg_split(
  71.                 '/\s*\?>[\n]?<\?php\s*/',
  72.                 $output
  73.             );
  74.             preg_match_all(
  75.                 '/\s*\?>[\n]?<\?php\s*/',
  76.                 $output,
  77.                 $curr_parts
  78.             );
  79.             $output '';
  80.             foreach ($curr_split as $idx => $curr_output) {
  81.                 $output .= $curr_output;
  82.                 if (isset($curr_parts][ $idx ])) {
  83.                     $output .= "\n";
  84.                 }
  85.             }
  86.         }
  87.         if (preg_match('/\?>\s*$/'$output)) {
  88.             $curr_split preg_split(
  89.                 '/\?>\s*$/',
  90.                 $output
  91.             );
  92.             $output '';
  93.             foreach ($curr_split as $idx => $curr_output) {
  94.                 $output .= $curr_output;
  95.             }
  96.         }
  97.         return $output;
  98.     }
  99. }