Add vim modelines to all files.
[htmlpurifier.git] / library / HTMLPurifier / AttrDef / CSS / ImportantDecorator.php
blob2990cff76e33b949d6c6b898dc16e79cc6d04dc7
1 <?php
3 /**
4 * Decorator which enables !important to be used in CSS values.
5 */
6 class HTMLPurifier_AttrDef_CSS_ImportantDecorator extends HTMLPurifier_AttrDef
8 protected $def, $allow;
10 /**
11 * @param $def Definition to wrap
12 * @param $allow Whether or not to allow !important
14 public function __construct($def, $allow = false) {
15 $this->def = $def;
16 $this->allow = $allow;
18 /**
19 * Intercepts and removes !important if necessary
21 public function validate($string, $config, $context) {
22 // test for ! and important tokens
23 $string = trim($string);
24 $is_important = false;
25 // :TODO: optimization: test directly for !important and ! important
26 if (strlen($string) >= 9 && substr($string, -9) === 'important') {
27 $temp = rtrim(substr($string, 0, -9));
28 // use a temp, because we might want to restore important
29 if (strlen($temp) >= 1 && substr($temp, -1) === '!') {
30 $string = rtrim(substr($temp, 0, -1));
31 $is_important = true;
34 $string = $this->def->validate($string, $config, $context);
35 if ($this->allow && $is_important) $string .= ' !important';
36 return $string;
40 // vim: et sw=4 sts=4