HTML.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2005 Dokeos S.A.
  6. Copyright (c) Bart Mollet, Hogeschool Gent
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  15. Mail: info@dokeos.com
  16. ==============================================================================
  17. */
  18. require_once ('HTML/QuickForm/Rule.php');
  19. require_once (api_get_path(SYS_PATH).'main/inc/lib/kses-0.2.2/kses.php');
  20. /**
  21. * QuickForm rule to check a html
  22. */
  23. class HTML_QuickForm_Rule_HTML extends HTML_QuickForm_Rule
  24. {
  25. /**
  26. * Function to validate HTML
  27. * @see HTML_QuickForm_Rule
  28. * @param string $html
  29. * @return boolean True if html is valid
  30. */
  31. function validate($html, $mode = NO_HTML)
  32. {
  33. $allowed_tags = $this->get_allowed_tags ($mode,$fullpage);
  34. $cleaned_html = kses($html, $allowed_tags);
  35. return $html == $cleaned_html;
  36. }
  37. /**
  38. * Get allowed tags
  39. * @param int $mode NO_HTML, STUDENT_HTML, TEACHER_HTML,
  40. * STUDENT_HTML_FULLPAGE or TEACHER_HTML_FULLPAGE
  41. * @param boolean $fullpage If true, the allowed tags for full-page editing
  42. * are returned.
  43. */
  44. function get_allowed_tags($mode)
  45. {
  46. //Include the allowed tags
  47. include(dirname(__FILE__).'/allowed_tags.inc.php');
  48. switch($mode)
  49. {
  50. case NO_HTML:
  51. return array();
  52. break;
  53. case STUDENT_HTML:
  54. return $allowed_tags_student;
  55. break;
  56. case STUDENT_HTML_FULLPAGE:
  57. return array_merge($allowed_tags_student,$allowed_tags_student_full_page);
  58. break;
  59. case TEACHER_HTML:
  60. return $allowed_tags_teacher;
  61. break;
  62. case TEACHER_HTML_FULLPAGE:
  63. return array_merge($allowed_tags_teacher,$allowed_tags_teacher_full_page);
  64. break;
  65. default:
  66. return array();
  67. break;
  68. }
  69. }
  70. }
  71. ?>