forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.php
2164 lines (1841 loc) · 90.9 KB
/
renderer.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/>.
/**
* Renderer for core_admin subsystem
*
* @package core
* @subpackage admin
* @copyright 2011 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Standard HTML output renderer for core_admin subsystem
*/
class core_admin_renderer extends plugin_renderer_base {
/**
* Display the 'Do you acknowledge the terms of the GPL' page. The first page
* during install.
* @return string HTML to output.
*/
public function install_licence_page() {
global $CFG;
$output = '';
$copyrightnotice = text_to_html(get_string('gpl3'));
$copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
$continue = new single_button(new moodle_url($this->page->url, array(
'lang' => $CFG->lang, 'agreelicense' => 1)), get_string('continue'), 'get');
$output .= $this->header();
$output .= $this->heading('<a href="http://moodle.org">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment');
$output .= $this->heading(get_string('copyrightnotice'));
$output .= $this->box($copyrightnotice, 'copyrightnotice');
$output .= html_writer::empty_tag('br');
$output .= $this->confirm(get_string('doyouagree'), $continue, "http://docs.moodle.org/dev/License");
$output .= $this->footer();
return $output;
}
/**
* Display page explaining proper upgrade process,
* there can not be any PHP file leftovers...
*
* @return string HTML to output.
*/
public function upgrade_stale_php_files_page() {
$output = '';
$output .= $this->header();
$output .= $this->heading(get_string('upgradestalefiles', 'admin'));
$output .= $this->box_start('generalbox', 'notice');
$output .= format_text(get_string('upgradestalefilesinfo', 'admin', get_docs_url('Upgrading')), FORMAT_MARKDOWN);
$output .= html_writer::empty_tag('br');
$output .= html_writer::tag('div', $this->single_button($this->page->url, get_string('reload'), 'get'), array('class' => 'buttons'));
$output .= $this->box_end();
$output .= $this->footer();
return $output;
}
/**
* Display the 'environment check' page that is displayed during install.
* @param int $maturity
* @param boolean $envstatus final result of the check (true/false)
* @param array $environment_results array of results gathered
* @param string $release moodle release
* @return string HTML to output.
*/
public function install_environment_page($maturity, $envstatus, $environment_results, $release) {
global $CFG;
$output = '';
$output .= $this->header();
$output .= $this->maturity_warning($maturity);
$output .= $this->heading("Moodle $release");
$output .= $this->release_notes_link();
$output .= $this->environment_check_table($envstatus, $environment_results);
if (!$envstatus) {
$output .= $this->upgrade_reload(new moodle_url($this->page->url, array('agreelicense' => 1, 'lang' => $CFG->lang)));
} else {
$output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
$output .= $this->continue_button(new moodle_url($this->page->url, array(
'agreelicense' => 1, 'confirmrelease' => 1, 'lang' => $CFG->lang)));
}
$output .= $this->footer();
return $output;
}
/**
* Displays the list of plugins with unsatisfied dependencies
*
* @param double|string|int $version Moodle on-disk version
* @param array $failed list of plugins with unsatisfied dependecies
* @param moodle_url $reloadurl URL of the page to recheck the dependencies
* @return string HTML
*/
public function unsatisfied_dependencies_page($version, array $failed, moodle_url $reloadurl) {
$output = '';
$output .= $this->header();
$output .= $this->heading(get_string('pluginscheck', 'admin'));
$output .= $this->warning(get_string('pluginscheckfailed', 'admin', array('pluginslist' => implode(', ', array_unique($failed)))));
$output .= $this->plugins_check_table(core_plugin_manager::instance(), $version, array('xdep' => true));
$output .= $this->warning(get_string('pluginschecktodo', 'admin'));
$output .= $this->continue_button($reloadurl);
$output .= $this->footer();
return $output;
}
/**
* Display the 'You are about to upgrade Moodle' page. The first page
* during upgrade.
* @param string $strnewversion
* @param int $maturity
* @param string $testsite
* @return string HTML to output.
*/
public function upgrade_confirm_page($strnewversion, $maturity, $testsite) {
$output = '';
$continueurl = new moodle_url($this->page->url, array('confirmupgrade' => 1, 'cache' => 0));
$continue = new single_button($continueurl, get_string('continue'), 'get');
$cancelurl = new moodle_url('/admin/index.php');
$output .= $this->header();
$output .= $this->maturity_warning($maturity);
$output .= $this->test_site_warning($testsite);
$output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continue, $cancelurl);
$output .= $this->footer();
return $output;
}
/**
* Display the environment page during the upgrade process.
* @param string $release
* @param boolean $envstatus final result of env check (true/false)
* @param array $environment_results array of results gathered
* @return string HTML to output.
*/
public function upgrade_environment_page($release, $envstatus, $environment_results) {
global $CFG;
$output = '';
$output .= $this->header();
$output .= $this->heading("Moodle $release");
$output .= $this->release_notes_link();
$output .= $this->environment_check_table($envstatus, $environment_results);
if (!$envstatus) {
$output .= $this->upgrade_reload(new moodle_url($this->page->url, array('confirmupgrade' => 1, 'cache' => 0)));
} else {
$output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
if (empty($CFG->skiplangupgrade) and current_language() !== 'en') {
$output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice');
}
$output .= $this->continue_button(new moodle_url($this->page->url, array(
'confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0)));
}
$output .= $this->footer();
return $output;
}
/**
* Display the upgrade page that lists all the plugins that require attention.
* @param core_plugin_manager $pluginman provides information about the plugins.
* @param \core\update\checker $checker provides information about available updates.
* @param int $version the version of the Moodle code from version.php.
* @param bool $showallplugins
* @param moodle_url $reloadurl
* @param moodle_url $continueurl
* @return string HTML to output.
*/
public function upgrade_plugin_check_page(core_plugin_manager $pluginman, \core\update\checker $checker,
$version, $showallplugins, $reloadurl, $continueurl) {
$output = '';
$output .= $this->header();
$output .= $this->box_start('generalbox', 'plugins-check-page');
$output .= html_writer::tag('p', get_string('pluginchecknotice', 'core_plugin'), array('class' => 'page-description'));
$output .= $this->check_for_updates_button($checker, $reloadurl);
$output .= $this->missing_dependencies($pluginman);
$output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
$output .= $this->box_end();
$output .= $this->upgrade_reload($reloadurl);
if ($pluginman->some_plugins_updatable()) {
$output .= $this->container_start('upgradepluginsinfo');
$output .= $this->help_icon('upgradepluginsinfo', 'core_admin', get_string('upgradepluginsfirst', 'core_admin'));
$output .= $this->container_end();
}
$button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get');
$button->class = 'continuebutton';
$output .= $this->render($button);
$output .= $this->footer();
return $output;
}
/**
* Display a page to confirm plugin installation cancelation.
*
* @param array $abortable list of \core\update\plugininfo
* @param moodle_url $continue
* @return string
*/
public function upgrade_confirm_abort_install_page(array $abortable, moodle_url $continue) {
$pluginman = core_plugin_manager::instance();
if (empty($abortable)) {
// The UI should not allow this.
throw new moodle_exception('err_no_plugin_install_abortable', 'core_plugin');
}
$out = $this->output->header();
$out .= $this->output->heading(get_string('cancelinstallhead', 'core_plugin'), 3);
$out .= $this->output->container(get_string('cancelinstallinfo', 'core_plugin'), 'cancelinstallinfo');
foreach ($abortable as $pluginfo) {
$out .= $this->output->heading($pluginfo->displayname.' ('.$pluginfo->component.')', 4);
$out .= $this->output->container(get_string('cancelinstallinfodir', 'core_plugin', $pluginfo->rootdir));
if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
$out .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
'alert alert-warning mt-2');
}
}
$out .= $this->plugins_management_confirm_buttons($continue, $this->page->url);
$out .= $this->output->footer();
return $out;
}
/**
* Display the admin notifications page.
* @param int $maturity
* @param bool $insecuredataroot warn dataroot is invalid
* @param bool $errorsdisplayed warn invalid dispaly error setting
* @param bool $cronoverdue warn cron not running
* @param bool $dbproblems warn db has problems
* @param bool $maintenancemode warn in maintenance mode
* @param bool $buggyiconvnomb warn iconv problems
* @param array|null $availableupdates array of \core\update\info objects or null
* @param int|null $availableupdatesfetch timestamp of the most recent updates fetch or null (unknown)
* @param string[] $cachewarnings An array containing warnings from the Cache API.
* @param array $eventshandlers Events 1 API handlers.
* @param bool $themedesignermode Warn about the theme designer mode.
* @param bool $devlibdir Warn about development libs directory presence.
* @param bool $mobileconfigured Whether the mobile web services have been enabled
* @param bool $overridetossl Whether or not ssl is being forced.
* @param bool $invalidforgottenpasswordurl Whether the forgotten password URL does not link to a valid URL.
* @param bool $croninfrequent If true, warn that cron hasn't run in the past few minutes
*
* @return string HTML to output.
*/
public function admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed,
$cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch,
$buggyiconvnomb, $registered, array $cachewarnings = array(), $eventshandlers = 0,
$themedesignermode = false, $devlibdir = false, $mobileconfigured = false,
$overridetossl = false, $invalidforgottenpasswordurl = false, $croninfrequent = false) {
global $CFG;
$output = '';
$output .= $this->header();
$output .= $this->maturity_info($maturity);
$output .= $this->legacy_log_store_writing_error();
$output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : '';
$output .= $this->insecure_dataroot_warning($insecuredataroot);
$output .= $this->development_libs_directories_warning($devlibdir);
$output .= $this->themedesignermode_warning($themedesignermode);
$output .= $this->display_errors_warning($errorsdisplayed);
$output .= $this->buggy_iconv_warning($buggyiconvnomb);
$output .= $this->cron_overdue_warning($cronoverdue);
$output .= $this->cron_infrequent_warning($croninfrequent);
$output .= $this->db_problems($dbproblems);
$output .= $this->maintenance_mode_warning($maintenancemode);
$output .= $this->overridetossl_warning($overridetossl);
$output .= $this->cache_warnings($cachewarnings);
$output .= $this->events_handlers($eventshandlers);
$output .= $this->registration_warning($registered);
$output .= $this->mobile_configuration_warning($mobileconfigured);
$output .= $this->forgotten_password_url_warning($invalidforgottenpasswordurl);
//////////////////////////////////////////////////////////////////////////////////////////////////
//// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
$output .= $this->moodle_copyright();
//////////////////////////////////////////////////////////////////////////////////////////////////
$output .= $this->footer();
return $output;
}
/**
* Display the plugin management page (admin/plugins.php).
*
* The filtering options array may contain following items:
* bool contribonly - show only contributed extensions
* bool updatesonly - show only plugins with an available update
*
* @param core_plugin_manager $pluginman
* @param \core\update\checker $checker
* @param array $options filtering options
* @return string HTML to output.
*/
public function plugin_management_page(core_plugin_manager $pluginman, \core\update\checker $checker, array $options = array()) {
$output = '';
$output .= $this->header();
$output .= $this->heading(get_string('pluginsoverview', 'core_admin'));
$output .= $this->check_for_updates_button($checker, $this->page->url);
$output .= $this->plugins_overview_panel($pluginman, $options);
$output .= $this->plugins_control_panel($pluginman, $options);
$output .= $this->footer();
return $output;
}
/**
* Renders a button to fetch for available updates.
*
* @param \core\update\checker $checker
* @param moodle_url $reloadurl
* @return string HTML
*/
public function check_for_updates_button(\core\update\checker $checker, $reloadurl) {
$output = '';
if ($checker->enabled()) {
$output .= $this->container_start('checkforupdates');
$output .= $this->single_button(
new moodle_url($reloadurl, array('fetchupdates' => 1)),
get_string('checkforupdates', 'core_plugin')
);
if ($timefetched = $checker->get_last_timefetched()) {
$timefetched = userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'));
$output .= $this->container(get_string('checkforupdateslast', 'core_plugin', $timefetched), 'lasttimefetched');
}
$output .= $this->container_end();
}
return $output;
}
/**
* Display a page to confirm the plugin uninstallation.
*
* @param core_plugin_manager $pluginman
* @param \core\plugininfo\base $pluginfo
* @param moodle_url $continueurl URL to continue after confirmation
* @param moodle_url $cancelurl URL to to go if cancelled
* @return string
*/
public function plugin_uninstall_confirm_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, moodle_url $continueurl, moodle_url $cancelurl) {
$output = '';
$pluginname = $pluginman->plugin_name($pluginfo->component);
$confirm = '<p>' . get_string('uninstallconfirm', 'core_plugin', array('name' => $pluginname)) . '</p>';
if ($extraconfirm = $pluginfo->get_uninstall_extra_warning()) {
$confirm .= $extraconfirm;
}
$output .= $this->output->header();
$output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
$output .= $this->output->confirm($confirm, $continueurl, $cancelurl);
$output .= $this->output->footer();
return $output;
}
/**
* Display a page with results of plugin uninstallation and offer removal of plugin files.
*
* @param core_plugin_manager $pluginman
* @param \core\plugininfo\base $pluginfo
* @param progress_trace_buffer $progress
* @param moodle_url $continueurl URL to continue to remove the plugin folder
* @return string
*/
public function plugin_uninstall_results_removable_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo,
progress_trace_buffer $progress, moodle_url $continueurl) {
$output = '';
$pluginname = $pluginman->plugin_name($pluginfo->component);
// Do not show navigation here, they must click one of the buttons.
$this->page->set_pagelayout('maintenance');
$this->page->set_cacheable(false);
$output .= $this->output->header();
$output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
$output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
$confirm = $this->output->container(get_string('uninstalldeleteconfirm', 'core_plugin',
array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'uninstalldeleteconfirm');
if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
$confirm .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
'alert alert-warning mt-2');
}
// After any uninstall we must execute full upgrade to finish the cleanup!
$output .= $this->output->confirm($confirm, $continueurl, new moodle_url('/admin/index.php'));
$output .= $this->output->footer();
return $output;
}
/**
* Display a page with results of plugin uninstallation and inform about the need to remove plugin files manually.
*
* @param core_plugin_manager $pluginman
* @param \core\plugininfo\base $pluginfo
* @param progress_trace_buffer $progress
* @return string
*/
public function plugin_uninstall_results_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, progress_trace_buffer $progress) {
$output = '';
$pluginname = $pluginfo->component;
$output .= $this->output->header();
$output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
$output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
$output .= $this->output->box(get_string('uninstalldelete', 'core_plugin',
array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'generalbox uninstalldelete');
$output .= $this->output->continue_button(new moodle_url('/admin/index.php'));
$output .= $this->output->footer();
return $output;
}
/**
* Display the plugin management page (admin/environment.php).
* @param array $versions
* @param string $version
* @param boolean $envstatus final result of env check (true/false)
* @param array $environment_results array of results gathered
* @return string HTML to output.
*/
public function environment_check_page($versions, $version, $envstatus, $environment_results) {
$output = '';
$output .= $this->header();
// Print the component download link
$output .= html_writer::tag('div', html_writer::link(
new moodle_url('/admin/environment.php', array('action' => 'updatecomponent', 'sesskey' => sesskey())),
get_string('updatecomponent', 'admin')),
array('class' => 'reportlink'));
// Heading.
$output .= $this->heading(get_string('environment', 'admin'));
// Box with info and a menu to choose the version.
$output .= $this->box_start();
$output .= html_writer::tag('div', get_string('adminhelpenvironment'));
$select = new single_select(new moodle_url('/admin/environment.php'), 'version', $versions, $version, null);
$select->label = get_string('moodleversion');
$output .= $this->render($select);
$output .= $this->box_end();
// The results
$output .= $this->environment_check_table($envstatus, $environment_results);
$output .= $this->footer();
return $output;
}
/**
* Output a warning message, of the type that appears on the admin notifications page.
* @param string $message the message to display.
* @param string $type type class
* @return string HTML to output.
*/
protected function warning($message, $type = 'warning') {
return $this->box($message, 'generalbox alert alert-' . $type);
}
/**
* Render an appropriate message if dataroot is insecure.
* @param bool $insecuredataroot
* @return string HTML to output.
*/
protected function insecure_dataroot_warning($insecuredataroot) {
global $CFG;
if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
} else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'danger');
} else {
return '';
}
}
/**
* Render a warning that a directory with development libs is present.
*
* @param bool $devlibdir True if the warning should be displayed.
* @return string
*/
protected function development_libs_directories_warning($devlibdir) {
if ($devlibdir) {
$moreinfo = new moodle_url('/report/security/index.php');
$warning = get_string('devlibdirpresent', 'core_admin', ['moreinfourl' => $moreinfo->out()]);
return $this->warning($warning, 'danger');
} else {
return '';
}
}
/**
* Render an appropriate message if dataroot is insecure.
* @param bool $errorsdisplayed
* @return string HTML to output.
*/
protected function display_errors_warning($errorsdisplayed) {
if (!$errorsdisplayed) {
return '';
}
return $this->warning(get_string('displayerrorswarning', 'admin'));
}
/**
* Render an appropriate message if themdesignermode is enabled.
* @param bool $themedesignermode true if enabled
* @return string HTML to output.
*/
protected function themedesignermode_warning($themedesignermode) {
if (!$themedesignermode) {
return '';
}
return $this->warning(get_string('themedesignermodewarning', 'admin'));
}
/**
* Render an appropriate message if iconv is buggy and mbstring missing.
* @param bool $buggyiconvnomb
* @return string HTML to output.
*/
protected function buggy_iconv_warning($buggyiconvnomb) {
if (!$buggyiconvnomb) {
return '';
}
return $this->warning(get_string('warningiconvbuggy', 'admin'));
}
/**
* Render an appropriate message if cron has not been run recently.
* @param bool $cronoverdue
* @return string HTML to output.
*/
public function cron_overdue_warning($cronoverdue) {
global $CFG;
if (!$cronoverdue) {
return '';
}
if (empty($CFG->cronclionly)) {
$url = new moodle_url('/admin/cron.php');
if (!empty($CFG->cronremotepassword)) {
$url = new moodle_url('/admin/cron.php', array('password' => $CFG->cronremotepassword));
}
return $this->warning(get_string('cronwarning', 'admin', $url->out()) . ' ' .
$this->help_icon('cron', 'admin'));
}
// $CFG->cronclionly is not empty: cron can run only from CLI.
return $this->warning(get_string('cronwarningcli', 'admin') . ' ' .
$this->help_icon('cron', 'admin'));
}
/**
* Render an appropriate message if cron is not being run frequently (recommended every minute).
*
* @param bool $croninfrequent
* @return string HTML to output.
*/
public function cron_infrequent_warning(bool $croninfrequent) : string {
global $CFG;
if (!$croninfrequent) {
return '';
}
$expectedfrequency = $CFG->expectedcronfrequency ?? 200;
return $this->warning(get_string('croninfrequent', 'admin', $expectedfrequency) . ' ' .
$this->help_icon('cron', 'admin'));
}
/**
* Render an appropriate message if there are any problems with the DB set-up.
* @param bool $dbproblems
* @return string HTML to output.
*/
public function db_problems($dbproblems) {
if (!$dbproblems) {
return '';
}
return $this->warning($dbproblems);
}
/**
* Renders cache warnings if there are any.
*
* @param string[] $cachewarnings
* @return string
*/
public function cache_warnings(array $cachewarnings) {
if (!count($cachewarnings)) {
return '';
}
return join("\n", array_map(array($this, 'warning'), $cachewarnings));
}
/**
* Renders events 1 API handlers warning.
*
* @param array $eventshandlers
* @return string
*/
public function events_handlers($eventshandlers) {
if ($eventshandlers) {
$components = '';
foreach ($eventshandlers as $eventhandler) {
$components .= $eventhandler->component . ', ';
}
$components = rtrim($components, ', ');
return $this->warning(get_string('eventshandlersinuse', 'admin', $components));
}
}
/**
* Render an appropriate message if the site in in maintenance mode.
* @param bool $maintenancemode
* @return string HTML to output.
*/
public function maintenance_mode_warning($maintenancemode) {
if (!$maintenancemode) {
return '';
}
$url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
$url = $url->out(); // get_string() does not support objects in params
return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
}
/**
* Render a warning that ssl is forced because the site was on loginhttps.
*
* @param bool $overridetossl Whether or not ssl is being forced.
* @return string
*/
protected function overridetossl_warning($overridetossl) {
if (!$overridetossl) {
return '';
}
$warning = get_string('overridetossl', 'core_admin');
return $this->warning($warning, 'warning');
}
/**
* Display a warning about installing development code if necesary.
* @param int $maturity
* @return string HTML to output.
*/
protected function maturity_warning($maturity) {
if ($maturity == MATURITY_STABLE) {
return ''; // No worries.
}
$maturitylevel = get_string('maturity' . $maturity, 'admin');
return $this->warning(
$this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
$this->container($this->doc_link('admin/versions', get_string('morehelp'))),
'danger');
}
/*
* If necessary, displays a warning about upgrading a test site.
*
* @param string $testsite
* @return string HTML
*/
protected function test_site_warning($testsite) {
if (!$testsite) {
return '';
}
$warning = (get_string('testsiteupgradewarning', 'admin', $testsite));
return $this->warning($warning, 'danger');
}
/**
* Output the copyright notice.
* @return string HTML to output.
*/
protected function moodle_copyright() {
global $CFG;
//////////////////////////////////////////////////////////////////////////////////////////////////
//// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
$copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
'<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
'Copyright © 1999 onwards, Martin Dougiamas<br />'.
'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'.
'<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
//////////////////////////////////////////////////////////////////////////////////////////////////
return $this->box($copyrighttext, 'copyright');
}
/**
* Display a warning about installing development code if necesary.
* @param int $maturity
* @return string HTML to output.
*/
protected function maturity_info($maturity) {
if ($maturity == MATURITY_STABLE) {
return ''; // No worries.
}
$level = 'warning';
if ($maturity == MATURITY_ALPHA) {
$level = 'danger';
}
$maturitylevel = get_string('maturity' . $maturity, 'admin');
$warningtext = get_string('maturitycoreinfo', 'admin', $maturitylevel);
$warningtext .= ' ' . $this->doc_link('admin/versions', get_string('morehelp'));
return $this->warning($warningtext, $level);
}
/**
* Displays the info about available Moodle core and plugin updates
*
* The structure of the $updates param has changed since 2.4. It contains not only updates
* for the core itself, but also for all other installed plugins.
*
* @param array|null $updates array of (string)component => array of \core\update\info objects or null
* @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
* @return string
*/
protected function available_updates($updates, $fetch) {
$updateinfo = '';
$someupdateavailable = false;
if (is_array($updates)) {
if (is_array($updates['core'])) {
$someupdateavailable = true;
$updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
foreach ($updates['core'] as $update) {
$updateinfo .= $this->moodle_available_update_info($update);
}
$updateinfo .= html_writer::tag('p', get_string('updateavailablerecommendation', 'core_admin'),
array('class' => 'updateavailablerecommendation'));
}
unset($updates['core']);
// If something has left in the $updates array now, it is updates for plugins.
if (!empty($updates)) {
$someupdateavailable = true;
$updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3);
$pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1));
$updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin',
array('url' => $pluginsoverviewurl->out())));
}
}
if (!$someupdateavailable) {
$now = time();
if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
$updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
}
}
$updateinfo .= $this->container_start('checkforupdates');
$fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0));
$updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin'));
if ($fetch) {
$updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
}
$updateinfo .= $this->container_end();
return $this->warning($updateinfo);
}
/**
* Display a warning about not being registered on Moodle.org if necesary.
*
* @param boolean $registered true if the site is registered on Moodle.org
* @return string HTML to output.
*/
protected function registration_warning($registered) {
if (!$registered && site_is_public()) {
if (has_capability('moodle/site:config', context_system::instance())) {
$registerbutton = $this->single_button(new moodle_url('/admin/registration/index.php'),
get_string('register', 'admin'));
$str = 'registrationwarning';
} else {
$registerbutton = '';
$str = 'registrationwarningcontactadmin';
}
return $this->warning( get_string($str, 'admin')
. ' ' . $this->help_icon('registration', 'admin') . $registerbutton ,
'error alert alert-danger');
}
return '';
}
/**
* Return an admin page warning if site is not registered with moodle.org
*
* @return string
*/
public function warn_if_not_registered() {
return $this->registration_warning(\core\hub\registration::is_registered());
}
/**
* Display a warning about the Mobile Web Services being disabled.
*
* @param boolean $mobileconfigured true if mobile web services are enabled
* @return string HTML to output.
*/
protected function mobile_configuration_warning($mobileconfigured) {
$output = '';
if (!$mobileconfigured) {
$settingslink = new moodle_url('/admin/settings.php', ['section' => 'mobilesettings']);
$configurebutton = $this->single_button($settingslink, get_string('enablemobilewebservice', 'admin'));
$output .= $this->warning(get_string('mobilenotconfiguredwarning', 'admin') . ' ' . $configurebutton);
}
return $output;
}
/**
* Display a warning about the forgotten password URL not linking to a valid URL.
*
* @param boolean $invalidforgottenpasswordurl true if the forgotten password URL is not valid
* @return string HTML to output.
*/
protected function forgotten_password_url_warning($invalidforgottenpasswordurl) {
$output = '';
if ($invalidforgottenpasswordurl) {
$settingslink = new moodle_url('/admin/settings.php', ['section' => 'manageauths']);
$configurebutton = $this->single_button($settingslink, get_string('check', 'moodle'));
$output .= $this->warning(get_string('invalidforgottenpasswordurl', 'admin') . ' ' . $configurebutton,
'error alert alert-danger');
}
return $output;
}
/**
* Helper method to render the information about the available Moodle update
*
* @param \core\update\info $updateinfo information about the available Moodle core update
*/
protected function moodle_available_update_info(\core\update\info $updateinfo) {
$boxclasses = 'moodleupdateinfo';
$info = array();
if (isset($updateinfo->release)) {
$info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
array('class' => 'info release'));
}
if (isset($updateinfo->version)) {
$info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
array('class' => 'info version'));
}
if (isset($updateinfo->maturity)) {
$info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
array('class' => 'info maturity'));
$boxclasses .= ' maturity'.$updateinfo->maturity;
}
if (isset($updateinfo->download)) {
$info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
}
if (isset($updateinfo->url)) {
$info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
array('class' => 'info more'));
}
$box = $this->output->box_start($boxclasses);
$box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
$box .= $this->output->box_end();
return $box;
}
/**
* Display a link to the release notes.
* @return string HTML to output.
*/
protected function release_notes_link() {
$releasenoteslink = get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/dev/Releases');
$releasenoteslink = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $releasenoteslink); // extremely ugly validation hack
return $this->box($releasenoteslink, 'generalbox alert alert-info');
}
/**
* Display the reload link that appears on several upgrade/install pages.
* @return string HTML to output.
*/
function upgrade_reload($url) {
return html_writer::empty_tag('br') .
html_writer::tag('div',
html_writer::link($url, $this->pix_icon('i/reload', '', '', array('class' => 'icon icon-pre')) .
get_string('reload'), array('title' => get_string('reload'))),
array('class' => 'continuebutton')) . html_writer::empty_tag('br');
}
/**
* Displays all known plugins and information about their installation or upgrade
*
* This default implementation renders all plugins into one big table. The rendering
* options support:
* (bool)full = false: whether to display up-to-date plugins, too
* (bool)xdep = false: display the plugins with unsatisified dependecies only
*
* @param core_plugin_manager $pluginman provides information about the plugins.
* @param int $version the version of the Moodle code from version.php.
* @param array $options rendering options
* @return string HTML code
*/
public function plugins_check_table(core_plugin_manager $pluginman, $version, array $options = array()) {
global $CFG;
$plugininfo = $pluginman->get_plugins();
if (empty($plugininfo)) {
return '';
}
$options['full'] = isset($options['full']) ? (bool)$options['full'] : false;
$options['xdep'] = isset($options['xdep']) ? (bool)$options['xdep'] : false;
$table = new html_table();
$table->id = 'plugins-check';
$table->head = array(
get_string('displayname', 'core_plugin').' / '.get_string('rootdir', 'core_plugin'),
get_string('versiondb', 'core_plugin'),