您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

49 行
1.5KB

  1. <?php
  2. /**
  3. * Implements special behavior for class attribute (normally NMTOKENS)
  4. */
  5. class HTMLPurifier_AttrDef_HTML_Class extends HTMLPurifier_AttrDef_HTML_Nmtokens
  6. {
  7. /**
  8. * @param string $string
  9. * @param HTMLPurifier_Config $config
  10. * @param HTMLPurifier_Context $context
  11. * @return bool|string
  12. */
  13. protected function split($string, $config, $context)
  14. {
  15. // really, this twiddle should be lazy loaded
  16. $name = $config->getDefinition('HTML')->doctype->name;
  17. if ($name == "XHTML 1.1" || $name == "XHTML 2.0") {
  18. return parent::split($string, $config, $context);
  19. } else {
  20. return preg_split('/\s+/', $string);
  21. }
  22. }
  23. /**
  24. * @param array $tokens
  25. * @param HTMLPurifier_Config $config
  26. * @param HTMLPurifier_Context $context
  27. * @return array
  28. */
  29. protected function filter($tokens, $config, $context)
  30. {
  31. $allowed = $config->get('Attr.AllowedClasses');
  32. $forbidden = $config->get('Attr.ForbiddenClasses');
  33. $ret = array();
  34. foreach ($tokens as $token) {
  35. if (($allowed === null || isset($allowed[$token])) &&
  36. !isset($forbidden[$token]) &&
  37. // We need this O(n) check because of PHP's array
  38. // implementation that casts -0 to 0.
  39. !in_array($token, $ret, true)
  40. ) {
  41. $ret[] = $token;
  42. }
  43. }
  44. return $ret;
  45. }
  46. }