HTMLPurifier.kses.php 923 B

12345678910111213141516171819202122232425262728293031
  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. {
  9. $config = HTMLPurifier_Config::createDefault();
  10. $allowed_elements = array();
  11. $allowed_attributes = array();
  12. foreach ($allowed_html as $element => $attributes) {
  13. $allowed_elements[$element] = true;
  14. foreach ($attributes as $attribute => $x) {
  15. $allowed_attributes["$element.$attribute"] = true;
  16. }
  17. }
  18. $config->set('HTML.AllowedElements', $allowed_elements);
  19. $config->set('HTML.AllowedAttributes', $allowed_attributes);
  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