Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace tool_brickfield\local\htmlchecker\common;
18
 
19
use tool_brickfield\local\htmlchecker\brickfield_accessibility;
20
 
21
/**
22
 * This is a helper class which organizes all the HTML tags into groups for finding.
23
 *
24
 * @package    tool_brickfield
25
 * @copyright  2020 onward: Brickfield Education Labs, www.brickfield.ie
26
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 */
28
class html_elements {
29
    /**
30
     * @var array An array of HTML tag names and their attributes
31
     */
32
    public static $htmlelements = [
33
        'img'        => ['text' => false],
34
        'p'          => ['text' => true],
35
        'pre'        => ['text' => true],
36
        'span'       => ['text' => true],
37
        'div'        => ['text' => true],
38
        'applet'     => ['text' => false],
39
        'embed'      => ['text' => false, 'media' => true],
40
        'object'     => ['text' => false, 'media' => true],
41
        'area'       => ['imagemap' => true],
42
        'b'          => ['text' => true, 'non-emphasis' => true],
43
        'i'          => ['text' => true, 'non-emphasis' => true],
44
        'font'       => ['text' => true, 'font' => true],
45
        'h1'         => ['text' => true, 'header' => true],
46
        'h2'         => ['text' => true, 'header' => true],
47
        'h3'         => ['text' => true, 'header' => true],
48
        'h4'         => ['text' => true, 'header' => true],
49
        'h5'         => ['text' => true, 'header' => true],
50
        'h6'         => ['text' => true, 'header' => true],
51
        'ul'         => ['text' => true, 'list' => true],
52
        'dl'         => ['text' => true, 'list' => true],
53
        'ol'         => ['text' => true, 'list' => true],
54
        'blockquote' => ['text' => true, 'quote' => true],
55
        'q'          => ['text' => true, 'quote' => true],
56
        'acronym'    => ['acronym' => true, 'text' => true],
57
        'abbr'       => ['acronym' => true, 'text' => true],
58
        'input'      => ['form' => true],
59
        'select'     => ['form' => true],
60
        'textarea'   => ['form' => true],
61
        brickfield_accessibility::BA_ERROR_TAG => ['text' => true],
62
    ];
63
 
64
    /**
65
     * Retrieves elements by an option.
66
     * @param string $option The option to search fore
67
     * @param bool $value Whether the option should be true or false
68
     * @return array An array of HTML tag names
69
     */
70
    public static function get_elements_by_option(string $option, bool $value = true): array {
71
        $results = [];
72
        foreach (self::$htmlelements as $k => $element) {
73
            if (isset($element[$option]) && ($element[$option] == $value)) {
74
                $results[] = $k;
75
            }
76
        }
77
        return $results;
78
    }
79
}