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;
|
|
|
18 |
|
|
|
19 |
use stdClass;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* The base class for a reporter
|
|
|
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 brickfield_accessibility_reporter {
|
|
|
29 |
/** @var object The current document's DOMDocument */
|
|
|
30 |
public $dom;
|
|
|
31 |
|
|
|
32 |
/** @var object The current brickfieldaccessibilitycss object */
|
|
|
33 |
public $css;
|
|
|
34 |
|
|
|
35 |
/** @var array An array of test names and the translation for the problems with it */
|
|
|
36 |
public $translation;
|
|
|
37 |
|
|
|
38 |
/** @var array A collection of ReportItem objects */
|
|
|
39 |
public $report;
|
|
|
40 |
|
|
|
41 |
/** @var array The path to the current document */
|
|
|
42 |
public $path;
|
|
|
43 |
|
|
|
44 |
/** @var object Additional options for this reporter */
|
|
|
45 |
public $options;
|
|
|
46 |
|
|
|
47 |
/** @var array An array of attributes to search for to turn into absolute paths rather than relative paths */
|
|
|
48 |
public $absoluteattributes = ['src', 'href'];
|
|
|
49 |
|
|
|
50 |
/** @var object|null A guideline object. */
|
|
|
51 |
public ?object $guideline = null;
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* The class constructor
|
|
|
55 |
* @param object $dom The current DOMDocument object
|
|
|
56 |
* @param object $css The current brickfield CSS object
|
|
|
57 |
* @param object $guideline The current guideline object
|
|
|
58 |
* @param string $path The current path
|
|
|
59 |
*/
|
|
|
60 |
public function __construct(&$dom, &$css, &$guideline, $path = '') {
|
|
|
61 |
$this->dom = &$dom;
|
|
|
62 |
$this->css = &$css;
|
|
|
63 |
$this->path = $path;
|
|
|
64 |
$this->options = new stdClass;
|
|
|
65 |
$this->guideline = &$guideline;
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
/**
|
|
|
69 |
* Sets options for the reporter
|
|
|
70 |
* @param array $options an array of options
|
|
|
71 |
*/
|
|
|
72 |
public function set_options(array $options) {
|
|
|
73 |
foreach ($options as $key => $value) {
|
|
|
74 |
$this->options->$key = $value;
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
/**
|
|
|
79 |
* Sets the absolute path for an element
|
|
|
80 |
* @param object $element A DOMElement object to turn into an absolute path
|
|
|
81 |
*/
|
|
|
82 |
public function set_absolute_path(&$element) {
|
|
|
83 |
$attr = false;
|
|
|
84 |
foreach ($this->absoluteattributes as $attribute) {
|
|
|
85 |
if ($element->hasAttribute($attribute)) {
|
|
|
86 |
$attr = $attribute;
|
|
|
87 |
}
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
if ($attr) {
|
|
|
91 |
$item = $element->getAttribute($attr);
|
|
|
92 |
// We are ignoring items with absolute URLs.
|
|
|
93 |
if (strpos($item, '://') === false) {
|
|
|
94 |
$item = implode('/', $this->path) . ltrim($item, '/');
|
|
|
95 |
$element->setAttribute($attr, $item);
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
}
|
|
|
99 |
}
|