2009-05-26 01:55:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements special behavior for class attribute (normally NMTOKENS)
|
|
|
|
*/
|
|
|
|
class HTMLPurifier_AttrDef_HTML_Class extends HTMLPurifier_AttrDef_HTML_Nmtokens
|
|
|
|
{
|
2009-05-26 05:07:40 +00:00
|
|
|
protected function split($string, $config, $context) {
|
|
|
|
// really, this twiddle should be lazy loaded
|
|
|
|
$name = $config->getDefinition('HTML')->doctype->name;
|
|
|
|
if ($name == "XHTML 1.1" || $name == "XHTML 2.0") {
|
|
|
|
return parent::split($string, $config, $context);
|
|
|
|
} else {
|
|
|
|
return preg_split('/\s+/', $string);
|
|
|
|
}
|
|
|
|
}
|
2009-05-26 01:55:44 +00:00
|
|
|
protected function filter($tokens, $config, $context) {
|
|
|
|
$allowed = $config->get('Attr.AllowedClasses');
|
|
|
|
$forbidden = $config->get('Attr.ForbiddenClasses');
|
|
|
|
$ret = array();
|
|
|
|
foreach ($tokens as $token) {
|
|
|
|
if (
|
|
|
|
($allowed === null || isset($allowed[$token])) &&
|
|
|
|
!isset($forbidden[$token])
|
|
|
|
) {
|
2009-05-26 05:07:40 +00:00
|
|
|
$ret[$token] = true;
|
2009-05-26 01:55:44 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-26 05:07:40 +00:00
|
|
|
return array_keys($ret);
|
2009-05-26 01:55:44 +00:00
|
|
|
}
|
|
|
|
}
|