Merge branch 'MDL-65812-editable-timeout' of https://github.com/brendanheywood/moodle
[moodle.git] / lib / setup.php
CommitLineData
da8759cb 1<?php
b37eac91 2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
da8759cb 18/**
19 * setup.php - Sets up sessions, connects to databases and so on
20 *
75249234 21 * Normally this is only called by the main config.php file
22 * Normally this file does not need to be edited.
b37eac91 23 *
78bfb562
PS
24 * @package core
25 * @subpackage lib
26 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
da8759cb 28 */
29
da8759cb 30/**
e1d1b796 31 * Holds the core settings that affect how Moodle works. Some of its fields
32 * are set in config.php, and the rest are loaded from the config table.
33 *
34 * Some typical settings in the $CFG global:
3b5ff37f
PS
35 * - $CFG->wwwroot - Path to moodle index directory in url format.
36 * - $CFG->dataroot - Path to moodle data files directory on server's filesystem.
37 * - $CFG->dirroot - Path to moodle's library folder on server's filesystem.
38 * - $CFG->libdir - Path to moodle's library folder on server's filesystem.
ef844148 39 * - $CFG->backuptempdir - Path to moodle's backup temp file directory on server's filesystem.
3e939871 40 * - $CFG->tempdir - Path to moodle's temp file directory on server's filesystem.
85b38061
PS
41 * - $CFG->cachedir - Path to moodle's cache directory on server's filesystem (shared by cluster nodes).
42 * - $CFG->localcachedir - Path to moodle's local cache directory (not shared by cluster nodes).
e1d1b796 43 *
44 * @global object $CFG
b37eac91 45 * @name $CFG
e1d1b796 46 */
b30fa335 47global $CFG; // this should be done much earlier in config.php before creating new $CFG instance
e1d1b796 48
fe79c400 49if (!isset($CFG)) {
a3d5830a 50 if (defined('PHPUNIT_TEST') and PHPUNIT_TEST) {
fe79c400
PS
51 echo('There is a missing "global $CFG;" at the beginning of the config.php file.'."\n");
52 exit(1);
53 } else {
54 // this should never happen, maybe somebody is accessing this file directly...
55 exit(1);
56 }
57}
58
3b5ff37f
PS
59// We can detect real dirroot path reliably since PHP 4.0.2,
60// it can not be anything else, there is no point in having this in config.php
1fcf0ca8 61$CFG->dirroot = dirname(__DIR__);
3b5ff37f 62
f46e869d
DM
63// File permissions on created directories in the $CFG->dataroot
64if (!isset($CFG->directorypermissions)) {
65 $CFG->directorypermissions = 02777; // Must be octal (that's why it's here)
66}
67if (!isset($CFG->filepermissions)) {
68 $CFG->filepermissions = ($CFG->directorypermissions & 0666); // strip execute flags
69}
70// Better also set default umask because developers often forget to include directory
71// permissions in mkdir() and chmod() after creating new files.
72if (!isset($CFG->umaskpermissions)) {
73 $CFG->umaskpermissions = (($CFG->directorypermissions & 0777) ^ 0777);
74}
75umask($CFG->umaskpermissions);
76
60129d5d
PS
77if (defined('BEHAT_SITE_RUNNING')) {
78 // We already switched to behat test site previously.
79
80} else if (!empty($CFG->behat_wwwroot) or !empty($CFG->behat_dataroot) or !empty($CFG->behat_prefix)) {
81 // The behat is configured on this server, we need to find out if this is the behat test
82 // site based on the URL used for access.
a2754d79
RT
83 require_once(__DIR__ . '/../lib/behat/lib.php');
84
85 // Update config variables for parallel behat runs.
86 behat_update_vars_for_process();
3c71c15c 87
36cc9f8e
RT
88 // If behat is being installed for parallel run, then we modify params for parallel run only.
89 if (behat_is_test_site() && !(defined('BEHAT_PARALLEL_UTIL') && empty($CFG->behatrunprocess))) {
3c71c15c
RT
90 clearstatcache();
91
60129d5d
PS
92 // Checking the integrity of the provided $CFG->behat_* vars and the
93 // selected wwwroot to prevent conflicts with production and phpunit environments.
94 behat_check_config_vars();
95
9bb80d20
PS
96 // Check that the directory does not contains other things.
97 if (!file_exists("$CFG->behat_dataroot/behattestdir.txt")) {
98 if ($dh = opendir($CFG->behat_dataroot)) {
99 while (($file = readdir($dh)) !== false) {
08e7f97e 100 if ($file === 'behat' or $file === '.' or $file === '..' or $file === '.DS_Store' or is_numeric($file)) {
9bb80d20
PS
101 continue;
102 }
027212b0
RT
103 behat_error(BEHAT_EXITCODE_CONFIG, "$CFG->behat_dataroot directory is not empty, ensure this is the " .
104 "directory where you want to install behat test dataroot");
9bb80d20
PS
105 }
106 closedir($dh);
107 unset($dh);
108 unset($file);
109 }
110
111 if (defined('BEHAT_UTIL')) {
112 // Now we create dataroot directory structure for behat tests.
113 testing_initdataroot($CFG->behat_dataroot, 'behat');
114 } else {
115 behat_error(BEHAT_EXITCODE_INSTALL);
116 }
117 }
118
60129d5d
PS
119 if (!defined('BEHAT_UTIL') and !defined('BEHAT_TEST')) {
120 // Somebody tries to access test site directly, tell them if not enabled.
36cc9f8e
RT
121 $behatdir = preg_replace("#[/|\\\]" . BEHAT_PARALLEL_SITE_NAME . "\d{0,}$#", '', $CFG->behat_dataroot);
122 if (!file_exists($behatdir . '/test_environment_enabled.txt')) {
60129d5d
PS
123 behat_error(BEHAT_EXITCODE_CONFIG, 'Behat is configured but not enabled on this test site.');
124 }
125 }
126
127 // Constant used to inform that the behat test site is being used,
128 // this includes all the processes executed by the behat CLI command like
129 // the site reset, the steps executed by the browser drivers when simulating
130 // a user session and a real session when browsing manually to $CFG->behat_wwwroot
131 // like the browser driver does automatically.
132 // Different from BEHAT_TEST as only this last one can perform CLI
133 // actions like reset the site or use data generators.
134 define('BEHAT_SITE_RUNNING', true);
135
136 // Clean extra config.php settings.
137 behat_clean_init_config();
138
139 // Now we can begin switching $CFG->X for $CFG->behat_X.
140 $CFG->wwwroot = $CFG->behat_wwwroot;
60129d5d
PS
141 $CFG->prefix = $CFG->behat_prefix;
142 $CFG->dataroot = $CFG->behat_dataroot;
143 }
144}
145
3b5ff37f
PS
146// Normalise dataroot - we do not want any symbolic links, trailing / or any other weirdness there
147if (!isset($CFG->dataroot)) {
56953adc
PS
148 if (isset($_SERVER['REMOTE_ADDR'])) {
149 header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable');
150 }
fe79c400 151 echo('Fatal error: $CFG->dataroot is not specified in config.php! Exiting.'."\n");
3b5ff37f
PS
152 exit(1);
153}
154$CFG->dataroot = realpath($CFG->dataroot);
155if ($CFG->dataroot === false) {
56953adc
PS
156 if (isset($_SERVER['REMOTE_ADDR'])) {
157 header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable');
158 }
fe79c400 159 echo('Fatal error: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.'."\n");
3b5ff37f 160 exit(1);
8b2ebe7f
PS
161} else if (!is_writable($CFG->dataroot)) {
162 if (isset($_SERVER['REMOTE_ADDR'])) {
163 header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable');
164 }
165 echo('Fatal error: $CFG->dataroot is not writable, admin has to fix directory permissions! Exiting.'."\n");
166 exit(1);
3b5ff37f
PS
167}
168
169// wwwroot is mandatory
170if (!isset($CFG->wwwroot) or $CFG->wwwroot === 'http://example.com/moodle') {
56953adc
PS
171 if (isset($_SERVER['REMOTE_ADDR'])) {
172 header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable');
173 }
fe79c400 174 echo('Fatal error: $CFG->wwwroot is not configured! Exiting.'."\n");
3b5ff37f
PS
175 exit(1);
176}
177
96f81ea3
PS
178// Make sure there is some database table prefix.
179if (!isset($CFG->prefix)) {
180 $CFG->prefix = '';
181}
182
3b5ff37f
PS
183// Define admin directory
184if (!isset($CFG->admin)) { // Just in case it isn't defined in config.php
185 $CFG->admin = 'admin'; // This is relative to the wwwroot and dirroot
186}
187
60f2c866
PS
188// Set up some paths.
189$CFG->libdir = $CFG->dirroot .'/lib';
190
383d3884 191// Allow overriding of tempdir but be backwards compatible
3e939871 192if (!isset($CFG->tempdir)) {
383d3884
TL
193 $CFG->tempdir = "$CFG->dataroot/temp";
194}
195
ef844148
MS
196// Allow overriding of backuptempdir but be backwards compatible
197if (!isset($CFG->backuptempdir)) {
198 $CFG->backuptempdir = "$CFG->tempdir/backup";
199}
200
383d3884
TL
201// Allow overriding of cachedir but be backwards compatible
202if (!isset($CFG->cachedir)) {
203 $CFG->cachedir = "$CFG->dataroot/cache";
3e939871
TL
204}
205
85b38061
PS
206// Allow overriding of localcachedir.
207if (!isset($CFG->localcachedir)) {
208 $CFG->localcachedir = "$CFG->dataroot/localcache";
209}
210
96f81ea3
PS
211// Location of all languages except core English pack.
212if (!isset($CFG->langotherroot)) {
213 $CFG->langotherroot = $CFG->dataroot.'/lang';
214}
215
216// Location of local lang pack customisations (dirs with _local suffix).
217if (!isset($CFG->langlocalroot)) {
218 $CFG->langlocalroot = $CFG->dataroot.'/lang';
219}
220
3b5ff37f
PS
221// The current directory in PHP version 4.3.0 and above isn't necessarily the
222// directory of the script when run from the command line. The require_once()
223// would fail, so we'll have to chdir()
224if (!isset($_SERVER['REMOTE_ADDR']) && isset($_SERVER['argv'][0])) {
5bd40408
PS
225 // do it only once - skip the second time when continuing after prevous abort
226 if (!defined('ABORT_AFTER_CONFIG') and !defined('ABORT_AFTER_CONFIG_CANCEL')) {
227 chdir(dirname($_SERVER['argv'][0]));
228 }
3b5ff37f
PS
229}
230
231// sometimes default PHP settings are borked on shared hosting servers, I wonder why they have to do that??
27466303 232ini_set('precision', 14); // needed for upgrades and gradebook
404ecca3 233ini_set('serialize_precision', 17); // Make float serialization consistent on all systems.
3b5ff37f
PS
234
235// Scripts may request no debug and error messages in output
236// please note it must be defined before including the config.php script
237// and in some cases you also need to set custom default exception handler
238if (!defined('NO_DEBUG_DISPLAY')) {
cb9ee2a9
PS
239 if (defined('AJAX_SCRIPT') and AJAX_SCRIPT) {
240 // Moodle AJAX scripts are expected to return json data, any PHP notices or errors break it badly,
241 // developers simply must learn to watch error log.
242 define('NO_DEBUG_DISPLAY', true);
243 } else {
244 define('NO_DEBUG_DISPLAY', false);
245 }
3b5ff37f
PS
246}
247
cbad562e
PS
248// Some scripts such as upgrade may want to prevent output buffering
249if (!defined('NO_OUTPUT_BUFFERING')) {
250 define('NO_OUTPUT_BUFFERING', false);
251}
252
5bd40408 253// PHPUnit tests need custom init
a3d5830a
PS
254if (!defined('PHPUNIT_TEST')) {
255 define('PHPUNIT_TEST', false);
5bd40408
PS
256}
257
58a3a34e
DM
258// Performance tests needs to always display performance info, even in redirections.
259if (!defined('MDL_PERF_TEST')) {
260 define('MDL_PERF_TEST', false);
261} else {
262 // We force the ones we need.
263 if (!defined('MDL_PERF')) {
264 define('MDL_PERF', true);
265 }
266 if (!defined('MDL_PERFDB')) {
267 define('MDL_PERFDB', true);
268 }
269 if (!defined('MDL_PERFTOFOOT')) {
270 define('MDL_PERFTOFOOT', true);
271 }
272}
273
94ef67cf
SH
274// When set to true MUC (Moodle caching) will be disabled as much as possible.
275// A special cache factory will be used to handle this situation and will use special "disabled" equivalents objects.
276// This ensure we don't attempt to read or create the config file, don't use stores, don't provide persistence or
277// storage of any kind.
278if (!defined('CACHE_DISABLE_ALL')) {
279 define('CACHE_DISABLE_ALL', false);
280}
281
d6a1f63b 282// When set to true MUC (Moodle caching) will not use any of the defined or default stores.
6fec1820 283// The Cache API will continue to function however this will force the use of the cachestore_dummy so all requests
d6a1f63b
SH
284// will be interacting with a static property and will never go to the proper cache stores.
285// Useful if you need to avoid the stores for one reason or another.
c9f40e77
SH
286if (!defined('CACHE_DISABLE_STORES')) {
287 define('CACHE_DISABLE_STORES', false);
d6a1f63b
SH
288}
289
d6e7a63d
PS
290// Servers should define a default timezone in php.ini, but if they don't then make sure no errors are shown.
291date_default_timezone_set(@date_default_timezone_get());
62c5e654 292
3b5ff37f 293// Detect CLI scripts - CLI scripts are executed from command line, do not have session and we do not want HTML in output
28bd3d9a
PS
294// In your new CLI scripts just add "define('CLI_SCRIPT', true);" before requiring config.php.
295// Please note that one script can not be accessed from both CLI and web interface.
3b5ff37f 296if (!defined('CLI_SCRIPT')) {
28bd3d9a
PS
297 define('CLI_SCRIPT', false);
298}
299if (defined('WEB_CRON_EMULATED_CLI')) {
300 if (!isset($_SERVER['REMOTE_ADDR'])) {
301 echo('Web cron can not be executed as CLI script any more, please use admin/cli/cron.php instead'."\n");
302 exit(1);
303 }
304} else if (isset($_SERVER['REMOTE_ADDR'])) {
305 if (CLI_SCRIPT) {
306 echo('Command line scripts can not be executed from the web interface');
307 exit(1);
308 }
309} else {
310 if (!CLI_SCRIPT) {
311 echo('Command line scripts must define CLI_SCRIPT before requiring config.php'."\n");
312 exit(1);
3b5ff37f
PS
313 }
314}
315
e5d48aad
316// All web service requests have WS_SERVER == true.
317if (!defined('WS_SERVER')) {
318 define('WS_SERVER', false);
319}
320
8820f4e7
PS
321// Detect CLI maintenance mode - this is useful when you need to mess with database, such as during upgrades
322if (file_exists("$CFG->dataroot/climaintenance.html")) {
323 if (!CLI_SCRIPT) {
f1c6d647
BH
324 header($_SERVER['SERVER_PROTOCOL'] . ' 503 Moodle under maintenance');
325 header('Status: 503 Moodle under maintenance');
326 header('Retry-After: 300');
8a7703ce 327 header('Content-type: text/html; charset=utf-8');
398862b9 328 header('X-UA-Compatible: IE=edge');
8820f4e7 329 /// Headers to make it not cacheable and json
27466303
PS
330 header('Cache-Control: no-store, no-cache, must-revalidate');
331 header('Cache-Control: post-check=0, pre-check=0', false);
332 header('Pragma: no-cache');
333 header('Expires: Mon, 20 Aug 1969 09:23:00 GMT');
334 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
335 header('Accept-Ranges: none');
8820f4e7
PS
336 readfile("$CFG->dataroot/climaintenance.html");
337 die;
338 } else {
e4c05ec7
PS
339 if (!defined('CLI_MAINTENANCE')) {
340 define('CLI_MAINTENANCE', true);
341 }
8820f4e7
PS
342 }
343} else {
e4c05ec7
PS
344 if (!defined('CLI_MAINTENANCE')) {
345 define('CLI_MAINTENANCE', false);
346 }
8820f4e7
PS
347}
348
2b53e97c
DP
349// Sometimes people use different PHP binary for web and CLI, make 100% sure they have the supported PHP version.
350if (version_compare(PHP_VERSION, '5.6.5') < 0) {
351 $phpversion = PHP_VERSION;
352 // Do NOT localise - lang strings would not work here and we CAN NOT move it to later place.
353 echo "Moodle 3.2 or later requires at least PHP 5.6.5 (currently using version $phpversion).\n";
354 echo "Some servers may have multiple PHP versions installed, are you using the correct executable?\n";
355 exit(1);
8de5d7b9
PS
356}
357
3b5ff37f
PS
358// Detect ajax scripts - they are similar to CLI because we can not redirect, output html, etc.
359if (!defined('AJAX_SCRIPT')) {
360 define('AJAX_SCRIPT', false);
361}
362
8a478446 363// Exact version of currently used yui2 and 3 library.
6fc17ca9 364$CFG->yui2version = '2.9.0';
2eb60257 365$CFG->yui3version = '3.17.2';
60f2c866 366
aea29737
AN
367// Patching the upstream YUI release.
368// For important information on patching YUI modules, please see http://docs.moodle.org/dev/YUI/Patching.
369// If we need to patch a YUI modules between official YUI releases, the yuipatchlevel will need to be manually
370// incremented here. The module will also need to be listed in the yuipatchedmodules.
371// When upgrading to a subsequent version of YUI, these should be reset back to 0 and an empty array.
2eb60257 372$CFG->yuipatchlevel = 0;
aea29737
AN
373$CFG->yuipatchedmodules = array(
374);
375
b0fc7898
DM
376if (!empty($CFG->disableonclickaddoninstall)) {
377 // This config.php flag has been merged into another one.
378 $CFG->disableupdateautodeploy = true;
379}
380
96f81ea3
PS
381// Store settings from config.php in array in $CFG - we can use it later to detect problems and overrides.
382if (!isset($CFG->config_php_settings)) {
383 $CFG->config_php_settings = (array)$CFG;
384 // Forced plugin settings override values from config_plugins table.
385 unset($CFG->config_php_settings['forced_plugin_settings']);
386 if (!isset($CFG->forced_plugin_settings)) {
387 $CFG->forced_plugin_settings = array();
388 }
389}
390
391if (isset($CFG->debug)) {
392 $CFG->debug = (int)$CFG->debug;
393} else {
394 $CFG->debug = 0;
395}
ce7b06bc 396$CFG->debugdeveloper = (($CFG->debug & (E_ALL | E_STRICT)) === (E_ALL | E_STRICT)); // DEBUG_DEVELOPER is not available yet.
96f81ea3 397
9240ecbd
PS
398if (!defined('MOODLE_INTERNAL')) { // Necessary because cli installer has to define it earlier.
399 /** Used by library scripts to check they are being called by Moodle. */
400 define('MOODLE_INTERNAL', true);
401}
402
9e19a0f0
PS
403// core_component can be used in any scripts, it does not need anything else.
404require_once($CFG->libdir .'/classes/component.php');
3b5ff37f 405
60f2c866
PS
406// special support for highly optimised scripts that do not need libraries and DB connection
407if (defined('ABORT_AFTER_CONFIG')) {
408 if (!defined('ABORT_AFTER_CONFIG_CANCEL')) {
0037dcc9 409 // hide debugging if not enabled in config.php - we do not want to disclose sensitive info
96f81ea3 410 error_reporting($CFG->debug);
463a9874
PS
411 if (NO_DEBUG_DISPLAY) {
412 // Some parts of Moodle cannot display errors and debug at all.
413 ini_set('display_errors', '0');
414 ini_set('log_errors', '1');
415 } else if (empty($CFG->debugdisplay)) {
27466303
PS
416 ini_set('display_errors', '0');
417 ini_set('log_errors', '1');
0037dcc9 418 } else {
27466303 419 ini_set('display_errors', '1');
0037dcc9 420 }
60f2c866
PS
421 require_once("$CFG->dirroot/lib/configonlylib.php");
422 return;
423 }
424}
425
c646dd26
EL
426// Early profiling start, based exclusively on config.php $CFG settings
427if (!empty($CFG->earlyprofilingenabled)) {
428 require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
38fc0130 429 profiling_start();
c646dd26
EL
430}
431
e1d1b796 432/**
433 * Database connection. Used for all access to the database.
434 * @global moodle_database $DB
b37eac91 435 * @name $DB
e1d1b796 436 */
437global $DB;
438
439/**
440 * Moodle's wrapper round PHP's $_SESSION.
441 *
442 * @global object $SESSION
b37eac91 443 * @name $SESSION
e1d1b796 444 */
445global $SESSION;
446
447/**
448 * Holds the user table record for the current user. Will be the 'guest'
449 * user record for people who are not logged in.
450 *
451 * $USER is stored in the session.
da8759cb 452 *
735b8567 453 * Items found in the user record:
da8759cb 454 * - $USER->email - The user's email address.
455 * - $USER->id - The unique integer identified of this user in the 'user' table.
456 * - $USER->email - The user's email address.
457 * - $USER->firstname - The user's first name.
458 * - $USER->lastname - The user's last name.
459 * - $USER->username - The user's login username.
460 * - $USER->secret - The user's ?.
461 * - $USER->lang - The user's language choice.
462 *
e1d1b796 463 * @global object $USER
b37eac91 464 * @name $USER
da8759cb 465 */
674fb525 466global $USER;
e1d1b796 467
f0f8f9a7
PS
468/**
469 * Frontpage course record
470 */
471global $SITE;
472
c13a5e71 473/**
474 * A central store of information about the current page we are
475 * generating in response to the user's request.
476 *
477 * @global moodle_page $PAGE
b37eac91 478 * @name $PAGE
c13a5e71 479 */
480global $PAGE;
481
da8759cb 482/**
e1d1b796 483 * The current course. An alias for $PAGE->course.
484 * @global object $COURSE
b37eac91 485 * @name $COURSE
da8759cb 486 */
487global $COURSE;
e1d1b796 488
da8759cb 489/**
78946b9b 490 * $OUTPUT is an instance of core_renderer or one of its subclasses. Use
34a2777c 491 * it to generate HTML for output.
da8759cb 492 *
c84a2dbe 493 * $OUTPUT is initialised the first time it is used. See {@link bootstrap_renderer}
494 * for the magic that does that. After $OUTPUT has been initialised, any attempt
495 * to change something that affects the current theme ($PAGE->course, logged in use,
496 * httpsrequried ... will result in an exception.)
34a2777c 497 *
cbcc9852
PS
498 * Please note the $OUTPUT is replacing the old global $THEME object.
499 *
34a2777c 500 * @global object $OUTPUT
501 * @name $OUTPUT
502 */
503global $OUTPUT;
504
b37eac91 505/**
506 * Full script path including all params, slash arguments, scheme and host.
33dca156
PS
507 *
508 * Note: Do NOT use for getting of current page URL or detection of https,
140f46a2 509 * instead use $PAGE->url or is_https().
33dca156 510 *
b37eac91 511 * @global string $FULLME
512 * @name $FULLME
513 */
11e7b506 514global $FULLME;
e1d1b796 515
b37eac91 516/**
517 * Script path including query string and slash arguments without host.
518 * @global string $ME
519 * @name $ME
520 */
11e7b506 521global $ME;
e1d1b796 522
b37eac91 523/**
524 * $FULLME without slasharguments and query string.
525 * @global string $FULLSCRIPT
526 * @name $FULLSCRIPT
527 */
11e7b506 528global $FULLSCRIPT;
e1d1b796 529
b37eac91 530/**
531 * Relative moodle script path '/course/view.php'
532 * @global string $SCRIPT
533 * @name $SCRIPT
534 */
11e7b506 535global $SCRIPT;
9d0dd812 536
469d4b7f
DM
537// The httpswwwroot has been deprecated, we keep it as an alias for backwards compatibility with plugins only.
538$CFG->httpswwwroot = $CFG->wwwroot;
539
4dffc775 540require_once($CFG->libdir .'/setuplib.php'); // Functions that MUST be loaded first
17da2e6f 541
cbad562e 542if (NO_OUTPUT_BUFFERING) {
871ed458 543 // we have to call this always before starting session because it discards headers!
cbad562e
PS
544 disable_output_buffering();
545}
546
0f0f0768
PS
547// Increase memory limits if possible
548raise_memory_limit(MEMORY_STANDARD);
549
4dffc775
PS
550// Time to start counting
551init_performance_info();
b7009474 552
4dffc775
PS
553// Put $OUTPUT in place, so errors can be displayed.
554$OUTPUT = new bootstrap_renderer();
9d0dd812 555
4c1c9175 556// set handler for uncaught exceptions - equivalent to print_error() call
a3d5830a
PS
557if (!PHPUNIT_TEST or PHPUNIT_UTIL) {
558 set_exception_handler('default_exception_handler');
559 set_error_handler('default_error_handler', E_ALL | E_STRICT);
560}
6800d78e 561
cfcbc34a 562// Acceptance tests needs special output to capture the errors,
920d7ffa
RT
563// but not necessary for behat CLI command and init script.
564if (defined('BEHAT_SITE_RUNNING') && !defined('BEHAT_TEST') && !defined('BEHAT_UTIL')) {
90ed22ab
DM
565 require_once(__DIR__ . '/behat/lib.php');
566 set_error_handler('behat_error_handler', E_ALL | E_STRICT);
567}
568
4ed6010a
PFO
569if (defined('WS_SERVER') && WS_SERVER) {
570 require_once($CFG->dirroot . '/webservice/lib.php');
571 set_exception_handler('early_ws_exception_handler');
572}
573
4dffc775 574// If there are any errors in the standard libraries we want to know!
a3d5830a 575error_reporting(E_ALL | E_STRICT);
c84a2dbe 576
4dffc775
PS
577// Just say no to link prefetching (Moz prefetching, Google Web Accelerator, others)
578// http://www.google.com/webmasters/faq.html#prefetchblock
579if (!empty($_SERVER['HTTP_X_moz']) && $_SERVER['HTTP_X_moz'] === 'prefetch'){
580 header($_SERVER['SERVER_PROTOCOL'] . ' 404 Prefetch Forbidden');
581 echo('Prefetch request forbidden.');
582 exit(1);
583}
b8cea9b2 584
3d732d84
EL
585//point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else
586//the problem is that we need specific version of quickforms and hacked excel files :-(
587ini_set('include_path', $CFG->libdir.'/pear' . PATH_SEPARATOR . ini_get('include_path'));
3d732d84 588
9e19a0f0
PS
589// Register our classloader, in theory somebody might want to replace it to load other hacked core classes.
590if (defined('COMPONENT_CLASSLOADER')) {
591 spl_autoload_register(COMPONENT_CLASSLOADER);
592} else {
593 spl_autoload_register('core_component::classloader');
594}
595
d6e7a63d
PS
596// Remember the default PHP timezone, we will need it later.
597core_date::store_default_php_timezone();
598
4dffc775 599// Load up standard libraries
4dffc775
PS
600require_once($CFG->libdir .'/filterlib.php'); // Functions for filtering test as it is output
601require_once($CFG->libdir .'/ajax/ajaxlib.php'); // Functions for managing our use of JavaScript and YUI
82b945db 602require_once($CFG->libdir .'/weblib.php'); // Functions relating to HTTP and content
fc72f49d 603require_once($CFG->libdir .'/outputlib.php'); // Functions for generating output
4dffc775
PS
604require_once($CFG->libdir .'/navigationlib.php'); // Class for generating Navigation structure
605require_once($CFG->libdir .'/dmllib.php'); // Database access
606require_once($CFG->libdir .'/datalib.php'); // Legacy lib with a big-mix of functions.
607require_once($CFG->libdir .'/accesslib.php'); // Access control functions
608require_once($CFG->libdir .'/deprecatedlib.php'); // Deprecated functions included for backward compatibility
609require_once($CFG->libdir .'/moodlelib.php'); // Other general-purpose functions
df997f84 610require_once($CFG->libdir .'/enrollib.php'); // Enrolment related functions
4dffc775
PS
611require_once($CFG->libdir .'/pagelib.php'); // Library that defines the moodle_page class, used for $PAGE
612require_once($CFG->libdir .'/blocklib.php'); // Library for controlling blocks
4dffc775
PS
613require_once($CFG->libdir .'/grouplib.php'); // Groups functions
614require_once($CFG->libdir .'/sessionlib.php'); // All session and cookie related stuff
615require_once($CFG->libdir .'/editorlib.php'); // All text editor related functions and classes
7c7d3afa 616require_once($CFG->libdir .'/messagelib.php'); // Messagelib functions
0d8b6a69 617require_once($CFG->libdir .'/modinfolib.php'); // Cached information on course-module instances
d6a1f63b 618require_once($CFG->dirroot.'/cache/lib.php'); // Cache API
4dffc775 619
4dffc775
PS
620// make sure PHP is not severly misconfigured
621setup_validate_php_configuration();
622
4dffc775
PS
623// Connect to the database
624setup_DB();
625
a3d5830a 626if (PHPUNIT_TEST and !PHPUNIT_UTIL) {
fc1785b0
AN
627 // Make sure tests do not run in parallel.
628 $suffix = '';
629 if (phpunit_util::is_in_isolated_process()) {
630 $suffix = '.isolated';
631 }
632 test_lock::acquire('phpunit', $suffix);
17b60e9d
PS
633 $dbhash = null;
634 try {
635 if ($dbhash = $DB->get_field('config', 'value', array('name'=>'phpunittest'))) {
636 // reset DB tables
637 phpunit_util::reset_database();
638 }
639 } catch (Exception $e) {
640 if ($dbhash) {
641 // we ned to reinit if reset fails
642 $DB->set_field('config', 'value', 'na', array('name'=>'phpunittest'));
17b60e9d
PS
643 }
644 }
645 unset($dbhash);
a3d5830a
PS
646}
647
96f81ea3
PS
648// Load up any configuration from the config table or MUC cache.
649if (PHPUNIT_TEST) {
650 phpunit_util::initialise_cfg();
4dffc775 651} else {
96f81ea3 652 initialise_cfg();
4dffc775 653}
dae73c05 654
96f81ea3
PS
655if (isset($CFG->debug)) {
656 $CFG->debug = (int)$CFG->debug;
657 error_reporting($CFG->debug);
658} else {
659 $CFG->debug = 0;
660}
ce7b06bc 661$CFG->debugdeveloper = (($CFG->debug & DEBUG_DEVELOPER) === DEBUG_DEVELOPER);
589376d3 662
96f81ea3
PS
663// Find out if PHP configured to display warnings,
664// this is a security problem because some moodle scripts may
665// disclose sensitive information.
666if (ini_get_bool('display_errors')) {
667 define('WARN_DISPLAY_ERRORS_ENABLED', true);
668}
669// If we want to display Moodle errors, then try and set PHP errors to match.
670if (!isset($CFG->debugdisplay)) {
671 // Keep it "as is" during installation.
672} else if (NO_DEBUG_DISPLAY) {
673 // Some parts of Moodle cannot display errors and debug at all.
674 ini_set('display_errors', '0');
675 ini_set('log_errors', '1');
676} else if (empty($CFG->debugdisplay)) {
677 ini_set('display_errors', '0');
678 ini_set('log_errors', '1');
589376d3 679} else {
96f81ea3
PS
680 // This is very problematic in XHTML strict mode!
681 ini_set('display_errors', '1');
589376d3 682}
a8a71844 683
38fc0130
PS
684// Register our shutdown manager, do NOT use register_shutdown_function().
685core_shutdown_manager::initialize();
686
4dffc775
PS
687// Verify upgrade is not running unless we are in a script that needs to execute in any case
688if (!defined('NO_UPGRADE_CHECK') and isset($CFG->upgraderunning)) {
689 if ($CFG->upgraderunning < time()) {
690 unset_config('upgraderunning');
aa893d6b 691 } else {
4dffc775 692 print_error('upgraderunning');
aa893d6b 693 }
4dffc775 694}
aa893d6b 695
c7b0e5e1
PS
696// enable circular reference collector in PHP 5.3,
697// it helps a lot when using large complex OOP structures such as in amos or gradebook
698if (function_exists('gc_enable')) {
699 gc_enable();
700}
1e3e716f 701
4dffc775
PS
702// detect unsupported upgrade jump as soon as possible - do not change anything, do not use system functions
703if (!empty($CFG->version) and $CFG->version < 2007101509) {
704 print_error('upgraderequires19', 'error');
705 die;
706}
475e9de8 707
4dffc775
PS
708// Calculate and set $CFG->ostype to be used everywhere. Possible values are:
709// - WINDOWS: for any Windows flavour.
710// - UNIX: for the rest
711// Also, $CFG->os can continue being used if more specialization is required
712if (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) {
713 $CFG->ostype = 'WINDOWS';
714} else {
715 $CFG->ostype = 'UNIX';
716}
717$CFG->os = PHP_OS;
820743c5 718
4dffc775 719// Configure ampersands in URLs
27466303 720ini_set('arg_separator.output', '&amp;');
de7e4ac9 721
4dffc775 722// Work around for a PHP bug see MDL-11237
27466303 723ini_set('pcre.backtrack_limit', 20971520); // 20 MB
e7aa5a88 724
144fb5e0
TL
725// Work around for PHP7 bug #70110. See MDL-52475 .
726if (ini_get('pcre.jit')) {
727 ini_set('pcre.jit', 0);
728}
729
d6e7a63d
PS
730// Set PHP default timezone to server timezone.
731core_date::set_default_server_timezone();
732
4dffc775 733// Location of standard files
4c1c9175
PS
734$CFG->wordlist = $CFG->libdir .'/wordlist.txt';
735$CFG->moddata = 'moddata';
f9903ed0 736
4dffc775
PS
737// neutralise nasty chars in PHP_SELF
738if (isset($_SERVER['PHP_SELF'])) {
739 $phppos = strpos($_SERVER['PHP_SELF'], '.php');
740 if ($phppos !== false) {
741 $_SERVER['PHP_SELF'] = substr($_SERVER['PHP_SELF'], 0, $phppos+4);
18b9d664 742 }
4dffc775
PS
743 unset($phppos);
744}
745
d2114969
PS
746// initialise ME's - this must be done BEFORE starting of session!
747initialise_fullme();
748
f0f8f9a7
PS
749// define SYSCONTEXTID in config.php if you want to save some queries,
750// after install it must match the system context record id.
751if (!defined('SYSCONTEXTID')) {
0601e0ee 752 context_system::instance();
f0f8f9a7
PS
753}
754
755// Defining the site - aka frontpage course
756try {
757 $SITE = get_site();
d79d5ac2 758} catch (moodle_exception $e) {
f0f8f9a7
PS
759 $SITE = null;
760 if (empty($CFG->version)) {
761 $SITE = new stdClass();
762 $SITE->id = 1;
ca5d6066 763 $SITE->shortname = null;
f0f8f9a7
PS
764 } else {
765 throw $e;
766 }
767}
768// And the 'default' course - this will usually get reset later in require_login() etc.
769$COURSE = clone($SITE);
5940a2bb 770// Id of the frontpage course.
f0f8f9a7
PS
771define('SITEID', $SITE->id);
772
df92ba9a 773// init session prevention flag - this is defined on pages that do not want session
28bd3d9a
PS
774if (CLI_SCRIPT) {
775 // no sessions in CLI scripts possible
776 define('NO_MOODLE_COOKIES', true);
777
e5d48aad
778} else if (WS_SERVER) {
779 // No sessions possible in web services.
780 define('NO_MOODLE_COOKIES', true);
781
28bd3d9a 782} else if (!defined('NO_MOODLE_COOKIES')) {
df92ba9a
PS
783 if (empty($CFG->version) or $CFG->version < 2009011900) {
784 // no session before sessions table gets created
785 define('NO_MOODLE_COOKIES', true);
786 } else if (CLI_SCRIPT) {
787 // CLI scripts can not have session
788 define('NO_MOODLE_COOKIES', true);
789 } else {
790 define('NO_MOODLE_COOKIES', false);
791 }
792}
793
d79d5ac2
PS
794// Start session and prepare global $SESSION, $USER.
795if (empty($CFG->sessiontimeout)) {
859ed92f 796 $CFG->sessiontimeout = 8 * 60 * 60;
d79d5ac2
PS
797}
798\core\session\manager::start();
18b9d664 799
3c98b7a5
PS
800// Set default content type and encoding, developers are still required to use
801// echo $OUTPUT->header() everywhere, anything that gets set later should override these headers.
802// This is intended to mitigate some security problems.
803if (AJAX_SCRIPT) {
804 if (!core_useragent::supports_json_contenttype()) {
805 // Some bloody old IE.
806 @header('Content-type: text/plain; charset=utf-8');
807 @header('X-Content-Type-Options: nosniff');
808 } else if (!empty($_FILES)) {
809 // Some ajax code may have problems with json and file uploads.
810 @header('Content-type: text/plain; charset=utf-8');
811 } else {
812 @header('Content-type: application/json; charset=utf-8');
813 }
814} else if (!CLI_SCRIPT) {
815 @header('Content-type: text/html; charset=utf-8');
816}
817
0c431257
PS
818// Initialise some variables that are supposed to be set in config.php only.
819if (!isset($CFG->filelifetime)) {
820 $CFG->filelifetime = 60*60*6;
821}
822
c646dd26 823// Late profiling, only happening if early one wasn't started
6af80cae
EL
824if (!empty($CFG->profilingenabled)) {
825 require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
38fc0130 826 profiling_start();
6af80cae
EL
827}
828
a3777547
PS
829// Hack to get around max_input_vars restrictions,
830// we need to do this after session init to have some basic DDoS protection.
831workaround_max_input_vars();
832
4dffc775 833// Process theme change in the URL.
998999e7
PS
834if (!empty($CFG->allowthemechangeonurl) and !empty($_GET['theme'])) {
835 // we have to use _GET directly because we do not want this to interfere with _POST
aff24313 836 $urlthemename = optional_param('theme', '', PARAM_PLUGIN);
4dffc775 837 try {
998999e7
PS
838 $themeconfig = theme_config::load($urlthemename);
839 // Makes sure the theme can be loaded without errors.
840 if ($themeconfig->name === $urlthemename) {
841 $SESSION->theme = $urlthemename;
842 } else {
843 unset($SESSION->theme);
844 }
845 unset($themeconfig);
846 unset($urlthemename);
4dffc775
PS
847 } catch (Exception $e) {
848 debugging('Failed to set the theme from the URL.', DEBUG_DEVELOPER, $e->getTrace());
18b9d664 849 }
4dffc775
PS
850}
851unset($urlthemename);
18b9d664 852
4dffc775
PS
853// Ensure a valid theme is set.
854if (!isset($CFG->theme)) {
e56b58e3 855 $CFG->theme = 'boost';
4dffc775
PS
856}
857
858// Set language/locale of printed times. If user has chosen a language that
859// that is different from the site language, then use the locale specified
860// in the language file. Otherwise, if the admin hasn't specified a locale
861// then use the one from the default language. Otherwise (and this is the
862// majority of cases), use the stored locale specified by admin.
4000129f
PS
863// note: do not accept lang parameter from POST
864if (isset($_GET['lang']) and ($lang = optional_param('lang', '', PARAM_SAFEDIR))) {
ecd7978c 865 if (get_string_manager()->translation_exists($lang, false)) {
4dffc775 866 $SESSION->lang = $lang;
3e9b5d5a 867 }
4dffc775
PS
868}
869unset($lang);
ab036ed9 870
c484af5a
BK
871// PARAM_SAFEDIR used instead of PARAM_LANG because using PARAM_LANG results
872// in an empty string being returned when a non-existant language is specified,
873// which would make it necessary to log out to undo the forcelang setting.
874// With PARAM_SAFEDIR, it's possible to specify ?forcelang=none to drop the forcelang effect.
875if ($forcelang = optional_param('forcelang', '', PARAM_SAFEDIR)) {
876 if (isloggedin()
877 && get_string_manager()->translation_exists($forcelang, false)
878 && has_capability('moodle/site:forcelanguage', context_system::instance())) {
879 $SESSION->forcelang = $forcelang;
880 } else if (isset($SESSION->forcelang)) {
881 unset($SESSION->forcelang);
882 }
883}
884unset($forcelang);
885
4dffc775 886setup_lang_from_browser();
ab036ed9 887
4dffc775
PS
888if (empty($CFG->lang)) {
889 if (empty($SESSION->lang)) {
3a915b06 890 $CFG->lang = 'en';
4dffc775
PS
891 } else {
892 $CFG->lang = $SESSION->lang;
16ba7351 893 }
4dffc775 894}
6800d78e 895
00dadbe1
PS
896// Set the default site locale, a lot of the stuff may depend on this
897// it is definitely too late to call this first in require_login()!
898moodle_setlocale();
4dffc775 899
f0f8f9a7
PS
900// Create the $PAGE global - this marks the PAGE and OUTPUT fully initialised, this MUST be done at the end of setup!
901if (!empty($CFG->moodlepageclass)) {
3edc37cb
PS
902 if (!empty($CFG->moodlepageclassfile)) {
903 require_once($CFG->moodlepageclassfile);
904 }
f0f8f9a7
PS
905 $classname = $CFG->moodlepageclass;
906} else {
907 $classname = 'moodle_page';
908}
909$PAGE = new $classname();
910unset($classname);
911
912
4dffc775 913if (!empty($CFG->debugvalidators) and !empty($CFG->guestloginbutton)) {
1302f765 914 if ($CFG->theme == 'standard') { // Temporary measure to help with XHTML validation
4dffc775
PS
915 if (isset($_SERVER['HTTP_USER_AGENT']) and empty($USER->id)) { // Allow W3CValidator in as user called w3cvalidator (or guest)
916 if ((strpos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') !== false) or
917 (strpos($_SERVER['HTTP_USER_AGENT'], 'Cynthia') !== false )) {
918 if ($user = get_complete_user_data("username", "w3cvalidator")) {
919 $user->ignoresesskey = true;
920 } else {
921 $user = guest_user();
9610a66e 922 }
d79d5ac2 923 \core\session\manager::set_user($user);
9610a66e 924 }
925 }
926 }
4dffc775 927}
9610a66e 928
4c1c9175 929// Apache log integration. In apache conf file one can use ${MOODULEUSER}n in
4dffc775 930// LogFormat to get the current logged in username in moodle.
c31a35b5
BH
931// Alternatvely for other web servers a header X-MOODLEUSER can be set which
932// can be using in the logfile and stripped out if needed.
b940ca99 933set_access_log_user();
c31a35b5 934
a559eee6 935
cbce7be7
DP
936// Ensure the urlrewriteclass is setup correctly (to avoid crippling site).
937if (isset($CFG->urlrewriteclass)) {
938 if (!class_exists($CFG->urlrewriteclass)) {
939 debugging("urlrewriteclass {$CFG->urlrewriteclass} was not found, disabling.");
940 unset($CFG->urlrewriteclass);
941 } else if (!in_array('core\output\url_rewriter', class_implements($CFG->urlrewriteclass))) {
942 debugging("{$CFG->urlrewriteclass} does not implement core\output\url_rewriter, disabling.", DEBUG_DEVELOPER);
943 unset($CFG->urlrewriteclass);
944 }
945}
946
4dffc775
PS
947// Use a custom script replacement if one exists
948if (!empty($CFG->customscripts)) {
949 if (($customscript = custom_script_path()) !== false) {
950 require ($customscript);
18259d4f 951 }
4dffc775 952}
18259d4f 953
a3d5830a
PS
954if (PHPUNIT_TEST) {
955 // no ip blocking, these are CLI only
956} else if (CLI_SCRIPT and !defined('WEB_CRON_EMULATED_CLI')) {
ade30ad3
RT
957 // no ip blocking
958} else if (!empty($CFG->allowbeforeblock)) { // allowed list processed before blocked list?
959 // in this case, ip in allowed list will be performed first
960 // for example, client IP is 192.168.1.1
961 // 192.168 subnet is an entry in allowed list
962 // 192.168.1.1 is banned in blocked list
963 // This ip will be banned finally
4dffc775
PS
964 if (!empty($CFG->allowedip)) {
965 if (!remoteip_in_list($CFG->allowedip)) {
966 die(get_string('ipblocked', 'admin'));
ab99c8f0 967 }
4dffc775
PS
968 }
969 // need further check, client ip may a part of
970 // allowed subnet, but a IP address are listed
971 // in blocked list.
972 if (!empty($CFG->blockedip)) {
973 if (remoteip_in_list($CFG->blockedip)) {
974 die(get_string('ipblocked', 'admin'));
5035228f 975 }
4dffc775 976 }
d255c6e9 977
4dffc775
PS
978} else {
979 // in this case, IPs in blocked list will be performed first
980 // for example, client IP is 192.168.1.1
981 // 192.168 subnet is an entry in blocked list
982 // 192.168.1.1 is allowed in allowed list
983 // This ip will be allowed finally
984 if (!empty($CFG->blockedip)) {
985 if (remoteip_in_list($CFG->blockedip)) {
986 // if the allowed ip list is not empty
987 // IPs are not included in the allowed list will be
988 // blocked too
989 if (!empty($CFG->allowedip)) {
990 if (!remoteip_in_list($CFG->allowedip)) {
d255c6e9 991 die(get_string('ipblocked', 'admin'));
992 }
4dffc775 993 } else {
d255c6e9 994 die(get_string('ipblocked', 'admin'));
995 }
5035228f 996 }
4dffc775
PS
997 }
998 // if blocked list is null
999 // allowed list should be tested
1000 if(!empty($CFG->allowedip)) {
1001 if (!remoteip_in_list($CFG->allowedip)) {
1002 die(get_string('ipblocked', 'admin'));
1003 }
ab99c8f0 1004 }
1005
4dffc775 1006}
092bfaf1 1007
99302c5e
PS
1008// // try to detect IE6 and prevent gzip because it is extremely buggy browser
1009if (!empty($_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false) {
b19d75a2 1010 ini_set('zlib.output_compression', 'Off');
99302c5e 1011 if (function_exists('apache_setenv')) {
b19d75a2 1012 apache_setenv('no-gzip', 1);
99302c5e
PS
1013 }
1014}
1015
48e114a5
PS
1016// Switch to CLI maintenance mode if required, we need to do it here after all the settings are initialised.
1017if (isset($CFG->maintenance_later) and $CFG->maintenance_later <= time()) {
1018 if (!file_exists("$CFG->dataroot/climaintenance.html")) {
1019 require_once("$CFG->libdir/adminlib.php");
1020 enable_cli_maintenance_mode();
1021 }
1022 unset_config('maintenance_later');
1023 if (AJAX_SCRIPT) {
1024 die;
1025 } else if (!CLI_SCRIPT) {
1026 redirect(new moodle_url('/'));
1027 }
1028}
99302c5e 1029
0c1bcb63
RT
1030// Add behat_shutdown_function to shutdown manager, so we can capture php errors,
1031// but not necessary for behat CLI command as it's being captured by behat process.
1032if (defined('BEHAT_SITE_RUNNING') && !defined('BEHAT_TEST')) {
1033 core_shutdown_manager::register_function('behat_shutdown_function');
1034}
1035
4dffc775
PS
1036// note: we can not block non utf-8 installations here, because empty mysql database
1037// might be converted to utf-8 in admin/index.php during installation
d5fac1cf
PS
1038
1039
1040
1041// this is a funny trick to make Eclipse believe that $OUTPUT and other globals
1042// contains an instance of core_renderer, etc. which in turn fixes autocompletion ;-)
1043if (false) {
1044 $DB = new moodle_database();
1045 $OUTPUT = new core_renderer(null, null);
1046 $PAGE = new moodle_page();
1047}
4ed105a9
BH
1048
1049// Allow plugins to callback as soon possible after setup.php is loaded.
1050$pluginswithfunction = get_plugins_with_function('after_config', 'lib.php');
1051foreach ($pluginswithfunction as $plugins) {
1052 foreach ($plugins as $function) {
1053 try {
1054 $function();
1055 } catch (Exception $e) {
1056 debugging("Exception calling '$function'", DEBUG_DEVELOPER, $e->getTrace());
1057 }
1058 }
1059}