Add support for user-provided alternate stylesheets
authorstevetruckstuff <stevetruckstuff@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sat, 30 Sep 2006 10:38:34 +0000 (10:38 +0000)
committerstevetruckstuff <stevetruckstuff@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sat, 30 Sep 2006 10:38:34 +0000 (10:38 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@11786 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/page_header.php
include/load_prefs.php
include/options/display.php

index ce9b3d456717e08627c92608ce05bad4566f285b..3445a319f8f9202fee4b8a41412d61fe119394e3 100644 (file)
@@ -71,6 +71,9 @@ function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE
 // FIXME: the following user pref ("sUserStyle"; rename as necessary) will have to be populated by the display prefs screen from a widget similar to the color themes widget (which it replaces) where its values should be full relative paths (from SM_PATH) to the selected css "themes" (either in template css/alternates dir or SM_PATH/css/alternates dir)
 // FIXME: uhhh, getPref() is not available yet here.  (at least on login page) Ugh.  Nor has load_prefs been included yet -- how do we fix this?
 //    $aUserStyles[] = getPref($data_dir, $username, 'sUserStyle', '');
+    if (!empty($chosen_theme) && substr($chosen_theme, 0, 2) == 'u_') {
+        $aUserStyles[] = substr($chosen_theme, 2) .'default.css';
+    }
 
     // 3. src/style.php
     $aUserStyles[] = $base_uri .'src/style.php?'
index 169908b74ebd62cbc5e74dd9f5a7c128cc904d6c..d86cf6cae78cd26ac8eccd8bc8b022568d23af78 100644 (file)
@@ -53,13 +53,16 @@ if (!$found_templateset) {
                      'default' : $aTemplateSet[$templateset_default]['ID'] );
 }
 
+$chosen_theme = getPref($data_dir, $username, 'chosen_theme');
+
+/*
 $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 */
+// need to adjust $chosen_theme path with SM_PATH
 $chosen_theme = preg_replace("/(\.\.\/){1,}/", SM_PATH, $chosen_theme);
 
 for ($i = 0; $i < count($theme); ++$i){
@@ -80,6 +83,7 @@ if (isset($chosen_theme) && $found_theme && (file_exists($chosen_theme))) {
     }
 }
 
+*/
 // user's icon theme, if using icons
 $icon_theme = getPref($data_dir, $username, 'icon_theme', 'images/themes/xp/' );
 
index d4dc021a340ca193e6d01fe22301464500202906..2774c9c372dbd52ce24bc201c2cd8d2810500826 100644 (file)
@@ -16,6 +16,11 @@ define('SMOPT_GRP_GENERAL', 0);
 define('SMOPT_GRP_MAILBOX', 1);
 define('SMOPT_GRP_MESSAGE', 2);
 
+/**
+ * Icon themes and user CSS themes should probably both be moved to conf.pl
+ * 
+ * TODO: move to conf.pl
+ **/
 // load icon themes if in use
 global $use_icons;
 if ($use_icons) {
@@ -32,6 +37,19 @@ if ($use_icons) {
     }
 }
 
+// load user-provided CSS themes
+global $css_themes;
+$dirName = SM_PATH . 'css';
+if (is_readable($dirName) && is_dir($dirName)) {
+    $d = dir($dirName);
+    while($dir = $d->read()) {
+        if ($dir != "." && $dir != "..") {
+            if (is_dir($dirName."/".$dir) && file_exists("$dirName/$dir/config.php"))
+                include("$dirName/$dir/config.php");
+        }
+    }
+}
+
 global $use_iframe;
 if (! isset($use_iframe)) $use_iframe=false;
 
@@ -51,7 +69,8 @@ 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, $sTemplateID;
+    $show_alternative_names, $use_icons, $use_iframe, $sTemplateID, 
+    $oTemplate, $css_themes;
 
     /* Build a simple array into which we will build options. */
     $optgrps = array();
@@ -86,36 +105,47 @@ function load_optpage_data_display() {
     }
 
     /* Load the theme option. */
+
+    /**
+     * User themes start with a 'u_', template themes start with a 't_' to
+     * differentiate which is which.  This seems kind of hackish, but we can
+     * come up with a better solution later.
+     * 
+     * TODO: Clean me.
+     **/
     $theme_values = array();
+    
+    // Always provide the template default first.
+    $theme_values['none'] = 'Template Default Theme';
+
     // List alternate themes provided by templates first
-#    var_dump(Template::get_template_file_directory());
-    #list_files
-    foreach ($theme as $theme_key => $theme_attributes) {
-        $theme_values[$theme_attributes['NAME']] = $theme_attributes['PATH'];
+/*
+ * Since this requires mods to the template class, I'm holding off on alternate
+ * template styles until Paul finishes template inheritence.
+ *      -- SB, 2006-09-30
+ * 
+    $template_provided = $oTemplate->get_alternative_stylesheets();
+    asort($template_provided);
+    foreach ($template_provided as $sheet=>$name) {
+        $theme_values['t_'.$sheet] = 'Template Theme - '.htmlspecialchars($name);
+    }
+*/
+    // Next, list styles provided in SM_PATH/css/
+    // FIXME, these should probably be defined in conf.pl!!
+    asort($css_themes);
+    foreach ($css_themes as $style) {
+        $theme_values['u_'.$style['PATH']] = 'User Theme - '.htmlspecialchars($style['NAME']);
     }
-    ksort($theme_values);
-    $theme_values = array_flip($theme_values);
+
     $optvals[SMOPT_GRP_GENERAL][] = array(
         'name'    => 'chosen_theme',
         'caption' => _("Theme"),
         'type'    => SMOPT_TYPE_STRLIST,
         'refresh' => SMOPT_REFRESH_ALL,
         'posvals' => $theme_values,
-        'save'    => 'save_option_theme'
+        'save'    => 'css_theme_save'
     );
 
-    $css_values = array( 'none' => _("Default" ) );
-    $css_dir = SM_PATH . 'themes/css';
-    if (is_readable($css_dir) && is_dir($css_dir)) {
-        $handle=opendir($css_dir);
-        while ($file = readdir($handle) ) {
-            if ( substr( $file, -4 ) == '.css' ) {
-                $css_values[$file] = substr( $file, 0, strlen( $file ) - 4 );
-            }
-        }
-        closedir($handle);
-    }
-
     /* Icon theme selection */
     if ($use_icons) {
         global $icon_themes, $icon_theme;
@@ -492,3 +522,23 @@ function icon_theme_save($option) {
        setPref($data_dir, $username, 'icon_theme', 'none');
 
 }
+
+function css_theme_save ($option) {
+    global $css_themes, $data_dir, $username;
+
+    // Don't assume the new value is there, double check
+    // and only save if found
+    //
+    $found = false;
+    reset($css_themes);
+    while (!$found && (list($index, $data) = each($css_themes))) {
+        if ('u_'.$data['PATH'] == $option->new_value)
+            $found = true;
+    }
+    if ($found)
+        setPref($data_dir, $username, 'chosen_theme', $option->new_value);
+    else
+       setPref($data_dir, $username, 'chosen_theme', 'none');
+}
+
+