- fixed handling of template_exits methode for all resource types

This commit is contained in:
Uwe.Tews
2009-09-30 18:28:50 +00:00
parent ed6df80a8f
commit 25d4535be6
8 changed files with 123 additions and 40 deletions

View File

@@ -1,6 +1,7 @@
09/30/2009
- fixed handling template_exits methode for all resource types
- bugfix for other cache resources than file
- the methodes assign_by_ref is now wrapped to assign, append_by_ref to append
- allow arrays of variables pass in display, fetch and createTemplate calls

View File

@@ -22,6 +22,19 @@ class Smarty_Internal_Resource_Extend {
public $template_lexer_class = 'Smarty_Internal_Templatelexer';
public $template_parser_class = 'Smarty_Internal_Templateparser';
/**
* Return flag if template source is existing
*
* @return boolean true
*/
public function isExisting($template)
{
if ($template->getTemplateFilepath() === false) {
return false;
} else {
return true;
}
}
/**
* Get filepath to template source
*
@@ -32,10 +45,11 @@ class Smarty_Internal_Resource_Extend {
{
$_files = explode('|', $_template->resource_name);
$_filepath = $_template->buildTemplateFilepath ($_files[count($_files)-1]);
if ($_filepath !== false) {
if ($_template->security) {
$_template->smarty->security_handler->isTrustedResourceDir($_filepath);
}
}
return $_filepath;
}
@@ -63,10 +77,13 @@ class Smarty_Internal_Resource_Extend {
$_files = array_reverse($_files);
foreach ($_files as $_file) {
$_filepath = $_template->buildTemplateFilepath ($_file);
// read template file
if ($_filepath === false) {
throw new Exception("Unable to load template \"file : {$_file}\"");
}
if ($_file != $_files[0]) {
$_template->properties['file_dependency']['F' . abs(crc32($_filepath))] = array($_filepath, filemtime($_filepath));
}
// read template file
$_content = file_get_contents($_filepath);
if ($_file != $_files[count($_files)-1]) {
if (preg_match_all('/(' . $this->smarty->left_delimiter . 'block(.+?)' . $this->smarty->right_delimiter . ')/', $_content, $s, PREG_OFFSET_CAPTURE) !=

View File

@@ -22,6 +22,20 @@ class Smarty_Internal_Resource_File {
public $template_lexer_class = 'Smarty_Internal_Templatelexer';
public $template_parser_class = 'Smarty_Internal_Templateparser';
/**
* Return flag if template source is existing
*
* @return boolean true
*/
public function isExisting($template)
{
if ($template->getTemplateFilepath() === false) {
return false;
} else {
return true;
}
}
/**
* Get filepath to template source
*
@@ -32,10 +46,11 @@ class Smarty_Internal_Resource_File {
{
$_filepath = $_template->buildTemplateFilepath ();
if ($_filepath !== false) {
if ($_template->security) {
$_template->smarty->security_handler->isTrustedResourceDir($_filepath);
}
}
return $_filepath;
}

View File

@@ -23,6 +23,19 @@ class Smarty_Internal_Resource_Registered {
public $template_lexer_class = 'Smarty_Internal_Templatelexer';
public $template_parser_class = 'Smarty_Internal_Templateparser';
/**
* Return flag if template source is existing
*
* @return boolean true
*/
public function isExisting($_template)
{
if (is_integer($this->getTemplateTimestamp($_template))) {
return true;
} else {
return false;
}
}
/**
* Get filepath to template source
*

View File

@@ -23,6 +23,19 @@ class Smarty_Internal_Resource_Stream {
public $template_lexer_class = 'Smarty_Internal_Templatelexer';
public $template_parser_class = 'Smarty_Internal_Templateparser';
/**
* Return flag if template source is existing
*
* @return boolean true
*/
public function isExisting($template)
{
if ($template->getTemplateSource() === false) {
return false;
} else {
return true;
}
}
/**
* Get filepath to template source
*

View File

@@ -4,6 +4,7 @@
* Smarty Internal Plugin Resource String
*
* Implements the strings as resource for Smarty template
*
* @package Smarty
* @subpackage TemplateResources
* @author Uwe Tews
@@ -22,6 +23,16 @@ class Smarty_Internal_Resource_String {
public $template_lexer_class = 'Smarty_Internal_Templatelexer';
public $template_parser_class = 'Smarty_Internal_Templateparser';
/**
* Return flag if template source is existing
*
* @return boolean true
*/
public function isExisting($template)
{
return true;
}
/**
* Get filepath to template source
*

View File

@@ -32,6 +32,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
public $resource_name = null;
private $usesCompiler = null;
private $isEvaluated = null;
private $isExisting = null;
// Template source
public $template_filepath = null;
public $template_source = null;
@@ -157,6 +158,19 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
return $this->template_source;
}
/**
* Returns if the template is existing
*
* The status is determined by the actual resource handler
*
* @return boolean true if the template exists
*/
public function isExisting ()
{
return $this->isExisting === null ?
$this->isExisting = $this->resource_objects[$this->resource_type]->isExisting($this) :
$this->isExisting;
}
/**
* Returns if the template resource uses the Smarty compiler
*
@@ -194,6 +208,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
*/
public function mustCompile ()
{
if (!$this->isExisting()) {
throw new Exception("Unable to load template \"{$this->resource_type} : {$this->resource_name}\"");
}
if ($this->mustCompile === null) {
$this->mustCompile = ($this->usesCompiler() && ($this->force_compile || $this->isEvaluated() || ($this->smarty->compile_check && $this->getCompiledTimestamp () !== $this->getTemplateTimestamp ())));
if ($this->mustCompile) {
@@ -592,7 +609,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
}
}
}
throw new Exception("Unable to load template \"{$file}\"");
// throw new Exception("Unable to load template \"{$file}\"");
return false;
}

View File

@@ -22,14 +22,10 @@
*/
function template_exists($smarty, $resource_name)
{
foreach((array)$smarty->template_dir as $_template_dir) {
$_filepath = $_template_dir . $resource_name;
if (file_exists($_filepath))
return true;
}
if (file_exists($resource_name)) return true;
// no tpl file found
return false;
// create template object
$tpl = new $smarty->template_class($resource_name, $smarty);
// check if it does exists
return $tpl->isExisting();
}
?>