HTML.php 1.8 KB

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