2009-02-21 07:58:30 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Post-transform that performs validation to the name attribute; if
|
|
|
|
* it is present with an equivalent id attribute, it is passed through;
|
|
|
|
* otherwise validation is performed.
|
|
|
|
*/
|
|
|
|
class HTMLPurifier_AttrTransform_NameSync extends HTMLPurifier_AttrTransform
|
|
|
|
{
|
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
2009-02-21 07:58:30 +00:00
|
|
|
$this->idDef = new HTMLPurifier_AttrDef_HTML_ID();
|
|
|
|
}
|
|
|
|
|
2013-07-16 11:56:14 +00:00
|
|
|
/**
|
|
|
|
* @param array $attr
|
|
|
|
* @param HTMLPurifier_Config $config
|
|
|
|
* @param HTMLPurifier_Context $context
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function transform($attr, $config, $context)
|
|
|
|
{
|
|
|
|
if (!isset($attr['name'])) {
|
|
|
|
return $attr;
|
|
|
|
}
|
2009-02-21 07:58:30 +00:00
|
|
|
$name = $attr['name'];
|
2013-07-16 11:56:14 +00:00
|
|
|
if (isset($attr['id']) && $attr['id'] === $name) {
|
|
|
|
return $attr;
|
|
|
|
}
|
2009-02-21 07:58:30 +00:00
|
|
|
$result = $this->idDef->validate($name, $config, $context);
|
2013-07-16 11:56:14 +00:00
|
|
|
if ($result === false) {
|
|
|
|
unset($attr['name']);
|
|
|
|
} else {
|
|
|
|
$attr['name'] = $result;
|
|
|
|
}
|
2009-02-21 07:58:30 +00:00
|
|
|
return $attr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// vim: et sw=4 sts=4
|