2006-07-30 16:35:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/AttrDef.php';
|
|
|
|
require_once 'HTMLPurifier/IDAccumulator.php';
|
2006-08-04 02:48:20 +00:00
|
|
|
|
|
|
|
// NOTE QUIRKY BEHAVIOR: even though this is the id processor, it
|
2006-08-11 20:23:41 +00:00
|
|
|
// will ignore directive Attr:IDBlacklist, since it will only
|
2006-08-04 02:48:20 +00:00
|
|
|
// go according to the ID accumulator. Since the accumulator is
|
|
|
|
// automatically generated, it will have already absorbed the
|
|
|
|
// blacklist. If you're hacking around, make sure you use load()!
|
2006-07-30 16:35:05 +00:00
|
|
|
|
|
|
|
class HTMLPurifier_AttrDef_ID extends HTMLPurifier_AttrDef
|
|
|
|
{
|
|
|
|
|
2006-08-05 00:30:31 +00:00
|
|
|
function validate($id, $config, &$accumulator) {
|
2006-07-30 16:35:05 +00:00
|
|
|
|
2006-08-05 00:30:31 +00:00
|
|
|
$id = trim($id); // trim it first
|
2006-07-30 16:35:05 +00:00
|
|
|
|
|
|
|
if ($id === '') return false;
|
|
|
|
if (isset($accumulator->ids[$id])) return false;
|
|
|
|
|
|
|
|
// we purposely avoid using regex, hopefully this is faster
|
|
|
|
|
|
|
|
if (ctype_alpha($id)) {
|
|
|
|
$result = true;
|
|
|
|
} else {
|
|
|
|
if (!ctype_alpha(@$id[0])) return false;
|
2006-08-04 00:11:54 +00:00
|
|
|
$trim = trim( // primitive style of regexps, I suppose
|
2006-07-30 16:35:05 +00:00
|
|
|
$id,
|
|
|
|
'A..Za..z0..9:-._'
|
|
|
|
);
|
|
|
|
$result = ($trim === '');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($result) $accumulator->add($id);
|
|
|
|
|
2006-08-04 00:11:54 +00:00
|
|
|
// if no change was made to the ID, return the result
|
|
|
|
// else, return the new id if stripping whitespace made it
|
|
|
|
// valid, or return false.
|
2006-08-05 00:30:31 +00:00
|
|
|
return $result ? $id : false;
|
2006-07-30 16:35:05 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|