1: <?php
2: /**
3: * This filter cleans up CSS output by running it through a PHP-based
4: * optimizer/compressor.
5: *
6: * Original library (version 1.3) from http://csstidy.sourceforge.net/
7: *
8: * Parameters:
9: * <pre>
10: * level - (string) Level of compression.
11: * DEFAULT: 'highest_compression'
12: * ob - (boolean) If true, return Csstidy object instead of string.
13: * DEFAULT: false
14: * preserve_css - (boolean) Set preserve_css flag in csstidy engine?
15: * DEFAULT: true
16: * </pre>
17: *
18: * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
19: *
20: * See the enclosed file COPYING for license information (GPL). If you
21: * did not receive this file, see http://www.horde.org/licenses/gpl.
22: *
23: * @author Michael Slusarz <slusarz@horde.org>
24: * @category Horde
25: * @license http://www.horde.org/licenses/gpl GPL
26: * @package Text_Filter
27: */
28: class Horde_Text_Filter_Csstidy extends Horde_Text_Filter_Base
29: {
30: /**
31: * Filter parameters.
32: *
33: * @var array
34: */
35: protected $_params = array(
36: 'level' => 'highest_compression',
37: 'ob' => false,
38: 'preserve_css' => true
39: );
40:
41: /**
42: * Executes any code necessary after applying the filter patterns.
43: *
44: * @param string $text The text after the filtering.
45: *
46: * @return mixed The modified text, or the Csstidy object if
47: * the 'ob' parameter is true.
48: */
49: public function postProcess($text)
50: {
51: /* Can't autoload since csstidy is an external package that doesn't
52: * conform to Horde naming standards. */
53: require_once dirname(__FILE__) . '/Csstidy/class.csstidy.php';
54:
55: $css_tidy = new csstidy();
56: $css_tidy->set_cfg('preserve_css', $this->_params['preserve_css']);
57: $css_tidy->load_template($this->_params['level']);
58: $css_tidy->parse($text);
59:
60: return empty($this->_params['ob'])
61: ? $css_tidy->print->plain()
62: : $css_tidy;
63: }
64:
65: }
66: