-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathsettings.php
203 lines (170 loc) · 9.72 KB
/
settings.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
<?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/>.
/**
* Local plugin "staticpage" - Settings
*
* @package local_staticpage
* @copyright 2013 Alexander Bias, Ulm University <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
// Globals.
global $CFG, $PAGE;
// Include lib.php.
require_once($CFG->dirroot.'/local/staticpage/lib.php');
// Check if this user has the right to manage static page documents.
$hasmanagedocuments = has_capability('local/staticpage:managedocuments', context_system::instance());
// The 'Documents' settings page and the 'List of static pages' settings page should be accessible for users
// with either the moodle/site:config or the local/staticpage:managedocuments capability.
// As there is no possibility to attach multiple capabilities with an OR rule to a settings page,
// we pick the capability to use here and pass it to the page later.
if ($hasmanagedocuments) {
$capabilityrequiredforpage = 'local/staticpage:managedocuments';
} else {
$capabilityrequiredforpage = 'moodle/site:config';
}
// Require one of these capabilities.
if ($hassiteconfig || $hasmanagedocuments) {
// Add new category to site admin navigation tree.
$ADMIN->add('root', new admin_category('local_staticpage',
get_string('pluginname', 'local_staticpage', null, true)));
// Create new documents page.
$page = new admin_settingpage('local_staticpage_documents',
get_string('documents', 'local_staticpage', null, true),
$capabilityrequiredforpage);
if ($ADMIN->fulltree) {
// Create document filearea widget.
$page->add(new \local_staticpage\admin_setting_staticpagestoredfile('local_staticpage/documents',
get_string('documents', 'local_staticpage', null, true),
get_string('documents_desc', 'local_staticpage', null, true),
'documents',
0,
['maxfiles' => -1, 'accepted_types' => '.html']));
}
// Add documents page to navigation category.
$ADMIN->add('local_staticpage', $page);
// Create new settings page.
$page = new admin_settingpage('local_staticpage_settings',
get_string('settings', 'core', null, true));
if ($ADMIN->fulltree) {
// Document title source.
$page->add(new admin_setting_heading('local_staticpage/documenttitlesourceheading',
get_string('documenttitlesource', 'local_staticpage', null, true),
''));
// Create document title source widget.
$titlesource[STATICPAGE_TITLE_H1] = get_string('documenttitlesourceh1', 'local_staticpage', null, false);
// Don't use string lazy loading here because the string will be directly used and
// would produce a PHP warning otherwise.
$titlesource[STATICPAGE_TITLE_HEAD] = get_string('documenttitlesourcehead', 'local_staticpage', null, true);
$page->add(new admin_setting_configselect('local_staticpage/documenttitlesource',
get_string('documenttitlesource', 'local_staticpage', null, true),
get_string('documenttitlesource_desc', 'local_staticpage', null, true),
STATICPAGE_TITLE_H1,
$titlesource));
$page->add(new admin_setting_configselect('local_staticpage/documentheadingsource',
get_string('documentheadingsource', 'local_staticpage', null, true),
get_string('documentheadingsource_desc', 'local_staticpage', null, true),
STATICPAGE_TITLE_H1,
$titlesource));
// Apache rewrite.
$page->add(new admin_setting_heading('local_staticpage/apacherewriteheading',
get_string('apacherewrite', 'local_staticpage', null, true),
''));
// Create apache rewrite control widget.
$page->add(new admin_setting_configcheckbox('local_staticpage/apacherewrite',
get_string('apacherewrite', 'local_staticpage', null, true),
get_string('apacherewrite_desc', 'local_staticpage', null, true),
0));
// Force login.
$page->add(new admin_setting_heading('local_staticpage/forceloginheading',
get_string('forcelogin', 'local_staticpage', null, true),
''));
// Create force login widget.
$forceloginmodes[STATICPAGE_FORCELOGIN_YES] = get_string('yes', 'core', null, true);
$forceloginmodes[STATICPAGE_FORCELOGIN_NO] = get_string('no', 'core', null, true);
$forceloginmodes[STATICPAGE_FORCELOGIN_GLOBAL] = get_string('forceloginglobal', 'local_staticpage', null, false);
// Don't use string lazy loading here because the string will be directly used and
// would produce a PHP warning otherwise.
$page->add(new admin_setting_configselect('local_staticpage/forcelogin',
get_string('forcelogin', 'local_staticpage', null, true),
get_string('forcelogin_desc', 'local_staticpage', null, true),
STATICPAGE_FORCELOGIN_GLOBAL,
$forceloginmodes));
// Process content.
$page->add(new admin_setting_heading('local_staticpage/processcontentheading',
get_string('processcontent', 'local_staticpage', null, true),
''));
// Create process filters widget.
$processfiltersmodes[STATICPAGE_PROCESSFILTERS_YES] = get_string('processfiltersyes', 'local_staticpage', null, false);
// Don't use string lazy loading here because the string will be directly used and
// would produce a PHP warning otherwise.
$processfiltersmodes[STATICPAGE_PROCESSFILTERS_NO] = get_string('processfiltersno', 'local_staticpage', null, true);
$page->add(new admin_setting_configselect('local_staticpage/processfilters',
get_string('processfilters', 'local_staticpage', null, true),
get_string('processfilters_desc', 'local_staticpage', null, true),
STATICPAGE_PROCESSFILTERS_YES,
$processfiltersmodes));
// Create clean HTML widget.
$cleanhtmlmodes[STATICPAGE_CLEANHTML_YES] = get_string('cleanhtmlyes', 'local_staticpage', null, false);
// Don't use string lazy loading here because the string will be directly used and
// would produce a PHP warning otherwise.
$cleanhtmlmodes[STATICPAGE_CLEANHTML_NO] = get_string('cleanhtmlno', 'local_staticpage', null, true);
$page->add(new admin_setting_configselect('local_staticpage/cleanhtml',
get_string('cleanhtml', 'local_staticpage', null, true),
get_string('cleanhtml_desc', 'local_staticpage', null, true),
STATICPAGE_CLEANHTML_YES,
$cleanhtmlmodes));
// Check availability.
$page->add(new admin_setting_heading('local_staticpage/checkavailabilityheading',
get_string('checkavailability', 'local_staticpage', null, true),
''));
// Create checkavailability widget.
$checkavailabilitymodes[STATICPAGE_CHECKAVAILABILITY_YES] =
get_string('checkavailabilityyes', 'local_staticpage', null, false);
// Don't use string lazy loading here because the string will be directly used and
// would produce a PHP warning otherwise.
$checkavailabilitymodes[STATICPAGE_CHECKAVAILABILITY_NO] =
get_string('checkavailabilityno', 'local_staticpage', null, true);
$page->add(new admin_setting_configselect('local_staticpage/checkavailability',
get_string('checkavailability', 'local_staticpage', null, true),
get_string('checkavailability_desc', 'local_staticpage', null, true),
STATICPAGE_CHECKAVAILABILITY_YES,
$checkavailabilitymodes));
// Create connect timeout widget.
$page->add(new admin_setting_configtext('local_staticpage/checkavailabilityconnecttimeout',
get_string('checkavailabilityconnecttimeout', 'local_staticpage', null, true),
get_string('checkavailabilityconnecttimeout_desc', 'local_staticpage', null, true),
0,
PARAM_INT,
4));
// Create timeout widget.
$page->add(new admin_setting_configtext('local_staticpage/checkavailabilitytimeout',
get_string('checkavailabilitytimeout', 'local_staticpage', null, true),
get_string('checkavailabilitytimeout_desc', 'local_staticpage', null, true),
0,
PARAM_INT,
4));
}
// Add settings page to navigation category.
$ADMIN->add('local_staticpage', $page);
// Create new external pagelist page.
$page = new admin_externalpage('local_staticpage_pagelist',
get_string('settingspagelist', 'local_staticpage', null, true),
new \core\url('/local/staticpage/settings_pagelist.php'),
$capabilityrequiredforpage);
// Add pagelist page to navigation category.
$ADMIN->add('local_staticpage', $page);
}