mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
- update compiler by moving no longer needed properties, code optimizations and other
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
===== 3.1.28-dev===== (xx.xx.2015)
|
||||
16.09.2015
|
||||
- update compiler by moving no longer needed properties, code optimizations and other
|
||||
|
||||
14.09.2015
|
||||
- optimize autoloader
|
||||
- optimize subtemplate handling
|
||||
|
@@ -119,7 +119,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '3.1.28-dev/60';
|
||||
const SMARTY_VERSION = '3.1.28-dev/61';
|
||||
|
||||
/**
|
||||
* define variable scopes
|
||||
|
@@ -165,9 +165,8 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase
|
||||
if ($compiler->template->compiled->has_nocache_code) {
|
||||
// $compiler->parent_compiler->template->tpl_function[$_name]['call_name_caching'] = $_funcNameCaching;
|
||||
$_funcNameCaching .= '_nocache';
|
||||
$output = "<?php\n";
|
||||
$output .= "/* {$_funcNameCaching} {$compiler->template->source->type}:{$compiler->template->source->name} */\n";
|
||||
$output .= "if (!function_exists('{$_funcNameCaching}')) {\n";
|
||||
$output = "<?php\n\n";
|
||||
$output .= "/* {block '{$_name}'} {$compiler->template->source->type}:{$compiler->template->source->name} */\n";
|
||||
$output .= "function {$_funcNameCaching} (\$_smarty_tpl, \$block) {\n";
|
||||
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n";
|
||||
$output .= "\$_smarty_tpl->cached->hashes['{$compiler->template->compiled->nocache_hash}'] = true;\n?>\n";
|
||||
@@ -176,13 +175,13 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase
|
||||
$output));
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
|
||||
$output = "<?php /*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n";
|
||||
$output .= "\n}\n}\n";
|
||||
$output .= "/*/ {$_funcName}_nocache */\n\n";
|
||||
$output .= "\n}\n";
|
||||
$output .= "/* {/block '{$_name}'} */\n\n";
|
||||
$output .= "?>\n";
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser,
|
||||
new Smarty_Internal_ParseTree_Tag($compiler->parser,
|
||||
$output));
|
||||
$compiler->parent_compiler->templateFunctionCode .= $f =
|
||||
$compiler->blockOrFunctionCode .= $f =
|
||||
$compiler->parser->current_buffer->to_smarty_php($compiler->parser);
|
||||
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
|
||||
$_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser,
|
||||
@@ -190,21 +189,20 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase
|
||||
array($this, 'removeNocache'),
|
||||
$_functionCode->to_smarty_php($compiler->parser)));
|
||||
}
|
||||
$output = "<?php\n";
|
||||
$output .= "/* {$_funcName} {$compiler->template->source->type}:{$compiler->template->source->name} */\n";
|
||||
$output .= "if (!function_exists('{$_funcName}')) {\n";
|
||||
$output = "<?php\n\n";
|
||||
$output .= "/* {block '{$_name}'} {$compiler->template->source->type}:{$compiler->template->source->name} */\n";
|
||||
$output .= "function {$_funcName}(\$_smarty_tpl, \$block) {?>";
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser,
|
||||
new Smarty_Internal_ParseTree_Tag($compiler->parser,
|
||||
$output));
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
|
||||
$output = "<?php\n}\n}\n";
|
||||
$output .= "/*/ {$_funcName} */\n";
|
||||
$output = "<?php\n}\n";
|
||||
$output .= "/* {/block '{$_name}'} */\n\n";
|
||||
$output .= "?>\n";
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser,
|
||||
new Smarty_Internal_ParseTree_Tag($compiler->parser,
|
||||
$output));
|
||||
$compiler->parent_compiler->templateFunctionCode .= $f =
|
||||
$compiler->blockOrFunctionCode .= $f =
|
||||
$compiler->parser->current_buffer->to_smarty_php($compiler->parser);
|
||||
// nocache plugins must be copied
|
||||
if (!empty($compiler->template->compiled->required_plugins['nocache'])) {
|
||||
|
@@ -66,8 +66,6 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
|
||||
$save = array($_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code,
|
||||
$compiler->template->caching);
|
||||
$this->openTag($compiler, 'function', $save);
|
||||
// set flag that we are compiling a template function
|
||||
$compiler->compiles_template_function = true;
|
||||
// Init temporary context
|
||||
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
|
||||
$compiler->template->compiled->has_nocache_code = false;
|
||||
@@ -107,8 +105,6 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
||||
$saved_data = $this->closeTag($compiler, array('function'));
|
||||
$_attr = $saved_data[0];
|
||||
$_name = trim($_attr['name'], "'\"");
|
||||
// reset flag that we are compiling a template function
|
||||
$compiler->compiles_template_function = false;
|
||||
$compiler->parent_compiler->template->tpl_function[$_name]['called_functions'] = $compiler->called_functions;
|
||||
$compiler->parent_compiler->template->tpl_function[$_name]['compiled_filepath'] = $compiler->parent_compiler->template->compiled->filepath;
|
||||
$compiler->parent_compiler->template->tpl_function[$_name]['uid'] = $compiler->template->source->uid;
|
||||
@@ -182,7 +178,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
||||
$output .= "/*/ {$_funcName} */\n\n";
|
||||
$output .= "?>\n";
|
||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
|
||||
$compiler->parent_compiler->templateFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
|
||||
$compiler->parent_compiler->blockOrFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
|
||||
// nocache plugins must be copied
|
||||
if (!empty($compiler->template->compiled->required_plugins['nocache'])) {
|
||||
foreach ($compiler->template->compiled->required_plugins['nocache'] as $plugin => $tmp) {
|
||||
|
@@ -209,55 +209,10 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
$c_id = isset($_attr['compile_id']) ? $_attr['compile_id'] : $compiler->template->compile_id;
|
||||
// we must observe different compile_id and caching
|
||||
$t_hash = sha1($c_id . ($_caching ? '--caching' : '--nocaching'));
|
||||
$tpl_name = null;
|
||||
|
||||
if (!isset($compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash])) {
|
||||
$compiler->smarty->allow_ambiguous_resources = true;
|
||||
/* @var Smarty_Internal_Template $tpl */
|
||||
$tpl = new $compiler->smarty->template_class (trim($fullResourceName, "'"), $compiler->smarty,
|
||||
$compiler->template, $compiler->template->cache_id, $c_id,
|
||||
$_caching);
|
||||
$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['uid'] =
|
||||
$tpl->source->uid;
|
||||
if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) {
|
||||
$tpl->compiled = new Smarty_Template_Compiled();
|
||||
$tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash;
|
||||
$tpl->loadCompiler();
|
||||
$tpl->compiler->inheritanceChild =
|
||||
$tpl->compiler->inheritanceForceChild = $compiler->inheritanceForceChild;
|
||||
$tpl->compiler->inheritance = $compiler->inheritance;
|
||||
// save unique function name
|
||||
$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['func'] =
|
||||
$tpl->compiled->unifunc = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
|
||||
// make sure whole chain gets compiled
|
||||
$tpl->mustCompile = true;
|
||||
$tpl->compiler->suppressTemplatePropertyHeader = true;
|
||||
$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['nocache_hash'] =
|
||||
$tpl->compiled->nocache_hash;
|
||||
// get compiled code
|
||||
$compiled_code = Smarty_Internal_Extension_CodeFrame::createFunctionFrame($tpl,
|
||||
$tpl->compiler->compileTemplate($tpl,
|
||||
null,
|
||||
$compiler->parent_compiler));
|
||||
$compiler->inheritanceParentIsChild = $tpl->compiler->inheritanceChild;
|
||||
$compiler->inheritance = $tpl->compiler->inheritance;
|
||||
unset($tpl->compiler);
|
||||
|
||||
// remove header code
|
||||
$compiled_code =
|
||||
preg_replace("/(<\?php \/\*%%SmartyHeaderCode:{$tpl->compiled->nocache_hash}%%\*\/(.+?)\/\*\/%%SmartyHeaderCode%%\*\/\?>\n)/s",
|
||||
'', $compiled_code);
|
||||
if ($tpl->compiled->has_nocache_code) {
|
||||
// replace nocache_hash
|
||||
$compiled_code =
|
||||
str_replace("{$tpl->compiled->nocache_hash}", $compiler->template->compiled->nocache_hash,
|
||||
$compiled_code);
|
||||
$compiler->template->compiled->has_nocache_code = true;
|
||||
}
|
||||
$compiler->parent_compiler->mergedSubTemplatesCode[$tpl->compiled->unifunc] = $compiled_code;
|
||||
$has_compiled_template = true;
|
||||
unset ($tpl);
|
||||
}
|
||||
$has_compiled_template =
|
||||
$this->compileInlineTemplate($compiler, $fullResourceName, $_caching, $hashResourceName, $t_hash,
|
||||
$c_id);
|
||||
} else {
|
||||
$has_compiled_template = true;
|
||||
}
|
||||
@@ -329,4 +284,63 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
$_output .= "?>\n";
|
||||
return $_output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile inline sub template
|
||||
*
|
||||
* @param \Smarty_Internal_SmartyTemplateCompiler $compiler
|
||||
* @param $fullResourceName
|
||||
* @param $_caching
|
||||
* @param $hashResourceName
|
||||
* @param $t_hash
|
||||
* @param $c_id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function compileInlineTemplate(Smarty_Internal_SmartyTemplateCompiler $compiler, $fullResourceName, $_caching, $hashResourceName, $t_hash, $c_id)
|
||||
{
|
||||
$compiler->smarty->allow_ambiguous_resources = true;
|
||||
/* @var Smarty_Internal_Template $tpl */
|
||||
$tpl = new $compiler->smarty->template_class (trim($fullResourceName, "'"), $compiler->smarty, $compiler->template,
|
||||
$compiler->template->cache_id, $c_id, $_caching);
|
||||
$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['uid'] = $tpl->source->uid;
|
||||
if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) {
|
||||
$tpl->compiled = new Smarty_Template_Compiled();
|
||||
$tpl->compiled->nocache_hash = $compiler->parent_compiler->template->compiled->nocache_hash;
|
||||
$tpl->loadCompiler();
|
||||
$tpl->compiler->inheritanceChild = $tpl->compiler->inheritanceForceChild = $compiler->inheritanceForceChild;
|
||||
$tpl->compiler->inheritance = $compiler->inheritance;
|
||||
// save unique function name
|
||||
$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['func'] =
|
||||
$tpl->compiled->unifunc = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
|
||||
// make sure whole chain gets compiled
|
||||
$tpl->mustCompile = true;
|
||||
$compiler->parent_compiler->mergedSubTemplatesData[$hashResourceName][$t_hash]['nocache_hash'] =
|
||||
$tpl->compiled->nocache_hash;
|
||||
// get compiled code
|
||||
$compiled_code = "<?php\n\n";
|
||||
$compiled_code .= "/* Start inline template \"{$tpl->source->type}:{$tpl->source->name}\" =============================*/\n";
|
||||
$compiled_code .= "function {$tpl->compiled->unifunc} (\$_smarty_tpl) {\n";
|
||||
$compiled_code .= "?>\n" . $tpl->compiler->compileTemplateSource($tpl, null, $compiler->parent_compiler);
|
||||
$compiled_code .= "<?php\n";
|
||||
$compiled_code .= "}\n?>\n";
|
||||
$compiled_code .= $tpl->compiler->postFilter($tpl->compiler->blockOrFunctionCode);
|
||||
$compiled_code .= "<?php\n\n";
|
||||
$compiled_code .= "/* End inline template \"{$tpl->source->type}:{$tpl->source->name}\" =============================*/\n";
|
||||
$compiled_code .= "?>";
|
||||
$compiler->inheritanceParentIsChild = $tpl->compiler->inheritanceChild;
|
||||
$compiler->inheritance = $tpl->compiler->inheritance;
|
||||
unset($tpl->compiler);
|
||||
if ($tpl->compiled->has_nocache_code) {
|
||||
// replace nocache_hash
|
||||
$compiled_code = str_replace("{$tpl->compiled->nocache_hash}", $compiler->template->compiled->nocache_hash,
|
||||
$compiled_code);
|
||||
$compiler->template->compiled->has_nocache_code = true;
|
||||
}
|
||||
$compiler->parent_compiler->mergedSubTemplatesCode[$tpl->compiled->unifunc] = $compiled_code;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -175,8 +175,7 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
|
||||
if ($_content != '') {
|
||||
// run pre filter if required
|
||||
if ((isset($nextCompiler->smarty->autoload_filters['pre']) ||
|
||||
isset($nextCompiler->smarty->registered_filters['pre'])) && !$nextCompiler->suppressFilter
|
||||
) {
|
||||
isset($nextCompiler->smarty->registered_filters['pre']))) {
|
||||
$_content = Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $nextCompiler->template);
|
||||
}
|
||||
$this->matchProperty($_content);
|
||||
|
@@ -23,7 +23,7 @@ class Smarty_Internal_Extension_CodeFrame
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function create(Smarty_Internal_Template $_template, $content = '', $cache = false)
|
||||
public static function create(Smarty_Internal_Template $_template, $content = '', $functions = '', $cache = false)
|
||||
{
|
||||
// build property code
|
||||
$properties['has_nocache_code'] = $_template->compiled->has_nocache_code;
|
||||
@@ -40,10 +40,8 @@ class Smarty_Internal_Extension_CodeFrame
|
||||
$properties['cache_lifetime'] = $_template->cache_lifetime;
|
||||
}
|
||||
$output = "<?php\n";
|
||||
$output .= "/*%%SmartyHeaderCode:{$_template->compiled->nocache_hash}%%*/\n";
|
||||
$output .= "\$_valid = \$_smarty_tpl->decodeProperties(" . var_export($properties, true) . ',' .
|
||||
($cache ? 'true' : 'false') . ");\n";
|
||||
$output .= "/*/%%SmartyHeaderCode%%*/\n";
|
||||
$output .= "if (\$_valid && !is_callable('{$properties['unifunc']}')) {\n";
|
||||
$output .= "function {$properties['unifunc']} (\$_smarty_tpl) {\n";
|
||||
// include code for plugins
|
||||
@@ -77,48 +75,11 @@ class Smarty_Internal_Extension_CodeFrame
|
||||
}
|
||||
}
|
||||
$output .= "?>\n";
|
||||
$output = self::appendCode($output, $content);
|
||||
return self::appendCode($output, "<?php }\n}\n?>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create code frame of compiled template function
|
||||
*
|
||||
* @param \Smarty_Internal_Template $_template
|
||||
* @param string $content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function createFunctionFrame(Smarty_Internal_Template $_template, $content = '')
|
||||
{
|
||||
$output = "<?php\n";
|
||||
$output .= "/*%%SmartyHeaderCode:{$_template->compiled->nocache_hash}%%*/\n";
|
||||
$output .= "/* {$_template->source->type}:{$_template->source->name} */\n";
|
||||
$output .= "if (\$_valid && !is_callable('{$_template->compiled->unifunc}')) {\n";
|
||||
$output .= "function {$_template->compiled->unifunc} (\$_smarty_tpl) {\n";
|
||||
$output .= "?>\n" . $content;
|
||||
$output .= "<?php\n";
|
||||
$output .= "/*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%*/\n";
|
||||
$output .= "}\n}\n?>";
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append code segments and remove unneeded ?> <?php transitions
|
||||
*
|
||||
* @param string $left
|
||||
* @param string $right
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function appendCode($left, $right)
|
||||
{
|
||||
if (preg_match('/\s*\?>[\n]?$/', $left) && preg_match('/^<\?php\s+/', $right)) {
|
||||
$left = preg_replace('/\s*\?>[\n]?$/', "\n", $left);
|
||||
$left .= preg_replace('/^<\?php\s+/', '', $right);
|
||||
} else {
|
||||
$left .= $right;
|
||||
}
|
||||
return $left;
|
||||
$output .= $content;
|
||||
$output .= "<?php }\n?>";
|
||||
$output .= $functions;
|
||||
$output .= "<?php }\n";
|
||||
// remove unneeded PHP tags
|
||||
return preg_replace('/\s*\?>[\n]?<\?php\s/', "\n", $output);
|
||||
}
|
||||
}
|
@@ -107,7 +107,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $inheritanceChild= false;
|
||||
public $inheritanceChild = false;
|
||||
|
||||
/**
|
||||
* Force all subtemplate calls to be inheritance childs
|
||||
@@ -186,27 +186,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
*/
|
||||
public $forceNocache = false;
|
||||
|
||||
/**
|
||||
* suppress Smarty header code in compiled template
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $suppressHeader = false;
|
||||
|
||||
/**
|
||||
* suppress template property header code in compiled template
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $suppressTemplatePropertyHeader = false;
|
||||
|
||||
/**
|
||||
* suppress pre and post filter
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $suppressFilter = false;
|
||||
|
||||
/**
|
||||
* flag if compiled template file shall we written
|
||||
*
|
||||
@@ -214,13 +193,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
*/
|
||||
public $write_compiled_code = true;
|
||||
|
||||
/**
|
||||
* flag if currently a template function is compiled
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $compiles_template_function = false;
|
||||
|
||||
/**
|
||||
* called sub functions from template function
|
||||
*
|
||||
@@ -229,11 +201,11 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
public $called_functions = array();
|
||||
|
||||
/**
|
||||
* compiled template function code
|
||||
* compiled template or block function code
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $templateFunctionCode = '';
|
||||
public $blockOrFunctionCode = '';
|
||||
|
||||
/**
|
||||
* php_handling setting either from Smarty or security
|
||||
@@ -312,27 +284,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
*/
|
||||
public $has_output = false;
|
||||
|
||||
/**
|
||||
* Universal cache
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $cache = array();
|
||||
|
||||
/**
|
||||
* Stack during {capture} compilation
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_capture_stack = array();
|
||||
|
||||
/**
|
||||
* Saved source resource
|
||||
*
|
||||
* @var \Smarty_Template_Source
|
||||
*/
|
||||
private $savedSource = null;
|
||||
|
||||
/**
|
||||
* Stack for {setfilter} {/setfilter}
|
||||
*
|
||||
@@ -410,16 +361,42 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
* @return bool true if compiling succeeded, false if it failed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function compileTemplate(Smarty_Internal_Template $template, $nocache = null, $parent_compiler = null)
|
||||
public function compileTemplate(Smarty_Internal_Template $template, $nocache = null,
|
||||
Smarty_Internal_TemplateCompilerBase $parent_compiler = null)
|
||||
{
|
||||
if (property_exists($template->smarty, 'plugin_search_order')) {
|
||||
$this->plugin_search_order = $template->smarty->plugin_search_order;
|
||||
}
|
||||
// save template object in compiler class
|
||||
$this->template = $template;
|
||||
$this->savedSource = $this->template->source;
|
||||
// get code frame of compiled template
|
||||
$_compiled_code =
|
||||
"<?php /* Smarty version " . Smarty::SMARTY_VERSION . ", created on " . strftime("%Y-%m-%d %H:%M:%S") .
|
||||
"\n compiled from \"" . $template->source->filepath . "\" */ ?>\n" .
|
||||
Smarty_Internal_Extension_CodeFrame::create($template, $this->compileTemplateSource($template, $nocache,
|
||||
$parent_compiler),
|
||||
$this->postFilter($this->blockOrFunctionCode) .
|
||||
join('', $this->mergedSubTemplatesCode));
|
||||
return $_compiled_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
@@ -432,20 +409,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
} else {
|
||||
$this->nocache_hash = $template->compiled->nocache_hash;
|
||||
}
|
||||
// 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";
|
||||
}
|
||||
$this->smarty->_current_file = $this->template->source->filepath;
|
||||
if ($this->smarty->debugging) {
|
||||
$this->smarty->_debug->start_compile($this->template);
|
||||
}
|
||||
$this->parent_compiler->template->compiled->file_dependency[$this->template->source->uid] =
|
||||
array($this->template->source->filepath, $this->template->source->getTimeStamp(),
|
||||
$this->template->source->type);
|
||||
// flag for nocache sections
|
||||
$this->nocache = $nocache;
|
||||
$this->tag_nocache = false;
|
||||
@@ -453,85 +416,84 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
$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
|
||||
$this->sources = array_reverse($template->source->components);
|
||||
$this->sources = array_reverse($this->template->source->components);
|
||||
$_content = '';
|
||||
} else {
|
||||
// get template source
|
||||
$_content = $this->template->source->getContent();
|
||||
}
|
||||
if ($_content != '') {
|
||||
// run pre filter if required
|
||||
if ($_content != '' && ((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);
|
||||
|
||||
$_compiled_code = $this->postFilter($this->doCompile($this->preFilter($_content), true));
|
||||
}
|
||||
catch (Exception $e) {
|
||||
if ($this->smarty->debugging) {
|
||||
$this->smarty->_debug->end_compile($this->template);
|
||||
}
|
||||
// free memory
|
||||
$this->parser = null;
|
||||
// restore source
|
||||
$this->template->source = $this->savedSource;
|
||||
$this->savedSource = null;
|
||||
$this->smarty->_current_file = $this->template->source->filepath;
|
||||
// return compiled code to template object
|
||||
$merged_code = '';
|
||||
if (!empty($this->mergedSubTemplatesCode)) {
|
||||
foreach ($this->mergedSubTemplatesCode as $code) {
|
||||
$merged_code .= $code;
|
||||
}
|
||||
}
|
||||
// run post filter 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 post filter 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$this->_tag_stack = array();
|
||||
$this->_tag_objects = array();
|
||||
// restore source
|
||||
$this->template->source = $this->savedSource;
|
||||
$this->savedSource = null;
|
||||
$this->smarty->_current_file = $this->template->source->filepath;
|
||||
// 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->template = null;
|
||||
$this->parser = null;
|
||||
return $_compiled_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionally process compiled code by post filter
|
||||
*
|
||||
* @param string $code compiled code
|
||||
*
|
||||
* @return string
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function postFilter($code)
|
||||
{
|
||||
// run post filter if on code
|
||||
if (!empty($code) &&
|
||||
(isset($this->smarty->autoload_filters['post']) || isset($this->smarty->registered_filters['post']))
|
||||
) {
|
||||
return Smarty_Internal_Filter_Handler::runFilter('post', $code, $this->template);
|
||||
} else {
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run optional prefilter
|
||||
*
|
||||
* @param string $_content template source
|
||||
*
|
||||
* @return string
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function preFilter($_content)
|
||||
{
|
||||
// run pre filter if required
|
||||
if ($_content != '' &&
|
||||
((isset($this->smarty->autoload_filters['pre']) || isset($this->smarty->registered_filters['pre'])))
|
||||
) {
|
||||
return Smarty_Internal_Filter_Handler::runFilter('pre', $_content, $this->template);
|
||||
} else {
|
||||
return $_content;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add code to call parent template on inheritance child templates
|
||||
*
|
||||
@@ -546,15 +508,14 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
$name = $this->extendsFileName;
|
||||
$this->extendsFileName = null;
|
||||
if (!$this->inheritanceForceChild && !$this->inheritance) {
|
||||
// drop any output of child templates
|
||||
array_unshift($parser->current_buffer->subtrees,
|
||||
new Smarty_Internal_ParseTree_Tag($parser, "<?php ob_start();\n\$_smarty_tpl->_Block = new Smarty_Internal_Runtime_Block();?>\n"));
|
||||
// drop any output of child templates
|
||||
array_unshift($parser->current_buffer->subtrees, new Smarty_Internal_ParseTree_Tag($parser,
|
||||
"<?php ob_start();\n\$_smarty_tpl->_Block = new Smarty_Internal_Runtime_Block();?>\n"));
|
||||
$this->inheritance = true;
|
||||
}
|
||||
$include = new Smarty_Internal_ParseTree_Tag($parser, $this->compileTag('include',
|
||||
array($name,
|
||||
array('scope' => 'parent'),
|
||||
array('inline' => true))));
|
||||
$include = new Smarty_Internal_ParseTree_Tag($parser, $this->compileTag('include', array($name,
|
||||
array('scope' => 'parent'),
|
||||
array('inline' => true))));
|
||||
if (!$this->inheritanceForceChild && !$this->inheritanceParentIsChild) {
|
||||
$parser->current_buffer->append_subtree($parser, new Smarty_Internal_ParseTree_Tag($parser,
|
||||
"<?php ob_end_clean();?>\n"));
|
||||
@@ -1177,47 +1138,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
str_replace("^#^", "'", addcslashes($code, '\'\\')) . "?>/*/%%SmartyNocache:{$this->nocache_hash}%%*/';\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* push current file and line offset on stack for tracing {block} source lines
|
||||
*
|
||||
* @param string $file new filename
|
||||
* @param string $uid uid of file
|
||||
* @param int $line line offset to source
|
||||
* @param bool $debug false debug end_compile shall not be called
|
||||
*/
|
||||
public function pushTrace($file, $uid, $line, $debug = true)
|
||||
{
|
||||
if ($this->smarty->debugging && $debug) {
|
||||
$this->smarty->_debug->end_compile($this->template);
|
||||
}
|
||||
array_push($this->trace_stack, array($this->smarty->_current_file, $this->trace_filepath, $this->trace_uid,
|
||||
$this->trace_line_offset));
|
||||
$this->trace_filepath = $this->smarty->_current_file = $file;
|
||||
$this->trace_uid = $uid;
|
||||
$this->trace_line_offset = $line;
|
||||
if ($this->smarty->debugging) {
|
||||
$this->smarty->_debug->start_compile($this->template);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* restore file and line offset
|
||||
*/
|
||||
public function popTrace()
|
||||
{
|
||||
if ($this->smarty->debugging) {
|
||||
$this->smarty->_debug->end_compile($this->template);
|
||||
}
|
||||
$r = array_pop($this->trace_stack);
|
||||
$this->smarty->_current_file = $r[0];
|
||||
$this->trace_filepath = $r[1];
|
||||
$this->trace_uid = $r[2];
|
||||
$this->trace_line_offset = $r[3];
|
||||
if ($this->smarty->debugging) {
|
||||
$this->smarty->_debug->start_compile($this->template);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* display compiler error messages without dying
|
||||
* If parameter $args is empty it is a parser detected syntax error.
|
||||
|
@@ -366,7 +366,7 @@ class Smarty_Template_Cached extends Smarty_Template_Resource_Base
|
||||
// don't write cache file
|
||||
return false;
|
||||
}
|
||||
$content = Smarty_Internal_Extension_CodeFrame::create($_template, $content, true);
|
||||
$content = Smarty_Internal_Extension_CodeFrame::create($_template, $content, '', true);
|
||||
if (!empty($_template->cached->tpl_function)) {
|
||||
foreach ($_template->cached->tpl_function as $funcParam) {
|
||||
if (is_file($funcParam['compiled_filepath'])) {
|
||||
|
Reference in New Issue
Block a user