HTML.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. }
  22. /**
  23. * Get allowed tags
  24. * @param int $mode NO_HTML, STUDENT_HTML, TEACHER_HTML,
  25. * STUDENT_HTML_FULLPAGE or TEACHER_HTML_FULLPAGE
  26. * @param boolean $fullpage If true, the allowed tags for full-page editing
  27. * are returned.
  28. */
  29. static function get_allowed_tags($mode)
  30. {
  31. // Include the allowed tags.
  32. //include(dirname(__FILE__).'/allowed_tags.inc.php');
  33. global $allowed_tags_student, $allowed_tags_student_full_page, $allowed_tags_teacher, $allowed_tags_teacher_full_page;
  34. switch($mode)
  35. {
  36. case NO_HTML:
  37. return array();
  38. break;
  39. case STUDENT_HTML:
  40. return $allowed_tags_student;
  41. break;
  42. case STUDENT_HTML_FULLPAGE:
  43. return array_merge($allowed_tags_student, $allowed_tags_student_full_page);
  44. break;
  45. case TEACHER_HTML:
  46. return $allowed_tags_teacher;
  47. break;
  48. case TEACHER_HTML_FULLPAGE:
  49. return array_merge($allowed_tags_teacher, $allowed_tags_teacher_full_page);
  50. break;
  51. default:
  52. return array();
  53. break;
  54. }
  55. }
  56. }