From 21c65f93e61e54a7ae6ef05f5aaa95d308a4ac21 Mon Sep 17 00:00:00 2001 From: andrei Date: Wed, 3 Apr 2002 19:31:11 +0000 Subject: [PATCH] Added template_exists() API. --- NEWS | 1 + Smarty.class.php | 13 ++++++++++--- libs/Smarty.class.php | 13 ++++++++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index ccc8fba5..e6fad643 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,4 @@ + - added template_exists() API function. (Andrei) - fixed a problem with using dynamic values for 'file' attribute of {include_php} tag. (Andrei) - added $smarty.template variable. (Andrei) diff --git a/Smarty.class.php b/Smarty.class.php index 407315f5..e053be40 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -469,6 +469,11 @@ class Smarty return $this->_rm_auto($this->compile_dir, $tpl_file, $compile_id); } + function template_exists($tpl_file) + { + return $this->_fetch_template_info($tpl_file, $source, $timestamp, true, true); + } + /*======================================================================*\ Function: get_template_vars Purpose: Returns an array containing template variables @@ -881,7 +886,7 @@ function _generate_debug_output() { Purpose: fetch the template info. Gets timestamp, and source if get_source is true \*======================================================================*/ - function _fetch_template_info($tpl_path, &$template_source, &$template_timestamp, $get_source = true) + function _fetch_template_info($tpl_path, &$template_source, &$template_timestamp, $get_source = true, $quiet = false) { $_return = false; if ($this->_parse_file_path($this->template_dir, $tpl_path, $resource_type, $resource_name)) { @@ -924,9 +929,11 @@ function _generate_debug_output() { } if (!$_return) { - $this->trigger_error("unable to read template resource: \"$tpl_path\""); + if (!$quiet) + $this->trigger_error("unable to read template resource: \"$tpl_path\""); } else if ($_return && $this->security && !$this->_is_secure($resource_type, $resource_name)) { - $this->trigger_error("(secure mode) accessing \"$tpl_path\" is not allowed"); + if (!$quiet) + $this->trigger_error("(secure mode) accessing \"$tpl_path\" is not allowed"); $template_source = null; $template_timestamp = null; return false; diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 407315f5..e053be40 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -469,6 +469,11 @@ class Smarty return $this->_rm_auto($this->compile_dir, $tpl_file, $compile_id); } + function template_exists($tpl_file) + { + return $this->_fetch_template_info($tpl_file, $source, $timestamp, true, true); + } + /*======================================================================*\ Function: get_template_vars Purpose: Returns an array containing template variables @@ -881,7 +886,7 @@ function _generate_debug_output() { Purpose: fetch the template info. Gets timestamp, and source if get_source is true \*======================================================================*/ - function _fetch_template_info($tpl_path, &$template_source, &$template_timestamp, $get_source = true) + function _fetch_template_info($tpl_path, &$template_source, &$template_timestamp, $get_source = true, $quiet = false) { $_return = false; if ($this->_parse_file_path($this->template_dir, $tpl_path, $resource_type, $resource_name)) { @@ -924,9 +929,11 @@ function _generate_debug_output() { } if (!$_return) { - $this->trigger_error("unable to read template resource: \"$tpl_path\""); + if (!$quiet) + $this->trigger_error("unable to read template resource: \"$tpl_path\""); } else if ($_return && $this->security && !$this->_is_secure($resource_type, $resource_name)) { - $this->trigger_error("(secure mode) accessing \"$tpl_path\" is not allowed"); + if (!$quiet) + $this->trigger_error("(secure mode) accessing \"$tpl_path\" is not allowed"); $template_source = null; $template_timestamp = null; return false;