From: pdontthink Date: Thu, 28 Sep 2006 14:21:51 +0000 (+0000) Subject: Misc templating changes. Note that the global template set indicator is now called . X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=28294310abf785f22d84bd92799c6e4afe01b664;p=squirrelmail.git Misc templating changes. Note that the global template set indicator is now called . git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@11752 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/include/constants.php b/include/constants.php index adaff817..3ae1327b 100644 --- a/include/constants.php +++ b/include/constants.php @@ -160,3 +160,10 @@ define('SQ_TYPE_STRING', 'string'); define('SQ_TYPE_BOOL', 'bool'); define('SQ_TYPE_ARRAY', 'array'); +/** + * Template engines supported + * @since 1.5.2 + */ +define('SQ_PHP_TEMPLATE', 'PHP_'); +define('SQ_SMARTY_TEMPLATE', 'Smarty_'); + diff --git a/include/init.php b/include/init.php index 93551521..5a0dac87 100644 --- a/include/init.php +++ b/include/init.php @@ -146,8 +146,8 @@ $theme = array(); $theme[0]['PATH'] = SM_PATH . 'themes/default_theme.php'; $theme[0]['NAME'] = 'Default'; $aTemplateSet = array(); -$aTemplateSet[0]['PATH'] = SM_PATH . 'templates/default/'; -$aTemplateSet[0]['NAME'] = 'Default template'; +$aTemplateSet[0]['ID'] = 'default'; +$aTemplateSet[0]['NAME'] = 'Default'; /* load site configuration */ require(SM_PATH . 'config/config.php'); /* load local configuration overrides */ @@ -215,6 +215,9 @@ ini_set('session.name' , $session_name); session_set_cookie_params (0, $base_uri); sqsession_is_active(); +include_once(SM_PATH . 'plugins/multilogin/functions.php'); +multilogin_sqoverride_config_do(); + /** * DISABLED. * Remove globalized session data in rg=on setups @@ -297,16 +300,34 @@ switch ($sInitLocation) { case 'style': // need to get the right template set up - sqGetGlobalVar('templatedir', $templatedir, SQ_GET); + // + sqGetGlobalVar('templateid', $templateid, SQ_GET); // sanitize just in case... - $templatedir = preg_replace('/(\.\.\/){1,}/', '', $templatedir); - - // could also conceivably make sure given templatedir is in $aTemplateSet + // + $templateid = preg_replace('/(\.\.\/){1,}/', '', $templateid); + + // make sure given template actually is available + // + $aTemplateSet = (!isset($aTemplateSet) || !is_array($aTemplateSet) + ? array() : $aTemplateSet); + $templateset_default = (!isset($templateset_default) ? 0 : $templateset_default); + $found_templateset = false; + for ($i = 0; $i < count($aTemplateSet); ++$i) { + if ($aTemplateSet[$i]['ID'] == $templateid) { + $found_templateset = true; + break; + } + } - // set template directory only if what was given is valid - if (is_dir(SM_PATH . 'templates/' . $templatedir . '/')) { - $sTplDir = SM_PATH . 'templates/' . $templatedir . '/'; +// FIXME: do we need/want to check here for actual presence of template sets? + // selected template not available, fall back to default template + // + if (!$found_templateset) { + $sTemplateID = (!isset($aTemplateSet[$templateset_default]['ID']) + ? 'default' : $aTemplateSet[$templateset_default]['ID']); + } else { + $sTemplateID = $templateid; } session_write_close(); @@ -382,19 +403,19 @@ switch ($sInitLocation) { /** * Initialize the template object (logout_error uses it) */ - require(SM_PATH . 'class/template/template.class.php'); + require(SM_PATH . 'class/template/Template.class.php'); /* - * $sTplDir is not initialized when a user is not logged in, so we will use - * the config file defaults here. If the neccesary variables are net set, - * force a default value. + * $sTemplateID is not initialized when a user is not logged in, so we + * will use the config file defaults here. If the neccesary variables + * are net set, force a default value. */ - $aTemplateSet = ( !isset($aTemplateSet) ? array() : $aTemplateSet ); + $aTemplateSet = (!isset($aTemplateSet) || !is_array($aTemplateSet) + ? array() : $aTemplateSet); $templateset_default = ( !isset($templateset_default) ? 0 : $templateset_default ); - $sTplDir = ( !isset($aTemplateSet[$templateset_default]['PATH']) ? - SM_PATH . 'templates/default/' : - $aTemplateSet[$templateset_default]['PATH'] ); - $oTemplate = new Template($sTplDir); + $sTemplateID = ( !isset($aTemplateSet[$templateset_default]['ID']) ? + 'default' : $aTemplateSet[$templateset_default]['ID'] ); + $oTemplate = Template::construct_template($sTemplateID); set_up_language($squirrelmail_language, true); logout_error( _("You must be logged in to access this page.") ); @@ -515,27 +536,28 @@ switch ($sInitLocation) { /** * Initialize the template object */ -require(SM_PATH . 'class/template/template.class.php'); +require(SM_PATH . 'class/template/Template.class.php'); /* - * $sTplDir is not initialized when a user is not logged in, so we will use - * the config file defaults here. If the neccesary variables are not set, - * force a default value. + * $sTemplateID is not initialized when a user is not logged in, so we + * will use the config file defaults here. If the neccesary variables + * are not set, force a default value. * - * If the user is logged in, $sTplDir will be set in load_prefs.php, so we - * shouldn't change it here. + * If the user is logged in, $sTemplateID will be set in load_prefs.php, + * so we shouldn't change it here. */ -if (!isset($sTplDir)) { - $aTemplateSet = ( !isset($aTemplateSet) ? array() : $aTemplateSet ); +if (!isset($sTemplateID)) { + $aTemplateSet = (!isset($aTemplateSet) || !is_array($aTemplateSet) + ? array() : $aTemplateSet); $templateset_default = ( !isset($templateset_default) ? 0 : $templateset_default ); - $sTplDir = !isset($aTemplateSet[$templateset_default]['PATH']) ? SM_PATH . 'templates/default/' : $aTemplateSet[$templateset_default]['PATH']; - $icon_theme_path = !$use_icons ? NULL : $sTplDir . 'images/'; + $sTemplateID = !isset($aTemplateSet[$templateset_default]['ID']) ? 'default' : $aTemplateSet[$templateset_default]['ID']; + $icon_theme_path = !$use_icons ? NULL : Template::calculate_template_images_directory($sTemplateID); } -$oTemplate = new Template($sTplDir); +$oTemplate = Template::construct_template($sTemplateID); // We want some variables to always be available to the template -$always_include = array('sTplDir', 'icon_theme_path'); +$always_include = array('sTemplateID', 'icon_theme_path'); foreach ($always_include as $var) { $oTemplate->assign($var, (isset($$var) ? $$var : NULL)); } diff --git a/include/load_prefs.php b/include/load_prefs.php index f9e6346d..169908b7 100644 --- a/include/load_prefs.php +++ b/include/load_prefs.php @@ -29,35 +29,34 @@ if( ! sqgetGlobalVar('username', $username, SQ_SESSION) ) { // TODO Get rid of "none" strings when NULL or false should be used, i hate them i hate them i hate them!!!. $custom_css = getPref($data_dir, $username, 'custom_css', 'none' ); -$theme = ( !isset($theme) ? array() : $theme ); -$color = ( !isset($color) ? array() : $color ); -$aTemplateSet = ( !isset($aTemplateSet) ? array() : $aTemplateSet ); +$aTemplateSet = (!isset($aTemplateSet) || !is_array($aTemplateSet) + ? array() : $aTemplateSet); $templateset_default = ( !isset($templateset_default) ? 0 : $templateset_default ); -$chosen_theme = getPref($data_dir, $username, 'chosen_theme'); -$sTplDir = getPref($data_dir, $username, 'sTplDir', SM_PATH . 'templates/default/'); -$found_templateset = false; - -/* need to adjust $chosen_template path with SM_PATH */ -$sTplDir = preg_replace("/(\.\.\/){1,}/", SM_PATH, $sTplDir); +$sTemplateID = getPref($data_dir, $username, 'sTemplateID', 'default'); +// check user prefs template selection against templates actually available +// +$found_templateset = false; for ($i = 0; $i < count($aTemplateSet); ++$i){ - if ($aTemplateSet[$i]['PATH'] == $sTplDir) { + if ($aTemplateSet[$i]['ID'] == $sTemplateID) { $found_templateset = true; break; } } -$sTplDir = ($found_templateset ? $sTplDir : ''); + +// FIXME: do we need/want to check here for actual presence of template sets? +// selected template not available, fall back to default template +// if (!$found_templateset) { - if (isset($aTemplateSet) && isset($aTemplateSet[$templateset_default]) && file_exists($aTemplateSet[$templateset_default]['PATH'])) { - $sTplDir = $aTemplateSet[$templateset_default]['PATH']; - } else { - $sTplDir = SM_PATH.'templates/default/'; - } -} else if (!file_exists($sTplDir)) { - $sTplDir = SM_PATH.'templates/default/'; + $sTemplateID = ( !isset($aTemplateSet[$templateset_default]['ID']) ? + 'default' : $aTemplateSet[$templateset_default]['ID'] ); } +$theme = ( !isset($theme) ? array() : $theme ); +$color = ( !isset($color) ? array() : $color ); + +$chosen_theme = getPref($data_dir, $username, 'chosen_theme'); $found_theme = false; /* need to adjust $chosen_theme path with SM_PATH */ @@ -89,7 +88,7 @@ $icon_theme = getPref($data_dir, $username, 'icon_theme', 'images/themes/xp/' ); * theme to use. If the admin has disabled icons, or the user has * set the icon theme to "None," no icons will be used. */ -$icon_theme_path = (!$use_icons || $icon_theme=='none') ? NULL : ($icon_theme == 'template' ? $sTplDir . 'images/' : $icon_theme); +$icon_theme_path = (!$use_icons || $icon_theme=='none') ? NULL : ($icon_theme == 'template' ? Template::calculate_template_images_directory($sTemplateID) : $icon_theme); // show (or not) flag and unflag buttons on mailbox list screen $show_flag_buttons = getPref($data_dir, $username, 'show_flag_buttons', SMPREF_ON ); diff --git a/include/options/display.php b/include/options/display.php index 2c93798e..cd7afb18 100644 --- a/include/options/display.php +++ b/include/options/display.php @@ -51,7 +51,7 @@ if (! isset($use_iframe)) $use_iframe=false; function load_optpage_data_display() { global $theme, $fontsets, $language, $languages,$aTemplateSet, $default_use_mdn, $squirrelmail_language, $allow_thread_sort, - $show_alternative_names, $use_icons, $use_iframe, $sTplDir; + $show_alternative_names, $use_icons, $use_iframe, $sTemplateID; /* Build a simple array into which we will build options. */ $optgrps = array(); @@ -69,15 +69,15 @@ function load_optpage_data_display() { $templateset_values = array(); foreach ($aTemplateSet as $sKey => $aTemplateSetAttributes) { - $templateset_values[$aTemplateSetAttributes['NAME']] = $aTemplateSetAttributes['PATH']; + $templateset_values[$aTemplateSetAttributes['NAME']] = $aTemplateSetAttributes['ID']; } ksort($templateset_values); $templateset_values = array_flip($templateset_values); // display template options only when there is more than one template if (count($templateset_values)>1) { $optvals[SMOPT_GRP_GENERAL][] = array( - 'name' => 'sTplDir', - 'caption' => _("Template"), + 'name' => 'sTemplateID', + 'caption' => _("Skin"), 'type' => SMOPT_TYPE_STRLIST, 'refresh' => SMOPT_REFRESH_ALL, 'posvals' => $templateset_values, @@ -328,6 +328,7 @@ function load_optpage_data_display() { 'size' => SMOPT_SIZE_TINY ); /* +FIXME! disabled because the template doesn't support it (yet?) $optvals[SMOPT_GRP_MAILBOX][] = array( 'name' => 'show_recipient_instead', @@ -437,7 +438,7 @@ function save_option_template($option) { /* Do checking to make sure $new_theme is in the array. */ $templateset_in_array = false; for ($i = 0; $i < count($aTemplateSet); ++$i) { - if ($aTemplateSet[$i]['PATH'] == $option->new_value) { + if ($aTemplateSet[$i]['ID'] == $option->new_value) { $templateset_in_array = true; break; }