You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

  1. <?php
  2. /**
  3. * Allows Microformats2 classes but rejects any others
  4. */
  5. class HTMLPurifier_AttrDef_HTML_Microformats2 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. $ret = array();
  32. foreach ($tokens as $token) {
  33. if(preg_match('/^([hpue]|dt)-[a-z\-]+$/', $token)) {
  34. $ret[] = $token;
  35. }
  36. }
  37. return $ret;
  38. }
  39. }