From: stevetruckstuff Date: Thu, 6 Apr 2006 19:49:28 +0000 (+0000) Subject: Added error handling if template.php or requested template is not found. X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=commitdiff_plain;h=4407b2e4adb7de2e846dd9362058812004e50ecc Added error handling if template.php or requested template is not found. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@11036 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/class/template/template.class.php b/class/template/template.class.php index 15163375..cd057650 100755 --- a/class/template/template.class.php +++ b/class/template/template.class.php @@ -73,20 +73,24 @@ class Template */ var $additional_css_sheets = array(); - /** - * Constructor - * - * @param string $sTplDir where the template set is located - */ - function Template($sTplDir) { - $this->template_dir = $sTplDir; + /** + * Constructor + * + * @param string $sTplDir where the template set is located + */ + function Template($sTplDir) { + $this->template_dir = $sTplDir; - // Pull in the tempalte config file - include ($this->template_dir . 'template.php'); - $this->templates_provided = is_array($templates_provided) ? $templates_provided : array(); - $this->required_js_files = is_array($required_js_files) ? $required_js_files : array(); - $this->provided_js_files = is_array($provided_js_files) ? $provided_js_files: array(); - $this->additional_css_sheets = is_array($additional_css_sheets) ? $additional_css_sheets : array(); + // Pull in the tempalte config file + if (!file_exists($this->template_dir . 'template.php')) { + trigger_error('No template.php could be found in the requested template directory ("'.$this->template_dir.'")', E_USER_ERROR); + } else { + include ($this->template_dir . 'template.php'); + $this->templates_provided = is_array($templates_provided) ? $templates_provided : array(); + $this->required_js_files = is_array($required_js_files) ? $required_js_files : array(); + $this->provided_js_files = is_array($provided_js_files) ? $provided_js_files: array(); + $this->additional_css_sheets = is_array($additional_css_sheets) ? $additional_css_sheets : array(); + } } @@ -203,9 +207,13 @@ class Template $t = &$this->values; // place values array directly in scope $template = in_array($file, $this->templates_provided) ? $this->template_dir . $file : SM_PATH .'templates/default/'. $file; - ob_start(); - include($template); - ob_end_flush(); + if (!file_exists($template)) { + trigger_error('The template "'.htmlspecialchars($file).'" could not be displayed!', E_USER_ERROR); + } else { + ob_start(); + include($template); + ob_end_flush(); + } } /** @@ -220,10 +228,16 @@ class Template $t = &$this->values; // place values array directly in scope $template = in_array($file, $this->templates_provided) ? $this->template_dir . $file : SM_PATH .'templates/default/'. $file; - include($template); - $contents = ob_get_contents(); - ob_end_clean(); - return $contents; + if (!file_exists($template)) { + trigger_error('The template "'.htmlspecialchars($file).'" could not be fetched!', E_USER_ERROR); + } else { + ob_start(); + include($template); + $contents = ob_get_contents(); + ob_end_flush(); + return $contents; + } + } /**