-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcore_renderer_toolbox.php
3327 lines (2959 loc) · 128 KB
/
core_renderer_toolbox.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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?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/>.
/**
* Trait for core renderer.
*
* @package theme_adaptable
* @copyright 2015-2019 Jeremy Hopkins (Coventry University)
* @copyright 2015-2019 Fernando Acedo (3-bits.com)
* @copyright 2017-2019 Manoj Solanki (Coventry University)
* @copyright 2021 G J Barnard
* {@link https://moodle.org/user/profile.php?id=442195}
* {@link https://gjbarnard.co.uk}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
namespace theme_adaptable\output;
use context_course;
use core\output\action_link;
use core\output\custom_menu_item;
use core\output\html_writer;
use core\output\pix_icon;
use core\url;
use core_block\output\block_contents;
use custom_menu as core_custom_menu;
use navigation_node;
use stdClass;
/**
* Trait for core and core maintenance renderers.
*/
trait core_renderer_toolbox {
/** @var custom_menu_item language The language menu if created */
protected $language = null;
/**
* Returns HTML attributes to use within the body tag. This includes an ID and classes.
*
* @since Moodle 2.5.1 2.6
* @param string|array $additionalclasses Any additional classes to give the body tag,
* @return string
*/
public function body_attributes($additionalclasses = []) {
if (\core_useragent::is_safari()) {
if (is_array($additionalclasses)) {
$additionalclasses[] = 'safari';
} else {
$additionalclasses .= ' safari';
}
}
return parent::body_attributes($additionalclasses);
}
/**
* Outputs the opening section of a box.
*
* @param string $classes A space-separated list of CSS classes
* @param string $id An optional ID
* @param array $attributes An array of other
* attributes to give the box.
* @return string the HTML to output.
*/
public function box_start($classes = 'generalbox', $id = null, $attributes = []) {
$this->opencontainers->push('box', html_writer::end_tag('div'));
$attributes['id'] = $id;
$attributes['class'] = 'box ' . \renderer_base::prepare_classes($classes);
return html_writer::start_tag('div', $attributes);
}
/**
* Outputs a container.
*
* @param string $contents The contents of the box
* @param string $classes A space-separated list of CSS classes
* @param string $id An optional ID
* @param array $attributes Optional other attributes as array
* @return string the HTML to output.
*/
public function container($contents, $classes = null, $id = null, $attributes = []) {
// Manipulate the grader report.
if ((!is_null($classes)) && ($classes == 'gradeparent')) {
$contents = preg_replace('/<th class="(header|userfield)(.*?)>(.*?)<\/th>/is',
'<th class="$1$2><div class="d-flex">$3</div></th>', $contents);
}
return $this->container_start($classes, $id, $attributes) . $contents . $this->container_end();
}
/**
* Returns user profile menu items.
*
* returns array of objects suitable for adding to an action_menu as items.
*/
protected function user_profile_menu_items() {
global $CFG, $COURSE;
$retval = [];
/* False or theme setting name to first array param (not all links have settings).
Entry type: link, divider or user.
False or Moodle version number to second param (only some links check version).
URL for link in third param.
Link text in fourth parameter.
Icon in fifth param. */
$usermenuitems = [];
$usermenuitems[] = ['enablemy', 'link', false, new url('/my'), get_string('myhome'),
\theme_adaptable\toolbox::getfontawesomemarkup('dashboard', ['mr-1']), ];
$usermenuitems[] = ['enableprofile', 'link', false, new url('/user/profile.php'), get_string('viewprofile'),
\theme_adaptable\toolbox::getfontawesomemarkup('user', ['mr-1']), ];
$usermenuitems[] = ['enableeditprofile', 'link', false, new url('/user/edit.php'), get_string('editmyprofile'),
\theme_adaptable\toolbox::getfontawesomemarkup('cog', ['mr-1']), ];
$usermenuitems[] = ['enableaccesstool', 'link', false, new url('/local/accessibilitytool/manage.php'),
get_string('enableaccesstool', 'theme_adaptable'),
\theme_adaptable\toolbox::getfontawesomemarkup('low-vision', ['mr-1']), ];
$usermenuitems[] = ['enableprivatefiles', 'link', false, new url('/user/files.php'),
get_string('privatefiles', 'block_private_files'), \theme_adaptable\toolbox::getfontawesomemarkup('file', ['mr-1']), ];
if (\theme_adaptable\toolbox::kalturaplugininstalled()) {
$usermenuitems[] = [false, 'link', false, new url('/local/mymedia/mymedia.php'),
get_string('nav_mymedia', 'local_mymedia'), $this->pix_icon('my-media', '', 'local_mymedia'), ];
}
$usermenuitems[] = ['enablegrades', 'link', false, new url('/grade/report/overview/index.php'), get_string('grades'),
\theme_adaptable\toolbox::getfontawesomemarkup('list-alt', ['mr-1']), ];
$usermenuitems[] = ['enablebadges', 'link', false, new url('/badges/mybadges.php'), get_string('badges'),
\theme_adaptable\toolbox::getfontawesomemarkup('certificate', ['mr-1']), ];
$usermenuitems[] = ['enablepref', 'link', '2015051100', new url('/user/preferences.php'), get_string('preferences'),
\theme_adaptable\toolbox::getfontawesomemarkup('cog', ['mr-1']), ];
$usermenuitems[] = ['enablenote', 'link', false, new url('/message/edit.php'), get_string('notifications'),
\theme_adaptable\toolbox::getfontawesomemarkup('paper-plane', ['mr-1']), ];
$usermenuitems[] = [false, 'divider'];
$usermenuitems[] = ['enableblog', 'link', false, new url('/blog/index.php'), get_string('enableblog', 'theme_adaptable'),
\theme_adaptable\toolbox::getfontawesomemarkup('rss', ['mr-1']), ];
$usermenuitems[] = ['enableposts', 'link', false, new url('/mod/forum/user.php'),
get_string('enableposts', 'theme_adaptable'), \theme_adaptable\toolbox::getfontawesomemarkup('commenting', ['mr-1']), ];
$usermenuitems[] = ['enablefeed', 'link', false, new url('/report/myfeedback/index.php'),
get_string('enablefeed', 'theme_adaptable'), \theme_adaptable\toolbox::getfontawesomemarkup('bullhorn', ['mr-1']), ];
$usermenuitems[] = ['enablecalendar', 'link', false, new url('/calendar/view.php'),
get_string('pluginname', 'block_calendar_month'),
\theme_adaptable\toolbox::getfontawesomemarkup('calendar', ['mr-1']), ];
// Custom user menu items postion.
$usermenuitems[] = [false, 'user'];
// Return.
if (is_role_switched($COURSE->id)) {
$returnurl = $this->page->url->out_as_local_url(false);
$url = new url('/course/switchrole.php', ['id' => $COURSE->id, 'sesskey' => sesskey(),
'switchrole' => '0', 'returnurl' => $returnurl]);
$usermenuitems[] = [false, 'link', false, $url, get_string('switchrolereturn'),
\theme_adaptable\toolbox::getfontawesomemarkup('user-o', ['mr-1']), ];
} else {
$context = context_course::instance($COURSE->id);
if (has_capability('moodle/role:switchroles', $context)) {
$returnurl = $this->page->url->out_as_local_url(false);
$url = new url('/course/switchrole.php', ['id' => $COURSE->id, 'switchrole' => '-1', 'returnurl' => $returnurl]);
$usermenuitems[] = [false, 'link', false, $url, get_string('switchroleto'),
\theme_adaptable\toolbox::getfontawesomemarkup('user-o', ['mr-1']), ];
}
}
$usermenuitems[] = [false, 'link', false, new url('/login/logout.php', ['sesskey' => sesskey()]), get_string('logout'),
\theme_adaptable\toolbox::getfontawesomemarkup('sign-out', ['mr-1']), ];
foreach ($usermenuitems as $usermenuitem) {
switch($usermenuitem[1]) {
case 'link':
$additem = true;
// If theme setting is specified in array but not enabled in theme settings do not add to menu.
if (!empty($usermenuitem[0])) {
$usermenuitemname = $usermenuitem[0];
if (empty($this->page->theme->settings->$usermenuitemname)) {
$additem = false;
}
}
// If item requires version number and moodle is below that version to not add to menu.
if ($usermenuitem[2] && $CFG->version < $usermenuitem[2]) {
$additem = false;
}
if ($additem) {
$item = new stdClass;
$item->itemtype = 'link';
$item->url = $usermenuitem[3];
$item->title = $usermenuitem[5] . $usermenuitem[4];
$retval[] = $item;
}
break;
case 'divider':
$item = new stdClass;
$item->itemtype = 'divider';
$retval[] = $item;
break;
case 'user':
$customitems = $this->user_convert_text_to_menu_items($CFG->customusermenuitems);
if ($customitems[0]) {
$divider = new stdClass();
$divider->itemtype = 'divider';
$retval[] = $divider;
foreach ($customitems[1] as $item) {
$retval[] = $item;
}
$retval[] = $divider;
}
break;
}
}
return $retval;
}
/**
* Converts a string into a flat array of menu items, where each menu items is a
* stdClass with fields type, url, title.
*
* @param string $text the menu items definition
* @return array [hasitems - bool, items - array].
*/
protected function user_convert_text_to_menu_items($text) {
$hasitems = false;
$lines = explode("\n", $text);
$children = [];
foreach ($lines as $line) {
$line = trim($line);
$bits = explode('|', $line, 3);
$itemtype = 'link';
if (preg_match("/^#+$/", $line)) {
$itemtype = 'divider';
} else if (!array_key_exists(0, $bits) || empty($bits[0])) {
// Every item must have a name to be valid.
continue;
} else {
$bits[0] = ltrim($bits[0], '-');
}
// Create the child.
$child = new stdClass();
$child->itemtype = $itemtype;
if ($itemtype === 'divider') {
// Add the divider to the list of children and skip link processing.
$children[] = $child;
continue;
}
// Name processing.
$namebits = explode(',', $bits[0], 2);
if (count($namebits) == 2) {
$namebits[1] = $namebits[1] ?: 'core';
// Check the validity of the identifier part of the string.
if (clean_param($namebits[0], PARAM_STRINGID) !== '' && clean_param($namebits[1], PARAM_COMPONENT) !== '') {
// Treat this as a language string.
$child->title = get_string($namebits[0], $namebits[1]);
$child->titleidentifier = implode(',', $namebits);
}
}
if (empty($child->title)) {
// Use it as is, don't even clean it.
$child->title = $bits[0];
$child->titleidentifier = str_replace(" ", "-", $bits[0]);
}
// URL processing.
if (!array_key_exists(1, $bits) || empty($bits[1])) {
// Unlike core, if invaild then skip.
unset($child);
continue;
} else {
// Nasty hack to replace the grades with the direct url.
if (strpos($bits[1], '/grade/report/mygrades.php') !== false) {
$bits[1] = user_mygrades_url();
}
// Make sure the url is a moodle url.
$bits[1] = new url(trim($bits[1]));
}
$child->url = $bits[1];
// Font Awesome processing.
if (array_key_exists(2, $bits)) {
$fa = trim($bits[2]);
$child->title = \theme_adaptable\toolbox::getfontawesomemarkup($fa, ['mr-1']) . $child->title;
}
// Add this child to the list of children.
$children[] = $child;
$hasitems = true;
}
return [$hasitems, $children];
}
/**
* Construct a user menu, returning HTML that can be echoed out by a
* layout file.
*
* @param stdClass $user A user object, usually $USER.
* @param bool $withlinks true if a dropdown should be built.
* @return string HTML fragment.
*/
public function user_menu($user = null, $withlinks = null) {
global $USER, $CFG;
require_once($CFG->dirroot . '/user/lib.php');
if (is_null($user)) {
$user = $USER;
}
// Note: This behaviour is intended to match that of core_renderer::login_info,
// but should not be considered to be good practice; layout options are
// intended to be theme-specific. Please don't copy this snippet anywhere else.
if (is_null($withlinks)) {
$withlinks = empty($this->page->layout_options['nologinlinks']);
}
// Add a class for when $withlinks is false.
$usermenuclasses = 'usermenu';
if (!$withlinks) {
$usermenuclasses .= ' withoutlinks';
}
$returnstr = "";
// If during initial install, return the empty return string.
if (during_initial_install()) {
return $returnstr;
}
// Adaptable modified.
$themesettings = \theme_adaptable\toolbox::get_settings();
$avatarclasses = "avatars";
$userpic = $this->user_picture($user, ['link' => false, 'visibletoscreenreaders' => false,
'size' => 35, 'class' => 'userpicture', ]);
$avatarcontents = html_writer::span($userpic, 'avatar current');
$usertextcontents = format_string(fullname($user));
// User menu dropdown.
if (!empty($themesettings->usernameposition)) {
$usernameposition = $themesettings->usernameposition;
if ($usernameposition == 'right') {
$usernamepositionleft = false;
} else {
$usernamepositionleft = true;
}
} else {
$usernamepositionleft = true;
}
if ($usernamepositionleft) {
$returnstr .= html_writer::span(
html_writer::span($usertextcontents, 'usertext mr-1') .
html_writer::span($avatarcontents, $avatarclasses),
'userbutton'
);
} else {
$returnstr .= html_writer::span(
html_writer::span($avatarcontents, $avatarclasses) .
html_writer::span($usertextcontents, 'usertext mr-1'),
'userbutton'
);
}
$navitems = $this->user_profile_menu_items();
// Create a divider (well, a filler).
$divider = new \action_menu_filler();
$divider->primary = false;
$am = new \action_menu();
$am->set_menu_trigger(
$returnstr,
'nav-link'
);
$am->set_action_label(get_string('usermenu'));
$am->set_nowrap_on_items();
if ($withlinks) {
$navitemcount = count($navitems);
$idx = 0;
foreach ($navitems as $key => $value) {
switch ($value->itemtype) {
case 'divider':
// If the nav item is a divider, add one and skip link processing.
$am->add($divider);
break;
case 'invalid':
// Silently skip invalid entries (should we post a notification?).
break;
case 'link':
// Process this as a link item.
$pix = null;
if (isset($value->pix) && !empty($value->pix)) {
$pix = new pix_icon($value->pix, '', null, ['class' => 'iconsmall']);
} else if (isset($value->imgsrc) && !empty($value->imgsrc)) {
$value->title = html_writer::img(
$value->imgsrc,
$value->title,
['class' => 'iconsmall']
) . $value->title;
}
$al = new \action_menu_link_secondary(
$value->url,
$pix,
$value->title,
['class' => 'icon']
);
if (!empty($value->titleidentifier)) {
$al->attributes['data-title'] = $value->titleidentifier;
}
$am->add($al);
break;
}
$idx++;
// Add dividers after the first item and before the last item.
if ($idx == 1 || $idx == $navitemcount - 1) {
$am->add($divider);
}
}
}
return html_writer::div(
$this->render($am),
$usermenuclasses
);
}
/**
* Prints a nice side block with an optional header.
*
* The content is described by a core_renderer::block_contents object.
*
* <div id="inst{$instanceid}" class="block_{$blockname} block">
* <div class="header"></div>
* <div class="content">
* ...CONTENT...
* <div class="footer">
* </div>
* </div>
* <div class="annotation">
* </div>
* </div>
*
* @param block_contents $bc HTML for the content
* @param string $region the region the block is appearing in.
* @return string the HTML to be output.
*/
public function block(block_contents $bc, $region) {
$bc = clone($bc); // Avoid messing up the object passed in.
$skiptitle = strip_tags($bc->title);
if (empty($bc->blockinstanceid) || !$skiptitle) {
$bc->collapsible = block_contents::NOT_HIDEABLE;
} else {
global $USER;
$USER->adaptable_user_pref['block' . $bc->blockinstanceid . 'hidden'] = PARAM_BOOL;
}
if (!empty($bc->blockinstanceid)) {
$bc->attributes['data-instanceid'] = $bc->blockinstanceid;
}
if ($bc->blockinstanceid && !empty($skiptitle)) {
$bc->attributes['aria-labelledby'] = 'instance-' . $bc->blockinstanceid . '-header';
} else if (!empty($bc->arialabel)) {
$bc->attributes['aria-label'] = $bc->arialabel;
}
if ($bc->dockable) {
$bc->attributes['data-dockable'] = 1;
}
if ($bc->collapsible == block_contents::HIDDEN) {
$bc->add_class('hidden');
}
if (!empty($bc->controls)) {
$bc->add_class('block_with_controls');
}
$bc->add_class('mb-3');
if (empty($skiptitle)) {
$skiptitle = get_string('skipblock', 'theme_adaptable', $bc->blockinstanceid);
}
$output = html_writer::link(
'#sb-' . $bc->skipid,
get_string('skipa', 'access', $skiptitle),
['class' => 'skip skip-block', 'id' => 'fsb-' . $bc->skipid]
);
$skipdest = html_writer::span(
'',
'skip-block-to',
['id' => 'sb-' . $bc->skipid]
);
if (!empty($bc->attributes['notitle'])) {
$bc->title = '';
}
$output .= html_writer::start_tag('section', $bc->attributes);
$output .= $this->block_header($bc);
$output .= $this->block_content($bc);
$output .= html_writer::end_tag('section');
$output .= $this->block_annotation($bc);
$output .= $skipdest;
return $output;
}
/**
* Produces a header for a block
*
* @param block_contents $bc
* @return string
*/
protected function block_header(block_contents $bc) {
$title = '';
if ($bc->title) {
$attributes = [];
$attributes['class'] = 'd-inline';
if ($bc->blockinstanceid) {
$attributes['id'] = 'instance-' . $bc->blockinstanceid . '-header';
}
$title = html_writer::tag('h2', $bc->title, $attributes);
}
$blockid = null;
if (isset($bc->attributes['id'])) {
$blockid = $bc->attributes['id'];
}
$controlshtml = $this->block_controls($bc->controls, $blockid);
$output = '';
if ($title || $controlshtml) {
$collapse = '';
if (isset($bc->attributes['id']) && $bc->collapsible != block_contents::NOT_HIDEABLE) {
$collapse =
html_writer::tag('div', '', [
'id' => 'instance-'.$bc->blockinstanceid.'-action',
'class' => 'block-action block-collapsible',
'data-instanceid' => $bc->blockinstanceid,
'title' => get_string('blockshowhide', 'theme_adaptable'),
]);
$this->page->requires->js_call_amd(
'theme_adaptable/collapseblock',
'collapseBlockInit'
);
}
$output .=
html_writer::tag(
'div',
$collapse . html_writer::tag(
'div',
html_writer::tag('div', '', ['class' => 'block_action']) . $title,
['class' => 'title']
). html_writer::tag('div', $controlshtml, ['class' => 'block-controls']),
['class' => 'header']
);
}
return $output;
}
/**
* Produces the content area for a block
*
* @param block_contents $bc
* @return string
*/
protected function block_content(block_contents $bc) {
$output = html_writer::start_tag('div', ['class' => 'content']);
if (!$bc->title && !$this->block_controls($bc->controls)) {
$output .= html_writer::tag('div', '', ['class' => 'block_action notitle']);
}
$output .= $bc->content;
$output .= $this->block_footer($bc);
$output .= html_writer::end_tag('div');
return $output;
}
/**
* Produces the footer for a block
*
* @param block_contents $bc
* @return string
*/
protected function block_footer(block_contents $bc) {
$output = '';
if ($bc->footer) {
$output .= html_writer::tag('div', $bc->footer, ['class' => 'footer']);
}
return $output;
}
/**
* Produces the annotation for a block
*
* @param block_contents $bc
* @return string
*/
protected function block_annotation(block_contents $bc) {
$output = '';
if ($bc->annotation) {
$output .= html_writer::tag('div', $bc->annotation, ['class' => 'blockannotation']);
}
return $output;
}
/**
* Returns standard navigation between activities in a course.
*
* @return string the navigation HTML.
*/
public function activity_navigation() {
// First we should check if we want to add navigation.
if (!$this->page->theme->settings->courseactivitynavigationenabled) {
return '';
}
$context = $this->page->context;
if (
($this->page->pagelayout !== 'incourse' && $this->page->pagelayout !== 'frametop')
|| $context->contextlevel != CONTEXT_MODULE
) {
return '';
}
// If the activity is in stealth mode, show no links.
if ($this->page->cm->is_stealth()) {
return '';
}
// Get a list of all the activities in the course.
$course = $this->page->cm->get_course();
$modules = get_fast_modinfo($course->id)->get_cms();
// Put the modules into an array in order by the position they are shown in the course.
$mods = [];
$activitylist = [];
foreach ($modules as $module) {
// Only add activities the user can access, aren't in stealth mode and have a url (eg. mod_label does not).
if (!$module->uservisible || $module->is_stealth() || empty($module->url)) {
continue;
}
$mods[$module->id] = $module;
// No need to add the current module to the list for the activity dropdown menu.
if ($module->id == $this->page->cm->id) {
continue;
}
// Module name.
$modname = $module->get_formatted_name();
// Display the hidden text if necessary.
if (!$module->visible) {
$modname .= ' ' . get_string('hiddenwithbrackets');
}
// Module URL.
$linkurl = new url($module->url, ['forceview' => 1]);
// Add module URL (as key) and name (as value) to the activity list array.
$activitylist[$linkurl->out(false)] = $modname;
}
$nummods = count($mods);
// If there is only one mod then do nothing.
if ($nummods == 1) {
return '';
}
// Get an array of just the course module ids used to get the cmid value based on their position in the course.
$modids = array_keys($mods);
// Get the position in the array of the course module we are viewing.
$position = array_search($this->page->cm->id, $modids);
$prevmod = null;
$nextmod = null;
// Check if we have a previous mod to show.
if ($position > 0) {
$prevmod = $mods[$modids[$position - 1]];
}
// Check if we have a next mod to show.
if ($position < ($nummods - 1)) {
$nextmod = $mods[$modids[$position + 1]];
}
$activitynav = new \core_course\output\activity_navigation($prevmod, $nextmod, $activitylist);
$renderer = $this->page->get_renderer('core', 'course');
return $renderer->render($activitynav);
}
/**
* Renders preferences groups.
*
* @param preferences_groups $renderable The renderable
* @return string The output.
*/
public function render_preferences_groups(\core\output\preferences_groups $renderable) {
return $this->render_from_template('core/preferences_groups', $renderable);
}
/**
* Returns list of alert messages for the user.
*
* @return string Markup if any.
*/
public function get_alert_messages() {
$markup = '';
$localtoolbox = \theme_adaptable\toolbox::get_local_toolbox();
if (is_object($localtoolbox)) {
$themesettings = \theme_adaptable\toolbox::get_settings();
$markup = $localtoolbox->get_alert_messages($themesettings, $this->page, $this);
}
return $markup;
}
/**
* Displays notices to alert teachers of problems with course such as being hidden.
*
* @return string Markup if any.
*/
public function get_course_alerts() {
$markup = '';
$localtoolbox = \theme_adaptable\toolbox::get_local_toolbox();
if (is_object($localtoolbox)) {
$themesettings = \theme_adaptable\toolbox::get_settings();
$markup = $localtoolbox->get_course_alerts($themesettings, $this->page, $this);
}
return $markup;
}
/**
* Returns all tracking methods.
*
* @return string Markup.
*/
public function get_all_tracking_methods() {
$markup = '';
$localtoolbox = \theme_adaptable\toolbox::get_local_toolbox();
if (is_object($localtoolbox)) {
$themesettings = \theme_adaptable\toolbox::get_settings();
$markup = $localtoolbox->get_all_tracking_methods($themesettings, $this->page, $this);
}
return $markup;
}
/**
* Returns HTML to display a "Turn editing on/off" button in a form.
*
* Note: Not called directly by theme but by core in its way of setting the 'page button'
* attribute. This version needed for 'Edit button keep position' in adaptable.js.
*
* @param url $url The URL + params to send through when clicking the button.
* @param string $method Not used.
* @return string HTML the button
*/
public function edit_button(url $url, string $method = 'post') {
$url->param('sesskey', sesskey());
if ($this->page->user_is_editing()) {
$url->param('edit', 'off');
$btn = 'btn-danger';
$title = get_string('turneditingoff');
$icon = 'fa-power-off';
} else {
$url->param('edit', 'on');
$btn = 'btn-success';
$title = get_string('turneditingon');
$icon = 'fa-edit';
}
$editingtext = \theme_adaptable\toolbox::get_setting('displayeditingbuttontext');
$buttontitle = '';
if ($editingtext) {
$buttontitle = $title;
} else {
$icon .= ' only';
}
return html_writer::tag('a', html_writer::tag('i', '', ['class' => $icon . ' fa fa-fw']) .
$buttontitle, ['href' => $url, 'class' => 'btn ' . $btn, 'title' => $title]);
}
/**
* Process user messages
*
* @param array $message
* @return array
*/
protected function process_message($message) {
global $DB, $USER;
$messagecontent = new stdClass();
if ($message->notification || $message->useridfrom < 1) {
$messagecontent->text = $message->smallmessage;
$messagecontent->type = 'notification';
if (empty($message->contexturl)) {
$messagecontent->url = new url(
'/message/index.php',
['user1' => $USER->id, 'viewing' => 'recentnotifications']
);
} else {
$messagecontent->url = new url($message->contexturl);
}
} else {
$messagecontent->type = 'message';
if ($message->fullmessageformat == FORMAT_HTML) {
$message->smallmessage = html_to_text($message->smallmessage);
}
if (strlen($message->smallmessage) > 18) {
$messagecontent->text = \core_text::substr($message->smallmessage, 0, 15) . '...';
} else {
$messagecontent->text = $message->smallmessage;
}
$messagecontent->from = $DB->get_record('user', ['id' => $message->useridfrom]);
$messagecontent->url = new url(
'/message/index.php',
['user1' => $USER->id, 'user2' => $message->useridfrom]
);
}
$messagecontent->date = userdate($message->timecreated, get_string('strftimetime', 'langconfig'));
$messagecontent->unread = empty($message->timeread);
return $messagecontent;
}
/**
* Returns html to render socialicons
*
* @return string
*/
public function socialicons() {
$socialiconlist = \theme_adaptable\toolbox::get_setting('socialiconlist');
if (empty($socialiconlist)) {
return '';
}
$target = \theme_adaptable\toolbox::get_setting('socialtarget', false, null, '_blank');
$retval = '';
$lines = explode("\n", $socialiconlist);
foreach ($lines as $line) {
if (strstr($line, '|')) {
$fields = explode('|', $line);
$retval .= '<a target="' . $target . '" title="' . $fields[1] . '" href="' . $fields[0] . '">';
$retval .= \theme_adaptable\toolbox::getfontawesomemarkup($fields[2]);
$retval .= '</a>';
}
}
return $retval;
}
/**
* Returns html to render news ticker.
* Note: Requires local_adaptable plugin.
*
* @return string
*/
public function get_news_ticker() {
$retval = '';
$localtoolbox = \theme_adaptable\toolbox::get_local_toolbox();
if (is_object($localtoolbox)) {
$themesettings = \theme_adaptable\toolbox::get_settings();
$retval = $localtoolbox->get_news_ticker($themesettings, $this->page, $this);
}
return $retval;
}
/**
* Renders block regions on front page (or any other page
* if specifying a different value for $settingsname). Used for various block region rendering.
*
* @param string $settingsname Setting name to retrieve from theme settings containing actual layout (e.g. 4-4-4-4)
* @param string $classnamebeginswith Used when building the blockname to retrieve for display
* @param string $customrowsetting If $settingsname value set to 'customrowsetting', then set this to
* the layout required to display a one row layout.
* When using this, ensure the appropriate number of block regions are defined in config.php.
* E.g. if $classnamebeginswith = 'my-block' and $customrowsetting = '4-4-0-0', 2 regions called
* 'my-block-a' and 'my-block-a' are expected to exist.
* @return string HTML output
*/
public function get_block_regions(
$settingsname,
$classnamebeginswith,
$customrowsetting = null
) {
$blockcount = 0;
$fields = [];
$retval = '';
if ($settingsname == 'customrowsetting') {
$fields[] = $customrowsetting;
} else {
for ($i = 1; $i <= 5; $i++) {
$marketrow = $settingsname . $i;
/* Need to check if the setting exists as this function is now
called for variable row numbers in block regions (e.g. course page
which is a single row of block regions). */
if (isset($this->page->theme->settings->$marketrow)) {
$marketrow = $this->page->theme->settings->$marketrow;
} else {
$marketrow = '0-0-0-0';
}
if ($marketrow != '0-0-0-0') {
$fields[] = $marketrow;
}
}
}
foreach ($fields as $field) {
$vals = explode('-', $field);
foreach ($vals as $val) {
if ($val > 0) {
$retval .= '<div class="my-1 col-md-' . $val . '">';
// Moodle does not seem to like numbers in region names so using letter instead.
$blockcount++;
$block = $classnamebeginswith . chr(96 + $blockcount);
$retval .= $this->blocks($block, 'block-region-front');
$retval .= '</div>';
}
}
}
return $retval;
}
/**
* Renders block regions for potentially hidden blocks. For example, 4-4-4-4 to 6-6-0-0
* would mean the last two blocks get inadvertently hidden. This function can recover and
* display those blocks. An override option also available to display blocks for the region, regardless.
*
* @param array $blocksarray Settings names containing the actual layout(s) (i.e. 4-4-4-4)
* @param array $classes Used when building the blockname to retrieve for display
* @param bool $displayall An override setting to simply display all blocks from the region
* @return string HTML output
*/
public function get_missing_block_regions($blocksarray, $classes = [], $displayall = false) {
$retval = '';
$editing = $this->page->user_is_editing();
if (!empty($blocksarray)) {
$classes = (array)$classes;
$missingblocks = '';
foreach ($blocksarray as $block) {
/* Do this for up to 8 rows (allows for expansion. Be careful
of losing blocks if this value changes from a high to low number!). */
for ($i = 1; $i <= 8; $i++) {
/* For each block region in a row, analyse the current layout (e.g. 6-6-0-0, 3-3-3-3). Check if less than
4 blocks (meaning a change in settings from say 4-4-4-4 to 6-6. Meaning missing blocks,
i.e. 6-6-0-0 means the two end ones may have content that is inadvertantly lost. */
$rowsetting = $block['settingsname'] . $i;
if (isset($this->page->theme->settings->$rowsetting)) {
$rowvalue = $this->page->theme->settings->$rowsetting;
$spannumbers = explode('-', $rowvalue);
$y = 0;
foreach ($spannumbers as $spannumber) {
$y++;
/* Here's the crucial bit. Check if span number is 0,
or $displayall is true (override) and if so, print it out. */
if ($spannumber == 0 || $displayall) {
$blockregion = $block['classnamebeginswith'] . chr(96 + $y);
$displayregion = $this->page->apply_theme_region_manipulations($blockregion);
// Check if the block actually has content to display before displaying.
if ($this->page->blocks->region_has_content($displayregion, $this)) {
if ($editing) {
$missingblocks .= get_string(