2006-08-04 02:48:20 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/AttrDef.php';
|
|
|
|
require_once 'HTMLPurifier/Config.php';
|
|
|
|
|
2006-08-20 21:47:15 +00:00
|
|
|
/**
|
|
|
|
* Validates the contents of the global HTML attribute class.
|
|
|
|
*/
|
2006-08-04 02:48:20 +00:00
|
|
|
class HTMLPurifier_AttrDef_Class extends HTMLPurifier_AttrDef
|
|
|
|
{
|
|
|
|
|
2006-08-12 16:04:40 +00:00
|
|
|
function validate($string, $config, &$context) {
|
2006-08-04 02:48:20 +00:00
|
|
|
|
2006-08-05 00:30:31 +00:00
|
|
|
$string = trim($string);
|
2006-08-04 02:48:20 +00:00
|
|
|
|
|
|
|
// early abort: '' and '0' (strings that convert to false) are invalid
|
|
|
|
if (!$string) return false;
|
|
|
|
|
|
|
|
// OPTIMIZABLE!
|
|
|
|
// do the preg_match, capture all subpatterns for reformulation
|
|
|
|
|
|
|
|
// we don't support U+00A1 and up codepoints or
|
|
|
|
// escaping because I don't know how to do that with regexps
|
|
|
|
// and plus it would complicate optimization efforts (you never
|
|
|
|
// see that anyway).
|
|
|
|
$matches = array();
|
2006-08-05 00:30:31 +00:00
|
|
|
$pattern = '/(?:(?<=\s)|\A)'.
|
|
|
|
'((?:--|-?[A-Za-z_])[A-Za-z_\-0-9]*)'.
|
|
|
|
'(?:(?=\s)|\z)/';
|
2006-08-04 02:48:20 +00:00
|
|
|
preg_match_all($pattern, $string, $matches);
|
|
|
|
|
2006-08-05 00:30:31 +00:00
|
|
|
if (empty($matches[1])) return false;
|
|
|
|
|
2006-08-04 02:48:20 +00:00
|
|
|
$new_string = '';
|
|
|
|
foreach ($matches[1] as $class_names) {
|
|
|
|
$new_string .= $class_names . ' ';
|
|
|
|
}
|
|
|
|
$new_string = rtrim($new_string);
|
|
|
|
|
2006-08-05 00:30:31 +00:00
|
|
|
return $new_string;
|
2006-08-04 02:48:20 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|