Relax allowed values of class for certain doctypes, see %Attr.ClassUseCDATA
[htmlpurifier/bfroehle.git] / library / HTMLPurifier / AttrDef / HTML / Class.php
blobc925cd39fdd9843f9521f79f4ef55e28a4979785
1 <?php
3 /**
4 * Implements special behavior for class attribute (normally NMTOKENS)
5 */
6 class HTMLPurifier_AttrDef_HTML_Class extends HTMLPurifier_AttrDef_HTML_Nmtokens
8 protected function split($string, $config, $context) {
9 // really, this twiddle should be lazy loaded
10 $name = $config->getDefinition('HTML')->doctype->name;
11 if ($name == "XHTML 1.1" || $name == "XHTML 2.0") {
12 return parent::split($string, $config, $context);
13 } else {
14 return preg_split('/\s+/', $string);
17 protected function filter($tokens, $config, $context) {
18 $allowed = $config->get('Attr.AllowedClasses');
19 $forbidden = $config->get('Attr.ForbiddenClasses');
20 $ret = array();
21 foreach ($tokens as $token) {
22 if (
23 ($allowed === null || isset($allowed[$token])) &&
24 !isset($forbidden[$token])
25 ) {
26 $ret[$token] = true;
29 return array_keys($ret);