From 0a823c7ad6542a26dda34dbbc72a51c21fd0ac99 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 25 Jun 2010 12:10:02 -0600 Subject: [PATCH] Add Horde_Themes::loadCssFiles() --- framework/Core/lib/Horde/Themes.php | 48 ++++++++++++++++++++++++------------- imp/view.php | 7 +----- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/framework/Core/lib/Horde/Themes.php b/framework/Core/lib/Horde/Themes.php index b3973cae4..46f0d03ba 100644 --- a/framework/Core/lib/Horde/Themes.php +++ b/framework/Core/lib/Horde/Themes.php @@ -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. * diff --git a/imp/view.php b/imp/view.php index fbaf7e329..9485f59b2 100644 --- a/imp/view.php +++ b/imp/view.php @@ -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); } } -- 2.11.0