mirror of
https://github.com/smarty-php/smarty.git
synced 2026-05-03 19:30:49 +02:00
- bugfix sha1() calculations at extends resource and some general improvments on sha1() handling
This commit is contained in:
@@ -20,20 +20,21 @@ class Smarty_Internal_Resource_Extends {
|
||||
// classes used for compiling Smarty templates from file resource
|
||||
public $compiler_class = 'Smarty_Internal_SmartyTemplateCompiler';
|
||||
public $template_lexer_class = 'Smarty_Internal_Templatelexer';
|
||||
public $template_parser_class = 'Smarty_Internal_Templateparser';
|
||||
public $template_parser_class = 'Smarty_Internal_Templateparser';
|
||||
// properties
|
||||
public $usesCompiler = true;
|
||||
public $isEvaluated = false;
|
||||
public $allFilepaths = array();
|
||||
|
||||
/**
|
||||
* Return flag if template source is existing
|
||||
*
|
||||
* @param object $template template object
|
||||
* @param object $_template template object
|
||||
* @return boolean result
|
||||
*/
|
||||
public function isExisting($template)
|
||||
public function isExisting($_template)
|
||||
{
|
||||
if ($template->getTemplateFilepath() === false) {
|
||||
if ($_template->getTemplateFilepath() === false) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
@@ -42,56 +43,59 @@ class Smarty_Internal_Resource_Extends {
|
||||
/**
|
||||
* Get filepath to template source
|
||||
*
|
||||
* @param object $template template object
|
||||
* @param object $_template template object
|
||||
* @return string filepath to template source file
|
||||
*/
|
||||
public function getTemplateFilepath($template)
|
||||
public function getTemplateFilepath($_template)
|
||||
{
|
||||
$_files = explode('|', $template->resource_name);
|
||||
$_filepath = $template->buildTemplateFilepath ($_files[count($_files)-1]);
|
||||
if ($_filepath !== false) {
|
||||
if ($template->security) {
|
||||
$template->smarty->security_handler->isTrustedResourceDir($_filepath);
|
||||
$sha1String = '';
|
||||
$_files = explode('|', $_template->resource_name);
|
||||
foreach ($_files as $_file) {
|
||||
$_filepath = $_template->buildTemplateFilepath ($_file);
|
||||
if ($_filepath !== false) {
|
||||
if ($_template->security) {
|
||||
$_template->smarty->security_handler->isTrustedResourceDir($_filepath);
|
||||
}
|
||||
}
|
||||
$sha1String .= $_filepath;
|
||||
$this->allFilepaths[] = $_filepath;
|
||||
}
|
||||
$_template->templateUid = sha1($sha1String);
|
||||
return $_filepath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get timestamp to template source
|
||||
*
|
||||
* @param object $template template object
|
||||
* @param object $_template template object
|
||||
* @return integer timestamp of template source file
|
||||
*/
|
||||
public function getTemplateTimestamp($template)
|
||||
public function getTemplateTimestamp($_template)
|
||||
{
|
||||
return filemtime($template->getTemplateFilepath());
|
||||
return filemtime($_template->getTemplateFilepath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read template source from file
|
||||
*
|
||||
* @param object $template template object
|
||||
* @param object $_template template object
|
||||
* @return string content of template source file
|
||||
*/
|
||||
public function getTemplateSource($template)
|
||||
public function getTemplateSource($_template)
|
||||
{
|
||||
$this->template = $template;
|
||||
// $saved_filepath = $template->getTemplateFilepath();
|
||||
$_files = explode('|', $template->resource_name);
|
||||
$_files = array_reverse($_files);
|
||||
foreach ($_files as $_file) {
|
||||
$_filepath = $template->buildTemplateFilepath ($_file);
|
||||
$this->template = $_template;
|
||||
$_files = array_reverse($this->allFilepaths);
|
||||
foreach ($_files as $_filepath) {
|
||||
// read template file
|
||||
if ($_filepath === false) {
|
||||
throw new Exception("Unable to load template \"file : {$_file}\"");
|
||||
}
|
||||
if ($_file != $_files[0]) {
|
||||
$template->properties['file_dependency'][sha1($_filepath)] = array($_filepath, filemtime($_filepath));
|
||||
if ($_filepath != $_files[0]) {
|
||||
$_template->properties['file_dependency'][sha1($_filepath)] = array($_filepath, filemtime($_filepath));
|
||||
}
|
||||
$template->template_filepath = $_filepath;
|
||||
$_template->template_filepath = $_filepath;
|
||||
$_content = file_get_contents($_filepath);
|
||||
if ($_file != $_files[count($_files)-1]) {
|
||||
if ($_filepath != $_files[count($_files)-1]) {
|
||||
if (preg_match_all('/(' . $this->smarty->left_delimiter . 'block(.+?)' . $this->smarty->right_delimiter . ')/', $_content, $_open, PREG_OFFSET_CAPTURE) !=
|
||||
preg_match_all('/(' . $this->smarty->left_delimiter . '\/block(.*?)' . $this->smarty->right_delimiter . ')/', $_content, $_close, PREG_OFFSET_CAPTURE)) {
|
||||
$this->smarty->trigger_error(" unmatched {block} {/block} pairs");
|
||||
@@ -103,11 +107,11 @@ class Smarty_Internal_Resource_Extends {
|
||||
$this->saveBlockData($_block_content, $_open[0][$_i][0], $_filepath);
|
||||
}
|
||||
} else {
|
||||
$template->template_source = $_content;
|
||||
$_template->template_source = $_content;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// $template->template_filepath = $saved_filepath;
|
||||
// $_template->template_filepath = $saved_filepath;
|
||||
}
|
||||
protected function saveBlockData($block_content, $block_tag, $_filepath)
|
||||
{
|
||||
@@ -141,35 +145,39 @@ class Smarty_Internal_Resource_Extends {
|
||||
/**
|
||||
* Get filepath to compiled template
|
||||
*
|
||||
* @param object $template template object
|
||||
* @param object $_template template object
|
||||
* @return string return path to compiled template
|
||||
*/
|
||||
public function getCompiledFilepath($template)
|
||||
public function getCompiledFilepath($_template)
|
||||
{
|
||||
$_compile_id = isset($template->compile_id) ? preg_replace('![^\w\|]+!', '_', $template->compile_id) : null;
|
||||
$_files = explode('|', $template->resource_name);
|
||||
$_filepath = sha1($template->getTemplateFilepath());
|
||||
$_compile_id = isset($_template->compile_id) ? preg_replace('![^\w\|]+!', '_', $_template->compile_id) : null;
|
||||
$_files = explode('|', $_template->resource_name);
|
||||
// calculate Uid if not already done
|
||||
if ($_template->templateUid == '') {
|
||||
$_template->getTemplateFilepath();
|
||||
}
|
||||
$_filepath = $_template->templateUid;
|
||||
// if use_sub_dirs, break file into directories
|
||||
if ($template->smarty->use_sub_dirs) {
|
||||
if ($_template->smarty->use_sub_dirs) {
|
||||
$_filepath = substr($_filepath, 0, 2) . DS
|
||||
. substr($_filepath, 2, 2) . DS
|
||||
. substr($_filepath, 4, 2) . DS
|
||||
. $_filepath;
|
||||
}
|
||||
$_compile_dir_sep = $template->smarty->use_sub_dirs ? DS : '^';
|
||||
$_compile_dir_sep = $_template->smarty->use_sub_dirs ? DS : '^';
|
||||
if (isset($_compile_id)) {
|
||||
$_filepath = $_compile_id . $_compile_dir_sep . $_filepath;
|
||||
}
|
||||
if ($template->caching) {
|
||||
if ($_template->caching) {
|
||||
$_cache = '.cache';
|
||||
} else {
|
||||
$_cache = '';
|
||||
}
|
||||
$_compile_dir = $template->smarty->compile_dir;
|
||||
$_compile_dir = $_template->smarty->compile_dir;
|
||||
if (substr($_compile_dir, -1) != DS) {
|
||||
$_compile_dir .= DS;
|
||||
}
|
||||
return $_compile_dir . $_filepath . '.' . $template->resource_type . '.' . basename($_files[count($_files)-1]) . $_cache . '.php';
|
||||
return $_compile_dir . $_filepath . '.' . $_template->resource_type . '.' . basename($_files[count($_files)-1]) . $_cache . '.php';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user