From 7186732cc657575d8abd86e99fc22a190991d10b Mon Sep 17 00:00:00 2001 From: pdontthink Date: Thu, 21 Sep 2006 12:51:27 +0000 Subject: [PATCH] Abstract template file location logic and enable plugin templating. This class still needs abstraction which is the next task here. Only possibly contentious change people should look at here is the use of file_exists() to find template files instead of reling on a hard-coded list of files in template.php. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@11727 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- class/template/template.class.php | 206 ++++++++++++++++++++++++------ 1 file changed, 169 insertions(+), 37 deletions(-) diff --git a/class/template/template.class.php b/class/template/template.class.php index 6bc25cca..bf2dcc3f 100755 --- a/class/template/template.class.php +++ b/class/template/template.class.php @@ -42,6 +42,13 @@ class Template */ var $template_dir = ''; + /** + * The default template directory + * + * @var string + */ + var $default_template_dir = 'templates/default/'; + /** * Template files provided by this template set * @@ -223,46 +230,171 @@ class Template } } - /** - * Display the template - * - * @param string $file The template file to use - */ - function display($file) - { - // Pull in our config file - $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; - 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(); + + /** + * + * Return the relative template directory path for this template set. + * + * @return string The relative path to the template directory based + * from the main SquirrelMail directory (SM_PATH). + * + */ + function get_template_file_directory() { + +//FIXME: temporarily parse off SM_PATH from the template dir class attribute until we can change the entire template subsystem such that the template dir is derived internally in this class from the template ID/name/attributes +return substr($this->template_dir, strlen(SM_PATH)); + return $this->template_dir; + } - } - /** - * Return the results of applying a template. - * - * @param string $file The template file to use - * @return string A string of the results - */ - function fetch($file) { - $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; - 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_clean(); - return $contents; + + /** + * + * Return the relative template directory path for the DEFAULT template set. + * + * @return string The relative path to the default template directory based + * from the main SquirrelMail directory (SM_PATH). + * + */ + function get_default_template_file_directory() { + + return $this->default_template_dir; + + } + + + /** + * + * Find the right template file. + * + * Templates are expected to be found in the template set directory + * (for example SM_PATH/templates/