mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 19:34:27 +02:00
- fixed handling of template_exits methode for all resource types
This commit is contained in:
@@ -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
|
||||
|
@@ -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 ($_template->security) {
|
||||
$_template->smarty->security_handler->isTrustedResourceDir($_filepath);
|
||||
if ($_filepath !== false) {
|
||||
if ($_template->security) {
|
||||
$_template->smarty->security_handler->isTrustedResourceDir($_filepath);
|
||||
}
|
||||
}
|
||||
|
||||
return $_filepath;
|
||||
}
|
||||
|
||||
@@ -62,11 +76,14 @@ class Smarty_Internal_Resource_Extend {
|
||||
$_files = explode('|', $_template->resource_name);
|
||||
$_files = array_reverse($_files);
|
||||
foreach ($_files as $_file) {
|
||||
$_filepath = $_template->buildTemplateFilepath ($_file);
|
||||
if ($_file != $_files[0]) {
|
||||
$_template->properties['file_dependency']['F'.abs(crc32($_filepath))] = array($_filepath, filemtime($_filepath));
|
||||
}
|
||||
$_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));
|
||||
}
|
||||
$_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) !=
|
||||
@@ -76,7 +93,7 @@ class Smarty_Internal_Resource_Extend {
|
||||
$block_count = count($s[0]);
|
||||
for ($i = 0; $i < $block_count; $i++) {
|
||||
$block_content = str_replace($this->smarty->left_delimiter . '$smarty.parent' . $this->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%',
|
||||
substr($_content, $s[0][$i][1] + strlen($s[0][$i][0]), $c[0][$i][1] - $s[0][$i][1] - strlen($s[0][$i][0])));
|
||||
substr($_content, $s[0][$i][1] + strlen($s[0][$i][0]), $c[0][$i][1] - $s[0][$i][1] - strlen($s[0][$i][0])));
|
||||
$this->saveBlockData($block_content, $s[0][$i][0]);
|
||||
}
|
||||
} else {
|
||||
|
@@ -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 ($_template->security) {
|
||||
$_template->smarty->security_handler->isTrustedResourceDir($_filepath);
|
||||
if ($_filepath !== false) {
|
||||
if ($_template->security) {
|
||||
$_template->smarty->security_handler->isTrustedResourceDir($_filepath);
|
||||
}
|
||||
}
|
||||
|
||||
return $_filepath;
|
||||
}
|
||||
|
||||
@@ -95,7 +110,7 @@ class Smarty_Internal_Resource_File {
|
||||
* @return string return path to compiled template
|
||||
*/
|
||||
public function getCompiledFilepath($_template)
|
||||
{
|
||||
{
|
||||
// $_filepath = md5($_template->resource_name);
|
||||
$_filepath = (string)abs(crc32($_template->resource_name));
|
||||
// if use_sub_dirs, break file into directories
|
||||
|
@@ -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
|
||||
*
|
||||
|
@@ -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
|
||||
*
|
||||
|
@@ -4,9 +4,10 @@
|
||||
* Smarty Internal Plugin Resource String
|
||||
*
|
||||
* Implements the strings as resource for Smarty template
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Uwe Tews
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
/**
|
||||
* Smarty Internal Plugin Resource String
|
||||
@@ -18,9 +19,19 @@ class Smarty_Internal_Resource_String {
|
||||
$this->smarty = $smarty;
|
||||
}
|
||||
// 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 $compiler_class = 'Smarty_Internal_SmartyTemplateCompiler';
|
||||
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
|
||||
@@ -29,11 +40,11 @@ class Smarty_Internal_Resource_String {
|
||||
* @return string return 'string' as template source is not a file
|
||||
*/
|
||||
public function getTemplateFilepath($_template)
|
||||
{
|
||||
{
|
||||
// no filepath for strings
|
||||
// return "string" for compiler error messages
|
||||
return 'string';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get timestamp to template source
|
||||
@@ -42,9 +53,9 @@ class Smarty_Internal_Resource_String {
|
||||
* @return boolean false as string resources have no timestamp
|
||||
*/
|
||||
public function getTemplateTimestamp($_template)
|
||||
{
|
||||
// strings must always be compiled and have no timestamp
|
||||
return false;
|
||||
{
|
||||
// strings must always be compiled and have no timestamp
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,9 +68,9 @@ class Smarty_Internal_Resource_String {
|
||||
{
|
||||
// return template string
|
||||
$_template->template_source = $_template->resource_name;
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return flag that this resource uses the compiler
|
||||
*
|
||||
@@ -69,8 +80,8 @@ class Smarty_Internal_Resource_String {
|
||||
{
|
||||
// resource string is template, needs compiler
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return flag that this resource is evaluated
|
||||
*
|
||||
@@ -81,7 +92,7 @@ class Smarty_Internal_Resource_String {
|
||||
// compiled template is evaluated instead of saved to disk
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get filepath to compiled template
|
||||
*
|
||||
@@ -89,10 +100,10 @@ class Smarty_Internal_Resource_String {
|
||||
* @return boolean return false as compiled template is not stored
|
||||
*/
|
||||
public function getCompiledFilepath($_template)
|
||||
{
|
||||
{
|
||||
// no filepath for strings
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@@ -31,7 +31,8 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase {
|
||||
public $resource_type = null;
|
||||
public $resource_name = null;
|
||||
private $usesCompiler = null;
|
||||
private $isEvaluated = 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;
|
||||
}
|
||||
|
||||
|
@@ -21,15 +21,11 @@
|
||||
* @return boolean status
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
?>
|
||||
|
Reference in New Issue
Block a user