Skip to content

Commit

Permalink
[mms] Move CSS minification to the Horde_CssMinify package.
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Feb 20, 2014
1 parent 6fc2373 commit 20aaee1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 70 deletions.
88 changes: 25 additions & 63 deletions framework/Core/lib/Horde/Themes/Css/Compress.php
Expand Up @@ -33,74 +33,36 @@ class Horde_Themes_Css_Compress
*/
public function compress($css)
{
global $browser, $conf;
global $browser, $conf, $injector;

$dataurl = (empty($conf['nobase64_img']) &&
$browser->hasFeature('dataurl'));
$out = '';

foreach ($css as $file) {
$data = file_get_contents($file['fs']);
$path = substr($file['uri'], 0, strrpos($file['uri'], '/') + 1);
$url = array();

try {
$css_parser = new Horde_Css_Parser($data);
} catch (Exception $e) {
/* If the CSS is broken, log error and output as-is. */
Horde::log($e, 'ERR');
$out .= $data;
continue;
}

foreach ($css_parser->doc->getContents() as $val) {
if ($val instanceof Sabberworm\CSS\Property\Import) {
$ob = Horde_Themes_Element::fromUri($path . $val->getLocation()->getURL()->getString());
$out .= $this->compress(array(array(
'app' => null,
'fs' => $ob->fs,
'uri' => $ob->uri
)));
$css_parser->doc->remove($val);
}
}

foreach ($css_parser->doc->getAllRuleSets() as $val) {
foreach ($val->getRules('background-') as $val2) {
$item = $val2->getValue();

if ($item instanceof Sabberworm\CSS\Value\URL) {
$url[] = $item;
} elseif ($item instanceof Sabberworm\CSS\Value\RuleValueList) {
foreach ($item->getListComponents() as $val3) {
if ($val3 instanceof Sabberworm\CSS\Value\URL) {
$url[] = $val3;
}
}
}
}
}
$files = array();
foreach ($css as $val) {
$files[$val['uri']] = $val['fs'];
}

foreach ($url as $val) {
$url_ob = $val->getURL();
$url_str = $url_ob->getString();
$parser = new Horde_CssMinify_CssParser($files, array(
'dataurl' => (empty($conf['nobase64_img']) && $browser->hasFeature('dataurl')) ? array($this, 'dataurlCallback') : null,
'import' => array($this, 'importCallback'),
'logger' => $injector->getInstance('Horde_Log_Logger')
));

if (Horde_Url_Data::isData($url_str)) {
$url_ob->setString($url_str);
} else {
if ($dataurl) {
/* Limit data to 16 KB in stylesheets. */
$url_ob->setString(Horde_Themes_Image::base64ImgData($path . $url_str, 16384));
} else {
$url_ob->setString($path . $url_str);
}
}
}
return $parser->minify();
}

$out .= $css_parser->compress();
}
/**
*/
public function dataurlCallback($uri)
{
/* Limit data to 16 KB in stylesheets. */
return Horde_Themes_Image::base64ImgData($uri, 16384);
}

return $out;
/**
*/
public function importCallback($uri)
{
$ob = Horde_Themes_Element::fromUri($uri);
return array($ob->uri, $ob->fs);
}

}
16 changes: 9 additions & 7 deletions framework/Core/package.xml
Expand Up @@ -39,6 +39,7 @@
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Move CSS minification to the Horde_CssMinify package.
* [mjr] Work around parsing broken incoming ActiveSync SMARTREPLY requests with incorrect character sets (Bug #12969).
* [mms] Add null driver for the content tagger.
* [jan] Add database configuration for Oracle.
Expand Down Expand Up @@ -1065,6 +1066,13 @@
<max>3.0.0alpha1</max>
<exclude>3.0.0alpha1</exclude>
</package>
<package>
<name>Horde_CssMinify</name>
<channel>pear.horde.org</channel>
<min>1.0.0</min>
<max>2.0.0alpha1</max>
<exclude>2.0.0alpha1</exclude>
</package>
<package>
<name>Horde_Data</name>
<channel>pear.horde.org</channel>
Expand Down Expand Up @@ -1233,13 +1241,6 @@
<max>3.0.0alpha1</max>
<exclude>3.0.0alpha1</exclude>
</package>
<package>
<name>Horde_Css_Parser</name>
<channel>pear.horde.org</channel>
<min>1.0.0</min>
<max>2.0.0alpha1</max>
<exclude>2.0.0alpha1</exclude>
</package>
<package>
<name>Horde_Translation</name>
<channel>pear.horde.org</channel>
Expand Down Expand Up @@ -3350,6 +3351,7 @@
<date>2014-02-13</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
* [mms] Move CSS minification to the Horde_CssMinify package.
* [mjr] Work around parsing broken incoming ActiveSync SMARTREPLY requests with incorrect character sets (Bug #12969).
* [mms] Add null driver for the content tagger.
* [jan] Add database configuration for Oracle.
Expand Down

0 comments on commit 20aaee1

Please sign in to comment.