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.

42 lines
1.1 KiB

  1. <?php
  2. namespace p3k\XRay\Formats;
  3. /**
  4. * Allows Microformats2 classes but rejects any others
  5. */
  6. class HTMLPurifier_AttrDef_HTML_Microformats2 extends \HTMLPurifier_AttrDef_HTML_Nmtokens
  7. {
  8. /**
  9. * @param string $string
  10. * @param HTMLPurifier_Config $config
  11. * @param HTMLPurifier_Context $context
  12. * @return bool|string
  13. */
  14. protected function split($string, $config, $context)
  15. {
  16. // really, this twiddle should be lazy loaded
  17. $name = $config->getDefinition('HTML')->doctype->name;
  18. if ($name == "XHTML 1.1" || $name == "XHTML 2.0") {
  19. return parent::split($string, $config, $context);
  20. } else {
  21. return preg_split('/\s+/', $string);
  22. }
  23. }
  24. /**
  25. * @param array $tokens
  26. * @param HTMLPurifier_Config $config
  27. * @param HTMLPurifier_Context $context
  28. * @return array
  29. */
  30. protected function filter($tokens, $config, $context)
  31. {
  32. $ret = array();
  33. foreach ($tokens as $token) {
  34. if(preg_match('/^([hpue]|dt)-[a-z\-]+$/', $token)) {
  35. $ret[] = $token;
  36. }
  37. }
  38. return $ret;
  39. }
  40. }