Skip to content

Commit

Permalink
[mms] Cache generation of print-specific CSS.
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Oct 7, 2013
1 parent 9bf6e83 commit ed948f5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
1 change: 1 addition & 0 deletions imp/docs/CHANGES
Expand Up @@ -2,6 +2,7 @@
v6.2.0-git
----------

[mms] Cache generation of print-specific CSS.
[mms] Add support for showing a contact image in the contacts popup box in
dynamic view.
[mms] Add ability to create a new filter rule from the contacts dropdown in the
Expand Down
48 changes: 33 additions & 15 deletions imp/lib/Contents/View.php
Expand Up @@ -266,24 +266,42 @@ public function printAttach($id)
}
}

$css = $page_output->css;
$style = '';

try {
$css_parser = new Horde_Css_Parser($css->loadCssFiles($css->getStylesheets()));

foreach ($css_parser->doc->getContents() as $val) {
if (($val instanceof Sabberworm\CSS\RuleSet\DeclarationBlock) &&
array_intersect($selectors, array_map('strval', $val->getSelectors()))) {
$style .= implode('', array_map('strval', $val->getRules()));
/* Cache CSS. */
$cache_list = array();
$cache_ob = $injector->getInstance('Horde_Cache');

$css_list = $page_output->css->getStylesheets();
foreach ($css_list as $val) {
$cache_list[] = $val;
$cache_list[] = filemtime($val);
}
$cache_id = hash('md5', implode('', $cache_list));

if (($style = $cache_ob->get($cache_id, 0)) === false) {
try {
$css_parser = new Horde_Css_Parser(
$page_output->css->loadCssFiles(
$page_output->css->getStylesheets()
)
);

$style = '';

foreach ($css_parser->doc->getContents() as $val) {
if (($val instanceof Sabberworm\CSS\RuleSet\DeclarationBlock) &&
array_intersect($selectors, array_map('strval', $val->getSelectors()))) {
$style .= implode('', array_map('strval', $val->getRules()));
}
}
}

if (strlen($style)) {
$elt->setAttribute('style', ($elt->hasAttribute('style') ? rtrim($elt->getAttribute('style'), ' ;') . ';' : '') . $style);
$cache_ob->set($cache_id, $style, 86400);
} catch (Exception $e) {
// Ignore CSS if it can't be parsed.
}
} catch (Exception $e) {
// Ignore CSS if it can't be parsed.
}

if (strlen($style)) {
$elt->setAttribute('style', ($elt->hasAttribute('style') ? rtrim($elt->getAttribute('style'), ' ;') . ';' : '') . $style);
}
}

Expand Down
1 change: 1 addition & 0 deletions imp/package.xml
Expand Up @@ -33,6 +33,7 @@
</stability>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
* [mms] Cache generation of print-specific CSS.
* [mms] Add support for showing a contact image in the contacts popup box in dynamic view.
* [mms] Add ability to create a new filter rule from the contacts dropdown in the dynamic view.
* [mms] More intelligent sizing of raw message parts opened in a popup window.
Expand Down

0 comments on commit ed948f5

Please sign in to comment.