Add Horde_Themes::loadCssFiles()
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 25 Jun 2010 18:10:02 +0000 (12:10 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 25 Jun 2010 18:11:32 +0000 (12:11 -0600)
framework/Core/lib/Horde/Themes.php
imp/view.php

index b3973ca..46f0d03 100644 (file)
@@ -77,22 +77,7 @@ class Horde_Themes
             }
 
             if (!$exists) {
-                $flags = defined('FILE_IGNORE_NEW_LINES')
-                    ? (FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)
-                    : 0;
-
-                foreach ($css as $file) {
-                    $path = substr($file['u'], 0, strrpos($file['u'], '/') + 1);
-
-                    // Fix relative URLs, convert graphics URLs to data URLs
-                    // (if possible), remove multiple whitespaces, and strip
-                    // comments.
-                    $tmp = preg_replace(array('/(url\(["\']?)([^\/])/i', '/\s+/', '/\/\*.*?\*\//'), array('$1' . $path . '$2', ' ', ''), implode('', file($file['f'], $flags)));
-                    if ($GLOBALS['browser']->hasFeature('dataurl')) {
-                        $tmp = preg_replace_callback('/(background(?:-image)?:[^;}]*(?:url\(["\']?))(.*?)((?:["\']?\)))/i', array(__CLASS__, 'stylesheetCallback'), $tmp);
-                    }
-                    $out .= $tmp;
-                }
+                $out = self::loadCssFiles($css);
 
                 /* Use CSS tidy to clean up file. */
                 if ($conf['cachecssparams']['compress'] == 'php') {
@@ -252,6 +237,37 @@ class Horde_Themes
     }
 
     /**
+     * Loads CSS files, cleans up the input, and concatenates to a string.
+     *
+     * @param array $files  List of CSS files as returned from
+     *                      getStylesheets().
+     *
+     * @return string  CSS data.
+     */
+    static public function loadCssFiles($files)
+    {
+        $flags = defined('FILE_IGNORE_NEW_LINES')
+            ? (FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)
+            : 0;
+        $out = '';
+
+        foreach ($files as $file) {
+            $path = substr($file['u'], 0, strrpos($file['u'], '/') + 1);
+
+            // Fix relative URLs, convert graphics URLs to data URLs
+            // (if possible), remove multiple whitespaces, and strip
+            // comments.
+            $tmp = preg_replace(array('/(url\(["\']?)([^\/])/i', '/\s+/', '/\/\*.*?\*\//'), array('$1' . $path . '$2', ' ', ''), implode('', file($file['f'], $flags)));
+            if ($GLOBALS['browser']->hasFeature('dataurl')) {
+                $tmp = preg_replace_callback('/(background(?:-image)?:[^;}]*(?:url\(["\']?))(.*?)((?:["\']?\)))/i', array(__CLASS__, 'stylesheetCallback'), $tmp);
+            }
+            $out .= $tmp;
+        }
+
+        return $out;
+    }
+
+    /**
      * Return the path to an image, using the default image if the image does
      * not exist in the current theme.
      *
index fbaf7e3..9485f59 100644 (file)
@@ -265,12 +265,7 @@ case 'print_attach':
                     }
                 }
 
-                $css = '';
-                foreach (Horde_Themes::getStylesheets() as $val) {
-                    $css .= file_get_contents($val['f']);
-                }
-
-                if ($style = Horde_Text_Filter::filter($css, 'csstidy', array('ob' => true))->filterBySelector($selectors)) {
+                if ($style = Horde_Text_Filter::filter(Horde_Themes::loadCssFiles(Horde_Themes::getStylesheets()), 'csstidy', array('ob' => true))->filterBySelector($selectors)) {
                     $elt->setAttribute('style', ($elt->hasAttribute('style') ? rtrim($elt->getAttribute('style'), ' ;') . ';' : '') . $style);
                 }
             }