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\checks;
18
 
19
use tool_brickfield\local\htmlchecker\brickfield_accessibility;
20
use tool_brickfield\local\htmlchecker\common\brickfield_accessibility_test;
21
use tool_brickfield\manager;
22
 
23
/**
24
 * Brickfield accessibility HTML checker library.
25
 *
26
 * Suspicious link text.
27
 * 'a' (anchor) element cannot contain any of the following text, such as (English): "click here".
28
 *
29
 * @package    tool_brickfield
30
 * @copyright  2020 onward: Brickfield Education Labs, www.brickfield.ie
31
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 */
33
class a_suspicious_link_text extends brickfield_accessibility_test {
34
    /**
35
     * @var int The default severity code for this test.
36
     */
37
    public $defaultseverity = brickfield_accessibility::BA_TEST_SEVERE;
38
 
39
    /**
40
     * The main check function. This is called by the parent class to actually check content
41
     */
42
    public function check(): void {
43
        // Need to process all enabled lang versions of invalidlinkphrases.
44
        $badtext = brickfield_accessibility_test::get_all_invalidlinkphrases();
45
 
46
        foreach ($this->get_all_elements('a') as $a) {
47
            if (in_array(strtolower(trim($a->nodeValue)), $badtext) || $a->nodeValue == $a->getAttribute('href')) {
48
                // If the link text matches invalid phrases.
49
                $this->add_report($a);
50
            } else if (brickfield_accessibility::match_urls($a->nodeValue, $a->getAttribute('href'))) {
51
                // If the link text is the same as the link URL.
52
                $this->add_report($a);
53
            }
54
        }
55
    }
56
 
57
    /**
58
     * Return all 'a' elements.
59
     *
60
     * @return array
61
     */
62
    public function search(): array {
63
        $data = [];
64
        foreach ($this->get_all_elements('a') as $a) {
65
            $data[] = $a;
66
        }
67
 
68
        return $data;
69
    }
70
}