]>
Commit | Line | Data |
---|---|---|
d4949327 NL |
1 | <?php\r |
2 | \r | |
3 | /**\r | |
4 | * Validates a rel/rev link attribute against a directive of allowed values\r | |
5 | * @note We cannot use Enum because link types allow multiple\r | |
6 | * values.\r | |
7 | * @note Assumes link types are ASCII text\r | |
8 | */\r | |
9 | class HTMLPurifier_AttrDef_HTML_LinkTypes extends HTMLPurifier_AttrDef\r | |
10 | {\r | |
11 | \r | |
12 | /**\r | |
13 | * Name config attribute to pull.\r | |
14 | * @type string\r | |
15 | */\r | |
16 | protected $name;\r | |
17 | \r | |
18 | /**\r | |
19 | * @param string $name\r | |
20 | */\r | |
21 | public function __construct($name)\r | |
22 | {\r | |
23 | $configLookup = array(\r | |
24 | 'rel' => 'AllowedRel',\r | |
25 | 'rev' => 'AllowedRev'\r | |
26 | );\r | |
27 | if (!isset($configLookup[$name])) {\r | |
28 | trigger_error(\r | |
29 | 'Unrecognized attribute name for link ' .\r | |
30 | 'relationship.',\r | |
31 | E_USER_ERROR\r | |
32 | );\r | |
33 | return;\r | |
34 | }\r | |
35 | $this->name = $configLookup[$name];\r | |
36 | }\r | |
37 | \r | |
38 | /**\r | |
39 | * @param string $string\r | |
40 | * @param HTMLPurifier_Config $config\r | |
41 | * @param HTMLPurifier_Context $context\r | |
42 | * @return bool|string\r | |
43 | */\r | |
44 | public function validate($string, $config, $context)\r | |
45 | {\r | |
46 | $allowed = $config->get('Attr.' . $this->name);\r | |
47 | if (empty($allowed)) {\r | |
48 | return false;\r | |
49 | }\r | |
50 | \r | |
51 | $string = $this->parseCDATA($string);\r | |
52 | $parts = explode(' ', $string);\r | |
53 | \r | |
54 | // lookup to prevent duplicates\r | |
55 | $ret_lookup = array();\r | |
56 | foreach ($parts as $part) {\r | |
57 | $part = strtolower(trim($part));\r | |
58 | if (!isset($allowed[$part])) {\r | |
59 | continue;\r | |
60 | }\r | |
61 | $ret_lookup[$part] = true;\r | |
62 | }\r | |
63 | \r | |
64 | if (empty($ret_lookup)) {\r | |
65 | return false;\r | |
66 | }\r | |
67 | $string = implode(' ', array_keys($ret_lookup));\r | |
68 | return $string;\r | |
69 | }\r | |
70 | }\r | |
71 | \r | |
72 | // vim: et sw=4 sts=4\r |