HTML.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. //require_once 'HTML/QuickForm/Rule.php';
  4. //require_once api_get_path(SYS_PATH).'main/inc/lib/kses-0.2.2/kses.php';
  5. /**
  6. * QuickForm rule to check a html
  7. */
  8. class HTML_QuickForm_Rule_HTML extends HTML_QuickForm_Rule
  9. {
  10. /**
  11. * Function to validate HTML
  12. * @see HTML_QuickForm_Rule
  13. * @param string $html
  14. * @return boolean True if html is valid
  15. */
  16. function validate($html, $mode = NO_HTML)
  17. {
  18. $allowed_tags = self::get_allowed_tags ($mode, $fullpage);
  19. //$cleaned_html = kses($html, $allowed_tags);
  20. //return $html == $cleaned_html;
  21. return true;
  22. }
  23. /**
  24. * Get allowed tags
  25. * @param int $mode NO_HTML, STUDENT_HTML, TEACHER_HTML,
  26. * STUDENT_HTML_FULLPAGE or TEACHER_HTML_FULLPAGE
  27. * @param boolean $fullpage If true, the allowed tags for full-page editing
  28. * are returned.
  29. */
  30. static function get_allowed_tags($mode)
  31. {
  32. // Include the allowed tags.
  33. //include(dirname(__FILE__).'/allowed_tags.inc.php');
  34. global $allowed_tags_student, $allowed_tags_student_full_page, $allowed_tags_teacher, $allowed_tags_teacher_full_page;
  35. switch($mode)
  36. {
  37. case NO_HTML:
  38. return array();
  39. break;
  40. case STUDENT_HTML:
  41. return $allowed_tags_student;
  42. break;
  43. case STUDENT_HTML_FULLPAGE:
  44. return array_merge($allowed_tags_student, $allowed_tags_student_full_page);
  45. break;
  46. case TEACHER_HTML:
  47. return $allowed_tags_teacher;
  48. break;
  49. case TEACHER_HTML_FULLPAGE:
  50. return array_merge($allowed_tags_teacher, $allowed_tags_teacher_full_page);
  51. break;
  52. default:
  53. return array();
  54. break;
  55. }
  56. }
  57. }