From: Michael M Slusarz Date: Wed, 20 Jan 2010 17:18:42 +0000 (-0700) Subject: Limit size of image data in stylesheets X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=17c4d1e6b4814dd0d4dcc84c2c5be460466c933d;p=horde.git Limit size of image data in stylesheets --- diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index 86f418af1..ef3f8bb2c 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -1502,19 +1502,26 @@ HTML; /** * Generate RFC 2397-compliant image data strings. * - * @param string $file Filename containing image data. + * @param string $file Filename containing image data. + * @param integer $limit Sets a hard size limit for image data; if + * exceeded, will not string encode. * * @return string The string to use in the image 'src' attribute; either * the image data if the browser supports, or the filepath * if not. */ - public function base64ImgData($file) + public function base64ImgData($file, $limit = null) { $dataurl = $GLOBALS['browser']->hasFeature('dataurl'); if (!$dataurl) { return $file; } + if (!is_null($limit) && + (is_bool($dataurl) || ($limit < $dataurl))) { + $dataurl = $limit; + } + /* Only encode image files if they are below the dataurl limit. */ $filename = realpath($GLOBALS['registry']->get('fileroot', 'horde')) . preg_replace('/^' . preg_quote($GLOBALS['registry']->get('webroot', 'horde'), '/') . '/', '', $file); if (!file_exists($filename)) { @@ -1755,7 +1762,8 @@ HTML; */ public function stylesheetCallback($matches) { - return $matches[1] . self::base64ImgData($matches[2]) . $matches[3]; + /* Limit data to 16 KB in stylesheets. */ + return $matches[1] . self::base64ImgData($matches[2], 16384) . $matches[3]; } /**