mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
replace property array by object properties
This commit is contained in:
@@ -98,7 +98,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
|||||||
$compiler->inheritance = true;
|
$compiler->inheritance = true;
|
||||||
$compiler->parser->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
|
$compiler->parser->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
|
||||||
$compiler->has_code = false;
|
$compiler->has_code = false;
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
// must merge includes
|
// must merge includes
|
||||||
if ($_attr['nocache'] == true) {
|
if ($_attr['nocache'] == true) {
|
||||||
@@ -135,7 +135,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
|||||||
}
|
}
|
||||||
$compiler->parser->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
|
$compiler->parser->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBLOCK);
|
||||||
$compiler->has_code = false;
|
$compiler->has_code = false;
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
// if called by {$smarty.block.child} we must search the name of enclosing {block}
|
// if called by {$smarty.block.child} we must search the name of enclosing {block}
|
||||||
if ($_name == null) {
|
if ($_name == null) {
|
||||||
@@ -164,7 +164,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
|||||||
}
|
}
|
||||||
$_tpl->tpl_vars = $compiler->template->tpl_vars;
|
$_tpl->tpl_vars = $compiler->template->tpl_vars;
|
||||||
$_tpl->variable_filters = $compiler->template->variable_filters;
|
$_tpl->variable_filters = $compiler->template->variable_filters;
|
||||||
$_tpl->properties['nocache_hash'] = $compiler->template->properties['nocache_hash'];
|
$_tpl->compiled->nocache_hash = $compiler->template->compiled->nocache_hash;
|
||||||
$_tpl->allow_relative_path = true;
|
$_tpl->allow_relative_path = true;
|
||||||
$_tpl->loadCompiler();
|
$_tpl->loadCompiler();
|
||||||
$_tpl->compiler->_tag_objects = $compiler->_tag_objects;
|
$_tpl->compiler->_tag_objects = $compiler->_tag_objects;
|
||||||
@@ -173,6 +173,7 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
|||||||
$_tpl->compiler->suppressFilter = true;
|
$_tpl->compiler->suppressFilter = true;
|
||||||
$_tpl->compiler->suppressTemplatePropertyHeader = true;
|
$_tpl->compiler->suppressTemplatePropertyHeader = true;
|
||||||
$nocache = $compiler->nocache || $compiler->tag_nocache;
|
$nocache = $compiler->nocache || $compiler->tag_nocache;
|
||||||
|
$_output = '';
|
||||||
if (strpos($compiler->template->block_data[$_name]['source'], self::parent) !== false) {
|
if (strpos($compiler->template->block_data[$_name]['source'], self::parent) !== false) {
|
||||||
$_output = str_replace(self::parent, $compiler->parser->current_buffer->to_smarty_php($compiler->parser), $_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler));
|
$_output = str_replace(self::parent, $compiler->parser->current_buffer->to_smarty_php($compiler->parser), $_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler));
|
||||||
} elseif ($compiler->template->block_data[$_name]['mode'] == 'prepend') {
|
} elseif ($compiler->template->block_data[$_name]['mode'] == 'prepend') {
|
||||||
@@ -184,12 +185,12 @@ class Smarty_Internal_Compile_Block extends Smarty_Internal_CompileBase
|
|||||||
} elseif (!empty($compiler->template->block_data[$_name])) {
|
} elseif (!empty($compiler->template->block_data[$_name])) {
|
||||||
$_output = $_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler);
|
$_output = $_tpl->compiler->compileTemplate($_tpl, $nocache, $compiler->parent_compiler);
|
||||||
}
|
}
|
||||||
$compiler->template->properties['file_dependency'] = array_merge($compiler->template->properties['file_dependency'], $_tpl->properties['file_dependency']);
|
$compiler->template->compiled->file_dependency = array_merge($compiler->template->compiled->file_dependency, $_tpl->compiled->file_dependency);
|
||||||
unset($compiler->template->properties['file_dependency'][$_tpl->source->uid]);
|
unset($compiler->template->compiled->file_dependency[$_tpl->source->uid]);
|
||||||
$compiler->template->properties['tpl_function'] = array_merge($compiler->template->properties['tpl_function'], $_tpl->properties['tpl_function']);
|
$compiler->template->tpl_function = array_merge($compiler->template->tpl_function, $_tpl->tpl_function);
|
||||||
$compiler->template->variable_filters = $_tpl->variable_filters;
|
$compiler->template->variable_filters = $_tpl->variable_filters;
|
||||||
if ($_tpl->has_nocache_code) {
|
if ($_tpl->compiled->has_nocache_code) {
|
||||||
$compiler->template->has_nocache_code = true;
|
$compiler->template->compiled->has_nocache_code = true;
|
||||||
}
|
}
|
||||||
foreach ($_tpl->required_plugins as $key => $tmp1) {
|
foreach ($_tpl->required_plugins as $key => $tmp1) {
|
||||||
if ($compiler->nocache && $compiler->template->caching) {
|
if ($compiler->nocache && $compiler->template->caching) {
|
||||||
@@ -273,8 +274,6 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase
|
|||||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||||
{
|
{
|
||||||
$compiler->has_code = true;
|
$compiler->has_code = true;
|
||||||
// check and get attributes
|
|
||||||
$_attr = $this->getAttributes($compiler, $args);
|
|
||||||
$saved_data = $this->closeTag($compiler, array('block'));
|
$saved_data = $this->closeTag($compiler, array('block'));
|
||||||
$_name = trim($saved_data[0]['name'], "\"'");
|
$_name = trim($saved_data[0]['name'], "\"'");
|
||||||
// reset flag for {block} tag
|
// reset flag for {block} tag
|
||||||
@@ -335,7 +334,7 @@ class Smarty_Internal_Compile_Blockclose extends Smarty_Internal_CompileBase
|
|||||||
$compiler->parser->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY);
|
$compiler->parser->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY);
|
||||||
}
|
}
|
||||||
$compiler->has_code = false;
|
$compiler->has_code = false;
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
if (isset($compiler->template->block_data[$_name]) &&
|
if (isset($compiler->template->block_data[$_name]) &&
|
||||||
!isset($compiler->template->block_data[$_name]['compiled'])
|
!isset($compiler->template->block_data[$_name]['compiled'])
|
||||||
@@ -435,10 +434,7 @@ class Smarty_Internal_Compile_Private_Child_Blockclose extends Smarty_Internal_C
|
|||||||
*/
|
*/
|
||||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||||
{
|
{
|
||||||
// check and get attributes
|
$saved_data = $this->closeTag($compiler, array('private_child_block'));
|
||||||
$_attr = $this->getAttributes($compiler, $args);
|
|
||||||
|
|
||||||
$saved_data = $this->closeTag($compiler, array('private_child_block'));
|
|
||||||
|
|
||||||
// end of child block
|
// end of child block
|
||||||
$compiler->popTrace();
|
$compiler->popTrace();
|
||||||
|
@@ -44,9 +44,9 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
|
|||||||
/**
|
/**
|
||||||
* Compiles code for the {function} tag
|
* Compiles code for the {function} tag
|
||||||
*
|
*
|
||||||
* @param array $args array with attributes from parser
|
* @param array $args array with attributes from parser
|
||||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||||
* @param array $parameter array with compilation parameter
|
* @param array $parameter array with compilation parameter
|
||||||
*
|
*
|
||||||
* @return bool true
|
* @return bool true
|
||||||
* @throws \SmartyCompilerException
|
* @throws \SmartyCompilerException
|
||||||
@@ -61,16 +61,15 @@ class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase
|
|||||||
}
|
}
|
||||||
unset($_attr['nocache']);
|
unset($_attr['nocache']);
|
||||||
$_name = trim($_attr['name'], "'\"");
|
$_name = trim($_attr['name'], "'\"");
|
||||||
$compiler->parent_compiler->templateProperties['tpl_function'][$_name] = array();
|
$compiler->parent_compiler->template->tpl_function[$_name] = array();
|
||||||
$save = array($_attr, $compiler->parser->current_buffer, $compiler->template->has_nocache_code, $compiler->template->required_plugins, $compiler->template->caching);
|
$save = array($_attr, $compiler->parser->current_buffer, $compiler->template->compiled->has_nocache_code,
|
||||||
|
$compiler->template->caching);
|
||||||
$this->openTag($compiler, 'function', $save);
|
$this->openTag($compiler, 'function', $save);
|
||||||
// set flag that we are compiling a template function
|
// set flag that we are compiling a template function
|
||||||
$compiler->compiles_template_function = true;
|
$compiler->compiles_template_function = true;
|
||||||
// Init temporary context
|
// Init temporary context
|
||||||
$compiler->template->required_plugins = array('compiled' => array(), 'nocache' => array());
|
|
||||||
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
|
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
|
||||||
$compiler->template->has_nocache_code = false;
|
$compiler->template->compiled->has_nocache_code = false;
|
||||||
$compiler->template->caching = true;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,9 +107,9 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
|||||||
$_name = trim($_attr['name'], "'\"");
|
$_name = trim($_attr['name'], "'\"");
|
||||||
// reset flag that we are compiling a template function
|
// reset flag that we are compiling a template function
|
||||||
$compiler->compiles_template_function = false;
|
$compiler->compiles_template_function = false;
|
||||||
$compiler->parent_compiler->templateProperties['tpl_function'][$_name]['called_functions'] = $compiler->called_functions;
|
$compiler->parent_compiler->template->tpl_function[$_name]['called_functions'] = $compiler->called_functions;
|
||||||
$compiler->parent_compiler->templateProperties['tpl_function'][$_name]['compiled_filepath'] = $compiler->parent_compiler->template->compiled->filepath;
|
$compiler->parent_compiler->template->tpl_function[$_name]['compiled_filepath'] = $compiler->parent_compiler->template->compiled->filepath;
|
||||||
$compiler->parent_compiler->templateProperties['tpl_function'][$_name]['uid'] = $compiler->template->source->uid;
|
$compiler->parent_compiler->template->tpl_function[$_name]['uid'] = $compiler->template->source->uid;
|
||||||
$compiler->called_functions = array();
|
$compiler->called_functions = array();
|
||||||
$_parameter = $_attr;
|
$_parameter = $_attr;
|
||||||
unset($_parameter['name']);
|
unset($_parameter['name']);
|
||||||
@@ -133,10 +132,10 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
|||||||
// setup buffer for template function code
|
// setup buffer for template function code
|
||||||
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
|
$compiler->parser->current_buffer = new Smarty_Internal_ParseTree_Template();
|
||||||
|
|
||||||
$_funcName = "smarty_template_function_{$_name}_{$compiler->template->properties['nocache_hash']}";
|
$_funcName = "smarty_template_function_{$_name}_{$compiler->template->compiled->nocache_hash}";
|
||||||
$_funcNameCaching = $_funcName . '_nocache';
|
$_funcNameCaching = $_funcName . '_nocache';
|
||||||
if ($compiler->template->has_nocache_code) {
|
if ($compiler->template->compiled->has_nocache_code) {
|
||||||
$compiler->parent_compiler->templateProperties['tpl_function'][$_name]['call_name_caching'] = $_funcNameCaching;
|
$compiler->parent_compiler->template->tpl_function[$_name]['call_name_caching'] = $_funcNameCaching;
|
||||||
$output = "<?php\n";
|
$output = "<?php\n";
|
||||||
$output .= "/* {$_funcNameCaching} */\n";
|
$output .= "/* {$_funcNameCaching} */\n";
|
||||||
$output .= "if (!function_exists('{$_funcNameCaching}')) {\n";
|
$output .= "if (!function_exists('{$_funcNameCaching}')) {\n";
|
||||||
@@ -159,28 +158,30 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
|||||||
$output .= "?>/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/';\n";
|
$output .= "?>/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/';\n";
|
||||||
}
|
}
|
||||||
$output .= "ob_start();\n";
|
$output .= "ob_start();\n";
|
||||||
|
$output .= "\$_smarty_tpl->compiled->has_nocache_code = true;\n";
|
||||||
$output .= $_paramsCode;
|
$output .= $_paramsCode;
|
||||||
$output .= "\$_smarty_tpl->properties['saved_tpl_vars'][] = \$_smarty_tpl->tpl_vars;\n";
|
$output .= "\$_smarty_tpl->_cache['saved_tpl_vars'][] = \$_smarty_tpl->tpl_vars;\n";
|
||||||
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value);\n}";
|
$output .= "foreach (\$params as \$key => \$value) {\n\$_smarty_tpl->tpl_vars[\$key] = new Smarty_Variable(\$value);\n}";
|
||||||
$output .= "\$params = var_export(\$params, true);\n";
|
$output .= "\$params = var_export(\$params, true);\n";
|
||||||
$output .= "echo \"/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php ";
|
$output .= "echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
|
||||||
$output .= "\\\$saved_tpl_vars = \\\$_smarty_tpl->tpl_vars;\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_Variable(\\\$value);\n}\n?>";
|
$output .= "\\\$saved_tpl_vars = \\\$_smarty_tpl->tpl_vars;\nforeach (\$params as \\\$key => \\\$value) {\n\\\$_smarty_tpl->tpl_vars[\\\$key] = new Smarty_Variable(\\\$value);\n}\n?>";
|
||||||
$output .= "/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/\n\";?>";
|
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\n\";?>";
|
||||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
|
$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);
|
$compiler->parser->current_buffer->append_subtree($compiler->parser, $_functionCode);
|
||||||
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php ";
|
$output = "<?php echo \"/*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/<?php ";
|
||||||
$output .= "foreach (Smarty::\\\$global_tpl_vars as \\\$key => \\\$value){\n";
|
$output .= "foreach (Smarty::\\\$global_tpl_vars as \\\$key => \\\$value){\n";
|
||||||
$output .= "if (\\\$_smarty_tpl->tpl_vars[\\\$key] === \\\$value) \\\$saved_tpl_vars[\\\$key] = \\\$value;\n}\n";
|
$output .= "if (\\\$_smarty_tpl->tpl_vars[\\\$key] === \\\$value) \\\$saved_tpl_vars[\\\$key] = \\\$value;\n}\n";
|
||||||
$output .= "\\\$_smarty_tpl->tpl_vars = \\\$saved_tpl_vars;?>\n";
|
$output .= "\\\$_smarty_tpl->tpl_vars = \\\$saved_tpl_vars;?>\n";
|
||||||
$output .= "/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/\";\n?>";
|
$output .= "/*/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%*/\";\n?>";
|
||||||
$output .= "<?php echo str_replace('{$compiler->template->properties['nocache_hash']}', \$_smarty_tpl->properties['nocache_hash'], ob_get_clean());\n";
|
$output .= "<?php echo str_replace('{$compiler->template->compiled->nocache_hash}', \$_smarty_tpl->compiled->nocache_hash, ob_get_clean());\n";
|
||||||
$output .= "\$_smarty_tpl->tpl_vars = array_pop(\$_smarty_tpl->properties['saved_tpl_vars']);\n}\n}\n";
|
$output .= "\$_smarty_tpl->tpl_vars = array_pop(\$_smarty_tpl->_cache['saved_tpl_vars']);\n}\n}\n";
|
||||||
$output .= "/*/ {$_funcName}_nocache */\n\n";
|
$output .= "/*/ {$_funcName}_nocache */\n\n";
|
||||||
$output .= "?>\n";
|
$output .= "?>\n";
|
||||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
|
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
|
||||||
$_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser, preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%\*\/';(\?>\n)?)/", array($this, 'removeNocache'), $_functionCode->to_smarty_php($compiler->parser)));
|
$_functionCode = new Smarty_Internal_ParseTree_Tag($compiler->parser, preg_replace_callback("/((<\?php )?echo '\/\*%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/([\S\s]*?)\/\*\/%%SmartyNocache:{$compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/", array($this,
|
||||||
|
'removeNocache'), $_functionCode->to_smarty_php($compiler->parser)));
|
||||||
}
|
}
|
||||||
$compiler->parent_compiler->templateProperties['tpl_function'][$_name]['call_name'] = $_funcName;
|
$compiler->parent_compiler->template->tpl_function[$_name]['call_name'] = $_funcName;
|
||||||
$output = "<?php\n";
|
$output = "<?php\n";
|
||||||
$output .= "/* {$_funcName} */\n";
|
$output .= "/* {$_funcName} */\n";
|
||||||
$output .= "if (!function_exists('{$_funcName}')) {\n";
|
$output .= "if (!function_exists('{$_funcName}')) {\n";
|
||||||
@@ -209,11 +210,11 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
|||||||
$compiler->parser->current_buffer->append_subtree($compiler->parser, new Smarty_Internal_ParseTree_Tag($compiler->parser, $output));
|
$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->templateFunctionCode .= $compiler->parser->current_buffer->to_smarty_php($compiler->parser);
|
||||||
// restore old buffer
|
// restore old buffer
|
||||||
|
|
||||||
$compiler->parser->current_buffer = $saved_data[1];
|
$compiler->parser->current_buffer = $saved_data[1];
|
||||||
// restore old status
|
// restore old status
|
||||||
$compiler->template->has_nocache_code = $saved_data[2];
|
$compiler->template->compiled->has_nocache_code = $saved_data[2];
|
||||||
$compiler->template->required_plugins = $saved_data[3];
|
$compiler->template->caching = $saved_data[3];
|
||||||
$compiler->template->caching = $saved_data[4];
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +225,7 @@ class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase
|
|||||||
*/
|
*/
|
||||||
function removeNocache($match)
|
function removeNocache($match)
|
||||||
{
|
{
|
||||||
$code = preg_replace("/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->properties['nocache_hash']}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->properties['nocache_hash']}%%\*\/';(\?>\n)?)/", '', $match[0]);
|
$code = preg_replace("/((<\?php )?echo '\/\*%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/)|(\/\*\/%%SmartyNocache:{$this->compiler->template->compiled->nocache_hash}%%\*\/';(\?>\n)?)/", '', $match[0]);
|
||||||
$code = str_replace(array('\\\'', '\\\\\''), array('\'', '\\\''), $code);
|
$code = str_replace(array('\\\'', '\\\\\''), array('\'', '\\\''), $code);
|
||||||
return $code;
|
return $code;
|
||||||
}
|
}
|
||||||
|
@@ -205,7 +205,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
|||||||
$compiler->smarty->allow_ambiguous_resources = true;
|
$compiler->smarty->allow_ambiguous_resources = true;
|
||||||
$tpl = new $compiler->smarty->template_class ($tpl_name, $compiler->smarty, $compiler->template, $compiler->template->cache_id, $c_id, $_caching);
|
$tpl = new $compiler->smarty->template_class ($tpl_name, $compiler->smarty, $compiler->template, $compiler->template->cache_id, $c_id, $_caching);
|
||||||
// save unique function name
|
// save unique function name
|
||||||
$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['func'] = $tpl->properties['unifunc'] = 'content_' .
|
$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['func'] = $tpl->compiled->unifunc = 'content_' .
|
||||||
str_replace(array('.', ','), '_', uniqid('', true));
|
str_replace(array('.', ','), '_', uniqid('', true));
|
||||||
if ($compiler->inheritance) {
|
if ($compiler->inheritance) {
|
||||||
$tpl->compiler->inheritance = true;
|
$tpl->compiler->inheritance = true;
|
||||||
@@ -214,20 +214,20 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
|||||||
$tpl->mustCompile = true;
|
$tpl->mustCompile = true;
|
||||||
if (!($tpl->source->uncompiled) && $tpl->source->exists) {
|
if (!($tpl->source->uncompiled) && $tpl->source->exists) {
|
||||||
$tpl->compiler->suppressTemplatePropertyHeader = true;
|
$tpl->compiler->suppressTemplatePropertyHeader = true;
|
||||||
$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['nocache_hash'] = $tpl->properties['nocache_hash'] = str_replace(array('.',
|
$compiler->parent_compiler->mergedSubTemplatesData[$tpl_name][$uid]['nocache_hash'] = $tpl->compiled->nocache_hash = str_replace(array('.',
|
||||||
','), '_', uniqid(rand(), true));
|
','), '_', uniqid(rand(), true));
|
||||||
// get compiled code
|
// get compiled code
|
||||||
$compiled_code = Smarty_Internal_Extension_CodeFrame::createFunctionFrame($tpl, $tpl->compiler->compileTemplate($tpl, null, $compiler->parent_compiler));
|
$compiled_code = Smarty_Internal_Extension_CodeFrame::createFunctionFrame($tpl, $tpl->compiler->compileTemplate($tpl, null, $compiler->parent_compiler));
|
||||||
unset($tpl->compiler);
|
unset($tpl->compiler);
|
||||||
|
|
||||||
// remove header code
|
// remove header code
|
||||||
$compiled_code = preg_replace("/(<\?php \/\*%%SmartyHeaderCode:{$tpl->properties['nocache_hash']}%%\*\/(.+?)\/\*\/%%SmartyHeaderCode%%\*\/\?>\n)/s", '', $compiled_code);
|
$compiled_code = preg_replace("/(<\?php \/\*%%SmartyHeaderCode:{$tpl->compiled->nocache_hash}%%\*\/(.+?)\/\*\/%%SmartyHeaderCode%%\*\/\?>\n)/s", '', $compiled_code);
|
||||||
if ($tpl->has_nocache_code) {
|
if ($tpl->compiled->has_nocache_code) {
|
||||||
// replace nocache_hash
|
// replace nocache_hash
|
||||||
$compiled_code = str_replace("{$tpl->properties['nocache_hash']}", $compiler->template->properties['nocache_hash'], $compiled_code);
|
$compiled_code = str_replace("{$tpl->compiled->nocache_hash}", $compiler->template->compiled->nocache_hash, $compiled_code);
|
||||||
$compiler->template->has_nocache_code = true;
|
$compiler->template->compiled->has_nocache_code = true;
|
||||||
}
|
}
|
||||||
$compiler->parent_compiler->mergedSubTemplatesCode[$tpl->properties['unifunc']] = $compiled_code;
|
$compiler->parent_compiler->mergedSubTemplatesCode[$tpl->compiled->unifunc] = $compiled_code;
|
||||||
$has_compiled_template = true;
|
$has_compiled_template = true;
|
||||||
if (!empty($tpl->required_plugins['compiled'])) {
|
if (!empty($tpl->required_plugins['compiled'])) {
|
||||||
foreach ($tpl->required_plugins['compiled'] as $name => $callBack) {
|
foreach ($tpl->required_plugins['compiled'] as $name => $callBack) {
|
||||||
@@ -279,7 +279,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
|||||||
if ($update_compile_id) {
|
if ($update_compile_id) {
|
||||||
$_output .= $compiler->makeNocacheCode("\$_compile_id_save[] = \$_smarty_tpl->compile_id;\n\$_smarty_tpl->compile_id = {$_compile_id};\n");
|
$_output .= $compiler->makeNocacheCode("\$_compile_id_save[] = \$_smarty_tpl->compile_id;\n\$_smarty_tpl->compile_id = {$_compile_id};\n");
|
||||||
}
|
}
|
||||||
if (!empty($_vars_nc) && $_caching == 9999 && $_smarty_tpl->caching) {
|
if (!empty($_vars_nc) && $_caching == 9999 && $compiler->template->caching) {
|
||||||
//$compiler->suppressNocacheProcessing = false;
|
//$compiler->suppressNocacheProcessing = false;
|
||||||
$_output .= substr($compiler->processNocacheCode('<?php ' . $_vars_nc . "?>\n", true), 6, - 3);
|
$_output .= substr($compiler->processNocacheCode('<?php ' . $_vars_nc . "?>\n", true), 6, - 3);
|
||||||
//$compiler->suppressNocacheProcessing = true;
|
//$compiler->suppressNocacheProcessing = true;
|
||||||
|
@@ -26,34 +26,32 @@ class Smarty_Internal_Extension_CodeFrame
|
|||||||
public static function create(Smarty_Internal_Template $_template, $content = '', $cache = false)
|
public static function create(Smarty_Internal_Template $_template, $content = '', $cache = false)
|
||||||
{
|
{
|
||||||
// build property code
|
// build property code
|
||||||
$_template->properties['has_nocache_code'] = $_template->has_nocache_code || !empty($_template->required_plugins['nocache']);
|
$properties['has_nocache_code'] = $_template->compiled->has_nocache_code;
|
||||||
$_template->properties['version'] = Smarty::SMARTY_VERSION;
|
$properties['version'] = Smarty::SMARTY_VERSION;
|
||||||
if (!isset($_template->properties['unifunc'])) {
|
$properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
|
||||||
$_template->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
|
$properties['tpl_function'] = $_template->tpl_function;
|
||||||
}
|
|
||||||
$properties = $_template->properties;
|
|
||||||
if (!$cache) {
|
if (!$cache) {
|
||||||
unset($properties['tpl_function']);
|
$properties['file_dependency'] = $_template->compiled->file_dependency;
|
||||||
if (!empty($_template->compiler->templateProperties)) {
|
} else {
|
||||||
$properties['tpl_function'] = $_template->compiler->templateProperties['tpl_function'];
|
$properties['file_dependency'] = $_template->cached->file_dependency;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$output = "<?php\n";
|
$output = "<?php\n";
|
||||||
$output .= "/*%%SmartyHeaderCode:{$_template->properties['nocache_hash']}%%*/\n";
|
$output .= "/*%%SmartyHeaderCode:{$_template->compiled->nocache_hash}%%*/\n";
|
||||||
if ($_template->smarty->direct_access_security) {
|
if ($_template->smarty->direct_access_security) {
|
||||||
$output .= "if(!defined('SMARTY_DIR')) exit('no direct access allowed');\n";
|
$output .= "if(!defined('SMARTY_DIR')) exit('no direct access allowed');\n";
|
||||||
}
|
}
|
||||||
$output .= "\$_valid = \$_smarty_tpl->decodeProperties(" . var_export($properties, true) . ',' . ($cache ? 'true' : 'false') . ");\n";
|
$output .= "\$_valid = \$_smarty_tpl->decodeProperties(" . var_export($properties, true) . ',' .
|
||||||
|
($cache ? 'true' : 'false') . ");\n";
|
||||||
$output .= "/*/%%SmartyHeaderCode%%*/\n";
|
$output .= "/*/%%SmartyHeaderCode%%*/\n";
|
||||||
$output .= "if (\$_valid && !is_callable('{$_template->properties['unifunc']}')) {\n";
|
$output .= "if (\$_valid && !is_callable('{$properties['unifunc']}')) {\n";
|
||||||
$output .= "function {$_template->properties['unifunc']} (\$_smarty_tpl) {\n";
|
$output .= "function {$properties['unifunc']} (\$_smarty_tpl) {\n";
|
||||||
// include code for plugins
|
// include code for plugins
|
||||||
if (!$cache) {
|
if (!$cache) {
|
||||||
if (!empty($_template->required_plugins['compiled'])) {
|
if (!empty($_template->required_plugins['compiled'])) {
|
||||||
foreach ($_template->required_plugins['compiled'] as $tmp) {
|
foreach ($_template->required_plugins['compiled'] as $tmp) {
|
||||||
foreach ($tmp as $data) {
|
foreach ($tmp as $data) {
|
||||||
$file = addslashes($data['file']);
|
$file = addslashes($data['file']);
|
||||||
if (is_Array($data['function'])) {
|
if (is_array($data['function'])) {
|
||||||
$output .= "if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) require_once '{$file}';\n";
|
$output .= "if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) require_once '{$file}';\n";
|
||||||
} else {
|
} else {
|
||||||
$output .= "if (!is_callable('{$data['function']}')) require_once '{$file}';\n";
|
$output .= "if (!is_callable('{$data['function']}')) require_once '{$file}';\n";
|
||||||
@@ -63,7 +61,7 @@ class Smarty_Internal_Extension_CodeFrame
|
|||||||
}
|
}
|
||||||
if (!empty($_template->required_plugins['nocache'])) {
|
if (!empty($_template->required_plugins['nocache'])) {
|
||||||
$_template->has_nocache_code = true;
|
$_template->has_nocache_code = true;
|
||||||
$output .= "echo '/*%%SmartyNocache:{$_template->properties['nocache_hash']}%%*/<?php \$_smarty = \$_smarty_tpl->smarty; ";
|
$output .= "echo '/*%%SmartyNocache:{$_template->compiled->nocache_hash}%%*/<?php \$_smarty = \$_smarty_tpl->smarty; ";
|
||||||
foreach ($_template->required_plugins['nocache'] as $tmp) {
|
foreach ($_template->required_plugins['nocache'] as $tmp) {
|
||||||
foreach ($tmp as $data) {
|
foreach ($tmp as $data) {
|
||||||
$file = addslashes($data['file']);
|
$file = addslashes($data['file']);
|
||||||
@@ -74,7 +72,7 @@ class Smarty_Internal_Extension_CodeFrame
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$output .= "?>/*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%*/';\n";
|
$output .= "?>/*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%*/';\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$output .= "?>\n";
|
$output .= "?>\n";
|
||||||
@@ -92,16 +90,13 @@ class Smarty_Internal_Extension_CodeFrame
|
|||||||
*/
|
*/
|
||||||
public static function createFunctionFrame(Smarty_Internal_Template $_template, $content = '')
|
public static function createFunctionFrame(Smarty_Internal_Template $_template, $content = '')
|
||||||
{
|
{
|
||||||
if (!isset($_template->properties['unifunc'])) {
|
|
||||||
$_template->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
|
|
||||||
}
|
|
||||||
$output = "<?php\n";
|
$output = "<?php\n";
|
||||||
$output .= "/*%%SmartyHeaderCode:{$_template->properties['nocache_hash']}%%*/\n";
|
$output .= "/*%%SmartyHeaderCode:{$_template->compiled->nocache_hash}%%*/\n";
|
||||||
$output .= "if (\$_valid && !is_callable('{$_template->properties['unifunc']}')) {\n";
|
$output .= "if (\$_valid && !is_callable('{$_template->compiled->unifunc}')) {\n";
|
||||||
$output .= "function {$_template->properties['unifunc']} (\$_smarty_tpl) {\n";
|
$output .= "function {$_template->compiled->unifunc} (\$_smarty_tpl) {\n";
|
||||||
$output .= "?>\n" . $content;
|
$output .= "?>\n" . $content;
|
||||||
$output .= "<?php\n";
|
$output .= "<?php\n";
|
||||||
$output .= "/*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%*/\n";
|
$output .= "/*/%%SmartyNocache:{$_template->compiled->nocache_hash}%%*/\n";
|
||||||
$output .= "}\n}\n?>";
|
$output .= "}\n}\n?>";
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
@@ -30,9 +30,9 @@ class Smarty_Internal_Function_Call_Handler
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function call($_name, Smarty_Internal_Template $_smarty_tpl, $_function, $_params, $_nocache)
|
public static function call($_name, Smarty_Internal_Template $_smarty_tpl, $_function)
|
||||||
{
|
{
|
||||||
$funcParam = $_smarty_tpl->properties['tpl_function'][$_name];
|
$funcParam = $_smarty_tpl->tpl_function[$_name];
|
||||||
if (is_file($funcParam['compiled_filepath'])) {
|
if (is_file($funcParam['compiled_filepath'])) {
|
||||||
// read compiled file
|
// read compiled file
|
||||||
$code = file_get_contents($funcParam['compiled_filepath']);
|
$code = file_get_contents($funcParam['compiled_filepath']);
|
||||||
@@ -41,7 +41,6 @@ class Smarty_Internal_Function_Call_Handler
|
|||||||
// grab source info from file dependency
|
// grab source info from file dependency
|
||||||
preg_match("/\s*'{$funcParam['uid']}'([\S\s]*?)\),/", $code, $match1);
|
preg_match("/\s*'{$funcParam['uid']}'([\S\s]*?)\),/", $code, $match1);
|
||||||
unset($code);
|
unset($code);
|
||||||
$output = '';
|
|
||||||
// make PHP function known
|
// make PHP function known
|
||||||
eval($match[0]);
|
eval($match[0]);
|
||||||
if (function_exists($_function)) {
|
if (function_exists($_function)) {
|
||||||
|
@@ -48,20 +48,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
*/
|
*/
|
||||||
public $mustCompile = null;
|
public $mustCompile = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* flag if template does contain nocache code sections
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
public $has_nocache_code = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* special compiled and cached template properties
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public $properties = array('file_dependency' => array(), 'nocache_hash' => '', 'tpl_function' => array(),);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* required plugins
|
* required plugins
|
||||||
*
|
*
|
||||||
@@ -104,6 +91,13 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
*/
|
*/
|
||||||
public $_capture_stack = array(0 => array());
|
public $_capture_stack = array(0 => array());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Known template functions
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $tpl_function = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create template data object
|
* Create template data object
|
||||||
* Some of the global Smarty settings copied to template scope
|
* Some of the global Smarty settings copied to template scope
|
||||||
@@ -245,9 +239,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
$this->cached->isCached($this);
|
$this->cached->isCached($this);
|
||||||
}
|
}
|
||||||
if (!($isCacheTpl) || !$this->cached->valid) {
|
if (!($isCacheTpl) || !$this->cached->valid) {
|
||||||
if ($isCacheTpl) {
|
|
||||||
$this->properties['tpl_function'] = array();
|
|
||||||
}
|
|
||||||
// render template (not loaded and not in cache)
|
// render template (not loaded and not in cache)
|
||||||
if ($this->smarty->debugging) {
|
if ($this->smarty->debugging) {
|
||||||
Smarty_Internal_Debug::start_render($this);
|
Smarty_Internal_Debug::start_render($this);
|
||||||
@@ -261,14 +252,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
} else {
|
} else {
|
||||||
$content = $this->source->renderUncompiled($this);
|
$content = $this->source->renderUncompiled($this);
|
||||||
}
|
}
|
||||||
if (!$this->source->recompiled && empty($this->properties['file_dependency'][$this->source->uid])) {
|
|
||||||
$this->properties['file_dependency'][$this->source->uid] = array($this->source->filepath,
|
|
||||||
$this->source->getTimeStamp(),
|
|
||||||
$this->source->type);
|
|
||||||
}
|
|
||||||
if ($parentIsTpl) {
|
if ($parentIsTpl) {
|
||||||
$this->parent->properties['file_dependency'] = array_merge($this->parent->properties['file_dependency'], $this->properties['file_dependency']);
|
$this->parent->tpl_function = array_merge($this->parent->tpl_function, $this->tpl_function);
|
||||||
//$this->parent->properties['tpl_function'] = array_merge($this->parent->properties['tpl_function'], $this->properties['tpl_function']);
|
|
||||||
}
|
}
|
||||||
if ($this->smarty->debugging) {
|
if ($this->smarty->debugging) {
|
||||||
Smarty_Internal_Debug::end_render($this);
|
Smarty_Internal_Debug::end_render($this);
|
||||||
@@ -282,21 +267,24 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
$compile_check = $this->smarty->compile_check;
|
$compile_check = $this->smarty->compile_check;
|
||||||
$this->smarty->compile_check = false;
|
$this->smarty->compile_check = false;
|
||||||
if ($parentIsTpl) {
|
if ($parentIsTpl) {
|
||||||
$this->properties['tpl_function'] = $this->parent->properties['tpl_function'];
|
$this->compiled->unifunc = $this->parent->compiled->unifunc;
|
||||||
}
|
}
|
||||||
if (!$this->cached->processed) {
|
if (!$this->cached->processed) {
|
||||||
$this->cached->process($this, true);
|
$this->cached->process($this, true);
|
||||||
}
|
}
|
||||||
$this->smarty->compile_check = $compile_check;
|
$this->smarty->compile_check = $compile_check;
|
||||||
$content = $this->getRenderedTemplateCode();
|
$content = $this->getRenderedTemplateCode($this->cached->unifunc);
|
||||||
if ($this->smarty->debugging) {
|
if ($this->smarty->debugging) {
|
||||||
Smarty_Internal_Debug::end_cache($this);
|
Smarty_Internal_Debug::end_cache($this);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($this->parent instanceof Smarty_Internal_Template && !empty($this->properties['nocache_hash']) && !empty($this->parent->properties['nocache_hash'])) {
|
if ($this->parent instanceof Smarty_Internal_Template && !empty($this->compiled->nocache_hash) &&
|
||||||
|
!empty($this->parent->compiled->nocache_hash)
|
||||||
|
) {
|
||||||
// replace nocache_hash
|
// replace nocache_hash
|
||||||
$content = str_replace("{$this->properties['nocache_hash']}", $this->parent->properties['nocache_hash'], $content);
|
$content = str_replace("{$this->compiled->nocache_hash}", $this->parent->compiled->nocache_hash, $content);
|
||||||
$this->parent->has_nocache_code = $this->parent->has_nocache_code || $this->has_nocache_code;
|
$this->parent->compiled->has_nocache_code = $this->parent->compiled->has_nocache_code ||
|
||||||
|
$this->compiled->has_nocache_code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -308,7 +296,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
Smarty_Internal_Debug::end_cache($this);
|
Smarty_Internal_Debug::end_cache($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((!$this->caching || $this->has_nocache_code || $this->source->recompiled) && !$no_output_filter &&
|
if ((!$this->caching || $this->cached->has_nocache_code || $this->source->recompiled) && !$no_output_filter &&
|
||||||
(isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))
|
(isset($this->smarty->autoload_filters['output']) || isset($this->smarty->registered_filters['output']))
|
||||||
) {
|
) {
|
||||||
$content = Smarty_Internal_Filter_Handler::runFilter('output', $content, $this);
|
$content = Smarty_Internal_Filter_Handler::runFilter('output', $content, $this);
|
||||||
@@ -351,9 +339,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($parentIsTpl) {
|
if ($parentIsTpl) {
|
||||||
$this->parent->properties['tpl_function'] = array_merge($this->parent->properties['tpl_function'], $this->properties['tpl_function']);
|
$this->parent->tpl_function = array_merge($this->parent->tpl_function, $this->tpl_function);
|
||||||
foreach ($this->required_plugins as $code => $tmp1) {
|
foreach ($this->required_plugins as $code => $tmp1) {
|
||||||
foreach ($tmp1 as $name => $tmp) {
|
foreach ($tmp1 as $name => $tmp) {
|
||||||
foreach ($tmp as $type => $data) {
|
foreach ($tmp as $type => $data) {
|
||||||
$this->parent->required_plugins[$code][$name][$type] = $data;
|
$this->parent->required_plugins[$code][$name][$type] = $data;
|
||||||
}
|
}
|
||||||
@@ -368,15 +356,17 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* get rendered template content by calling compiled or cached template code
|
* get rendered template content by calling compiled or cached template code
|
||||||
*
|
*
|
||||||
|
* @param string $unifunc function with template code
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @throws Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function getRenderedTemplateCode()
|
public function getRenderedTemplateCode($unifunc)
|
||||||
{
|
{
|
||||||
$level = ob_get_level();
|
$level = ob_get_level();
|
||||||
try {
|
try {
|
||||||
ob_start();
|
ob_start();
|
||||||
if (empty($this->properties['unifunc']) || !is_callable($this->properties['unifunc'])) {
|
if (empty($unifunc) || !is_callable($unifunc)) {
|
||||||
throw new SmartyException("Invalid compiled template for '{$this->template_resource}'");
|
throw new SmartyException("Invalid compiled template for '{$this->template_resource}'");
|
||||||
}
|
}
|
||||||
if (isset($this->smarty->security_policy)) {
|
if (isset($this->smarty->security_policy)) {
|
||||||
@@ -386,14 +376,14 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
//
|
//
|
||||||
// render compiled or saved template code
|
// render compiled or saved template code
|
||||||
//
|
//
|
||||||
$this->properties['unifunc']($this);
|
$unifunc($this);
|
||||||
// any unclosed {capture} tags ?
|
// any unclosed {capture} tags ?
|
||||||
if (isset($this->_capture_stack[0][0])) {
|
if (isset($this->_capture_stack[0][0])) {
|
||||||
$this->capture_error();
|
$this->capture_error();
|
||||||
}
|
}
|
||||||
array_shift($this->_capture_stack);
|
array_shift($this->_capture_stack);
|
||||||
if (isset($this->smarty->security_policy)) {
|
if (isset($this->smarty->security_policy)) {
|
||||||
$this->smarty->security_policy->exitTemplate($this);
|
$this->smarty->security_policy->exitTemplate();
|
||||||
}
|
}
|
||||||
return ob_get_clean();
|
return ob_get_clean();
|
||||||
}
|
}
|
||||||
@@ -483,7 +473,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
* @param array $data passed parameter template variables
|
* @param array $data passed parameter template variables
|
||||||
* @param int $parent_scope scope in which {include} should execute
|
* @param int $parent_scope scope in which {include} should execute
|
||||||
*
|
*
|
||||||
* @returns object template object
|
* @returns \Smarty_Internal_Template template object
|
||||||
*/
|
*/
|
||||||
public function setupSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope)
|
public function setupSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope)
|
||||||
{
|
{
|
||||||
@@ -508,10 +498,13 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
$this->smarty->template_objects[$_templateId] = $tpl;
|
$this->smarty->template_objects[$_templateId] = $tpl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// get variables from calling scope
|
if ($caching == 9999) {
|
||||||
|
$tpl->cached = $this->cached;
|
||||||
|
}
|
||||||
|
// get variables from calling scope
|
||||||
if ($parent_scope == Smarty::SCOPE_LOCAL) {
|
if ($parent_scope == Smarty::SCOPE_LOCAL) {
|
||||||
$tpl->tpl_vars = $this->tpl_vars;
|
$tpl->tpl_vars = $this->tpl_vars;
|
||||||
} elseif ($parent_scope == Smarty::SCOPE_PARENT) {
|
} elseif ($parent_scope == Smarty::SCOPE_PARENT) {
|
||||||
$tpl->tpl_vars = &$this->tpl_vars;
|
$tpl->tpl_vars = &$this->tpl_vars;
|
||||||
} elseif ($parent_scope == Smarty::SCOPE_GLOBAL) {
|
} elseif ($parent_scope == Smarty::SCOPE_GLOBAL) {
|
||||||
$tpl->tpl_vars = &Smarty::$global_tpl_vars;
|
$tpl->tpl_vars = &Smarty::$global_tpl_vars;
|
||||||
@@ -527,7 +520,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
$tpl->tpl_vars[$_key] = new Smarty_Variable($_val);
|
$tpl->tpl_vars[$_key] = new Smarty_Variable($_val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$tpl->properties['tpl_function'] = $this->properties['tpl_function'];
|
$tpl->tpl_function = $this->tpl_function;
|
||||||
return $tpl;
|
return $tpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -549,22 +542,17 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
public function getInlineSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope, $hash, $content_func)
|
public function getInlineSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope, $hash, $content_func)
|
||||||
{
|
{
|
||||||
$tpl = $this->setupSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope);
|
$tpl = $this->setupSubTemplate($template, $cache_id, $compile_id, $caching, $cache_lifetime, $data, $parent_scope);
|
||||||
$tpl->properties['nocache_hash'] = $hash;
|
$tpl->compiled->nocache_hash = $hash;
|
||||||
if ($this->smarty->debugging) {
|
if ($this->smarty->debugging) {
|
||||||
Smarty_Internal_Debug::start_template($tpl);
|
Smarty_Internal_Debug::start_template($tpl);
|
||||||
Smarty_Internal_Debug::start_render($tpl);
|
Smarty_Internal_Debug::start_render($tpl);
|
||||||
}
|
}
|
||||||
$tpl->properties['unifunc'] = $content_func;
|
$output = $tpl->getRenderedTemplateCode($content_func);
|
||||||
$output = $tpl->getRenderedTemplateCode();
|
|
||||||
if ($this->smarty->debugging) {
|
if ($this->smarty->debugging) {
|
||||||
Smarty_Internal_Debug::end_template($tpl);
|
Smarty_Internal_Debug::end_template($tpl);
|
||||||
Smarty_Internal_Debug::end_render($tpl);
|
Smarty_Internal_Debug::end_render($tpl);
|
||||||
}
|
}
|
||||||
if (!empty($tpl->properties['file_dependency'])) {
|
return str_replace($tpl->compiled->nocache_hash, $this->compiled->nocache_hash, $output);
|
||||||
$this->properties['file_dependency'] = array_merge($this->properties['file_dependency'], $tpl->properties['file_dependency']);
|
|
||||||
}
|
|
||||||
$this->properties['tpl_function'] = $tpl->properties['tpl_function'];
|
|
||||||
return str_replace($tpl->properties['nocache_hash'], $this->properties['nocache_hash'], $output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -579,14 +567,14 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
*/
|
*/
|
||||||
public function callTemplateFunction($name, Smarty_Internal_Template $_smarty_tpl, $params, $nocache)
|
public function callTemplateFunction($name, Smarty_Internal_Template $_smarty_tpl, $params, $nocache)
|
||||||
{
|
{
|
||||||
if (isset($_smarty_tpl->properties['tpl_function'][$name])) {
|
if (isset($_smarty_tpl->tpl_function[$name])) {
|
||||||
if (!$_smarty_tpl->caching || ($_smarty_tpl->caching && $nocache)) {
|
if (!$_smarty_tpl->caching || ($_smarty_tpl->caching && $nocache)) {
|
||||||
$function = $_smarty_tpl->properties['tpl_function'][$name]['call_name'];
|
$function = $_smarty_tpl->tpl_function[$name]['call_name'];
|
||||||
} else {
|
} else {
|
||||||
if (isset($_smarty_tpl->properties['tpl_function'][$name]['call_name_caching'])) {
|
if (isset($_smarty_tpl->tpl_function[$name]['call_name_caching'])) {
|
||||||
$function = $_smarty_tpl->properties['tpl_function'][$name]['call_name_caching'];
|
$function = $_smarty_tpl->tpl_function[$name]['call_name_caching'];
|
||||||
} else {
|
} else {
|
||||||
$function = $_smarty_tpl->properties['tpl_function'][$name]['call_name'];
|
$function = $_smarty_tpl->tpl_function[$name]['call_name'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (function_exists($function)) {
|
if (function_exists($function)) {
|
||||||
@@ -614,7 +602,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
*/
|
*/
|
||||||
public function decodeProperties($properties, $cache = false)
|
public function decodeProperties($properties, $cache = false)
|
||||||
{
|
{
|
||||||
$properties['version'] = (isset($properties['version'])) ? $properties['version'] : '';
|
|
||||||
$is_valid = true;
|
$is_valid = true;
|
||||||
if (Smarty::SMARTY_VERSION != $properties['version']) {
|
if (Smarty::SMARTY_VERSION != $properties['version']) {
|
||||||
// new version must rebuild
|
// new version must rebuild
|
||||||
@@ -652,23 +639,21 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
|||||||
) {
|
) {
|
||||||
$is_valid = false;
|
$is_valid = false;
|
||||||
}
|
}
|
||||||
|
if (isset($properties['cache_lifetime'])) {
|
||||||
|
$this->cached->cache_lifetime = $properties['cache_lifetime'];
|
||||||
|
}
|
||||||
$this->cached->valid = $is_valid;
|
$this->cached->valid = $is_valid;
|
||||||
|
$resource = $this->cached;
|
||||||
} else {
|
} else {
|
||||||
$this->mustCompile = !$is_valid;
|
$this->mustCompile = !$is_valid;
|
||||||
|
$resource = $this->compiled;
|
||||||
}
|
}
|
||||||
if ($is_valid) {
|
if ($is_valid) {
|
||||||
$this->has_nocache_code = $properties['has_nocache_code'];
|
$resource->unifunc = $properties['unifunc'];
|
||||||
// $this->properties['nocache_hash'] = $properties['nocache_hash'];
|
$resource->has_nocache_code = $properties['has_nocache_code'];
|
||||||
if (isset($properties['cache_lifetime'])) {
|
// $this->compiled->nocache_hash = $properties['nocache_hash'];
|
||||||
$this->properties['cache_lifetime'] = $properties['cache_lifetime'];
|
$resource->file_dependency = $properties['file_dependency'];
|
||||||
}
|
$this->tpl_function = $properties['tpl_function'];
|
||||||
foreach (array('file_dependency', 'tpl_function') as $property) {
|
|
||||||
if (isset($properties[$property])) {
|
|
||||||
$this->properties[$property] = array_merge($this->properties[$property], $properties[$property]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->properties['version'] = $properties['version'];
|
|
||||||
$this->properties['unifunc'] = $properties['unifunc'];
|
|
||||||
}
|
}
|
||||||
return $is_valid;
|
return $is_valid;
|
||||||
}
|
}
|
||||||
|
@@ -367,10 +367,10 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
}
|
}
|
||||||
$this->parent_compiler = $parent_compiler ? $parent_compiler : $this;
|
$this->parent_compiler = $parent_compiler ? $parent_compiler : $this;
|
||||||
$nocache = isset($nocache) ? $nocache : false;
|
$nocache = isset($nocache) ? $nocache : false;
|
||||||
if (empty($template->properties['nocache_hash'])) {
|
if (empty($template->compiled->nocache_hash)) {
|
||||||
$template->properties['nocache_hash'] = $this->nocache_hash;
|
$template->compiled->nocache_hash = $this->nocache_hash;
|
||||||
} else {
|
} else {
|
||||||
$this->nocache_hash = $template->properties['nocache_hash'];
|
$this->nocache_hash = $template->compiled->nocache_hash;
|
||||||
}
|
}
|
||||||
// template header code
|
// template header code
|
||||||
$template_header = '';
|
$template_header = '';
|
||||||
@@ -387,6 +387,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
$this->sources = array_reverse($template->source->components);
|
$this->sources = array_reverse($template->source->components);
|
||||||
}
|
}
|
||||||
$loop = 0;
|
$loop = 0;
|
||||||
|
$_compiled_code = '';
|
||||||
// the $this->sources array can get additional elements while compiling by the {extends} tag
|
// the $this->sources array can get additional elements while compiling by the {extends} tag
|
||||||
while ($this->template->source = array_shift($this->sources)) {
|
while ($this->template->source = array_shift($this->sources)) {
|
||||||
$this->smarty->_current_file = $this->template->source->filepath;
|
$this->smarty->_current_file = $this->template->source->filepath;
|
||||||
@@ -394,9 +395,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
Smarty_Internal_Debug::start_compile($this->template);
|
Smarty_Internal_Debug::start_compile($this->template);
|
||||||
}
|
}
|
||||||
$no_sources = count($this->sources);
|
$no_sources = count($this->sources);
|
||||||
$this->parent_compiler->template->properties['file_dependency'][$this->template->source->uid] = array($this->template->source->filepath,
|
$this->parent_compiler->template->compiled->file_dependency[$this->template->source->uid] = array($this->template->source->filepath,
|
||||||
$this->template->source->getTimeStamp(),
|
$this->template->source->getTimeStamp(),
|
||||||
$this->template->source->type);
|
$this->template->source->type);
|
||||||
$loop ++;
|
$loop ++;
|
||||||
if ($no_sources) {
|
if ($no_sources) {
|
||||||
$this->inheritance_child = true;
|
$this->inheritance_child = true;
|
||||||
@@ -407,10 +408,9 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
$this->nocache = $nocache;
|
$this->nocache = $nocache;
|
||||||
$this->tag_nocache = false;
|
$this->tag_nocache = false;
|
||||||
// reset has nocache code flag
|
// reset has nocache code flag
|
||||||
$this->template->has_nocache_code = false;
|
$this->template->compiled->has_nocache_code = false;
|
||||||
$this->has_variable_string = false;
|
$this->has_variable_string = false;
|
||||||
$this->prefix_code = array();
|
$this->prefix_code = array();
|
||||||
$_compiled_code = '';
|
|
||||||
// get template source
|
// get template source
|
||||||
$_content = $this->template->source->getContent();
|
$_content = $this->template->source->getContent();
|
||||||
if ($_content != '') {
|
if ($_content != '') {
|
||||||
@@ -538,7 +538,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
}
|
}
|
||||||
// compile the smarty tag (required compile classes to compile the tag are auto loaded)
|
// compile the smarty tag (required compile classes to compile the tag are auto loaded)
|
||||||
if (($_output = $this->callTagCompiler($tag, $args, $parameter)) === false) {
|
if (($_output = $this->callTagCompiler($tag, $args, $parameter)) === false) {
|
||||||
if (isset($this->parent_compiler->templateProperties['tpl_function'][$tag])) {
|
if (isset($this->parent_compiler->template->tpl_function[$tag])) {
|
||||||
// template defined by {template} tag
|
// template defined by {template} tag
|
||||||
$args['_attr']['name'] = "'" . $tag . "'";
|
$args['_attr']['name'] = "'" . $tag . "'";
|
||||||
$_output = $this->callTagCompiler('call', $args, $parameter);
|
$_output = $this->callTagCompiler('call', $args, $parameter);
|
||||||
@@ -779,7 +779,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
// not a variable variable
|
// not a variable variable
|
||||||
$var = trim($variable, '\'');
|
$var = trim($variable, '\'');
|
||||||
$this->tag_nocache = $this->tag_nocache | $this->template->getVariable($var, null, true, false)->nocache;
|
$this->tag_nocache = $this->tag_nocache | $this->template->getVariable($var, null, true, false)->nocache;
|
||||||
$this->template->properties['variables'][$var] = $this->tag_nocache | $this->nocache;
|
// todo $this->template->compiled->properties['variables'][$var] = $this->tag_nocache | $this->nocache;
|
||||||
}
|
}
|
||||||
return '$_smarty_tpl->tpl_vars[' . $variable . ']->value';
|
return '$_smarty_tpl->tpl_vars[' . $variable . ']->value';
|
||||||
}
|
}
|
||||||
@@ -982,7 +982,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
if ((!($this->template->source->recompiled) || $this->forceNocache) && $this->template->caching &&
|
if ((!($this->template->source->recompiled) || $this->forceNocache) && $this->template->caching &&
|
||||||
!$this->suppressNocacheProcessing && ($this->nocache || $this->tag_nocache)
|
!$this->suppressNocacheProcessing && ($this->nocache || $this->tag_nocache)
|
||||||
) {
|
) {
|
||||||
$this->template->has_nocache_code = true;
|
$this->template->compiled->has_nocache_code = true;
|
||||||
$_output = addcslashes($content, '\'\\');
|
$_output = addcslashes($content, '\'\\');
|
||||||
$_output = str_replace("^#^", "'", $_output);
|
$_output = str_replace("^#^", "'", $_output);
|
||||||
$_output = "<?php echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/" . $_output .
|
$_output = "<?php echo '/*%%SmartyNocache:{$this->nocache_hash}%%*/" . $_output .
|
||||||
|
@@ -9,49 +9,15 @@
|
|||||||
* @author Rodney Rehm
|
* @author Rodney Rehm
|
||||||
* @property string $content compiled content
|
* @property string $content compiled content
|
||||||
*/
|
*/
|
||||||
class Smarty_Template_Compiled
|
class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Compiled Filepath
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $filepath = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiled Timestamp
|
* nocache hash
|
||||||
*
|
|
||||||
* @var integer
|
|
||||||
*/
|
|
||||||
public $timestamp = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compiled Existence
|
|
||||||
*
|
|
||||||
* @var boolean
|
|
||||||
*/
|
|
||||||
public $exists = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compiled Content Loaded
|
|
||||||
*
|
|
||||||
* @var boolean
|
|
||||||
*/
|
|
||||||
public $processed = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Code of recompiled template resource
|
|
||||||
*
|
*
|
||||||
* @var string|null
|
* @var string|null
|
||||||
*/
|
*/
|
||||||
public $code = null;
|
public $nocache_hash = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* unique function name for compiled template code
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $unifunc = '';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create Compiled Object container
|
* create Compiled Object container
|
||||||
@@ -72,7 +38,7 @@ class Smarty_Template_Compiled
|
|||||||
$smarty = $_template->smarty;
|
$smarty = $_template->smarty;
|
||||||
$source = $_template->source;
|
$source = $_template->source;
|
||||||
// check runtime cache
|
// check runtime cache
|
||||||
if (!$source->recompiled && $smarty->resource_caching) {
|
if (!$source->recompiled && ($smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)) {
|
||||||
$_cache_key = $source->unique_resource . '#';
|
$_cache_key = $source->unique_resource . '#';
|
||||||
if ($_template->caching) {
|
if ($_template->caching) {
|
||||||
$_cache_key .= 'caching#';
|
$_cache_key .= 'caching#';
|
||||||
@@ -89,7 +55,7 @@ class Smarty_Template_Compiled
|
|||||||
$compiled->populateCompiledFilepath($_template);
|
$compiled->populateCompiledFilepath($_template);
|
||||||
}
|
}
|
||||||
// runtime cache
|
// runtime cache
|
||||||
if (!$source->recompiled && $smarty->resource_caching) {
|
if (!$source->recompiled && ($smarty->resource_cache_mode & Smarty::RESOURCE_CACHE_ON)) {
|
||||||
$source->compileds[$_cache_key] = $compiled;
|
$source->compileds[$_cache_key] = $compiled;
|
||||||
}
|
}
|
||||||
return $compiled;
|
return $compiled;
|
||||||
@@ -166,7 +132,7 @@ class Smarty_Template_Compiled
|
|||||||
$level = ob_get_level();
|
$level = ob_get_level();
|
||||||
ob_start();
|
ob_start();
|
||||||
try {
|
try {
|
||||||
eval("?>" . $this->code);
|
eval("?>" . $this->buffer);
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
while (ob_get_level() > $level) {
|
while (ob_get_level() > $level) {
|
||||||
@@ -175,7 +141,7 @@ class Smarty_Template_Compiled
|
|||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
ob_get_clean();
|
ob_get_clean();
|
||||||
$this->code = null;
|
$this->buffer = null;
|
||||||
} else {
|
} else {
|
||||||
$this->loadCompiledTemplate($_template);
|
$this->loadCompiledTemplate($_template);
|
||||||
}
|
}
|
||||||
@@ -190,7 +156,6 @@ class Smarty_Template_Compiled
|
|||||||
$_template->smarty->compile_check = $compileCheck;
|
$_template->smarty->compile_check = $compileCheck;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->unifunc = $_template->properties['unifunc'];
|
|
||||||
$this->processed = true;
|
$this->processed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,8 +192,10 @@ class Smarty_Template_Compiled
|
|||||||
if (!$this->processed) {
|
if (!$this->processed) {
|
||||||
$this->process($_template);
|
$this->process($_template);
|
||||||
}
|
}
|
||||||
$_template->properties['unifunc'] = $this->unifunc;
|
if (isset($_template->cached)){
|
||||||
return $_template->getRenderedTemplateCode();
|
$_template->cached->file_dependency = array_merge($_template->cached->file_dependency, $this->file_dependency);
|
||||||
|
}
|
||||||
|
return $_template->getRenderedTemplateCode($this->unifunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -242,9 +209,10 @@ class Smarty_Template_Compiled
|
|||||||
public function compileTemplateSource(Smarty_Internal_Template $_template)
|
public function compileTemplateSource(Smarty_Internal_Template $_template)
|
||||||
{
|
{
|
||||||
$_template->source->compileds = array();
|
$_template->source->compileds = array();
|
||||||
if (!$_template->source->recompiled) {
|
$this->file_dependency = array();
|
||||||
$_template->properties['file_dependency'] = array();
|
$this->tpl_function = array();
|
||||||
}
|
$this->nocache_hash = null;
|
||||||
|
$this->unifunc = null;
|
||||||
// compile locking
|
// compile locking
|
||||||
if (!$_template->source->recompiled) {
|
if (!$_template->source->recompiled) {
|
||||||
if ($saved_timestamp = $_template->compiled->getTimeStamp()) {
|
if ($saved_timestamp = $_template->compiled->getTimeStamp()) {
|
||||||
@@ -295,7 +263,7 @@ class Smarty_Template_Compiled
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
$this->code = $code;
|
$this->buffer = $code;
|
||||||
}
|
}
|
||||||
$this->timestamp = time();
|
$this->timestamp = time();
|
||||||
$this->exists = true;
|
$this->exists = true;
|
||||||
@@ -314,7 +282,7 @@ class Smarty_Template_Compiled
|
|||||||
if (!$_template->source->recompiled) {
|
if (!$_template->source->recompiled) {
|
||||||
return file_get_contents($this->filepath);
|
return file_get_contents($this->filepath);
|
||||||
}
|
}
|
||||||
return isset($this->content) ? $this->content : false;
|
return isset($this->buffer) ? $this->buffer : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
162
libs/sysplugins/smarty_template_resource_base.php
Normal file
162
libs/sysplugins/smarty_template_resource_base.php
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smarty Template Resource Base Object
|
||||||
|
* Meta Data Container for Template Resource Files
|
||||||
|
*
|
||||||
|
* @package Smarty
|
||||||
|
* @subpackage TemplateResources
|
||||||
|
* @author Rodney Rehm
|
||||||
|
*/
|
||||||
|
abstract class Smarty_Template_Resource_Base
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Compiled Filepath
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $filepath = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compiled Timestamp
|
||||||
|
*
|
||||||
|
* @var integer
|
||||||
|
*/
|
||||||
|
public $timestamp = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compiled Existence
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
public $exists = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template Compile Id (Smarty_Internal_Template::$compile_id)
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $compile_id = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compiled Content Loaded
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
public $processed = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* unique function name for compiled template code
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $unifunc = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* flag if template does contain nocache code sections
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $has_nocache_code = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* resource file dependency
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $file_dependency = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Code of recompiled template resource
|
||||||
|
*
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
public $buffer = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* required plugins
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $required_plugins = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process resource
|
||||||
|
*
|
||||||
|
* @param Smarty_Internal_Template $_template template object
|
||||||
|
*/
|
||||||
|
abstract public function process(Smarty_Internal_Template $_template);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* render template code
|
||||||
|
*
|
||||||
|
* @param Smarty_Internal_Template $_template
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function render(Smarty_Internal_Template $_template)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!$this->processed) {
|
||||||
|
$this->process($_template);
|
||||||
|
}
|
||||||
|
return $_template->getRenderedTemplateCode($this->unifunc);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write compiled code by handler
|
||||||
|
*
|
||||||
|
* @param Smarty_Internal_Template $_template template object
|
||||||
|
* @param string $code compiled code
|
||||||
|
*
|
||||||
|
* @return boolean success
|
||||||
|
*/
|
||||||
|
public function write(Smarty_Internal_Template $_template, $code)
|
||||||
|
{
|
||||||
|
if (!$_template->source->recompiled) {
|
||||||
|
$obj = new Smarty_Internal_Write_File();
|
||||||
|
if ($obj->writeFile($this->filepath, $code, $_template->smarty) === true) {
|
||||||
|
$this->timestamp = $this->exists = is_file($this->filepath);
|
||||||
|
if ($this->exists) {
|
||||||
|
$this->timestamp = filemtime($this->filepath);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
$this->buffer = $code;
|
||||||
|
}
|
||||||
|
$this->timestamp = time();
|
||||||
|
$this->exists = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read compiled content from handler
|
||||||
|
*
|
||||||
|
* @param Smarty_Internal_Template $_template template object
|
||||||
|
*
|
||||||
|
* @return string content
|
||||||
|
*/
|
||||||
|
public function read(Smarty_Internal_Template $_template)
|
||||||
|
{
|
||||||
|
if (!$_template->source->recompiled) {
|
||||||
|
return file_get_contents($this->filepath);
|
||||||
|
}
|
||||||
|
return isset($this->content) ? $this->content : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get compiled time stamp
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getTimeStamp()
|
||||||
|
{
|
||||||
|
if ($this->exists && !isset($this->timestamp)) {
|
||||||
|
$this->timestamp = @filemtime($this->filepath);
|
||||||
|
}
|
||||||
|
return $this->timestamp;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user