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