]> git.immae.eu Git - github/wallabag/wallabag.git/blame - inc/3rdparty/htmlpurifier/HTMLPurifier/AttrDef/CSS/ImportantDecorator.php
remove autoload section in composer.json
[github/wallabag/wallabag.git] / inc / 3rdparty / htmlpurifier / HTMLPurifier / AttrDef / CSS / ImportantDecorator.php
CommitLineData
d4949327
NL
1<?php\r
2\r
3/**\r
4 * Decorator which enables !important to be used in CSS values.\r
5 */\r
6class HTMLPurifier_AttrDef_CSS_ImportantDecorator extends HTMLPurifier_AttrDef\r
7{\r
8 /**\r
9 * @type HTMLPurifier_AttrDef\r
10 */\r
11 public $def;\r
12 /**\r
13 * @type bool\r
14 */\r
15 public $allow;\r
16\r
17 /**\r
18 * @param HTMLPurifier_AttrDef $def Definition to wrap\r
19 * @param bool $allow Whether or not to allow !important\r
20 */\r
21 public function __construct($def, $allow = false)\r
22 {\r
23 $this->def = $def;\r
24 $this->allow = $allow;\r
25 }\r
26\r
27 /**\r
28 * Intercepts and removes !important if necessary\r
29 * @param string $string\r
30 * @param HTMLPurifier_Config $config\r
31 * @param HTMLPurifier_Context $context\r
32 * @return bool|string\r
33 */\r
34 public function validate($string, $config, $context)\r
35 {\r
36 // test for ! and important tokens\r
37 $string = trim($string);\r
38 $is_important = false;\r
39 // :TODO: optimization: test directly for !important and ! important\r
40 if (strlen($string) >= 9 && substr($string, -9) === 'important') {\r
41 $temp = rtrim(substr($string, 0, -9));\r
42 // use a temp, because we might want to restore important\r
43 if (strlen($temp) >= 1 && substr($temp, -1) === '!') {\r
44 $string = rtrim(substr($temp, 0, -1));\r
45 $is_important = true;\r
46 }\r
47 }\r
48 $string = $this->def->validate($string, $config, $context);\r
49 if ($this->allow && $is_important) {\r
50 $string .= ' !important';\r
51 }\r
52 return $string;\r
53 }\r
54}\r
55\r
56// vim: et sw=4 sts=4\r