-
Notifications
You must be signed in to change notification settings - Fork 34
/
block_accessibility.php
364 lines (306 loc) · 13.7 KB
/
block_accessibility.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Define the accessibility block's class
*
* @package block_accessibility
* @author Mark Johnson <[email protected]>
* @copyright 2010 Tauntons College, UK
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/blocks/accessibility/lib.php');
/**
* accessibility Block's class
*/
class block_accessibility extends block_base {
/**
* URL of the JavaScript file.
*/
const JS_URL = '/blocks/accessibility/module.js';
/**
* URL of the CSS declaration file.
*/
const CSS_URL = '/blocks/accessibility/userstyles.php';
/**
* URL of the fontsize file.
*/
const FONTSIZE_URL = '/blocks/accessibility/changesize.php';
/**
* URL of the colour change file.
*/
const COLOUR_URL = '/blocks/accessibility/changecolour.php';
/**
* URL of the database file.
*/
const DB_URL = '/blocks/accessibility/database.php';
/**
* Set the title and include the stylesheet
*
* We need to include the stylesheet here rather than in {@see get_content()} since get_content
* is sometimes called after $OUTPUT->heading(), e.g. such as /user/index.php where the middle
* region is hard-coded.
* However, /admin/plugins.php calls init() for each plugin after $OUTPUT->heading(), so the
* sheet is not included at all on that page.
*/
public function init() {
$this->title = get_string('pluginname', 'block_accessibility');
}
/**
* Called after init(). Here we have instance id so we can use config for specific instance
* The function will include CSS declarations into Moodle Page
* CSS declarations will be generated according to user settings and instance configuration
*
*/
public function specialization() {
$instanceid = $this->instance->id;
if (!$this->page->requires->is_head_done()) {
// Link default/saved settings to a page.
// Each block instance has it's own configuration form, so we need instance id.
$cssurl = new moodle_url(self::CSS_URL, ["instance_id" => $instanceid]);
$this->page->requires->css($cssurl);
}
}
/**
* instance_allow_multiple explicitly tells there cannot be multiple
* block instance on the same page
*
*/
public function instance_allow_multiple() {
return false;
}
/**
* Set where the block should be allowed to be added
*
* @return array
*/
public function applicable_formats() {
return array('all' => true);
}
/**
* Generate the contents for the block
*
* @return object Block contents and footer
*/
public function get_content() {
global $USER;
global $FULLME;
global $DB;
// Until Issue #63 is fixed, we don't want to display block for unauthenticated users.
if (!isloggedin()) {
return null;
}
if ($this->content !== null) {
return $this->content;
}
// Get the current page url (redirection after action when no Javascript).
$params = array('redirect' => $FULLME);
// Set block services paths: changesize.php, changecolour.php and database.php.
$sizeurl = new moodle_url(self::FONTSIZE_URL, $params);
$coloururl = new moodle_url(self::COLOUR_URL, $params);
$params['op'] = 'save';
$params['size'] = true;
$params['scheme'] = true;
$dburl = new moodle_url(self::DB_URL, $params);
// Initialization of increase_font, decrease_font and save button.
$incattrs = array(
'title' => get_string('inctext', 'block_accessibility'),
'id' => "block_accessibility_inc",
'href' => $sizeurl->out(false, array('op' => 'inc'))
);
$decattrs = array(
'title' => get_string('dectext', 'block_accessibility'),
'id' => "block_accessibility_dec",
'href' => $sizeurl->out(false, array('op' => 'dec'))
);
$saveattrs = array(
'title' => get_string('save', 'block_accessibility'),
'id' => "block_accessibility_save",
'href' => $dburl->out(false)
);
// Initialization of reset button.
$resetattrs = array(
'id' => 'block_accessibility_reset',
'title' => get_string('resettext', 'block_accessibility'),
'href' => $sizeurl->out(false, array('op' => 'reset'))
);
// If any of increase/decrease buttons reached maximum size, disable it.
if (isset($USER->fontsize)) {
if ($USER->fontsize == MIN_FONTSIZE) {
$decattrs['class'] = 'disabled';
unset($decattrs['href']);
}
if ($USER->fontsize == MAX_FONTSIZE) {
$incattrs['class'] = 'disabled';
unset($incattrs['href']);
}
} else {
// Or disable reset button.
$resetattrs['class'] = 'disabled';
}
// Initialization of scheme profiles buttons.
$c1attrs = array(
'title' => get_string('col1text', 'block_accessibility'),
'id' => 'block_accessibility_colour1',
'href' => $coloururl->out(false, array('scheme' => 1))
);
$c2attrs = array(
'title' => get_string('col2text', 'block_accessibility'),
'id' => 'block_accessibility_colour2',
'href' => $coloururl->out(false, array('scheme' => 2))
);
$c3attrs = array(
'title' => get_string('col3text', 'block_accessibility'),
'id' => 'block_accessibility_colour3',
'href' => $coloururl->out(false, array('scheme' => 3))
);
$c4attrs = array(
'title' => get_string('col4text', 'block_accessibility'),
'id' => 'block_accessibility_colour4',
'href' => $coloururl->out(false, array('scheme' => 4))
);
if (!isset($USER->colourscheme)) {
$c1attrs['class'] = 'disabled';
}
// The display:inline-block CSS declaration is not applied to block's buttons because IE7 doesn't support, float is
// used instead for IE7 only.
$clearfix = '';
if (preg_match('/(?i)msie [1-7]/', $_SERVER['HTTP_USER_AGENT'])) {
$clearfix = html_writer::tag('div', '', array('style' => 'clear:both')); // Required for IE7.
}
// Render block HTML.
$content = '';
$strchar = get_string('char', 'block_accessibility');
$resetchar = "R";
$divattrs = array('id' => 'accessibility_controls', 'class' => 'content');
$listattrs = array('id' => 'block_accessibility_textresize', 'class' => 'button_row');
$content .= html_writer::start_tag('div', $divattrs);
$content .= html_writer::start_tag('ul', $listattrs);
$content .= html_writer::start_tag('li', array('class' => 'access-button'));
$content .= html_writer::tag('a', $strchar . '-', $decattrs);
$content .= html_writer::end_tag('li');
$content .= html_writer::start_tag('li', array('class' => 'access-button'));
$content .= html_writer::tag('a', $strchar, $resetattrs);
$content .= html_writer::end_tag('li');
$content .= html_writer::start_tag('li', array('class' => 'access-button'));
$content .= html_writer::tag('a', $strchar . '+', $incattrs);
$content .= html_writer::end_tag('li');
$content .= html_writer::start_tag('li', array('class' => 'access-button'));
$content .= html_writer::tag('a', ' ', $saveattrs);
$content .= html_writer::end_tag('li');
$content .= html_writer::end_tag('ul');
$content .= $clearfix;
// Colour change buttons.
$content .= html_writer::start_tag('ul', array('id' => 'block_accessibility_changecolour'));
$content .= html_writer::start_tag('li', array('class' => 'access-button'));
$content .= html_writer::tag('a', $resetchar, $c1attrs);
$content .= html_writer::end_tag('li');
$content .= html_writer::start_tag('li', array('class' => 'access-button'));
$content .= html_writer::tag('a', $strchar, $c2attrs);
$content .= html_writer::end_tag('li');
$content .= html_writer::start_tag('li', array('class' => 'access-button'));
$content .= html_writer::tag('a', $strchar, $c3attrs);
$content .= html_writer::end_tag('li');
$content .= html_writer::start_tag('li', array('class' => 'access-button'));
$content .= html_writer::tag('a', $strchar, $c4attrs);
$content .= html_writer::end_tag('li');
$content .= html_writer::end_tag('ul');
$content .= $clearfix;
// Display "settings saved" or etc.
if (isset($USER->accessabilitymsg)) {
$message = $USER->accessabilitymsg;
unset($USER->accessabilitymsg);
} else {
$message = '';
}
$messageattrs = array('id' => 'block_accessibility_message', 'class' => 'clearfix');
$content .= html_writer::tag('div', $message, $messageattrs);
// Data to pass to module.js.
$jsdata['autoload_atbar'] = false;
$jsdata['instance_id'] = $this->instance->id;
// Render ATBar.
$showatbar = DEFAULT_SHOWATBAR;
if (isset($this->config->showATbar)) {
$showatbar = $this->config->showATbar;
}
if ($showatbar) {
// Load database record for a current user.
$options = $DB->get_record('block_accessibility', array('userid' => $USER->id));
// Initialize ATBar.
$checkboxattrs = array(
'type' => 'checkbox',
'value' => 1,
'id' => 'atbar_auto',
'name' => 'atbar_auto',
'class' => 'atbar_control',
);
$labelattrs = array(
'for' => 'atbar_auto',
'class' => 'atbar_control'
);
if ($options && $options->autoload_atbar) {
$checkboxattrs['checked'] = 'checked';
$jsdata['autoload_atbar'] = true;
}
// ATbar launch button (if javascript is enabled).
$launchattrs = array(
'type' => 'button',
'value' => get_string('launchtoolbar', 'block_accessibility'),
'id' => 'block_accessibility_launchtoolbar',
'class' => 'atbar_control access-button'
);
// Render ATBar.
$content .= html_writer::empty_tag('input', $launchattrs);
$spanattrs = array('class' => 'atbar-always');
$content .= html_writer::start_tag('span', $spanattrs);
$content .= html_writer::empty_tag('input', $checkboxattrs);
$strlaunch = get_string('autolaunch', 'block_accessibility');
$content .= html_writer::tag('label', $strlaunch, $labelattrs);
$content .= html_writer::end_tag('span');
}
$content .= html_writer::end_tag('div');
// Loader icon.
$spanattrs = array('id' => 'loader-icon');
$content .= html_writer::start_tag('span', $spanattrs);
$content .= html_writer::end_tag('span');
$content .= $clearfix;
$this->content = new stdClass;
$this->content->footer = '';
$this->content->text = $content;
// Keep in mind that dynamic AJAX mode cannot work properly with IE <= 8 (for now), so javascript will not even be loaded.
if (!preg_match('/(?i)msie [1-8]/', $_SERVER['HTTP_USER_AGENT'])) {
// Language strings to pass to module.js.
$this->page->requires->string_for_js('saved', 'block_accessibility');
$this->page->requires->string_for_js('jsnosave', 'block_accessibility');
$this->page->requires->string_for_js('reset', 'block_accessibility');
$this->page->requires->string_for_js('jsnosizereset', 'block_accessibility');
$this->page->requires->string_for_js('jsnocolourreset', 'block_accessibility');
$this->page->requires->string_for_js('jsnosize', 'block_accessibility');
$this->page->requires->string_for_js('jsnocolour', 'block_accessibility');
$this->page->requires->string_for_js('jsnosizereset', 'block_accessibility');
$this->page->requires->string_for_js('jsnotloggedin', 'block_accessibility');
$this->page->requires->string_for_js('launchtoolbar', 'block_accessibility');
$jsmodule = array(
'name' => 'block_accessibility',
'fullpath' => self::JS_URL,
'requires' => array('base', 'node', 'stylesheet')
);
// Include js script and pass the arguments.
$this->page->requires->js_init_call('M.block_accessibility.init', $jsdata, false, $jsmodule);
}
return $this->content;
}
}