]>
Commit | Line | Data |
---|---|---|
d4949327 NL |
1 | <?php\r |
2 | \r | |
3 | /**\r | |
4 | * Microsoft's proprietary filter: CSS property\r | |
5 | * @note Currently supports the alpha filter. In the future, this will\r | |
6 | * probably need an extensible framework\r | |
7 | */\r | |
8 | class HTMLPurifier_AttrDef_CSS_Filter extends HTMLPurifier_AttrDef\r | |
9 | {\r | |
10 | /**\r | |
11 | * @type HTMLPurifier_AttrDef_Integer\r | |
12 | */\r | |
13 | protected $intValidator;\r | |
14 | \r | |
15 | public function __construct()\r | |
16 | {\r | |
17 | $this->intValidator = new HTMLPurifier_AttrDef_Integer();\r | |
18 | }\r | |
19 | \r | |
20 | /**\r | |
21 | * @param string $value\r | |
22 | * @param HTMLPurifier_Config $config\r | |
23 | * @param HTMLPurifier_Context $context\r | |
24 | * @return bool|string\r | |
25 | */\r | |
26 | public function validate($value, $config, $context)\r | |
27 | {\r | |
28 | $value = $this->parseCDATA($value);\r | |
29 | if ($value === 'none') {\r | |
30 | return $value;\r | |
31 | }\r | |
32 | // if we looped this we could support multiple filters\r | |
33 | $function_length = strcspn($value, '(');\r | |
34 | $function = trim(substr($value, 0, $function_length));\r | |
35 | if ($function !== 'alpha' &&\r | |
36 | $function !== 'Alpha' &&\r | |
37 | $function !== 'progid:DXImageTransform.Microsoft.Alpha'\r | |
38 | ) {\r | |
39 | return false;\r | |
40 | }\r | |
41 | $cursor = $function_length + 1;\r | |
42 | $parameters_length = strcspn($value, ')', $cursor);\r | |
43 | $parameters = substr($value, $cursor, $parameters_length);\r | |
44 | $params = explode(',', $parameters);\r | |
45 | $ret_params = array();\r | |
46 | $lookup = array();\r | |
47 | foreach ($params as $param) {\r | |
48 | list($key, $value) = explode('=', $param);\r | |
49 | $key = trim($key);\r | |
50 | $value = trim($value);\r | |
51 | if (isset($lookup[$key])) {\r | |
52 | continue;\r | |
53 | }\r | |
54 | if ($key !== 'opacity') {\r | |
55 | continue;\r | |
56 | }\r | |
57 | $value = $this->intValidator->validate($value, $config, $context);\r | |
58 | if ($value === false) {\r | |
59 | continue;\r | |
60 | }\r | |
61 | $int = (int)$value;\r | |
62 | if ($int > 100) {\r | |
63 | $value = '100';\r | |
64 | }\r | |
65 | if ($int < 0) {\r | |
66 | $value = '0';\r | |
67 | }\r | |
68 | $ret_params[] = "$key=$value";\r | |
69 | $lookup[$key] = true;\r | |
70 | }\r | |
71 | $ret_parameters = implode(',', $ret_params);\r | |
72 | $ret_function = "$function($ret_parameters)";\r | |
73 | return $ret_function;\r | |
74 | }\r | |
75 | }\r | |
76 | \r | |
77 | // vim: et sw=4 sts=4\r |