2010-09-09 03:14:17 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validates a rel/rev link attribute against a directive of allowed values
|
|
|
|
* @note We cannot use Enum because link types allow multiple
|
|
|
|
* values.
|
|
|
|
* @note Assumes link types are ASCII text
|
|
|
|
*/
|
|
|
|
class HTMLPurifier_AttrDef_HTML_LinkTypes extends HTMLPurifier_AttrDef
|
|
|
|
{
|
|
|
|
|
2016-02-09 10:06:17 +00:00
|
|
|
/**
|
|
|
|
* Name config attribute to pull.
|
|
|
|
* @type string
|
|
|
|
*/
|
2010-09-09 03:14:17 +00:00
|
|
|
protected $name;
|
|
|
|
|
2016-02-09 10:06:17 +00:00
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
*/
|
|
|
|
public function __construct($name)
|
|
|
|
{
|
2010-09-09 03:14:17 +00:00
|
|
|
$configLookup = array(
|
|
|
|
'rel' => 'AllowedRel',
|
|
|
|
'rev' => 'AllowedRev'
|
|
|
|
);
|
|
|
|
if (!isset($configLookup[$name])) {
|
2016-02-09 10:06:17 +00:00
|
|
|
trigger_error(
|
|
|
|
'Unrecognized attribute name for link ' .
|
|
|
|
'relationship.',
|
|
|
|
E_USER_ERROR
|
|
|
|
);
|
2010-09-09 03:14:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->name = $configLookup[$name];
|
|
|
|
}
|
|
|
|
|
2016-02-09 10:06:17 +00:00
|
|
|
/**
|
|
|
|
* @param string $string
|
|
|
|
* @param HTMLPurifier_Config $config
|
|
|
|
* @param HTMLPurifier_Context $context
|
|
|
|
* @return bool|string
|
|
|
|
*/
|
|
|
|
public function validate($string, $config, $context)
|
|
|
|
{
|
2010-09-09 03:14:17 +00:00
|
|
|
$allowed = $config->get('Attr.' . $this->name);
|
2016-02-09 10:06:17 +00:00
|
|
|
if (empty($allowed)) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-09 03:14:17 +00:00
|
|
|
|
|
|
|
$string = $this->parseCDATA($string);
|
|
|
|
$parts = explode(' ', $string);
|
|
|
|
|
|
|
|
// lookup to prevent duplicates
|
|
|
|
$ret_lookup = array();
|
|
|
|
foreach ($parts as $part) {
|
|
|
|
$part = strtolower(trim($part));
|
2016-02-09 10:06:17 +00:00
|
|
|
if (!isset($allowed[$part])) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-09-09 03:14:17 +00:00
|
|
|
$ret_lookup[$part] = true;
|
|
|
|
}
|
|
|
|
|
2016-02-09 10:06:17 +00:00
|
|
|
if (empty($ret_lookup)) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-09 03:14:17 +00:00
|
|
|
$string = implode(' ', array_keys($ret_lookup));
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// vim: et sw=4 sts=4
|