HTMLPurifier.kses.php 955 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /**
  3. * @file
  4. * Emulation layer for code that used kses(), substituting in HTML Purifier.
  5. */
  6. require_once dirname(__FILE__) . '/HTMLPurifier.auto.php';
  7. function kses($string, $allowed_html, $allowed_protocols = null) {
  8. $config = HTMLPurifier_Config::createDefault();
  9. $allowed_elements = array();
  10. $allowed_attributes = array();
  11. foreach ($allowed_html as $element => $attributes) {
  12. $allowed_elements[$element] = true;
  13. foreach ($attributes as $attribute => $x) {
  14. $allowed_attributes["$element.$attribute"] = true;
  15. }
  16. }
  17. $config->set('HTML.AllowedElements', $allowed_elements);
  18. $config->set('HTML.AllowedAttributes', $allowed_attributes);
  19. $allowed_schemes = array();
  20. if ($allowed_protocols !== null) {
  21. $config->set('URI.AllowedSchemes', $allowed_protocols);
  22. }
  23. $purifier = new HTMLPurifier($config);
  24. return $purifier->purify($string);
  25. }
  26. // vim: et sw=4 sts=4