HTMLPurifier 4.4.0
/home/ezyang/Dev/htmlpurifier/library/HTMLPurifier/AttrDef/HTML/LinkTypes.php
Go to the documentation of this file.
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         // lookup to prevent duplicates
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         $string = implode(' ', array_keys($ret_lookup));
00046 
00047         return $string;
00048 
00049     }
00050 
00051 }
00052 
00053 // vim: et sw=4 sts=4