From: pdontthink Date: Wed, 10 Sep 2008 03:04:14 +0000 (+0000) Subject: Allow template sets to define what the content-type of their output is. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=0d56053e93791b494820d5d35d0d200ac4451dda;p=squirrelmail.git Allow template sets to define what the content-type of their output is. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@13272 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/class/template/Template.class.php b/class/template/Template.class.php index 31244fd6..e02bc05f 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 // @@ -491,6 +503,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 * diff --git a/functions/page_header.php b/functions/page_header.php index 22413f41..377beacf 100644 --- a/functions/page_header.php +++ b/functions/page_header.php @@ -108,7 +108,7 @@ function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE * recommendations and switch to unicode. */ $header_tags .= "\n"; - $header_tags .= '' . "\n"; + $header_tags .= '' . "\n"; } if ($do_hook) { // NOTE! plugins here MUST assign output to template diff --git a/include/init.php b/include/init.php index 166967aa..1ca78e0e 100644 --- a/include/init.php +++ b/include/init.php @@ -369,7 +369,7 @@ require(SM_PATH . 'functions/prefs.php'); * the current user is NOT that user, turn them * back on */ -sqgetGlobalVar('username',$username,SQ_SESSION); +sqgetGlobalVar('username', $username, SQ_SESSION); if ($disable_plugins && !empty($disable_plugins_user) && $username != $disable_plugins_user) { $disable_plugins = false; @@ -451,6 +451,7 @@ if (! sqgetGlobalVar('squirrelmail_language',$squirrelmail_language,SQ_COOKIE)) * Do something special for some pages. This is based on the PAGE_NAME constant * set at the top of every page. */ +$set_up_langage_after_template_setup = FALSE; switch (PAGE_NAME) { case 'style': @@ -623,18 +624,7 @@ switch (PAGE_NAME) { } // /dont understand - /** - * Set up the language. - */ - $err=set_up_language(getPref($data_dir, $username, 'language')); - - // Japanese translation used without mbstring support - if ($err==2) { - $sError = "

Your administrator needs to have PHP installed with the multibyte string extension enabled (using configure option --enable-mbstring).

\n" - . "

This system has assumed that you accidently switched to Japanese and has reverted your language preference to English.

\n" - . "

Please refresh this page in order to continue using your webmail.

\n"; - error_box($sError); - } + $set_up_langage_after_template_setup = TRUE; $timeZone = getPref($data_dir, $username, 'timezone'); @@ -718,11 +708,34 @@ foreach ($always_include as $var) { $nbsp = $oTemplate->fetch('non_breaking_space.tpl'); $br = $oTemplate->fetch('line_break.tpl'); + +/** + * Set up the language. + * + * This code block corresponds to the *default* block of the switch + * statement above, but the language cannot be set up until after the + * template is instantiated, so we set $set_up_langage_after_template_setup + * above and do the linguistic stuff now. + */ +if ($set_up_langage_after_template_setup) { + $err=set_up_language(getPref($data_dir, $username, 'language')); + + // Japanese translation used without mbstring support + if ($err==2) { + $sError = "

Your administrator needs to have PHP installed with the multibyte string extension enabled (using configure option --enable-mbstring).

\n" + . "

This system has assumed that you accidently switched to Japanese and has reverted your language preference to English.

\n" + . "

Please refresh this page in order to continue using your webmail.

\n"; + error_box($sError); + } +} + + /** * Initialize our custom error handler object */ $oErrorHandler = new ErrorHandler($oTemplate,'error_message.tpl'); + /** * Activate custom error handling */ diff --git a/include/languages.php b/include/languages.php index 7ecea5b1..8847f617 100644 --- a/include/languages.php +++ b/include/languages.php @@ -374,15 +374,24 @@ function fixcharset($charset) { * 1 = mbstring support is not present, * 2 = mbstring support is not present, user's translation reverted to en_US. * - * @param string $sm_language translation used by user's interface - * @param bool $do_search use browser's preferred language detection functions. Defaults to false. - * @param bool $default set $sm_language to $squirrelmail_default_language if language detection fails or language is not set. Defaults to false. + * @param string $sm_language Translation used by user's interface + * @param bool $do_search Use browser's preferred language detection functions. + * Defaults to false. + * @param bool $default Set $sm_language to $squirrelmail_default_language if + * language detection fails or language is not set. + * Defaults to false. + * @param string $content_type The content type being served currently (OPTIONAL; + * if not specified, defaults to whatever the template + * set that is in use has defined). + * * @return int function execution error codes. + * */ -function set_up_language($sm_language, $do_search = false, $default = false) { +function set_up_language($sm_language, $do_search=false, + $default=false, $content_type='') { static $SetupAlready = 0; - global $use_gettext, $languages, + global $use_gettext, $languages, $oTemplate, $squirrelmail_language, $squirrelmail_default_language, $default_charset, $sm_notAlias, $username, $data_dir; @@ -393,6 +402,10 @@ function set_up_language($sm_language, $do_search = false, $default = false) { $SetupAlready = TRUE; sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER); + // grab content type if needed + // + if (empty($content_type)) $content_type = $oTemplate->get_content_type(); + /** * If function is asked to detect preferred language * OR squirrelmail default language is set to empty string @@ -517,7 +530,7 @@ function set_up_language($sm_language, $do_search = false, $default = false) { $squirrelmail_language = $sm_notAlias; if ($squirrelmail_language == 'ja_JP') { - header ('Content-Type: text/html; charset=EUC-JP'); + $oTemplate->header ('Content-Type: ' . $content_type . '; charset=EUC-JP'); if (!function_exists('mb_internal_encoding')) { // Error messages can't be displayed here $error = 1; @@ -535,9 +548,9 @@ function set_up_language($sm_language, $do_search = false, $default = false) { mb_internal_encoding('EUC-JP'); mb_http_output('pass'); } elseif ($squirrelmail_language == 'en_US') { - header( 'Content-Type: text/html; charset=' . $default_charset ); + $oTemplate->header( 'Content-Type: ' . $content_type . '; charset=' . $default_charset ); } else { - header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] ); + $oTemplate->header( 'Content-Type: ' . $content_type . '; charset=' . $languages[$sm_notAlias]['CHARSET'] ); } /** * mbstring.func_overload fix (#929644). diff --git a/templates/default/config.php b/templates/default/config.php index e7b403b0..dc439687 100644 --- a/templates/default/config.php +++ b/templates/default/config.php @@ -17,6 +17,12 @@ $template_engine = SQ_PHP_TEMPLATE; +/** + * Indicates what the content type is for this template set. + */ +$content_type = 'text/html'; + + /** * If non-empty, indicates which template set this set is derived from. * diff --git a/templates/default_advanced/config.php b/templates/default_advanced/config.php index 5cb32fda..f974e9de 100644 --- a/templates/default_advanced/config.php +++ b/templates/default_advanced/config.php @@ -17,6 +17,12 @@ $template_engine = SQ_PHP_TEMPLATE; +/** + * Indicates what the content type is for this template set. + */ +$content_type = 'text/html'; + + /** * If non-empty, indicates which template set this set is derived from. *