public function compileTemplate(Smarty_Internal_Template $template) { if (empty($template->properties['nocache_hash'])) { $template->properties['nocache_hash'] = $this->nocache_hash; } else { $this->nocache_hash = $template->properties['nocache_hash']; } $this->nocache = false; $this->tag_nocache = false; $this->template = $template; $this->template->has_nocache_code = false; $this->smarty->_current_file = $saved_filepath = $this->template->source->filepath; $template_header = ''; if (!$this->suppressHeader) { $template_header .= "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n"; $template_header .= " compiled from \"" . $this->template->source->filepath . "\" */ ?>\n"; } do { $this->abort_and_recompile = false; $_content = $template->source->content; if (isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) { $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template); } if ($_content == '') { if ($this->suppressTemplatePropertyHeader) { $code = ''; } else { $code = $template_header . $template->createTemplateCodeFrame(); } return $code; } $_compiled_code = $this->doCompile($_content); } while ($this->abort_and_recompile); $this->template->source->filepath = $saved_filepath; unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex, $this->template); self::$_tag_objects = array(); $merged_code = ''; if (!$this->suppressMergedTemplates && !empty($this->merged_templates)) { foreach ($this->merged_templates as $code) { $merged_code .= $code; } if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) { $merged_code = Smarty_Internal_Filter_Handler::runFilter('post', $merged_code, $template); } } if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) { $_compiled_code = Smarty_Internal_Filter_Handler::runFilter('post', $_compiled_code, $template); } if ($this->suppressTemplatePropertyHeader) { $code = $_compiled_code . $merged_code; } else { $code = $template_header . $template->createTemplateCodeFrame($_compiled_code) . $merged_code; } unset($template->source->content); return $code; }
/** * Method to compile a Smarty template * * @param Smarty_Internal_Template $template template object to compile * @return bool true if compiling succeeded, false if it failed */ public function compileTemplate(Smarty_Internal_Template $template) { if (empty($template->properties['nocache_hash'])) { $template->properties['nocache_hash'] = $this->nocache_hash; } else { $this->nocache_hash = $template->properties['nocache_hash']; } // flag for nochache sections $this->nocache = false; $this->tag_nocache = false; // save template object in compiler class $this->template = $template; // reset has noche code flag $this->template->has_nocache_code = false; $this->smarty->_current_file = $saved_filepath = $this->template->source->filepath; // template header code $template_header = ''; if (!$this->suppressHeader) { $template_header .= "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n"; $template_header .= " compiled from \"" . $this->template->source->filepath . "\" */ ?>\n"; } do { // flag for aborting current and start recompile $this->abort_and_recompile = false; // get template source $_content = $template->source->content; // run prefilter if required if (isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) { $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template); } // on empty template just return header if ($_content == '') { if ($this->suppressTemplatePropertyHeader) { $code = ''; } else { $code = $template_header . $template->createTemplateCodeFrame(); } return $code; } // call compiler $_compiled_code = $this->doCompile($_content); } while ($this->abort_and_recompile); $this->template->source->filepath = $saved_filepath; // free memory unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex, $this->template); self::$_tag_objects = array(); // return compiled code to template object $merged_code = ''; if (!$this->suppressMergedTemplates && !empty($this->merged_templates)) { foreach ($this->merged_templates as $code) { $merged_code .= $code; } // run postfilter if required on merged code if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) { $merged_code = Smarty_Internal_Filter_Handler::runFilter('post', $merged_code, $template); } } // run postfilter if required on compiled template code if (isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) { $_compiled_code = Smarty_Internal_Filter_Handler::runFilter('post', $_compiled_code, $template); } if ($this->suppressTemplatePropertyHeader) { $code = $_compiled_code . $merged_code; } else { $code = $template_header . $template->createTemplateCodeFrame($_compiled_code) . $merged_code; } return $code; }
/** * Compiles the template * * If the template is not evaluated the compiled template is saved on disk */ public function compileTemplateSource() { if (!$this->resource_object->isEvaluated) { $this->properties['file_dependency'] = array(); $this->properties['file_dependency'][$this->templateUid] = array($this->getTemplateFilepath(), $this->getTemplateTimestamp(), $this->resource_type); } if ($this->smarty->debugging) { Smarty_Internal_Debug::start_compile($this); } // compile template if (!is_object($this->compiler_object)) { // load compiler $this->smarty->loadPlugin($this->resource_object->compiler_class); $this->compiler_object = new $this->resource_object->compiler_class($this->resource_object->template_lexer_class, $this->resource_object->template_parser_class, $this->smarty); } // compile locking if ($this->smarty->compile_locking && !$this->resource_object->isEvaluated) { if ($saved_timestamp = $this->getCompiledTimestamp()) { touch($this->getCompiledFilepath()); } } // call compiler try { $this->compiler_object->compileTemplate($this); } catch (Exception $e) { // restore old timestamp in case of error if ($this->smarty->compile_locking && !$this->resource_object->isEvaluated && $saved_timestamp) { touch($this->getCompiledFilepath(), $saved_timestamp); } throw $e; } // compiling succeded if (!$this->resource_object->isEvaluated && $this->write_compiled_code) { // write compiled template Smarty_Internal_Write_File::writeFile($this->getCompiledFilepath(), $this->compiled_template, $this->smarty); } if ($this->smarty->debugging) { Smarty_Internal_Debug::end_compile($this); } // release objects to free memory Smarty_Internal_TemplateCompilerBase::$_tag_objects = array(); unset($this->compiler_object->parser->root_buffer, $this->compiler_object->parser->current_buffer, $this->compiler_object->parser, $this->compiler_object->lex, $this->compiler_object->template, $this->compiler_object); }
/** * Compile template source and run optional post filter * * @param \Smarty_Internal_Template $template * @param null|bool $nocache flag if template must be compiled in nocache mode * @param \Smarty_Internal_TemplateCompilerBase $parent_compiler * * @return string * @throws \Exception */ public function compileTemplateSource(Smarty_Internal_Template $template, $nocache = null, Smarty_Internal_TemplateCompilerBase $parent_compiler = null) { try { // save template object in compiler class $this->template = $template; if (property_exists($this->template->smarty, 'plugin_search_order')) { $this->plugin_search_order = $this->template->smarty->plugin_search_order; } if ($this->smarty->debugging) { $this->smarty->_debug->start_compile($this->template); } if (isset($this->template->smarty->security_policy)) { $this->php_handling = $this->template->smarty->security_policy->php_handling; } else { $this->php_handling = $this->template->smarty->php_handling; } $this->parent_compiler = $parent_compiler ? $parent_compiler : $this; $nocache = isset($nocache) ? $nocache : false; if (empty($template->compiled->nocache_hash)) { $template->compiled->nocache_hash = $this->nocache_hash; } else { $this->nocache_hash = $template->compiled->nocache_hash; } // flag for nocache sections $this->nocache = $nocache; $this->tag_nocache = false; // reset has nocache code flag $this->template->compiled->has_nocache_code = false; $this->has_variable_string = false; $this->prefix_code = array(); // add file dependency $this->parent_compiler->template->compiled->file_dependency[$this->template->source->uid] = array($this->template->source->filepath, $this->template->source->getTimeStamp(), $this->template->source->type); $this->smarty->_current_file = $this->template->source->filepath; // get template source if (!empty($this->template->source->components)) { // we have array of inheritance templates by extends: resource // generate corresponding source code sequence $_content = Smarty_Internal_Compile_Extends::extendsSourceArrayCode($this->template->source->components); } else { // get template source $_content = $this->template->source->getContent(); } $_compiled_code = $this->postFilter($this->doCompile($this->preFilter($_content), true)); } catch (Exception $e) { if ($this->smarty->debugging) { $this->smarty->_debug->end_compile($this->template); } $this->_tag_stack = array(); self::$_tag_objects = array(); // free memory $this->parent_compiler = null; $this->template = null; $this->parser = null; throw $e; } if ($this->smarty->debugging) { $this->smarty->_debug->end_compile($this->template); } $this->parent_compiler = null; $this->parser = null; return $_compiled_code; }
/** * Method to compile a Smarty template * @param Smarty_Internal_Template $template template object to compile * @param bool $nocache true is shall be compiled in nocache mode * @param null|Smarty_Internal_TemplateCompilerBase $parent_compiler * @return bool true if compiling succeeded, false if it failed */ public function compileTemplate(Smarty_Internal_Template $template, $nocache = NULL, $parent_compiler = NULL) { // save template object in compiler class $this->template = $template; if (isset($this->template->smarty->security_policy)) { $this->php_handling = $this->template->smarty->security_policy->php_handling; } else { $this->php_handling = $this->template->smarty->php_handling; } $this->parent_compiler = $parent_compiler ? $parent_compiler : $this; $nocache = isset($nocache) ? $nocache : FALSE; if (empty($template->properties['nocache_hash'])) { $template->properties['nocache_hash'] = $this->nocache_hash; } else { $this->nocache_hash = $template->properties['nocache_hash']; } // flag for nochache sections $this->nocache = $nocache; $this->tag_nocache = FALSE; // reset has nocache code flag $this->template->has_nocache_code = FALSE; $save_source = $this->template->source; // template header code $template_header = ''; if (!$this->suppressHeader) { $template_header .= "<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n"; $template_header .= " compiled from \"" . $this->template->source->filepath . "\" */ ?>\n"; } if (empty($this->template->source->components)) { $this->sources = [$template->source]; } else { // we have array of inheritance templates by extends: resource $this->sources = array_reverse($template->source->components); } $loop = 0; // the $this->sources array can get additional elements while compiling by the {extends} tag while ($this->template->source = array_shift($this->sources)) { $this->smarty->_current_file = $this->template->source->filepath; if ($this->smarty->debugging) { Smarty_Internal_Debug::start_compile($this->template); } $no_sources = count($this->sources); $this->parent_compiler->template->properties['file_dependency'][$this->template->source->uid] = [$this->template->source->filepath, $this->template->source->timestamp, $this->template->source->type]; $loop++; if ($no_sources) { $this->inheritance_child = TRUE; } else { $this->inheritance_child = FALSE; } do { // flag for nochache sections $this->nocache = $nocache; $this->tag_nocache = FALSE; // reset has nocache code flag $this->template->has_nocache_code = FALSE; $this->has_variable_string = FALSE; $this->prefix_code = []; $_compiled_code = ''; // flag for aborting current and start recompile $this->abort_and_recompile = FALSE; // get template source $_content = $this->template->source->content; if ($_content != '') { // run prefilter if required if ((isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) && !$this->suppressFilter) { $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template); } // call compiler $_compiled_code = $this->doCompile($_content, TRUE); } } while ($this->abort_and_recompile); if ($this->smarty->debugging) { Smarty_Internal_Debug::end_compile($this->template); } } // restore source $this->template->source = $save_source; unset($save_source); $this->smarty->_current_file = $this->template->source->filepath; // free memory unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex); self::$_tag_objects = []; // return compiled code to template object $merged_code = ''; if (!empty($this->mergedSubTemplatesCode)) { foreach ($this->mergedSubTemplatesCode as $code) { $merged_code .= $code; } } // run postfilter if required on compiled template code if ((isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) && !$this->suppressFilter && $_compiled_code != '') { $_compiled_code = Smarty_Internal_Filter_Handler::runFilter('post', $_compiled_code, $template); } if ($this->suppressTemplatePropertyHeader) { $_compiled_code .= $merged_code; } else { $_compiled_code = $template_header . Smarty_Internal_Extension_CodeFrame::create($template, $_compiled_code) . $merged_code; } if (!empty($this->templateFunctionCode)) { // run postfilter if required on compiled template code if ((isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) && !$this->suppressFilter) { $_compiled_code .= Smarty_Internal_Filter_Handler::runFilter('post', $this->templateFunctionCode, $template); } else { $_compiled_code .= $this->templateFunctionCode; } } // unset content because template inheritance could have replace source with parent code unset($template->source->content); $this->parent_compiler = NULL; $this->template = NULL; return $_compiled_code; }
/** * Method to compile a Smarty template * * @param Smarty_Internal_Template $template template object to compile * @param bool $nocache true is shall be compiled in nocache mode * * @param Smarty_Internal_TemplateCompilerBase $parent_compiler * * @return bool true if compiling succeeded, false if it failed * @throws \SmartyException */ public function compileTemplate(Smarty_Internal_Template $template, $nocache = null, Smarty_Internal_TemplateCompilerBase $parent_compiler = null) { $this->parent_compiler = $parent_compiler ? $parent_compiler : $this; $nocache = isset($nocache) ? $nocache : false; // flag for nochache sections $this->nocache = $nocache; $this->tag_nocache = false; // save template object in compiler class $this->template = $template; // template header code $template_header = ''; if (!$this->suppressHeader) { $template_header .= "/* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") . "\n"; $template_header .= " compiled from \"" . $this->template->source->filepath . "\" */\n"; } if ($isExtendsResource = !empty($this->template->source->components)) { // we have array of inheritance templates by extends: resource $this->sources = array_reverse($template->source->components); } // the $this->sources array can get additional elements while compiling by the {extends} tag if (!$isExtendsResource) { $this->inheritance_child = $this->template->source->isChild; $this->smarty->_current_file = $this->template->source->filepath; if ($this->smarty->debugging) { Smarty_Internal_Debug::start_compile($this->template); } if (!($this->template->source->recompiled || $this->template->source->type == 'string' || $this->template->source->type == 'extends')) { $this->parent_compiler->resourceInfo[$this->template->source->uid] = $this->template->source->getResourceInfo($this->template); } } do { // flag for aborting current and start recompile $this->abort_and_recompile = false; if ($isExtendsResource) { $_content = ''; } else { // get template source $_content = $this->template->source->content; } if ($_content != '') { // run prefilter if required if ((isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) && !$this->suppressFilter) { $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template); } } // call compiler $_compiled_code = $this->doCompile($_content); } while ($this->abort_and_recompile); if ($this->smarty->debugging) { Smarty_Internal_Debug::end_compile($this->template); } // free memory unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex); self::$_tag_objects = array(); // return compiled code to template object // run postfilter if required on compiled template code if ((isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) && !$this->suppressFilter && $_compiled_code != '') { $_compiled_code = Smarty_Internal_Filter_Handler::runFilter('post', $_compiled_code, $template); } // unset content because template inheritance could have replace source with parent code unset($template->source->content); $this->parent_compiler = null; $this->template = null; if ($this->suppressTemplatePropertyHeader) { return $_compiled_code; } else { $properties = array('resourceInfo' => $this->resourceInfo, 'isInheritanceChild' => $this->inheritance_child); if (isset($this->templateProperties['tpl_function'])) { $properties['templateFunctions'] = $this->templateProperties['tpl_function']; } if (isset($this->templateProperties['block_function'])) { $properties['blockFunctions'] = $this->templateProperties['block_function']; } foreach ($this->plugins as $tmp) { foreach ($tmp as $plugin) { $properties['plugins'][$plugin['file']] = $plugin['function']; } } foreach ($this->nocachePlugins as $tmp) { foreach ($tmp as $plugin) { $properties['nocachePlugins'][$plugin['file']] = $plugin['function']; } } return Smarty_Internal_Extension_CodeFrame::create($template, $properties, $_compiled_code, $template_header); } }
/** * Method to compile a Smarty template. * * @param Smarty_Internal_Template $template template object to compile * @param bool $nocache true is shall be compiled in nocache mode * * @return bool true if compiling succeeded, false if it failed */ public function compileTemplate(Smarty_Internal_Template $template, $nocache = false) { if (empty($template->properties['nocache_hash'])) { $template->properties['nocache_hash'] = $this->nocache_hash; } else { $this->nocache_hash = $template->properties['nocache_hash']; } // flag for nochache sections $this->nocache = $nocache; $this->tag_nocache = false; // save template object in compiler class $this->template = $template; // reset has nocache code flag $this->template->has_nocache_code = false; $save_source = $this->template->source; // template header code $template_header = ''; if (!$this->suppressHeader) { $template_header .= '<?php /* Smarty version ' . Smarty::SMARTY_VERSION . ', created on ' . strftime('%Y-%m-%d %H:%M:%S') . "\n"; $template_header .= ' compiled from "' . $this->template->source->filepath . "\" */ ?>\n"; } if (empty($this->template->source->components)) { $this->sources = array($template->source); } else { // we have array of inheritance templates by extends: resource $this->sources = array_reverse($template->source->components); } $loop = 0; // the $this->sources array can get additional elements while compiling by the {extends} tag while ($this->template->source = array_shift($this->sources)) { $this->smarty->_current_file = $this->template->source->filepath; if ($this->smarty->debugging) { Smarty_Internal_Debug::start_compile($this->template); } $no_sources = count($this->sources); if ($loop || $no_sources) { $this->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->filepath, $this->template->source->timestamp, $this->template->source->type); } ++$loop; if ($no_sources) { $this->inheritance_child = true; } else { $this->inheritance_child = false; } do { $_compiled_code = ''; // flag for aborting current and start recompile $this->abort_and_recompile = false; // get template source $_content = $this->template->source->content; if ($_content != '') { // run prefilter if required if ((isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])) && !$this->suppressFilter) { $_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $template); } // call compiler $_compiled_code = $this->doCompile($_content); } } while ($this->abort_and_recompile); if ($this->smarty->debugging) { Smarty_Internal_Debug::end_compile($this->template); } } // restore source $this->template->source = $save_source; unset($save_source); $this->smarty->_current_file = $this->template->source->filepath; // free memory unset($this->parser->root_buffer, $this->parser->current_buffer, $this->parser, $this->lex, $this->template); self::$_tag_objects = array(); // return compiled code to template object $merged_code = ''; if (!$this->suppressMergedTemplates && !empty($this->merged_templates)) { foreach ($this->merged_templates as $code) { $merged_code .= $code; } } // run postfilter if required on compiled template code if ((isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post'])) && !$this->suppressFilter && $_compiled_code != '') { $_compiled_code = Smarty_Internal_Filter_Handler::runFilter('post', $_compiled_code, $template); } if ($this->suppressTemplatePropertyHeader) { $code = $_compiled_code . $merged_code; } else { $code = $template_header . $template->createTemplateCodeFrame($_compiled_code) . $merged_code; } // unset content because template inheritance could have replace source with parent code unset($template->source->content); return $code; }