00001 <?php
00002
00009 class HTMLPurifier_AttrDef_HTML_LinkTypes extends HTMLPurifier_AttrDef
00010 {
00011
00013 protected $name;
00014
00015 public function __construct($name) {
00016 $configLookup = array(
00017 'rel' => 'AllowedRel',
00018 'rev' => 'AllowedRev'
00019 );
00020 if (!isset($configLookup[$name])) {
00021 trigger_error('Unrecognized attribute name for link '.
00022 'relationship.', E_USER_ERROR);
00023 return;
00024 }
00025 $this->name = $configLookup[$name];
00026 }
00027
00028 public function validate($string, $config, $context) {
00029
00030 $allowed = $config->get('Attr', $this->name);
00031 if (empty($allowed)) return false;
00032
00033 $string = $this->parseCDATA($string);
00034 $parts = explode(' ', $string);
00035
00036
00037 $ret_lookup = array();
00038 foreach ($parts as $part) {
00039 $part = strtolower(trim($part));
00040 if (!isset($allowed[$part])) continue;
00041 $ret_lookup[$part] = true;
00042 }
00043
00044 if (empty($ret_lookup)) return false;
00045
00046 $ret_array = array();
00047 foreach ($ret_lookup as $part => $bool) $ret_array[] = $part;
00048 $string = implode(' ', $ret_array);
00049
00050 return $string;
00051
00052 }
00053
00054 }
00055