PSR-2 reformatting PHPDoc corrections
[htmlpurifier.git] / library / HTMLPurifier / AttrDef / HTML / LinkTypes.php
blob63fa04c15c0040fb6df332d067c2a38a8b1342b1
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 /**
13 * Name config attribute to pull.
14 * @type string
16 protected $name;
18 /**
19 * @param string $name
21 public function __construct($name)
23 $configLookup = array(
24 'rel' => 'AllowedRel',
25 'rev' => 'AllowedRev'
27 if (!isset($configLookup[$name])) {
28 trigger_error(
29 'Unrecognized attribute name for link ' .
30 'relationship.',
31 E_USER_ERROR
33 return;
35 $this->name = $configLookup[$name];
38 /**
39 * @param string $string
40 * @param HTMLPurifier_Config $config
41 * @param HTMLPurifier_Context $context
42 * @return bool|string
44 public function validate($string, $config, $context)
46 $allowed = $config->get('Attr.' . $this->name);
47 if (empty($allowed)) {
48 return false;
51 $string = $this->parseCDATA($string);
52 $parts = explode(' ', $string);
54 // lookup to prevent duplicates
55 $ret_lookup = array();
56 foreach ($parts as $part) {
57 $part = strtolower(trim($part));
58 if (!isset($allowed[$part])) {
59 continue;
61 $ret_lookup[$part] = true;
64 if (empty($ret_lookup)) {
65 return false;
67 $string = implode(' ', array_keys($ret_lookup));
68 return $string;
72 // vim: et sw=4 sts=4