Passed
Push — 1.11.x ( bce6cd...c146d9 )
by Angel Fernando Quiroz
12:25
created

main/inc/lib/formvalidator/Rule/HTML.php (1 issue)

1
<?php
2
/* For licensing terms, see /license.txt */
3
4
require_once api_get_path(SYS_PATH).'main/inc/lib/kses-0.2.2/kses.php';
5
6
/**
7
 * QuickForm rule to check a html.
8
 */
9
class HTML_QuickForm_Rule_HTML extends HTML_QuickForm_Rule
10
{
11
    /**
12
     * Function to validate HTML.
13
     *
14
     * @see HTML_QuickForm_Rule
15
     *
16
     * @param string $html
17
     *
18
     * @return bool True if html is valid
19
     */
20
    public function validate($html, $mode = NO_HTML)
21
    {
22
        $allowed_tags = self::get_allowed_tags($mode, $fullpage);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fullpage seems to be never defined.
Loading history...
23
        $cleaned_html = kses($html, $allowed_tags);
24
25
        return $html == $cleaned_html;
26
    }
27
28
    /**
29
     * Get allowed tags.
30
     *
31
     * @param int $mode NO_HTML, STUDENT_HTML, TEACHER_HTML,
32
     *                  STUDENT_HTML_FULLPAGE or TEACHER_HTML_FULLPAGE
33
     */
34
    public static function get_allowed_tags($mode)
35
    {
36
        // Include the allowed tags.
37
        //include __DIR__.'/allowed_tags.inc.php';
38
        global $allowed_tags_student, $allowed_tags_student_full_page, $allowed_tags_teacher, $allowed_tags_teacher_full_page;
39
        switch ($mode) {
40
            case NO_HTML:
41
                return [];
42
                break;
43
            case STUDENT_HTML:
44
                return $allowed_tags_student;
45
                break;
46
            case STUDENT_HTML_FULLPAGE:
47
                return array_merge($allowed_tags_student, $allowed_tags_student_full_page);
48
                break;
49
            case TEACHER_HTML:
50
                return $allowed_tags_teacher;
51
                break;
52
            case TEACHER_HTML_FULLPAGE:
53
                return array_merge($allowed_tags_teacher, $allowed_tags_teacher_full_page);
54
                break;
55
            default:
56
                return [];
57
                break;
58
        }
59
    }
60
}
61