MDL-22054 skip loading of missing modules
[moodle.git] / admin / settings / plugins.php
CommitLineData
11b749ca 1<?php
220a90c5 2
b63a6a63 3/*
4 * Please note that is file is always loaded last - it means that you can inject entries into other categories too.
5 */
6
78946b9b 7if ($hassiteconfig) {
ff4b9fcb 8 $ADMIN->add('modules', new admin_category('modsettings', get_string('activitymodules')));
220a90c5 9 $ADMIN->add('modsettings', new admin_page_managemods());
823e64a7 10 if ($modules = $DB->get_records('modules')) {
220a90c5 11 $modulebyname = array();
12
13 foreach ($modules as $module) {
fc61cecd
PS
14 if (!file_exists("$CFG->dirroot/mod/$module->name/lib.php")) {
15 continue;
16 }
220a90c5 17 $strmodulename = get_string('modulename', $module->name);
18 // Deal with modules which are lacking the language string
19 if ($strmodulename == '[[modulename]]') {
20 $textlib = textlib_get_instance();
21 $strmodulename = $textlib->strtotitle($module->name);
22 }
23 $modulebyname[$strmodulename] = $module;
24 }
25 ksort($modulebyname);
26
27 foreach ($modulebyname as $strmodulename=>$module) {
28 $modulename = $module->name;
c37415a0 29 if (file_exists($CFG->dirroot.'/mod/'.$modulename.'/settingstree.php')) {
30 include($CFG->dirroot.'/mod/'.$modulename.'/settingstree.php');
31 } else if (file_exists($CFG->dirroot.'/mod/'.$modulename.'/settings.php')) {
220a90c5 32 // do not show disabled modules in tree, keep only settings link on manage page
33 $settings = new admin_settingpage('modsetting'.$modulename, $strmodulename, 'moodle/site:config', !$module->visible);
34 if ($ADMIN->fulltree) {
35 include($CFG->dirroot.'/mod/'.$modulename.'/settings.php');
36 }
37 $ADMIN->add('modsettings', $settings);
220a90c5 38 }
39 }
40 }
41
b032b490 42 // hidden script for converting journals to online assignments (or something like that) linked from elsewhere
43 $ADMIN->add('modsettings', new admin_externalpage('oacleanup', 'Online Assignment Cleanup', $CFG->wwwroot.'/'.$CFG->admin.'/oacleanup.php', 'moodle/site:config', true));
220a90c5 44
45 $ADMIN->add('modules', new admin_category('blocksettings', get_string('blocks')));
46 $ADMIN->add('blocksettings', new admin_page_manageblocks());
ab2eb65c 47 if ($blocks = $DB->get_records('block')) {
220a90c5 48 $blockbyname = array();
49
50 foreach ($blocks as $block) {
6682cf18
PS
51 if (!file_exists("$CFG->dirroot/blocks/$block->name")) {
52 continue;
53 }
01ca2df0 54 if(($blockobject = block_instance($block->name)) === false) {
55 // Failed to load
56 continue;
220a90c5 57 }
01ca2df0 58 $blockbyname[$blockobject->get_title()] = $block;
220a90c5 59 }
60 ksort($blockbyname);
61
62 foreach ($blockbyname as $strblockname=>$block) {
63 $blockname = $block->name;
64 if (file_exists($CFG->dirroot.'/blocks/'.$blockname.'/settings.php')) {
65 $settings = new admin_settingpage('blocksetting'.$blockname, $strblockname, 'moodle/site:config', !$block->visible);
66 if ($ADMIN->fulltree) {
67 include($CFG->dirroot.'/blocks/'.$blockname.'/settings.php');
68 }
69 $ADMIN->add('blocksettings', $settings);
70
71 } else if (file_exists($CFG->dirroot.'/blocks/'.$blockname.'/config_global.html')) {
72 $ADMIN->add('blocksettings', new admin_externalpage('blocksetting'.$blockname, $strblockname, "$CFG->wwwroot/$CFG->admin/block.php?block=$block->id", 'moodle/site:config', !$block->visible));
73 }
74 }
75 }
76
c5d2d0dd 77
a5747cf8 78/// Editor plugins
79 $ADMIN->add('modules', new admin_category('editorsettings', get_string('editors', 'editor')));
80 $temp = new admin_settingpage('manageeditors', get_string('editorsettings', 'editor'));
81 $temp->add(new admin_setting_manageeditors());
82 $ADMIN->add('editorsettings', $temp);
83
7a856a93
DC
84 $editors_available = get_available_editors();
85 $url = $CFG->wwwroot.'/'.$CFG->admin.'/editors.php?sesskey='.sesskey();
86 foreach ($editors_available as $editor=>$editorstr) {
87 if (file_exists($CFG->dirroot . '/lib/editor/'.$editor.'/settings.php')) {
88 $editor_setting = new admin_externalpage('editorsettings'.$editor, $editorstr, $url.'&amp;action=edit&amp;editor='.$editor);
89 $ADMIN->add('editorsettings', $editor_setting);
90 }
91 }
1dce6261
DC
92/// License types
93 $ADMIN->add('modules', new admin_category('licensesettings', get_string('license')));
94 $temp = new admin_settingpage('managelicenses', get_string('license'));
ba74f517
DC
95
96 require_once($CFG->libdir . '/licenselib.php');
97 $licenses = array();
98 $array = explode(',', $CFG->licenses);
99 foreach ($array as $value) {
100 $licenses[$value] = get_string($value, 'license');
101 }
102 $temp->add(new admin_setting_configselect('sitedefaultlicense', get_string('configsitedefaultlicense','admin'), get_string('configsitedefaultlicensehelp','admin'), 'allrightsreserved', $licenses));
103
104 $ADMIN->add('licensesettings', $temp);
105
1dce6261
DC
106 $temp->add(new admin_setting_managelicenses());
107 $ADMIN->add('licensesettings', $temp);
a5747cf8 108
109/// Filter plugins
220a90c5 110 $ADMIN->add('modules', new admin_category('filtersettings', get_string('managefilters')));
dcdf3b29 111
112 $ADMIN->add('filtersettings', new admin_page_managefilters());
113
220a90c5 114 // "filtersettings" settingpage
dcdf3b29 115 $temp = new admin_settingpage('commonfiltersettings', get_string('commonfiltersettings', 'admin'));
220a90c5 116 if ($ADMIN->fulltree) {
5b8fa09b 117 $cachetimes = array(
118 604800 => get_string('numdays','',7),
119 86400 => get_string('numdays','',1),
120 43200 => get_string('numhours','',12),
121 10800 => get_string('numhours','',3),
122 7200 => get_string('numhours','',2),
123 3600 => get_string('numhours','',1),
124 2700 => get_string('numminutes','',45),
125 1800 => get_string('numminutes','',30),
126 900 => get_string('numminutes','',15),
127 600 => get_string('numminutes','',10),
128 540 => get_string('numminutes','',9),
129 480 => get_string('numminutes','',8),
130 420 => get_string('numminutes','',7),
131 360 => get_string('numminutes','',6),
132 300 => get_string('numminutes','',5),
133 240 => get_string('numminutes','',4),
134 180 => get_string('numminutes','',3),
135 120 => get_string('numminutes','',2),
136 60 => get_string('numminutes','',1),
137 30 => get_string('numseconds','',30),
138 0 => get_string('no')
139 );
109e3cb2 140 $items = array();
5b8fa09b 141 $items[] = new admin_setting_configselect('cachetext', get_string('cachetext', 'admin'), get_string('configcachetext', 'admin'), 60, $cachetimes);
142 $items[] = new admin_setting_configselect('filteruploadedfiles', get_string('filteruploadedfiles', 'admin'), get_string('configfilteruploadedfiles', 'admin'), 0,
143 array('0' => get_string('none'), '1' => get_string('allfiles'), '2' => get_string('htmlfilesonly')));
109e3cb2 144 $items[] = new admin_setting_configcheckbox('filtermatchoneperpage', get_string('filtermatchoneperpage', 'admin'), get_string('configfiltermatchoneperpage', 'admin'), 0);
145 $items[] = new admin_setting_configcheckbox('filtermatchonepertext', get_string('filtermatchonepertext', 'admin'), get_string('configfiltermatchonepertext', 'admin'), 0);
109e3cb2 146 foreach ($items as $item) {
147 $item->set_updatedcallback('reset_text_filters_cache');
148 $temp->add($item);
149 }
220a90c5 150 }
151 $ADMIN->add('filtersettings', $temp);
152
5b8fa09b 153 $activefilters = filter_get_globally_enabled();
b810a4d3 154 $filternames = filter_get_all_installed();
155 foreach ($filternames as $filterpath => $strfiltername) {
156 if (file_exists("$CFG->dirroot/$filterpath/filtersettings.php")) {
157 $settings = new admin_settingpage('filtersetting'.str_replace('/', '', $filterpath),
5b8fa09b 158 $strfiltername, 'moodle/site:config', !isset($activefilters[$filterpath]));
b810a4d3 159 if ($ADMIN->fulltree) {
160 include("$CFG->dirroot/$filterpath/filtersettings.php");
220a90c5 161 }
b810a4d3 162 $ADMIN->add('filtersettings', $settings);
220a90c5 163 }
164 }
67a87e7d 165
78946b9b
PS
166
167 //== Portfolio settings ==
168 require_once($CFG->libdir. '/portfoliolib.php');
b810a4d3 169 $catname = get_string('portfolios', 'portfolio');
67a87e7d 170 $manage = get_string('manageportfolios', 'portfolio');
171 $url = "$CFG->wwwroot/$CFG->admin/portfolio.php";
172
90658eef 173 $ADMIN->add('modules', new admin_category('portfoliosettings', $catname, empty($CFG->enableportfolios)));
67a87e7d 174
a50ef3d3 175 // jump through hoops to do what we want
176 $temp = new admin_settingpage('manageportfolios', get_string('manageportfolios', 'portfolio'));
bee4bce2 177 $temp->add(new admin_setting_heading('manageportfolios', get_string('activeportfolios', 'portfolio'), ''));
a50ef3d3 178 $temp->add(new admin_setting_manageportfolio());
bee4bce2 179 $temp->add(new admin_setting_heading('manageportfolioscommon', get_string('commonsettings', 'admin'), get_string('commonsettingsdesc', 'portfolio')));
180 $fileinfo = portfolio_filesize_info(); // make sure this is defined in one place since its used inside portfolio too to detect insane settings
181 $fileoptions = $fileinfo['options'];
182 $temp->add(new admin_setting_configselect(
183 'portfolio_moderate_filesize_threshold',
184 get_string('moderatefilesizethreshold', 'portfolio'),
185 get_string('moderatefilesizethresholddesc', 'portfolio'),
186 $fileinfo['moderate'], $fileoptions));
187 $temp->add(new admin_setting_configselect(
188 'portfolio_high_filesize_threshold',
189 get_string('highfilesizethreshold', 'portfolio'),
190 get_string('highfilesizethresholddesc', 'portfolio'),
191 $fileinfo['high'], $fileoptions));
192
193 $temp->add(new admin_setting_configtext(
194 'portfolio_moderate_db_threshold',
195 get_string('moderatedbsizethreshold', 'portfolio'),
196 get_string('moderatedbsizethresholddesc', 'portfolio'),
197 20, PARAM_INTEGER, 3));
198
199 $temp->add(new admin_setting_configtext(
200 'portfolio_high_db_threshold',
201 get_string('highdbsizethreshold', 'portfolio'),
202 get_string('highdbsizethresholddesc', 'portfolio'),
203 50, PARAM_INTEGER, 3));
a50ef3d3 204
205 $ADMIN->add('portfoliosettings', $temp);
206 $ADMIN->add('portfoliosettings', new admin_externalpage('portfolionew', get_string('addnewportfolio', 'portfolio'), $url, 'moodle/site:config', true), '', $url);
207 $ADMIN->add('portfoliosettings', new admin_externalpage('portfoliodelete', get_string('deleteportfolio', 'portfolio'), $url, 'moodle/site:config', true), '', $url);
208 $ADMIN->add('portfoliosettings', new admin_externalpage('portfoliocontroller', get_string('manageportfolios', 'portfolio'), $url, 'moodle/site:config', true), '', $url);
209
08d5e18b 210 foreach (portfolio_instances(false, false) as $portfolio) {
edf1fc35 211 require_once($CFG->dirroot . '/portfolio/' . $portfolio->get('plugin') . '/lib.php');
67a87e7d 212 $classname = 'portfolio_plugin_' . $portfolio->get('plugin');
a50ef3d3 213 $ADMIN->add(
214 'portfoliosettings',
08d5e18b 215 new admin_externalpage(
216 'portfoliosettings' . $portfolio->get('id'),
658837bb 217 $portfolio->get('name'),
08d5e18b 218 $url . '?edit=' . $portfolio->get('id'),
219 'moodle/site:config',
220 !$portfolio->get('visible')
221 ),
a50ef3d3 222 $portfolio->get('name'),
223 $url . ' ?edit=' . $portfolio->get('id')
224 );
67a87e7d 225 }
4a65c39a 226
227 // repository setting
228 require_once("$CFG->dirroot/repository/lib.php");
229 $catname =get_string('repositories', 'repository');
04bd6d2d 230 $managerepo = get_string('manage', 'repository');
231 $url = $CFG->wwwroot.'/'.$CFG->admin.'/repository.php';
4a65c39a 232 $ADMIN->add('modules', new admin_category('repositorysettings', $catname));
04bd6d2d 233 $temp = new admin_settingpage('managerepositories', $managerepo);
5a8ca187 234 $temp->add(new admin_setting_heading('managerepositories', get_string('activerepository', 'repository'), ''));
4a65c39a 235 $temp->add(new admin_setting_managerepository());
5a8ca187 236 $temp->add(new admin_setting_heading('managerepositoriescommonheading', get_string('commonsettings', 'admin'), ''));
5430f05b 237 $temp->add(new admin_setting_configtext('repositorycacheexpire', get_string('cacheexpire', 'repository'), get_string('configcacheexpire', 'repository'), 120));
99d52655 238 $temp->add(new admin_setting_configcheckbox('repositoryallowexternallinks', get_string('allowexternallinks', 'repository'), get_string('configallowexternallinks', 'repository'), 1));
4a65c39a 239 $ADMIN->add('repositorysettings', $temp);
4f2b9a4f 240 $ADMIN->add('repositorysettings', new admin_externalpage('repositorynew',
0d099914 241 get_string('addplugin', 'repository'), $url, 'moodle/site:config', true),
4a65c39a 242 '', $url);
243 $ADMIN->add('repositorysettings', new admin_externalpage('repositorydelete',
244 get_string('deleterepository', 'repository'), $url, 'moodle/site:config', true),
245 '', $url);
246 $ADMIN->add('repositorysettings', new admin_externalpage('repositorycontroller',
247 get_string('managerepositories', 'repository'), $url, 'moodle/site:config', true),
248 '', $url);
0d099914 249 $ADMIN->add('repositorysettings', new admin_externalpage('repositoryinstancenew',
250 get_string('createrepository', 'repository'), $url, 'moodle/site:config', true),
251 '', $url);
252 $ADMIN->add('repositorysettings', new admin_externalpage('repositoryinstanceedit',
253 get_string('editrepositoryinstance', 'repository'), $url, 'moodle/site:config', true),
254 '', $url);
78946b9b 255 foreach (repository::get_types() as $repositorytype) {
edb50637 256 //display setup page for plugins with: general options or multiple instances (e.g. has instance config)
dbc01944 257 $typeoptionnames = repository::static_function($repositorytype->get_typename(), 'get_type_option_names');
258 $instanceoptionnames = repository::static_function($repositorytype->get_typename(), 'get_instance_option_names');
edb50637 259 if (!empty($typeoptionnames) || !empty($instanceoptionnames)) {
4a65c39a 260 $ADMIN->add('repositorysettings',
a6600395 261 new admin_externalpage('repositorysettings'.$repositorytype->get_typename(),
262 $repositorytype->get_readablename(),
263 $url . '?edit=' . $repositorytype->get_typename()),
4a65c39a 264 'moodle/site:config');
265 }
266 }
78946b9b 267}
bee4bce2 268
5ae9f539 269/// Web services
cc93c7da 270 $ADMIN->add('modules', new admin_category('webservicesettings', get_string('webservices', 'webservice')));
3e6161fb 271 /// overview page
272 $temp = new admin_settingpage('webservicesoverview', get_string('webservicesoverview', 'webservice'));
273 $temp->add(new admin_setting_webservicesoverview());
274 $ADMIN->add('webservicesettings', $temp);
275 /// manage service
cc93c7da 276 $temp = new admin_settingpage('externalservices', get_string('externalservices', 'webservice'));
8399c714 277 $temp->add(new admin_setting_heading('manageserviceshelpexplaination', get_string('information', 'webservice'), get_string('servicehelpexplanation', 'webservice')));
cc93c7da 278 $temp->add(new admin_setting_manageexternalservices());
279 $ADMIN->add('webservicesettings', $temp);
72977b37 280 $ADMIN->add('webservicesettings', new admin_externalpage('externalservice', get_string('externalservice', 'webservice'), "$CFG->wwwroot/$CFG->admin/webservice/service.php", 'moodle/site:config', true));
281 $ADMIN->add('webservicesettings', new admin_externalpage('externalservicefunctions', get_string('externalservicefunctions', 'webservice'), "$CFG->wwwroot/$CFG->admin/webservice/service_functions.php", 'moodle/site:config', true));
282 $ADMIN->add('webservicesettings', new admin_externalpage('externalserviceusers', get_string('externalserviceusers', 'webservice'), "$CFG->wwwroot/$CFG->admin/webservice/service_users.php", 'moodle/site:config', true));
5ae9f539 283 /// manage protocol page link
cc93c7da 284 $temp = new admin_settingpage('webserviceprotocols', get_string('manageprotocols', 'webservice'));
da124b5e 285 $temp->add(new admin_setting_managewebserviceprotocols());
cc93c7da 286 if (empty($CFG->enablewebservices)) {
287 $temp->add(new admin_setting_heading('webservicesaredisabled', '', get_string('disabledwarning', 'webservice')));
288 }
4b4b53a7 289 $url = new moodle_url('/webservice/wsdoc.php');
290 $atag =html_writer::start_tag('a', array('href' => $url)).get_string('documentation', 'webservice').html_writer::end_tag('a');
291 $temp->add(new admin_setting_configcheckbox('enablewsdocumentation', get_string('enablewsdocumentation', 'admin'), get_string('configenablewsdocumentation', 'admin', $atag), false));
cc93c7da 292 $ADMIN->add('webservicesettings', $temp);
5ae9f539 293 /// links to protocol pages
cc93c7da 294 $webservices_available = get_plugin_list('webservice');
295 $active_webservices = empty($CFG->webserviceprotocols) ? array() : explode(',', $CFG->webserviceprotocols);
296 foreach ($webservices_available as $webservice => $location) {
297 if (file_exists("$location/settings.php")) {
298 $name = get_string('pluginname', 'webservice_'.$webservice);
299 $settings = new admin_settingpage('webservicesetting'.$webservice, $name, 'moodle/site:config', !in_array($webservice, $active_webservices) or empty($CFG->enablewebservices));
300 if ($ADMIN->fulltree) {
301 include("$location/settings.php");
302 }
303 $ADMIN->add('webservicesettings', $settings);
304 }
305 }
5ae9f539 306 /// manage token page link
15e417fe 307 $ADMIN->add('webservicesettings', new admin_externalpage('addwebservicetoken', get_string('managetokens', 'webservice'), "$CFG->wwwroot/$CFG->admin/webservice/tokens.php", 'moodle/site:config', true));
5ae9f539 308 $temp = new admin_settingpage('webservicetokens', get_string('managetokens', 'webservice'));
309 $temp->add(new admin_setting_managewebservicetokens());
310 if (empty($CFG->enablewebservices)) {
311 $temp->add(new admin_setting_heading('webservicesaredisabled', '', get_string('disabledwarning', 'webservice')));
312 }
313 $ADMIN->add('webservicesettings', $temp);
314
cc93c7da 315
78946b9b 316if ($hassiteconfig || has_capability('moodle/question:config', $systemcontext)) {
bee4bce2 317 // Question type settings.
318 $ADMIN->add('modules', new admin_category('qtypesettings', get_string('questiontypes', 'admin')));
319 $ADMIN->add('qtypesettings', new admin_page_manageqtypes());
320 require_once($CFG->libdir . '/questionlib.php');
321 global $QTYPES;
322 foreach ($QTYPES as $qtype) {
323 $settingsfile = $qtype->plugin_dir() . '/settings.php';
324 if (file_exists($settingsfile)) {
325 $settings = new admin_settingpage('qtypesetting' . $qtype->name(),
326 $qtype->local_name(), 'moodle/question:config');
327 if ($ADMIN->fulltree) {
328 include($settingsfile);
329 }
330 $ADMIN->add('qtypesettings', $settings);
331 }
332 }
220a90c5 333}
b63a6a63 334
335
1bcb7eb5 336$ADMIN->add('reports', new admin_externalpage('comments', get_string('comments'), $CFG->wwwroot.'/comment/', 'moodle/site:viewreports'));
b63a6a63 337/// Now add reports
338
17da2e6f 339foreach (get_plugin_list('report') as $plugin => $plugindir) {
340 $settings_path = "$plugindir/settings.php";
b63a6a63 341 if (file_exists($settings_path)) {
342 include($settings_path);
343 continue;
344 }
345
17da2e6f 346 $index_path = "$plugindir/index.php";
b63a6a63 347 if (!file_exists($index_path)) {
348 continue;
349 }
350 // old style 3rd party plugin without settings.php
17da2e6f 351 $www_path = "$CFG->wwwroot/$CFG->admin/report/$plugin/index.php";
c5fce2fa 352 $reportname = get_string($plugin, 'report_' . $plugin);
353 $ADMIN->add('reports', new admin_externalpage('report'.$plugin, $reportname, $www_path, 'moodle/site:viewreports'));
b63a6a63 354}
355
17da2e6f 356
357/// Add all local plugins - must be always last!
1ed47309
DM
358if ($hassiteconfig) {
359 $ADMIN->add('modules', new admin_category('localplugins', get_string('localplugins')));
360 $ADMIN->add('localplugins', new admin_externalpage('managelocalplugins', get_string('localpluginsmanage'),
361 $CFG->wwwroot . '/' . $CFG->admin . '/localplugins.php'));
362}
17da2e6f 363
364foreach (get_plugin_list('local') as $plugin => $plugindir) {
365 $settings_path = "$plugindir/settings.php";
366 if (file_exists($settings_path)) {
367 include($settings_path);
368 continue;
369 }
1bcb7eb5 370}