From 854a25dbccf427760edcdebb475ea3dcad1edd69 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Sun, 21 Nov 2010 15:06:22 -0700 Subject: [PATCH] Add getBaseStylesheetList() and addThemeStylesheet() --- framework/Core/lib/Horde/Themes/Css.php | 124 +++++++++++++++++++++----------- 1 file changed, 81 insertions(+), 43 deletions(-) diff --git a/framework/Core/lib/Horde/Themes/Css.php b/framework/Core/lib/Horde/Themes/Css.php index 7d6a38d4b..79eb0ce76 100644 --- a/framework/Core/lib/Horde/Themes/Css.php +++ b/framework/Core/lib/Horde/Themes/Css.php @@ -23,9 +23,17 @@ class Horde_Themes_Css protected $_cssFiles = array(); /** + * A list of additional themed stylesheet files to add to the output. + * + * @var array + */ + protected $_cssThemeFiles = array(); + + /** * Adds an external stylesheet to the output. * - * @param string $file + * @param string $file The CSS filepath. + * @param string $url The CSS URL. */ public function addStylesheet($file, $url) { @@ -33,6 +41,16 @@ class Horde_Themes_Css } /** + * Adds a themed stylesheet to the output. + * + * @param string $file The stylesheet name. + */ + public function addThemeStylesheet($file) + { + $this->_cssThemeFiles[$file] = true; + } + + /** * Generate the stylesheet URLs needed to display the current page. * Honors configuration choices as to stylesheet caching. * @@ -125,12 +143,13 @@ class Horde_Themes_Css /** * Return the list of base stylesheets to display. * - * @param mixed $theme The theme to use; specify an empty value to - * retrieve the theme from user preferences, and - * false for no theme. - * @param array $options Additional options: + * @param mixed $theme The theme to use; specify an empty value to + * retrieve the theme from user preferences, and + * false for no theme. + * @param array $opts Additional options: *
      * 'app' - (string) The current application.
+     * 'nobase' - (boolean) If true, don't load base stylesheets.
      * 'nohorde' - (boolean) If true, don't load files from Horde.
      * 'sub' - (string) A subdirectory containing additional CSS files to
      *         load as an overlay to the base CSS files.
@@ -141,54 +160,30 @@ class Horde_Themes_Css
      *
      * @return array  TODO
      */
-    public function getStylesheets($theme = '', $options = array())
+    public function getStylesheets($theme = '', array $opts = array())
     {
         if (($theme === '') && isset($GLOBALS['prefs'])) {
             $theme = $GLOBALS['prefs']->getValue('theme');
         }
 
         $css = array();
+        $css_list = empty($opts['nobase'])
+            ? $this->getBaseStylesheetList()
+            : array();
 
-        $css_list = array('screen');
-        if (isset($GLOBALS['registry']->nlsconfig['rtl'][$GLOBALS['language']])) {
-            $css_list[] = 'rtl';
-        }
-
-        /* Collect browser specific stylesheets if needed. */
-        switch ($GLOBALS['browser']->getBrowser()) {
-        case 'msie':
-            $ie_major = $GLOBALS['browser']->getMajor();
-            if ($ie_major == 8) {
-                $css_list[] = 'ie8';
-            } elseif ($ie_major == 7) {
-                $css_list[] = 'ie7';
-            } elseif ($ie_major < 7) {
-                $css_list[] = 'ie6_or_less';
-            }
-            break;
-
-
-        case 'opera':
-            $css_list[] = 'opera';
-            break;
-
-        case 'mozilla':
-            $css_list[] = 'mozilla';
-            break;
-
-        case 'webkit':
-            $css_list[] = 'webkit';
-        }
+        $css_list = array_unique(array_merge($css_list, $this->_cssThemeFiles));
 
-        $curr_app = empty($options['app'])
+        $curr_app = empty($opts['app'])
             ? $GLOBALS['registry']->getApp()
-            : $options['app'];
-        if (empty($options['nohorde'])) {
+            : $opts['app'];
+        if (empty($opts['nohorde'])) {
             $apps = array_unique(array('horde', $curr_app));
         } else {
             $apps = ($curr_app == 'horde') ? array() : array($curr_app);
         }
-        $sub = empty($options['sub']) ? null : $options['sub'];
+        $sub = empty($opts['sub'])
+            ? null
+            : $opts['sub'];
 
         foreach ($apps as $app) {
             $themes_fs = $GLOBALS['registry']->get('themesfs', $app) . '/';
@@ -196,12 +191,12 @@ class Horde_Themes_Css
 
             foreach (array_filter(array_unique(array('default', $theme))) as $theme_name) {
                 foreach ($css_list as $css_name) {
-                    if (empty($options['subonly'])) {
-                        $css[$themes_fs . $theme_name . '/' . $css_name . '.css'] = $themes_uri . $theme_name . '/' . $css_name . '.css';
+                    if (empty($opts['subonly'])) {
+                        $css[$themes_fs . $theme_name . '/' . $css_name] = $themes_uri . $theme_name . '/' . $css_name;
                     }
 
                     if ($sub && ($app == $curr_app)) {
-                        $css[$themes_fs . $theme_name . '/' . $sub . '/' . $css_name . '.css'] = $themes_uri . $theme_name . '/' . $sub . '/' . $css_name . '.css';
+                        $css[$themes_fs . $theme_name . '/' . $sub . '/' . $css_name] = $themes_uri . $theme_name . '/' . $sub . '/' . $css_name;
                     }
                 }
             }
@@ -231,6 +226,49 @@ class Horde_Themes_Css
     }
 
     /**
+     * Returns the list of base stylesheets, based on the current language
+     * and browser settings.
+     *
+     * @return array  A list of base CSS files to load.
+     */
+    public function getBaseStylesheetList()
+    {
+        $css_list = array('screen.css');
+
+        if (isset($GLOBALS['registry']->nlsconfig['rtl'][$GLOBALS['language']])) {
+            $css_list[] = 'rtl.css';
+        }
+
+        /* Collect browser specific stylesheets if needed. */
+        switch ($GLOBALS['browser']->getBrowser()) {
+        case 'msie':
+            $ie_major = $GLOBALS['browser']->getMajor();
+            if ($ie_major == 8) {
+                $css_list[] = 'ie8.css';
+            } elseif ($ie_major == 7) {
+                $css_list[] = 'ie7.css';
+            } elseif ($ie_major < 7) {
+                $css_list[] = 'ie6_or_less.css';
+            }
+            break;
+
+
+        case 'opera':
+            $css_list[] = 'opera.css';
+            break;
+
+        case 'mozilla':
+            $css_list[] = 'mozilla.css';
+            break;
+
+        case 'webkit':
+            $css_list[] = 'webkit.css';
+        }
+
+        return $css_list;
+    }
+
+    /**
      * Loads CSS files, cleans up the input, and concatenates to a string.
      *
      * @param array $files  List of CSS files as returned from
-- 
2.11.0