X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=class%2Ftemplate%2FTemplate.class.php;h=204b7d3af19f03082a76d0760c7f72b6d95ceeca;hp=31244fd6eb60fad81e4f070588803b7d2d774206;hb=1f2f93e6751d2c1b957aa7d197269b5c49df5d72;hpb=69fabf5e6d4bf82740bae74fbcbcc248b46707c9 diff --git a/class/template/Template.class.php b/class/template/Template.class.php index 31244fd6..204b7d3a 100644 --- a/class/template/Template.class.php +++ b/class/template/Template.class.php @@ -69,6 +69,11 @@ class Template */ var $template_engine = ''; + /** + * The content type for this template set + */ + var $content_type = ''; + /** * The fall-back template ID * @@ -191,6 +196,13 @@ class Template = Template::calculate_template_file_directory($this->fallback_template_set_id); + // determine content type, defaulting to text/html + // + $this->content_type = Template::get_template_config($this->template_set_id, + 'content_type', + 'text/html'); + + // determine template engine // FIXME: assuming PHP template engine may not necessarily be a good thing // @@ -201,7 +213,7 @@ class Template // get template file cache // - $this->template_file_cache = Template::cache_template_file_hierarchy(); + $this->template_file_cache = Template::cache_template_file_hierarchy($template_set_id); } @@ -307,6 +319,42 @@ class Template } + /** + * Determine what the RPC template set is. + * + * NOTE that if the default setting cannot be found in the + * main SquirrelMail configuration settings that the value + * of $default is returned. + * + * @param string $default The template set ID to use if + * the default setting cannot be + * found in SM config (optional; + * defaults to "default_rpc"). + * + * @return string The ID of the RPC template set. + * + * @static + * + */ + function get_rpc_template_set($default='default_rpc') { + +// FIXME: do we want to place any restrictions on the ID such as +// making sure no slashes included? + + // values are in main SM config file + // + global $rpc_templateset; + $rpc_templateset = (!isset($rpc_templateset) + ? $default : $rpc_templateset); + + // FIXME: note that it is possible for this to + // point to an invalid (nonexistent) template set + // and that error will not be caught here + // + return $rpc_templateset; + + } + /** * Allow template set to override plugin configuration by either * adding or removing plugins. @@ -491,6 +539,18 @@ class Template } + /** + * Return the content-type for this template set. + * + * @return string The content-type. + * + */ + function get_content_type() { + + return $this->content_type; + + } + /** * Get template set config setting * @@ -621,6 +681,14 @@ class Template * constructed and stored in session before being returned * to the caller. * + * @param string $template_set_id The template set for which + * the cache should be built. + * This function will save more + * than one set's files, so it + * may be called multiple times + * with different values for this + * argument. When regenerating, + * all set caches are dumped. * @param boolean $regenerate_cache When TRUE, the file hierarchy * is reloaded and stored fresh * (optional; default FALSE). @@ -631,12 +699,12 @@ class Template * empty - no additional files). * * @return array Template file hierarchy array, whose keys - * are all the template file names (with path - * information relative to the template set's - * base directory, e.g., "css/style.css") - * found in all parent template sets including - * the ultimate fall-back template set. - * Array values are sub-arrays with the + * are all the template file names for the given + * template set ID (with path information relative + * to the template set's base directory, e.g., + * "css/style.css") found in all parent template + * sets including the ultimate fall-back template + * set. Array values are sub-arrays with the * following key-value pairs: * * PATH -- file path, relative to SM_PATH @@ -646,7 +714,8 @@ class Template * @static * */ - function cache_template_file_hierarchy($regenerate_cache=FALSE, + function cache_template_file_hierarchy($template_set_id, + $regenerate_cache=FALSE, $additional_files=array()) { sqGetGlobalVar('template_file_hierarchy', $template_file_hierarchy, @@ -655,51 +724,39 @@ class Template if ($regenerate_cache) unset($template_file_hierarchy); - if (!empty($template_file_hierarchy)) { + if (!empty($template_file_hierarchy[$template_set_id])) { // have to add additional files if given before returning // if (!empty($additional_files)) { - $template_file_hierarchy = array_merge($template_file_hierarchy, - $additional_files); + $template_file_hierarchy[$template_set_id] + = array_merge($template_file_hierarchy[$template_set_id], + $additional_files); + sqsession_register($template_file_hierarchy, 'template_file_hierarchy'); } - return $template_file_hierarchy; + return $template_file_hierarchy[$template_set_id]; } // nothing in cache apparently, so go build it now // - // FIXME: not sure if there is any possibility that - // this could be called when $sTemplateID has - // yet to be defined... throw error for now, - // but if the error occurs, it's a coding error - // rather than a configuration error - // - global $sTemplateID; - if (empty($sTemplateID)) { + $template_file_hierarchy[$template_set_id] = Template::catalog_template_files($template_set_id); - trigger_error('Template set ID unknown', E_USER_ERROR); - - } else { - - $template_file_hierarchy = Template::catalog_template_files($sTemplateID); - - // additional files, if any - // - if (!empty($additional_files)) { - $template_file_hierarchy = array_merge($template_file_hierarchy, - $additional_files); - } - - sqsession_register($template_file_hierarchy, - 'template_file_hierarchy'); + // additional files, if any + // + if (!empty($additional_files)) { + $template_file_hierarchy[$template_set_id] + = array_merge($template_file_hierarchy[$template_set_id], + $additional_files); + } - return $template_file_hierarchy; + sqsession_register($template_file_hierarchy, + 'template_file_hierarchy'); - } + return $template_file_hierarchy[$template_set_id]; } @@ -861,7 +918,9 @@ class Template ) ); $this->template_file_cache - = $this->cache_template_file_hierarchy(FALSE, $file_list); + = $this->cache_template_file_hierarchy($this->template_set_id, + FALSE, + $file_list); return TRUE; } @@ -1330,16 +1389,23 @@ FIXME: We could make the incoming array more complex so it can * * @param mixed $headers A list of (or a single) header * text to be sent. + * @param boolean $replace Whether or not to replace header(s) + * previously sent header(s) of the + * same type (this parameter may be + * ignored in some implementations + * of this class if the target interface + * does not support this functionality) + * (OPTIONAL; default = TRUE, always replace). * */ - function header($headers) + function header($headers, $replace=TRUE) { if (!is_array($headers)) $headers = array($headers); foreach ($headers as $header) { $this->assign('header', $header); - header($this->fetch('header.tpl')); + header($this->fetch('header.tpl'), $replace); } }