Add vim modelines to all files.
[htmlpurifier.git] / library / HTMLPurifier / AttrDef / HTML / LinkTypes.php
blob8a0da0c89e0ccc02aa501b3d4b0d5e33e7dc3005
1 <?php
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 class HTMLPurifier_AttrDef_HTML_LinkTypes extends HTMLPurifier_AttrDef
12 /** Name config attribute to pull. */
13 protected $name;
15 public function __construct($name) {
16 $configLookup = array(
17 'rel' => 'AllowedRel',
18 'rev' => 'AllowedRev'
20 if (!isset($configLookup[$name])) {
21 trigger_error('Unrecognized attribute name for link '.
22 'relationship.', E_USER_ERROR);
23 return;
25 $this->name = $configLookup[$name];
28 public function validate($string, $config, $context) {
30 $allowed = $config->get('Attr', $this->name);
31 if (empty($allowed)) return false;
33 $string = $this->parseCDATA($string);
34 $parts = explode(' ', $string);
36 // lookup to prevent duplicates
37 $ret_lookup = array();
38 foreach ($parts as $part) {
39 $part = strtolower(trim($part));
40 if (!isset($allowed[$part])) continue;
41 $ret_lookup[$part] = true;
44 if (empty($ret_lookup)) return false;
45 $string = implode(' ', array_keys($ret_lookup));
47 return $string;
53 // vim: et sw=4 sts=4