From: Michael M Slusarz Date: Mon, 12 Jan 2009 23:09:22 +0000 (-0700) Subject: Initial support for embedded image data in CSS X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=624b959ec733846a46eea3515ac4eacdc4aeda1f;p=horde.git Initial support for embedded image data in CSS Beginning to implement Ticket #7174. Eventually, all images should be moved into CSS to allow for maximum caching. --- diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index 579c11d48..22ef11292 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -1686,9 +1686,15 @@ class IMP $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, remove multiple whitespaces, and - // strip comments. - $out .= preg_replace(array('/(url\(["\']?)([^\/])/i', '/\s+/', '/\/\*.*?\*\//'), array('$1' . $path . '$2', ' ', ''), implode('', file($file['f'], $flags))); + + // 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('IMP', 'stylesheetCallback'), $tmp); + } + $out .= $tmp; } switch ($cache_type) { @@ -1712,6 +1718,17 @@ class IMP } /** + * TODO + */ + public function stylesheetCallback($matches) + { + return $matches[1] . + 'data:image/' . substr($matches[2], strrpos($matches[2], '.') + 1) . ';base64,' . + base64_encode(file_get_contents(dirname(realpath($GLOBALS['registry']->get('fileroot', 'horde'))) . $matches[2])) . + $matches[3]; + } + + /** * TODO - Temporary DIMP fix. */ private function _getDIMPStylesheets($theme = '')