You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.9 KiB
63 lines
1.9 KiB
![]()
19 years ago
|
<?php
|
||
![]()
15 years ago
|
/* For licensing terms, see /license.txt */
|
||
![]()
16 years ago
|
|
||
![]()
15 years ago
|
require_once api_get_path(SYS_PATH).'main/inc/lib/kses-0.2.2/kses.php';
|
||
![]()
16 years ago
|
|
||
![]()
19 years ago
|
/**
|
||
![]()
8 years ago
|
* QuickForm rule to check a html.
|
||
![]()
19 years ago
|
*/
|
||
|
class HTML_QuickForm_Rule_HTML extends HTML_QuickForm_Rule
|
||
|
{
|
||
![]()
15 years ago
|
/**
|
||
![]()
8 years ago
|
* Function to validate HTML.
|
||
|
*
|
||
![]()
15 years ago
|
* @see HTML_QuickForm_Rule
|
||
![]()
8 years ago
|
*
|
||
![]()
15 years ago
|
* @param string $html
|
||
![]()
8 years ago
|
*
|
||
|
* @return bool True if html is valid
|
||
![]()
15 years ago
|
*/
|
||
![]()
8 years ago
|
public function validate($html, $mode = NO_HTML)
|
||
![]()
15 years ago
|
{
|
||
![]()
8 years ago
|
$allowed_tags = self::get_allowed_tags($mode, $fullpage);
|
||
![]()
15 years ago
|
$cleaned_html = kses($html, $allowed_tags);
|
||
![]()
8 years ago
|
|
||
![]()
15 years ago
|
return $html == $cleaned_html;
|
||
|
}
|
||
|
|
||
|
/**
|
||
![]()
8 years ago
|
* Get allowed tags.
|
||
|
*
|
||
|
* @param int $mode NO_HTML, STUDENT_HTML, TEACHER_HTML,
|
||
|
* STUDENT_HTML_FULLPAGE or TEACHER_HTML_FULLPAGE
|
||
|
* @param bool $fullpage if true, the allowed tags for full-page editing
|
||
|
* are returned
|
||
![]()
15 years ago
|
*/
|
||
![]()
8 years ago
|
public static function get_allowed_tags($mode)
|
||
![]()
15 years ago
|
{
|
||
|
// Include the allowed tags.
|
||
![]()
9 years ago
|
//include __DIR__.'/allowed_tags.inc.php';
|
||
![]()
15 years ago
|
global $allowed_tags_student, $allowed_tags_student_full_page, $allowed_tags_teacher, $allowed_tags_teacher_full_page;
|
||
![]()
8 years ago
|
switch ($mode) {
|
||
![]()
15 years ago
|
case NO_HTML:
|
||
![]()
8 years ago
|
return [];
|
||
![]()
15 years ago
|
break;
|
||
|
case STUDENT_HTML:
|
||
|
return $allowed_tags_student;
|
||
|
break;
|
||
|
case STUDENT_HTML_FULLPAGE:
|
||
![]()
15 years ago
|
return array_merge($allowed_tags_student, $allowed_tags_student_full_page);
|
||
![]()
15 years ago
|
break;
|
||
|
case TEACHER_HTML:
|
||
|
return $allowed_tags_teacher;
|
||
|
break;
|
||
|
case TEACHER_HTML_FULLPAGE:
|
||
![]()
15 years ago
|
return array_merge($allowed_tags_teacher, $allowed_tags_teacher_full_page);
|
||
![]()
15 years ago
|
break;
|
||
|
default:
|
||
![]()
8 years ago
|
return [];
|
||
![]()
15 years ago
|
break;
|
||
|
}
|
||
|
}
|
||
![]()
19 years ago
|
}
|