2004-09-25 05:30:03 +00:00
|
|
|
<?php
|
2009-05-26 03:57:03 +00:00
|
|
|
|
|
|
|
// 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/>.
|
|
|
|
|
2004-09-25 05:30:03 +00:00
|
|
|
/**
|
|
|
|
* setup.php - Sets up sessions, connects to databases and so on
|
|
|
|
*
|
2005-02-19 17:52:30 +00:00
|
|
|
* Normally this is only called by the main config.php file
|
|
|
|
* Normally this file does not need to be edited.
|
2009-05-26 03:57:03 +00:00
|
|
|
*
|
2010-07-25 13:35:05 +00:00
|
|
|
* @package core
|
|
|
|
* @subpackage lib
|
|
|
|
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2004-09-25 05:30:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2009-04-16 08:59:46 +00:00
|
|
|
* Holds the core settings that affect how Moodle works. Some of its fields
|
|
|
|
* are set in config.php, and the rest are loaded from the config table.
|
|
|
|
*
|
|
|
|
* Some typical settings in the $CFG global:
|
2010-05-21 17:32:15 +00:00
|
|
|
* - $CFG->wwwroot - Path to moodle index directory in url format.
|
|
|
|
* - $CFG->dataroot - Path to moodle data files directory on server's filesystem.
|
|
|
|
* - $CFG->dirroot - Path to moodle's library folder on server's filesystem.
|
|
|
|
* - $CFG->libdir - Path to moodle's library folder on server's filesystem.
|
2011-08-11 03:01:22 +09:30
|
|
|
* - $CFG->tempdir - Path to moodle's temp file directory on server's filesystem.
|
2011-08-11 03:23:26 +09:30
|
|
|
* - $CFG->cachedir - Path to moodle's cache directory on server's filesystem.
|
2009-04-16 08:59:46 +00:00
|
|
|
*
|
|
|
|
* @global object $CFG
|
2009-05-26 03:57:03 +00:00
|
|
|
* @name $CFG
|
2009-04-16 08:59:46 +00:00
|
|
|
*/
|
2010-08-26 15:31:18 +00:00
|
|
|
global $CFG; // this should be done much earlier in config.php before creating new $CFG instance
|
2009-04-16 08:59:46 +00:00
|
|
|
|
2010-08-26 16:25:13 +00:00
|
|
|
if (!isset($CFG)) {
|
2012-03-31 23:51:02 +02:00
|
|
|
if (defined('PHPUNIT_TEST') and PHPUNIT_TEST) {
|
2010-08-26 16:25:13 +00:00
|
|
|
echo('There is a missing "global $CFG;" at the beginning of the config.php file.'."\n");
|
|
|
|
exit(1);
|
|
|
|
} else {
|
|
|
|
// this should never happen, maybe somebody is accessing this file directly...
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-21 17:32:15 +00:00
|
|
|
// We can detect real dirroot path reliably since PHP 4.0.2,
|
|
|
|
// it can not be anything else, there is no point in having this in config.php
|
|
|
|
$CFG->dirroot = dirname(dirname(__FILE__));
|
|
|
|
|
|
|
|
// Normalise dataroot - we do not want any symbolic links, trailing / or any other weirdness there
|
|
|
|
if (!isset($CFG->dataroot)) {
|
2010-08-26 14:57:32 +00:00
|
|
|
if (isset($_SERVER['REMOTE_ADDR'])) {
|
|
|
|
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable');
|
|
|
|
}
|
2010-08-26 16:25:13 +00:00
|
|
|
echo('Fatal error: $CFG->dataroot is not specified in config.php! Exiting.'."\n");
|
2010-05-21 17:32:15 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
$CFG->dataroot = realpath($CFG->dataroot);
|
|
|
|
if ($CFG->dataroot === false) {
|
2010-08-26 14:57:32 +00:00
|
|
|
if (isset($_SERVER['REMOTE_ADDR'])) {
|
|
|
|
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable');
|
|
|
|
}
|
2010-08-26 16:25:13 +00:00
|
|
|
echo('Fatal error: $CFG->dataroot is not configured properly, directory does not exist or is not accessible! Exiting.'."\n");
|
2010-05-21 17:32:15 +00:00
|
|
|
exit(1);
|
2010-08-29 14:14:21 +00:00
|
|
|
} else if (!is_writable($CFG->dataroot)) {
|
|
|
|
if (isset($_SERVER['REMOTE_ADDR'])) {
|
|
|
|
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable');
|
|
|
|
}
|
|
|
|
echo('Fatal error: $CFG->dataroot is not writable, admin has to fix directory permissions! Exiting.'."\n");
|
|
|
|
exit(1);
|
2010-05-21 17:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// wwwroot is mandatory
|
|
|
|
if (!isset($CFG->wwwroot) or $CFG->wwwroot === 'http://example.com/moodle') {
|
2010-08-26 14:57:32 +00:00
|
|
|
if (isset($_SERVER['REMOTE_ADDR'])) {
|
|
|
|
header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Unavailable');
|
|
|
|
}
|
2010-08-26 16:25:13 +00:00
|
|
|
echo('Fatal error: $CFG->wwwroot is not configured! Exiting.'."\n");
|
2010-05-21 17:32:15 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2012-11-12 17:30:31 +08:00
|
|
|
// Default URL for acceptance testing.
|
|
|
|
if (!isset($CFG->test_wwwroot)) {
|
|
|
|
$CFG->test_wwwroot = 'http://localhost:8000';
|
|
|
|
}
|
|
|
|
|
2012-12-07 12:03:38 +08:00
|
|
|
// Switch to test site only when test environment is enabled: Both when the
|
|
|
|
// acceptance tests are running and when Behat is requiring moodle codebase.
|
2012-11-30 16:24:41 +08:00
|
|
|
if ((php_sapi_name() === 'cli-server' || defined('BEHAT_RUNNING')) &&
|
2012-11-12 17:30:31 +08:00
|
|
|
file_exists($CFG->dataroot . '/behat/test_environment_enabled.txt')) {
|
|
|
|
$CFG->wwwroot = $CFG->test_wwwroot;
|
2012-10-11 09:46:11 +08:00
|
|
|
$CFG->passwordsaltmain = 'phpunit';
|
|
|
|
$CFG->originaldataroot = $CFG->dataroot;
|
2012-10-10 10:50:44 +08:00
|
|
|
$CFG->prefix = $CFG->phpunit_prefix;
|
|
|
|
$CFG->dataroot = $CFG->phpunit_dataroot;
|
|
|
|
}
|
|
|
|
|
2010-05-21 17:32:15 +00:00
|
|
|
// Define admin directory
|
|
|
|
if (!isset($CFG->admin)) { // Just in case it isn't defined in config.php
|
|
|
|
$CFG->admin = 'admin'; // This is relative to the wwwroot and dirroot
|
|
|
|
}
|
|
|
|
|
2009-12-25 19:51:40 +00:00
|
|
|
// Set up some paths.
|
|
|
|
$CFG->libdir = $CFG->dirroot .'/lib';
|
|
|
|
|
2011-08-11 03:23:26 +09:30
|
|
|
// Allow overriding of tempdir but be backwards compatible
|
2011-08-11 03:01:22 +09:30
|
|
|
if (!isset($CFG->tempdir)) {
|
2011-08-11 03:23:26 +09:30
|
|
|
$CFG->tempdir = "$CFG->dataroot/temp";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow overriding of cachedir but be backwards compatible
|
|
|
|
if (!isset($CFG->cachedir)) {
|
|
|
|
$CFG->cachedir = "$CFG->dataroot/cache";
|
2011-08-11 03:01:22 +09:30
|
|
|
}
|
|
|
|
|
2010-05-21 17:32:15 +00:00
|
|
|
// The current directory in PHP version 4.3.0 and above isn't necessarily the
|
|
|
|
// directory of the script when run from the command line. The require_once()
|
|
|
|
// would fail, so we'll have to chdir()
|
|
|
|
if (!isset($_SERVER['REMOTE_ADDR']) && isset($_SERVER['argv'][0])) {
|
2012-03-21 10:31:37 +01:00
|
|
|
// do it only once - skip the second time when continuing after prevous abort
|
|
|
|
if (!defined('ABORT_AFTER_CONFIG') and !defined('ABORT_AFTER_CONFIG_CANCEL')) {
|
|
|
|
chdir(dirname($_SERVER['argv'][0]));
|
|
|
|
}
|
2010-05-21 17:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// sometimes default PHP settings are borked on shared hosting servers, I wonder why they have to do that??
|
2010-11-19 01:39:30 +00:00
|
|
|
ini_set('precision', 14); // needed for upgrades and gradebook
|
2010-05-21 17:32:15 +00:00
|
|
|
|
|
|
|
// Scripts may request no debug and error messages in output
|
|
|
|
// please note it must be defined before including the config.php script
|
|
|
|
// and in some cases you also need to set custom default exception handler
|
|
|
|
if (!defined('NO_DEBUG_DISPLAY')) {
|
|
|
|
define('NO_DEBUG_DISPLAY', false);
|
|
|
|
}
|
|
|
|
|
2010-11-19 03:40:43 +00:00
|
|
|
// Some scripts such as upgrade may want to prevent output buffering
|
|
|
|
if (!defined('NO_OUTPUT_BUFFERING')) {
|
|
|
|
define('NO_OUTPUT_BUFFERING', false);
|
|
|
|
}
|
|
|
|
|
2012-03-21 10:31:37 +01:00
|
|
|
// PHPUnit tests need custom init
|
2012-03-31 23:51:02 +02:00
|
|
|
if (!defined('PHPUNIT_TEST')) {
|
|
|
|
define('PHPUNIT_TEST', false);
|
2012-03-21 10:31:37 +01:00
|
|
|
}
|
|
|
|
|
2012-11-22 10:33:57 +13:00
|
|
|
// When set to true MUC (Moodle caching) will be disabled as much as possible.
|
|
|
|
// A special cache factory will be used to handle this situation and will use special "disabled" equivalents objects.
|
|
|
|
// This ensure we don't attempt to read or create the config file, don't use stores, don't provide persistence or
|
|
|
|
// storage of any kind.
|
|
|
|
if (!defined('CACHE_DISABLE_ALL')) {
|
|
|
|
define('CACHE_DISABLE_ALL', false);
|
|
|
|
}
|
|
|
|
|
2012-09-10 15:28:32 +12:00
|
|
|
// When set to true MUC (Moodle caching) will not use any of the defined or default stores.
|
2012-09-17 10:04:47 +12:00
|
|
|
// The Cache API will continue to function however this will force the use of the cachestore_dummy so all requests
|
2012-09-10 15:28:32 +12:00
|
|
|
// will be interacting with a static property and will never go to the proper cache stores.
|
|
|
|
// Useful if you need to avoid the stores for one reason or another.
|
2012-11-13 09:28:22 +13:00
|
|
|
if (!defined('CACHE_DISABLE_STORES')) {
|
|
|
|
define('CACHE_DISABLE_STORES', false);
|
2012-09-10 15:28:32 +12:00
|
|
|
}
|
|
|
|
|
2010-05-31 09:15:26 +00:00
|
|
|
// Servers should define a default timezone in php.ini, but if they don't then make sure something is defined.
|
|
|
|
// This is a quick hack. Ideally we should ask the admin for a value. See MDL-22625 for more on this.
|
2010-06-11 13:59:13 +00:00
|
|
|
if (function_exists('date_default_timezone_set') and function_exists('date_default_timezone_get')) {
|
2010-11-19 01:39:30 +00:00
|
|
|
$olddebug = error_reporting(0);
|
|
|
|
date_default_timezone_set(date_default_timezone_get());
|
|
|
|
error_reporting($olddebug);
|
|
|
|
unset($olddebug);
|
2010-05-31 09:15:26 +00:00
|
|
|
}
|
|
|
|
|
2010-05-21 17:32:15 +00:00
|
|
|
// Detect CLI scripts - CLI scripts are executed from command line, do not have session and we do not want HTML in output
|
2010-08-17 12:33:30 +00:00
|
|
|
// In your new CLI scripts just add "define('CLI_SCRIPT', true);" before requiring config.php.
|
|
|
|
// Please note that one script can not be accessed from both CLI and web interface.
|
2010-05-21 17:32:15 +00:00
|
|
|
if (!defined('CLI_SCRIPT')) {
|
2010-08-17 12:33:30 +00:00
|
|
|
define('CLI_SCRIPT', false);
|
|
|
|
}
|
|
|
|
if (defined('WEB_CRON_EMULATED_CLI')) {
|
|
|
|
if (!isset($_SERVER['REMOTE_ADDR'])) {
|
|
|
|
echo('Web cron can not be executed as CLI script any more, please use admin/cli/cron.php instead'."\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else if (isset($_SERVER['REMOTE_ADDR'])) {
|
|
|
|
if (CLI_SCRIPT) {
|
|
|
|
echo('Command line scripts can not be executed from the web interface');
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!CLI_SCRIPT) {
|
|
|
|
echo('Command line scripts must define CLI_SCRIPT before requiring config.php'."\n");
|
|
|
|
exit(1);
|
2010-05-21 17:32:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-18 12:48:39 +00:00
|
|
|
// Detect CLI maintenance mode - this is useful when you need to mess with database, such as during upgrades
|
|
|
|
if (file_exists("$CFG->dataroot/climaintenance.html")) {
|
|
|
|
if (!CLI_SCRIPT) {
|
2011-01-14 09:32:17 +01:00
|
|
|
header('Content-type: text/html; charset=utf-8');
|
2012-11-09 17:27:29 +01:00
|
|
|
header('X-UA-Compatible: IE=edge');
|
2010-10-18 12:48:39 +00:00
|
|
|
/// Headers to make it not cacheable and json
|
2010-11-19 01:39:30 +00:00
|
|
|
header('Cache-Control: no-store, no-cache, must-revalidate');
|
|
|
|
header('Cache-Control: post-check=0, pre-check=0', false);
|
|
|
|
header('Pragma: no-cache');
|
|
|
|
header('Expires: Mon, 20 Aug 1969 09:23:00 GMT');
|
|
|
|
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
|
|
|
header('Accept-Ranges: none');
|
2010-10-18 12:48:39 +00:00
|
|
|
readfile("$CFG->dataroot/climaintenance.html");
|
|
|
|
die;
|
|
|
|
} else {
|
2010-10-19 07:36:22 +00:00
|
|
|
if (!defined('CLI_MAINTENANCE')) {
|
|
|
|
define('CLI_MAINTENANCE', true);
|
|
|
|
}
|
2010-10-18 12:48:39 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-10-19 07:36:22 +00:00
|
|
|
if (!defined('CLI_MAINTENANCE')) {
|
|
|
|
define('CLI_MAINTENANCE', false);
|
|
|
|
}
|
2010-10-18 12:48:39 +00:00
|
|
|
}
|
|
|
|
|
2011-08-21 12:19:59 +02:00
|
|
|
if (CLI_SCRIPT) {
|
|
|
|
// sometimes people use different PHP binary for web and CLI, make 100% sure they have the supported PHP version
|
|
|
|
if (version_compare(phpversion(), '5.3.2') < 0) {
|
|
|
|
$phpversion = phpversion();
|
|
|
|
// do NOT localise - lang strings would not work here and we CAN NOT move it to later place
|
|
|
|
echo "Moodle 2.1 or later requires at least PHP 5.3.2 (currently using version $phpversion).\n";
|
|
|
|
echo "Some servers may have multiple PHP versions installed, are you using the correct executable?\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-21 17:32:15 +00:00
|
|
|
// Detect ajax scripts - they are similar to CLI because we can not redirect, output html, etc.
|
|
|
|
if (!defined('AJAX_SCRIPT')) {
|
|
|
|
define('AJAX_SCRIPT', false);
|
|
|
|
}
|
|
|
|
|
2010-05-22 19:59:59 +00:00
|
|
|
// File permissions on created directories in the $CFG->dataroot
|
|
|
|
if (empty($CFG->directorypermissions)) {
|
|
|
|
$CFG->directorypermissions = 02777; // Must be octal (that's why it's here)
|
|
|
|
}
|
|
|
|
if (empty($CFG->filepermissions)) {
|
|
|
|
$CFG->filepermissions = ($CFG->directorypermissions & 0666); // strip execute flags
|
|
|
|
}
|
|
|
|
// better also set default umask because recursive mkdir() does not apply permissions recursively otherwise
|
|
|
|
umask(0000);
|
|
|
|
|
2009-12-25 19:51:40 +00:00
|
|
|
// exact version of currently used yui2 and 3 library
|
2011-08-19 07:49:06 +02:00
|
|
|
$CFG->yui2version = '2.9.0';
|
2012-12-15 12:55:36 +01:00
|
|
|
$CFG->yui3version = '3.8.0';
|
2009-12-25 19:51:40 +00:00
|
|
|
|
2010-05-21 17:32:15 +00:00
|
|
|
|
2009-12-25 19:51:40 +00:00
|
|
|
// special support for highly optimised scripts that do not need libraries and DB connection
|
|
|
|
if (defined('ABORT_AFTER_CONFIG')) {
|
|
|
|
if (!defined('ABORT_AFTER_CONFIG_CANCEL')) {
|
2010-01-05 20:31:42 +00:00
|
|
|
// hide debugging if not enabled in config.php - we do not want to disclose sensitive info
|
|
|
|
if (isset($CFG->debug)) {
|
|
|
|
error_reporting($CFG->debug);
|
|
|
|
} else {
|
|
|
|
error_reporting(0);
|
|
|
|
}
|
2012-04-25 09:08:10 +02:00
|
|
|
if (NO_DEBUG_DISPLAY) {
|
|
|
|
// Some parts of Moodle cannot display errors and debug at all.
|
|
|
|
ini_set('display_errors', '0');
|
|
|
|
ini_set('log_errors', '1');
|
|
|
|
} else if (empty($CFG->debugdisplay)) {
|
2010-11-19 01:39:30 +00:00
|
|
|
ini_set('display_errors', '0');
|
|
|
|
ini_set('log_errors', '1');
|
2010-01-05 20:31:42 +00:00
|
|
|
} else {
|
2010-11-19 01:39:30 +00:00
|
|
|
ini_set('display_errors', '1');
|
2010-01-05 20:31:42 +00:00
|
|
|
}
|
2009-12-25 19:51:40 +00:00
|
|
|
require_once("$CFG->dirroot/lib/configonlylib.php");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-26 20:17:36 +00:00
|
|
|
/** Used by library scripts to check they are being called by Moodle */
|
2010-07-26 20:22:49 +00:00
|
|
|
if (!defined('MOODLE_INTERNAL')) { // necessary because cli installer has to define it earlier
|
|
|
|
define('MOODLE_INTERNAL', true);
|
|
|
|
}
|
2010-07-25 12:56:08 +00:00
|
|
|
|
2011-03-19 00:32:45 +01:00
|
|
|
// Early profiling start, based exclusively on config.php $CFG settings
|
|
|
|
if (!empty($CFG->earlyprofilingenabled)) {
|
|
|
|
require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
|
|
|
|
if (profiling_start()) {
|
|
|
|
register_shutdown_function('profiling_stop');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-16 08:59:46 +00:00
|
|
|
/**
|
|
|
|
* Database connection. Used for all access to the database.
|
|
|
|
* @global moodle_database $DB
|
2009-05-26 03:57:03 +00:00
|
|
|
* @name $DB
|
2009-04-16 08:59:46 +00:00
|
|
|
*/
|
|
|
|
global $DB;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Moodle's wrapper round PHP's $_SESSION.
|
|
|
|
*
|
|
|
|
* @global object $SESSION
|
2009-05-26 03:57:03 +00:00
|
|
|
* @name $SESSION
|
2009-04-16 08:59:46 +00:00
|
|
|
*/
|
|
|
|
global $SESSION;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Holds the user table record for the current user. Will be the 'guest'
|
|
|
|
* user record for people who are not logged in.
|
|
|
|
*
|
|
|
|
* $USER is stored in the session.
|
2004-09-25 05:30:03 +00:00
|
|
|
*
|
2005-12-13 02:21:02 +00:00
|
|
|
* Items found in the user record:
|
2004-09-25 05:30:03 +00:00
|
|
|
* - $USER->email - The user's email address.
|
|
|
|
* - $USER->id - The unique integer identified of this user in the 'user' table.
|
|
|
|
* - $USER->email - The user's email address.
|
|
|
|
* - $USER->firstname - The user's first name.
|
|
|
|
* - $USER->lastname - The user's last name.
|
|
|
|
* - $USER->username - The user's login username.
|
|
|
|
* - $USER->secret - The user's ?.
|
|
|
|
* - $USER->lang - The user's language choice.
|
|
|
|
*
|
2009-04-16 08:59:46 +00:00
|
|
|
* @global object $USER
|
2009-05-26 03:57:03 +00:00
|
|
|
* @name $USER
|
2004-09-25 05:30:03 +00:00
|
|
|
*/
|
2004-09-28 02:51:56 +00:00
|
|
|
global $USER;
|
2009-04-16 08:59:46 +00:00
|
|
|
|
2011-10-21 16:35:19 +02:00
|
|
|
/**
|
|
|
|
* Frontpage course record
|
|
|
|
*/
|
|
|
|
global $SITE;
|
|
|
|
|
2009-05-06 08:29:22 +00:00
|
|
|
/**
|
|
|
|
* A central store of information about the current page we are
|
|
|
|
* generating in response to the user's request.
|
|
|
|
*
|
|
|
|
* @global moodle_page $PAGE
|
2009-05-26 03:57:03 +00:00
|
|
|
* @name $PAGE
|
2009-05-06 08:29:22 +00:00
|
|
|
*/
|
|
|
|
global $PAGE;
|
|
|
|
|
2004-09-25 05:30:03 +00:00
|
|
|
/**
|
2009-04-16 08:59:46 +00:00
|
|
|
* The current course. An alias for $PAGE->course.
|
|
|
|
* @global object $COURSE
|
2009-05-26 03:57:03 +00:00
|
|
|
* @name $COURSE
|
2004-09-25 05:30:03 +00:00
|
|
|
*/
|
|
|
|
global $COURSE;
|
2009-04-16 08:59:46 +00:00
|
|
|
|
2004-09-25 05:30:03 +00:00
|
|
|
/**
|
2009-12-16 18:00:58 +00:00
|
|
|
* $OUTPUT is an instance of core_renderer or one of its subclasses. Use
|
2009-06-26 09:06:16 +00:00
|
|
|
* it to generate HTML for output.
|
2004-09-25 05:30:03 +00:00
|
|
|
*
|
2009-06-29 05:00:45 +00:00
|
|
|
* $OUTPUT is initialised the first time it is used. See {@link bootstrap_renderer}
|
|
|
|
* for the magic that does that. After $OUTPUT has been initialised, any attempt
|
|
|
|
* to change something that affects the current theme ($PAGE->course, logged in use,
|
|
|
|
* httpsrequried ... will result in an exception.)
|
2009-06-26 09:06:16 +00:00
|
|
|
*
|
2009-12-23 18:23:21 +00:00
|
|
|
* Please note the $OUTPUT is replacing the old global $THEME object.
|
|
|
|
*
|
2009-06-26 09:06:16 +00:00
|
|
|
* @global object $OUTPUT
|
|
|
|
* @name $OUTPUT
|
|
|
|
*/
|
|
|
|
global $OUTPUT;
|
|
|
|
|
2009-05-26 03:57:03 +00:00
|
|
|
/**
|
|
|
|
* Full script path including all params, slash arguments, scheme and host.
|
2011-12-09 21:26:36 +01:00
|
|
|
*
|
|
|
|
* Note: Do NOT use for getting of current page URL or detection of https,
|
|
|
|
* instead use $PAGE->url or strpos($CFG->httpswwwroot, 'https:') === 0
|
|
|
|
*
|
2009-05-26 03:57:03 +00:00
|
|
|
* @global string $FULLME
|
|
|
|
* @name $FULLME
|
|
|
|
*/
|
2009-01-05 21:37:20 +00:00
|
|
|
global $FULLME;
|
2009-04-16 08:59:46 +00:00
|
|
|
|
2009-05-26 03:57:03 +00:00
|
|
|
/**
|
|
|
|
* Script path including query string and slash arguments without host.
|
|
|
|
* @global string $ME
|
|
|
|
* @name $ME
|
|
|
|
*/
|
2009-01-05 21:37:20 +00:00
|
|
|
global $ME;
|
2009-04-16 08:59:46 +00:00
|
|
|
|
2009-05-26 03:57:03 +00:00
|
|
|
/**
|
|
|
|
* $FULLME without slasharguments and query string.
|
|
|
|
* @global string $FULLSCRIPT
|
|
|
|
* @name $FULLSCRIPT
|
|
|
|
*/
|
2009-01-05 21:37:20 +00:00
|
|
|
global $FULLSCRIPT;
|
2009-04-16 08:59:46 +00:00
|
|
|
|
2009-05-26 03:57:03 +00:00
|
|
|
/**
|
|
|
|
* Relative moodle script path '/course/view.php'
|
|
|
|
* @global string $SCRIPT
|
|
|
|
* @name $SCRIPT
|
|
|
|
*/
|
2009-01-05 21:37:20 +00:00
|
|
|
global $SCRIPT;
|
2005-07-14 20:11:29 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// Store settings from config.php in array in $CFG - we can use it later to detect problems and overrides
|
|
|
|
$CFG->config_php_settings = (array)$CFG;
|
2010-05-19 13:30:13 +00:00
|
|
|
// Forced plugin settings override values from config_plugins table
|
|
|
|
unset($CFG->config_php_settings['forced_plugin_settings']);
|
|
|
|
if (!isset($CFG->forced_plugin_settings)) {
|
|
|
|
$CFG->forced_plugin_settings = array();
|
|
|
|
}
|
2009-10-31 22:35:06 +00:00
|
|
|
// Set httpswwwroot default value (this variable will replace $CFG->wwwroot
|
|
|
|
// inside some URLs used in HTTPSPAGEREQUIRED pages.
|
|
|
|
$CFG->httpswwwroot = $CFG->wwwroot;
|
2006-01-05 07:08:10 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
require_once($CFG->libdir .'/setuplib.php'); // Functions that MUST be loaded first
|
2009-06-19 14:25:56 +00:00
|
|
|
|
2010-11-19 03:40:43 +00:00
|
|
|
if (NO_OUTPUT_BUFFERING) {
|
2010-11-20 03:49:20 +00:00
|
|
|
// we have to call this always before starting session because it discards headers!
|
2010-11-19 03:40:43 +00:00
|
|
|
disable_output_buffering();
|
|
|
|
}
|
|
|
|
|
2010-10-19 09:23:08 +00:00
|
|
|
// Increase memory limits if possible
|
|
|
|
raise_memory_limit(MEMORY_STANDARD);
|
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// Time to start counting
|
|
|
|
init_performance_info();
|
2009-07-01 05:54:26 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// Put $OUTPUT in place, so errors can be displayed.
|
|
|
|
$OUTPUT = new bootstrap_renderer();
|
2005-07-14 20:11:29 +00:00
|
|
|
|
2009-11-01 09:44:11 +00:00
|
|
|
// set handler for uncaught exceptions - equivalent to print_error() call
|
2012-03-31 23:51:02 +02:00
|
|
|
if (!PHPUNIT_TEST or PHPUNIT_UTIL) {
|
|
|
|
set_exception_handler('default_exception_handler');
|
|
|
|
set_error_handler('default_error_handler', E_ALL | E_STRICT);
|
|
|
|
}
|
2008-06-25 17:31:23 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// If there are any errors in the standard libraries we want to know!
|
2012-03-31 23:51:02 +02:00
|
|
|
error_reporting(E_ALL | E_STRICT);
|
2009-06-29 05:00:45 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// Just say no to link prefetching (Moz prefetching, Google Web Accelerator, others)
|
|
|
|
// http://www.google.com/webmasters/faq.html#prefetchblock
|
|
|
|
if (!empty($_SERVER['HTTP_X_moz']) && $_SERVER['HTTP_X_moz'] === 'prefetch'){
|
|
|
|
header($_SERVER['SERVER_PROTOCOL'] . ' 404 Prefetch Forbidden');
|
|
|
|
echo('Prefetch request forbidden.');
|
|
|
|
exit(1);
|
|
|
|
}
|
2005-04-01 10:00:18 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
if (!isset($CFG->prefix)) { // Just in case it isn't defined in config.php
|
|
|
|
$CFG->prefix = '';
|
|
|
|
}
|
2005-05-07 03:07:08 +00:00
|
|
|
|
2010-04-10 20:35:52 +00:00
|
|
|
// location of all languages except core English pack
|
|
|
|
if (!isset($CFG->langotherroot)) {
|
|
|
|
$CFG->langotherroot = $CFG->dataroot.'/lang';
|
|
|
|
}
|
|
|
|
|
|
|
|
// location of local lang pack customisations (dirs with _local suffix)
|
|
|
|
if (!isset($CFG->langlocalroot)) {
|
|
|
|
$CFG->langlocalroot = $CFG->dataroot.'/lang';
|
|
|
|
}
|
|
|
|
|
2010-03-23 11:14:26 +00:00
|
|
|
//point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else
|
|
|
|
//the problem is that we need specific version of quickforms and hacked excel files :-(
|
|
|
|
ini_set('include_path', $CFG->libdir.'/pear' . PATH_SEPARATOR . ini_get('include_path'));
|
|
|
|
//point zend include path to moodles lib/zend so that includes and requires will search there for files before anywhere else
|
|
|
|
//please note zend library is supposed to be used only from web service protocol classes, it may be removed in future
|
|
|
|
ini_set('include_path', $CFG->libdir.'/zend' . PATH_SEPARATOR . ini_get('include_path'));
|
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// Load up standard libraries
|
|
|
|
require_once($CFG->libdir .'/textlib.class.php'); // Functions to handle multibyte strings
|
|
|
|
require_once($CFG->libdir .'/filterlib.php'); // Functions for filtering test as it is output
|
|
|
|
require_once($CFG->libdir .'/ajax/ajaxlib.php'); // Functions for managing our use of JavaScript and YUI
|
|
|
|
require_once($CFG->libdir .'/weblib.php'); // Functions relating to HTTP and content
|
|
|
|
require_once($CFG->libdir .'/outputlib.php'); // Functions for generating output
|
|
|
|
require_once($CFG->libdir .'/navigationlib.php'); // Class for generating Navigation structure
|
|
|
|
require_once($CFG->libdir .'/dmllib.php'); // Database access
|
|
|
|
require_once($CFG->libdir .'/datalib.php'); // Legacy lib with a big-mix of functions.
|
|
|
|
require_once($CFG->libdir .'/accesslib.php'); // Access control functions
|
|
|
|
require_once($CFG->libdir .'/deprecatedlib.php'); // Deprecated functions included for backward compatibility
|
|
|
|
require_once($CFG->libdir .'/moodlelib.php'); // Other general-purpose functions
|
MDL-21782 reworked enrolment framework, the core infrastructure is in place, the basic plugins are all implemented; see the tracker issue for list of unfinished bits, expect more changes and improvements during the next week
AMOS START
MOV [sendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage,enrol_self]
MOV [configsendcoursewelcomemessage,core_admin],[sendcoursewelcomemessage_desc,enrol_self]
MOV [enrolstartdate,core],[enrolstartdate,enrol_self]
MOV [enrolenddate,core],[enrolenddate,enrol_self]
CPY [welcometocourse,core],[welcometocourse,enrol_self]
CPY [welcometocoursetext,core],[welcometocoursetext,enrol_self]
MOV [notenrollable,core],[notenrollable,core_enrol]
MOV [enrolenddaterror,core],[enrolenddaterror,enrol_self]
MOV [enrolmentkeyhint,core],[passwordinvalidhint,enrol_self]
MOV [coursemanager,core_admin],[coursecontact,core_admin]
MOV [configcoursemanager,core_admin],[coursecontact_desc,core_admin]
MOV [enrolledincourserole,core],[enrolledincourserole,enrol_manual]
MOV [enrolme,core],[enrolme,core_enrol]
MOV [unenrol,core],[unenrol,core_enrol]
MOV [unenrolme,core],[unenrolme,core_enrol]
MOV [enrolmentnew,core],[enrolmentnew,core_enrol]
MOV [enrolmentnewuser,core],[enrolmentnewuser,core_enrol]
MOV [enrolments,core],[enrolments,core_enrol]
MOV [enrolperiod,core],[enrolperiod,core_enrol]
MOV [unenrolroleusers,core],[unenrolroleusers,core_enrol]
AMOS END
2010-06-21 15:30:49 +00:00
|
|
|
require_once($CFG->libdir .'/enrollib.php'); // Enrolment related functions
|
2009-10-31 22:35:06 +00:00
|
|
|
require_once($CFG->libdir .'/pagelib.php'); // Library that defines the moodle_page class, used for $PAGE
|
|
|
|
require_once($CFG->libdir .'/blocklib.php'); // Library for controlling blocks
|
|
|
|
require_once($CFG->libdir .'/eventslib.php'); // Events functions
|
|
|
|
require_once($CFG->libdir .'/grouplib.php'); // Groups functions
|
|
|
|
require_once($CFG->libdir .'/sessionlib.php'); // All session and cookie related stuff
|
|
|
|
require_once($CFG->libdir .'/editorlib.php'); // All text editor related functions and classes
|
2009-11-07 10:27:57 +00:00
|
|
|
require_once($CFG->libdir .'/messagelib.php'); // Messagelib functions
|
2011-01-26 10:29:16 +00:00
|
|
|
require_once($CFG->libdir .'/modinfolib.php'); // Cached information on course-module instances
|
2012-09-10 15:28:32 +12:00
|
|
|
require_once($CFG->dirroot.'/cache/lib.php'); // Cache API
|
2009-10-31 22:35:06 +00:00
|
|
|
|
|
|
|
// make sure PHP is not severly misconfigured
|
|
|
|
setup_validate_php_configuration();
|
|
|
|
|
|
|
|
// Connect to the database
|
|
|
|
setup_DB();
|
|
|
|
|
2012-03-31 23:51:02 +02:00
|
|
|
if (PHPUNIT_TEST and !PHPUNIT_UTIL) {
|
2012-04-06 20:36:18 +02:00
|
|
|
// make sure tests do not run in parallel
|
2013-01-11 13:57:19 +08:00
|
|
|
test_lock::acquire('phpunit');
|
2012-05-20 13:19:27 +02:00
|
|
|
$dbhash = null;
|
|
|
|
try {
|
|
|
|
if ($dbhash = $DB->get_field('config', 'value', array('name'=>'phpunittest'))) {
|
|
|
|
// reset DB tables
|
|
|
|
phpunit_util::reset_database();
|
|
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
|
|
if ($dbhash) {
|
|
|
|
// we ned to reinit if reset fails
|
|
|
|
$DB->set_field('config', 'value', 'na', array('name'=>'phpunittest'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($dbhash);
|
2012-03-31 23:51:02 +02:00
|
|
|
}
|
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// Disable errors for now - needed for installation when debug enabled in config.php
|
|
|
|
if (isset($CFG->debug)) {
|
|
|
|
$originalconfigdebug = $CFG->debug;
|
|
|
|
unset($CFG->debug);
|
|
|
|
} else {
|
2012-03-31 23:51:02 +02:00
|
|
|
$originalconfigdebug = null;
|
2009-10-31 22:35:06 +00:00
|
|
|
}
|
2003-04-10 13:46:52 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// Load up any configuration from the config table
|
2012-04-13 11:48:34 +02:00
|
|
|
|
|
|
|
if (PHPUNIT_TEST) {
|
|
|
|
phpunit_util::initialise_cfg();
|
|
|
|
} else {
|
|
|
|
initialise_cfg();
|
|
|
|
}
|
2002-12-07 07:27:58 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// Verify upgrade is not running unless we are in a script that needs to execute in any case
|
|
|
|
if (!defined('NO_UPGRADE_CHECK') and isset($CFG->upgraderunning)) {
|
|
|
|
if ($CFG->upgraderunning < time()) {
|
|
|
|
unset_config('upgraderunning');
|
2006-09-10 21:10:48 +00:00
|
|
|
} else {
|
2009-10-31 22:35:06 +00:00
|
|
|
print_error('upgraderunning');
|
2006-09-10 21:10:48 +00:00
|
|
|
}
|
2009-10-31 22:35:06 +00:00
|
|
|
}
|
2006-09-10 21:10:48 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// Turn on SQL logging if required
|
|
|
|
if (!empty($CFG->logsql)) {
|
|
|
|
$DB->set_logging(true);
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// Prevent warnings from roles when upgrading with debug on
|
|
|
|
if (isset($CFG->debug)) {
|
|
|
|
$originaldatabasedebug = $CFG->debug;
|
|
|
|
unset($CFG->debug);
|
|
|
|
} else {
|
2012-03-31 23:51:02 +02:00
|
|
|
$originaldatabasedebug = null;
|
2009-10-31 22:35:06 +00:00
|
|
|
}
|
2008-08-16 12:16:01 +00:00
|
|
|
|
2010-07-21 20:32:09 +00:00
|
|
|
// enable circular reference collector in PHP 5.3,
|
|
|
|
// it helps a lot when using large complex OOP structures such as in amos or gradebook
|
|
|
|
if (function_exists('gc_enable')) {
|
|
|
|
gc_enable();
|
|
|
|
}
|
2002-08-17 13:01:06 +00:00
|
|
|
|
2010-10-19 10:00:29 +00:00
|
|
|
// Register default shutdown tasks - such as Apache memory release helper, perf logging, etc.
|
2009-10-31 22:35:06 +00:00
|
|
|
if (function_exists('register_shutdown_function')) {
|
|
|
|
register_shutdown_function('moodle_request_shutdown');
|
|
|
|
}
|
2002-12-30 03:24:07 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// Set error reporting back to normal
|
2012-03-31 23:51:02 +02:00
|
|
|
if ($originaldatabasedebug === null) {
|
2009-10-31 22:35:06 +00:00
|
|
|
$CFG->debug = DEBUG_MINIMAL;
|
|
|
|
} else {
|
|
|
|
$CFG->debug = $originaldatabasedebug;
|
|
|
|
}
|
2012-03-31 23:51:02 +02:00
|
|
|
if ($originalconfigdebug !== null) {
|
2009-10-31 22:35:06 +00:00
|
|
|
$CFG->debug = $originalconfigdebug;
|
|
|
|
}
|
|
|
|
unset($originalconfigdebug);
|
|
|
|
unset($originaldatabasedebug);
|
|
|
|
error_reporting($CFG->debug);
|
|
|
|
|
2010-05-19 13:30:13 +00:00
|
|
|
// find out if PHP configured to display warnings,
|
2009-10-31 22:35:06 +00:00
|
|
|
// this is a security problem because some moodle scripts may
|
|
|
|
// disclose sensitive information
|
|
|
|
if (ini_get_bool('display_errors')) {
|
|
|
|
define('WARN_DISPLAY_ERRORS_ENABLED', true);
|
|
|
|
}
|
|
|
|
// If we want to display Moodle errors, then try and set PHP errors to match
|
|
|
|
if (!isset($CFG->debugdisplay)) {
|
|
|
|
// keep it "as is" during installation
|
|
|
|
} else if (NO_DEBUG_DISPLAY) {
|
|
|
|
// some parts of Moodle cannot display errors and debug at all.
|
2010-11-19 01:39:30 +00:00
|
|
|
ini_set('display_errors', '0');
|
|
|
|
ini_set('log_errors', '1');
|
2009-10-31 22:35:06 +00:00
|
|
|
} else if (empty($CFG->debugdisplay)) {
|
2010-11-19 01:39:30 +00:00
|
|
|
ini_set('display_errors', '0');
|
|
|
|
ini_set('log_errors', '1');
|
2009-10-31 22:35:06 +00:00
|
|
|
} else {
|
|
|
|
// This is very problematic in XHTML strict mode!
|
2010-11-19 01:39:30 +00:00
|
|
|
ini_set('display_errors', '1');
|
2009-10-31 22:35:06 +00:00
|
|
|
}
|
2006-03-29 23:38:46 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// detect unsupported upgrade jump as soon as possible - do not change anything, do not use system functions
|
|
|
|
if (!empty($CFG->version) and $CFG->version < 2007101509) {
|
|
|
|
print_error('upgraderequires19', 'error');
|
|
|
|
die;
|
|
|
|
}
|
2006-03-29 23:38:46 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// Calculate and set $CFG->ostype to be used everywhere. Possible values are:
|
|
|
|
// - WINDOWS: for any Windows flavour.
|
|
|
|
// - UNIX: for the rest
|
|
|
|
// Also, $CFG->os can continue being used if more specialization is required
|
|
|
|
if (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) {
|
|
|
|
$CFG->ostype = 'WINDOWS';
|
|
|
|
} else {
|
|
|
|
$CFG->ostype = 'UNIX';
|
|
|
|
}
|
|
|
|
$CFG->os = PHP_OS;
|
2006-04-07 22:58:07 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// Configure ampersands in URLs
|
2010-11-19 01:39:30 +00:00
|
|
|
ini_set('arg_separator.output', '&');
|
2004-09-07 09:49:41 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// Work around for a PHP bug see MDL-11237
|
2010-11-19 01:39:30 +00:00
|
|
|
ini_set('pcre.backtrack_limit', 20971520); // 20 MB
|
2007-09-13 06:42:49 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// Location of standard files
|
2009-11-01 09:44:11 +00:00
|
|
|
$CFG->wordlist = $CFG->libdir .'/wordlist.txt';
|
|
|
|
$CFG->moddata = 'moddata';
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// A hack to get around magic_quotes_gpc being turned on
|
|
|
|
// It is strongly recommended to disable "magic_quotes_gpc"!
|
|
|
|
if (ini_get_bool('magic_quotes_gpc')) {
|
|
|
|
function stripslashes_deep($value) {
|
|
|
|
$value = is_array($value) ?
|
|
|
|
array_map('stripslashes_deep', $value) :
|
|
|
|
stripslashes($value);
|
|
|
|
return $value;
|
2009-06-29 05:00:45 +00:00
|
|
|
}
|
2009-10-31 22:35:06 +00:00
|
|
|
$_POST = array_map('stripslashes_deep', $_POST);
|
|
|
|
$_GET = array_map('stripslashes_deep', $_GET);
|
|
|
|
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
|
|
|
|
$_REQUEST = array_map('stripslashes_deep', $_REQUEST);
|
|
|
|
if (!empty($_SERVER['REQUEST_URI'])) {
|
|
|
|
$_SERVER['REQUEST_URI'] = stripslashes($_SERVER['REQUEST_URI']);
|
2009-01-06 12:31:20 +00:00
|
|
|
}
|
2009-10-31 22:35:06 +00:00
|
|
|
if (!empty($_SERVER['QUERY_STRING'])) {
|
|
|
|
$_SERVER['QUERY_STRING'] = stripslashes($_SERVER['QUERY_STRING']);
|
|
|
|
}
|
|
|
|
if (!empty($_SERVER['HTTP_REFERER'])) {
|
|
|
|
$_SERVER['HTTP_REFERER'] = stripslashes($_SERVER['HTTP_REFERER']);
|
2003-07-28 16:37:12 +00:00
|
|
|
}
|
2009-10-31 22:35:06 +00:00
|
|
|
if (!empty($_SERVER['PATH_INFO'])) {
|
|
|
|
$_SERVER['PATH_INFO'] = stripslashes($_SERVER['PATH_INFO']);
|
|
|
|
}
|
|
|
|
if (!empty($_SERVER['PHP_SELF'])) {
|
|
|
|
$_SERVER['PHP_SELF'] = stripslashes($_SERVER['PHP_SELF']);
|
|
|
|
}
|
|
|
|
if (!empty($_SERVER['PATH_TRANSLATED'])) {
|
|
|
|
$_SERVER['PATH_TRANSLATED'] = stripslashes($_SERVER['PATH_TRANSLATED']);
|
|
|
|
}
|
|
|
|
}
|
2002-07-02 07:02:28 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// neutralise nasty chars in PHP_SELF
|
|
|
|
if (isset($_SERVER['PHP_SELF'])) {
|
|
|
|
$phppos = strpos($_SERVER['PHP_SELF'], '.php');
|
|
|
|
if ($phppos !== false) {
|
|
|
|
$_SERVER['PHP_SELF'] = substr($_SERVER['PHP_SELF'], 0, $phppos+4);
|
2005-02-01 08:00:58 +00:00
|
|
|
}
|
2009-10-31 22:35:06 +00:00
|
|
|
unset($phppos);
|
|
|
|
}
|
|
|
|
|
2011-10-21 09:52:18 +02:00
|
|
|
// initialise ME's - this must be done BEFORE starting of session!
|
|
|
|
initialise_fullme();
|
|
|
|
|
2011-10-21 16:35:19 +02:00
|
|
|
// define SYSCONTEXTID in config.php if you want to save some queries,
|
|
|
|
// after install it must match the system context record id.
|
|
|
|
if (!defined('SYSCONTEXTID')) {
|
|
|
|
get_system_context();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Defining the site - aka frontpage course
|
|
|
|
try {
|
|
|
|
$SITE = get_site();
|
|
|
|
} catch (dml_exception $e) {
|
|
|
|
$SITE = null;
|
|
|
|
if (empty($CFG->version)) {
|
|
|
|
$SITE = new stdClass();
|
|
|
|
$SITE->id = 1;
|
|
|
|
} else {
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// And the 'default' course - this will usually get reset later in require_login() etc.
|
|
|
|
$COURSE = clone($SITE);
|
|
|
|
/** @deprecated Id of the frontpage course, use $SITE->id instead */
|
|
|
|
define('SITEID', $SITE->id);
|
|
|
|
|
2010-08-16 17:47:36 +00:00
|
|
|
// init session prevention flag - this is defined on pages that do not want session
|
2010-08-17 12:33:30 +00:00
|
|
|
if (CLI_SCRIPT) {
|
|
|
|
// no sessions in CLI scripts possible
|
|
|
|
define('NO_MOODLE_COOKIES', true);
|
|
|
|
|
|
|
|
} else if (!defined('NO_MOODLE_COOKIES')) {
|
2010-08-16 17:47:36 +00:00
|
|
|
if (empty($CFG->version) or $CFG->version < 2009011900) {
|
|
|
|
// no session before sessions table gets created
|
|
|
|
define('NO_MOODLE_COOKIES', true);
|
|
|
|
} else if (CLI_SCRIPT) {
|
|
|
|
// CLI scripts can not have session
|
|
|
|
define('NO_MOODLE_COOKIES', true);
|
|
|
|
} else {
|
|
|
|
define('NO_MOODLE_COOKIES', false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// start session and prepare global $SESSION, $USER
|
|
|
|
session_get_instance();
|
|
|
|
$SESSION = &$_SESSION['SESSION'];
|
|
|
|
$USER = &$_SESSION['USER'];
|
2005-02-01 08:00:58 +00:00
|
|
|
|
2011-03-19 00:32:45 +01:00
|
|
|
// Late profiling, only happening if early one wasn't started
|
2010-11-20 13:22:27 +01:00
|
|
|
if (!empty($CFG->profilingenabled)) {
|
|
|
|
require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
|
2011-03-19 00:32:45 +01:00
|
|
|
if (profiling_start()) {
|
|
|
|
register_shutdown_function('profiling_stop');
|
|
|
|
}
|
2010-11-20 13:22:27 +01:00
|
|
|
}
|
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// Process theme change in the URL.
|
2009-12-20 16:25:41 +00:00
|
|
|
if (!empty($CFG->allowthemechangeonurl) and !empty($_GET['theme'])) {
|
|
|
|
// we have to use _GET directly because we do not want this to interfere with _POST
|
2011-09-24 15:07:27 +02:00
|
|
|
$urlthemename = optional_param('theme', '', PARAM_PLUGIN);
|
2009-10-31 22:35:06 +00:00
|
|
|
try {
|
2009-12-20 16:25:41 +00:00
|
|
|
$themeconfig = theme_config::load($urlthemename);
|
|
|
|
// Makes sure the theme can be loaded without errors.
|
|
|
|
if ($themeconfig->name === $urlthemename) {
|
|
|
|
$SESSION->theme = $urlthemename;
|
|
|
|
} else {
|
|
|
|
unset($SESSION->theme);
|
|
|
|
}
|
|
|
|
unset($themeconfig);
|
|
|
|
unset($urlthemename);
|
2009-10-31 22:35:06 +00:00
|
|
|
} catch (Exception $e) {
|
|
|
|
debugging('Failed to set the theme from the URL.', DEBUG_DEVELOPER, $e->getTrace());
|
2005-02-01 08:00:58 +00:00
|
|
|
}
|
2009-10-31 22:35:06 +00:00
|
|
|
}
|
|
|
|
unset($urlthemename);
|
2005-02-01 08:00:58 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// Ensure a valid theme is set.
|
|
|
|
if (!isset($CFG->theme)) {
|
|
|
|
$CFG->theme = 'standardwhite';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set language/locale of printed times. If user has chosen a language that
|
|
|
|
// that is different from the site language, then use the locale specified
|
|
|
|
// in the language file. Otherwise, if the admin hasn't specified a locale
|
|
|
|
// then use the one from the default language. Otherwise (and this is the
|
|
|
|
// majority of cases), use the stored locale specified by admin.
|
2010-04-10 20:41:26 +00:00
|
|
|
// note: do not accept lang parameter from POST
|
|
|
|
if (isset($_GET['lang']) and ($lang = optional_param('lang', '', PARAM_SAFEDIR))) {
|
2010-04-14 14:38:33 +00:00
|
|
|
if (get_string_manager()->translation_exists($lang, false)) {
|
2009-10-31 22:35:06 +00:00
|
|
|
$SESSION->lang = $lang;
|
2003-01-20 08:09:25 +00:00
|
|
|
}
|
2009-10-31 22:35:06 +00:00
|
|
|
}
|
|
|
|
unset($lang);
|
2007-02-12 14:58:44 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
setup_lang_from_browser();
|
2007-02-12 14:58:44 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
if (empty($CFG->lang)) {
|
|
|
|
if (empty($SESSION->lang)) {
|
2010-04-10 07:24:56 +00:00
|
|
|
$CFG->lang = 'en';
|
2009-10-31 22:35:06 +00:00
|
|
|
} else {
|
|
|
|
$CFG->lang = $SESSION->lang;
|
2003-05-26 15:38:52 +00:00
|
|
|
}
|
2009-10-31 22:35:06 +00:00
|
|
|
}
|
2008-06-25 17:31:23 +00:00
|
|
|
|
2010-03-02 11:51:36 +00:00
|
|
|
// Set the default site locale, a lot of the stuff may depend on this
|
|
|
|
// it is definitely too late to call this first in require_login()!
|
|
|
|
moodle_setlocale();
|
2009-10-31 22:35:06 +00:00
|
|
|
|
2011-10-21 16:35:19 +02:00
|
|
|
// Create the $PAGE global - this marks the PAGE and OUTPUT fully initialised, this MUST be done at the end of setup!
|
|
|
|
if (!empty($CFG->moodlepageclass)) {
|
2012-08-15 13:41:39 +02:00
|
|
|
if (!empty($CFG->moodlepageclassfile)) {
|
|
|
|
require_once($CFG->moodlepageclassfile);
|
|
|
|
}
|
2011-10-21 16:35:19 +02:00
|
|
|
$classname = $CFG->moodlepageclass;
|
|
|
|
} else {
|
|
|
|
$classname = 'moodle_page';
|
|
|
|
}
|
|
|
|
$PAGE = new $classname();
|
|
|
|
unset($classname);
|
|
|
|
|
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
if (!empty($CFG->debugvalidators) and !empty($CFG->guestloginbutton)) {
|
|
|
|
if ($CFG->theme == 'standard' or $CFG->theme == 'standardwhite') { // Temporary measure to help with XHTML validation
|
|
|
|
if (isset($_SERVER['HTTP_USER_AGENT']) and empty($USER->id)) { // Allow W3CValidator in as user called w3cvalidator (or guest)
|
|
|
|
if ((strpos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') !== false) or
|
|
|
|
(strpos($_SERVER['HTTP_USER_AGENT'], 'Cynthia') !== false )) {
|
|
|
|
if ($user = get_complete_user_data("username", "w3cvalidator")) {
|
|
|
|
$user->ignoresesskey = true;
|
|
|
|
} else {
|
|
|
|
$user = guest_user();
|
2004-09-07 07:38:44 +00:00
|
|
|
}
|
2009-10-31 22:35:06 +00:00
|
|
|
session_set_user($user);
|
2004-09-07 07:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-10-31 22:35:06 +00:00
|
|
|
}
|
2004-09-07 07:38:44 +00:00
|
|
|
|
2009-11-01 09:44:11 +00:00
|
|
|
// Apache log integration. In apache conf file one can use ${MOODULEUSER}n in
|
2009-10-31 22:35:06 +00:00
|
|
|
// LogFormat to get the current logged in username in moodle.
|
|
|
|
if ($USER && function_exists('apache_note')
|
|
|
|
&& !empty($CFG->apacheloguser) && isset($USER->username)) {
|
|
|
|
$apachelog_userid = $USER->id;
|
|
|
|
$apachelog_username = clean_filename($USER->username);
|
|
|
|
$apachelog_name = '';
|
|
|
|
if (isset($USER->firstname)) {
|
|
|
|
// We can assume both will be set
|
|
|
|
// - even if to empty.
|
|
|
|
$apachelog_name = clean_filename($USER->firstname . " " .
|
|
|
|
$USER->lastname);
|
|
|
|
}
|
|
|
|
if (session_is_loggedinas()) {
|
|
|
|
$realuser = session_get_realuser();
|
|
|
|
$apachelog_username = clean_filename($realuser->username." as ".$apachelog_username);
|
|
|
|
$apachelog_name = clean_filename($realuser->firstname." ".$realuser->lastname ." as ".$apachelog_name);
|
|
|
|
$apachelog_userid = clean_filename($realuser->id." as ".$apachelog_userid);
|
|
|
|
}
|
|
|
|
switch ($CFG->apacheloguser) {
|
|
|
|
case 3:
|
|
|
|
$logname = $apachelog_username;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
$logname = $apachelog_name;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
default:
|
|
|
|
$logname = $apachelog_userid;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
apache_note('MOODLEUSER', $logname);
|
|
|
|
}
|
2005-05-16 02:51:05 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// Use a custom script replacement if one exists
|
|
|
|
if (!empty($CFG->customscripts)) {
|
|
|
|
if (($customscript = custom_script_path()) !== false) {
|
|
|
|
require ($customscript);
|
2005-07-14 15:35:23 +00:00
|
|
|
}
|
2009-10-31 22:35:06 +00:00
|
|
|
}
|
2005-07-14 15:35:23 +00:00
|
|
|
|
2012-03-31 23:51:02 +02:00
|
|
|
if (PHPUNIT_TEST) {
|
|
|
|
// no ip blocking, these are CLI only
|
|
|
|
} else if (CLI_SCRIPT and !defined('WEB_CRON_EMULATED_CLI')) {
|
2011-11-14 10:09:10 +08:00
|
|
|
// no ip blocking
|
|
|
|
} else if (!empty($CFG->allowbeforeblock)) { // allowed list processed before blocked list?
|
|
|
|
// in this case, ip in allowed list will be performed first
|
|
|
|
// for example, client IP is 192.168.1.1
|
|
|
|
// 192.168 subnet is an entry in allowed list
|
|
|
|
// 192.168.1.1 is banned in blocked list
|
|
|
|
// This ip will be banned finally
|
2009-10-31 22:35:06 +00:00
|
|
|
if (!empty($CFG->allowedip)) {
|
|
|
|
if (!remoteip_in_list($CFG->allowedip)) {
|
|
|
|
die(get_string('ipblocked', 'admin'));
|
2008-07-14 08:14:31 +00:00
|
|
|
}
|
2009-10-31 22:35:06 +00:00
|
|
|
}
|
|
|
|
// need further check, client ip may a part of
|
|
|
|
// allowed subnet, but a IP address are listed
|
|
|
|
// in blocked list.
|
|
|
|
if (!empty($CFG->blockedip)) {
|
|
|
|
if (remoteip_in_list($CFG->blockedip)) {
|
|
|
|
die(get_string('ipblocked', 'admin'));
|
2008-07-22 04:07:58 +00:00
|
|
|
}
|
2009-10-31 22:35:06 +00:00
|
|
|
}
|
2008-07-25 08:27:50 +00:00
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
} else {
|
|
|
|
// in this case, IPs in blocked list will be performed first
|
|
|
|
// for example, client IP is 192.168.1.1
|
|
|
|
// 192.168 subnet is an entry in blocked list
|
|
|
|
// 192.168.1.1 is allowed in allowed list
|
|
|
|
// This ip will be allowed finally
|
|
|
|
if (!empty($CFG->blockedip)) {
|
|
|
|
if (remoteip_in_list($CFG->blockedip)) {
|
|
|
|
// if the allowed ip list is not empty
|
|
|
|
// IPs are not included in the allowed list will be
|
|
|
|
// blocked too
|
|
|
|
if (!empty($CFG->allowedip)) {
|
|
|
|
if (!remoteip_in_list($CFG->allowedip)) {
|
2008-07-25 08:27:50 +00:00
|
|
|
die(get_string('ipblocked', 'admin'));
|
|
|
|
}
|
2009-10-31 22:35:06 +00:00
|
|
|
} else {
|
2008-07-25 08:27:50 +00:00
|
|
|
die(get_string('ipblocked', 'admin'));
|
|
|
|
}
|
2008-07-22 04:07:58 +00:00
|
|
|
}
|
2009-10-31 22:35:06 +00:00
|
|
|
}
|
|
|
|
// if blocked list is null
|
|
|
|
// allowed list should be tested
|
|
|
|
if(!empty($CFG->allowedip)) {
|
|
|
|
if (!remoteip_in_list($CFG->allowedip)) {
|
|
|
|
die(get_string('ipblocked', 'admin'));
|
|
|
|
}
|
2008-07-14 08:14:31 +00:00
|
|
|
}
|
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
}
|
2009-07-09 20:07:51 +00:00
|
|
|
|
2012-04-28 18:00:06 +02:00
|
|
|
// // try to detect IE6 and prevent gzip because it is extremely buggy browser
|
|
|
|
if (!empty($_SERVER['HTTP_USER_AGENT']) and strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false) {
|
|
|
|
@ini_set('zlib.output_compression', 'Off');
|
|
|
|
if (function_exists('apache_setenv')) {
|
|
|
|
@apache_setenv('no-gzip', 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-31 22:35:06 +00:00
|
|
|
// note: we can not block non utf-8 installations here, because empty mysql database
|
|
|
|
// might be converted to utf-8 in admin/index.php during installation
|
2010-01-13 11:25:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this is a funny trick to make Eclipse believe that $OUTPUT and other globals
|
|
|
|
// contains an instance of core_renderer, etc. which in turn fixes autocompletion ;-)
|
|
|
|
if (false) {
|
|
|
|
$DB = new moodle_database();
|
|
|
|
$OUTPUT = new core_renderer(null, null);
|
|
|
|
$PAGE = new moodle_page();
|
|
|
|
}
|