mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-20696 fixed coding style: lib/setup.php is the first file people start reading when hacking moodle, it has to use the best coding style possible ;-)
This commit is contained in:
parent
47c2811b95
commit
4dffc77519
1 changed files with 481 additions and 485 deletions
458
lib/setup.php
458
lib/setup.php
|
@ -176,227 +176,225 @@ if (!isset($CFG->wwwroot)) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Detect CLI scripts - CLI scripts are executed from command line, do not have session and we do not want HTML in output
|
// Detect CLI scripts - CLI scripts are executed from command line, do not have session and we do not want HTML in output
|
||||||
if (!defined('CLI_SCRIPT')) { // CLI_SCRIPT might be defined in 'fake' CLI scripts like admin/cron.php
|
if (!defined('CLI_SCRIPT')) { // CLI_SCRIPT might be defined in 'fake' CLI scripts like admin/cron.php
|
||||||
if (isset($_SERVER['REMOTE_ADDR'])) {
|
if (isset($_SERVER['REMOTE_ADDR'])) {
|
||||||
define('CLI_SCRIPT', false);
|
define('CLI_SCRIPT', false);
|
||||||
} else {
|
} else {
|
||||||
/** @ignore */
|
/** @ignore */
|
||||||
define('CLI_SCRIPT', true);
|
define('CLI_SCRIPT', true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// sometimes default PHP settings are borked on shared hosting servers, I wonder why they have to do that??
|
// sometimes default PHP settings are borked on shared hosting servers, I wonder why they have to do that??
|
||||||
@ini_set('precision', 14); // needed for upgrades and gradebook
|
@ini_set('precision', 14); // needed for upgrades and gradebook
|
||||||
|
|
||||||
|
// The current directory in PHP version 4.3.0 and above isn't necessarily the
|
||||||
/// 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()
|
||||||
/// directory of the script when run from the command line. The require_once()
|
// would fail, so we'll have to chdir()
|
||||||
/// would fail, so we'll have to chdir()
|
if (!isset($_SERVER['REMOTE_ADDR']) && isset($_SERVER['argv'][0])) {
|
||||||
if (!isset($_SERVER['REMOTE_ADDR']) && isset($_SERVER['argv'][0])) {
|
|
||||||
chdir(dirname($_SERVER['argv'][0]));
|
chdir(dirname($_SERVER['argv'][0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
/// Store settings from config.php in array in $CFG - we can use it later to detect problems and overrides
|
// Set up some paths.
|
||||||
$CFG->config_php_settings = (array)$CFG;
|
$CFG->libdir = $CFG->dirroot .'/lib';
|
||||||
|
|
||||||
/// Set up some paths.
|
if (!isset($CFG->themedir)) {
|
||||||
$CFG->libdir = $CFG->dirroot .'/lib';
|
|
||||||
|
|
||||||
if (!isset($CFG->themedir)) {
|
|
||||||
$CFG->themedir = $CFG->dirroot.'/theme';
|
$CFG->themedir = $CFG->dirroot.'/theme';
|
||||||
$CFG->themewww = $CFG->wwwroot.'/theme';
|
$CFG->themewww = $CFG->wwwroot.'/theme';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set httpswwwroot default value (this variable will replace $CFG->wwwroot
|
// Set httpswwwroot default value (this variable will replace $CFG->wwwroot
|
||||||
/// inside some URLs used in HTTPSPAGEREQUIRED pages.
|
// inside some URLs used in HTTPSPAGEREQUIRED pages.
|
||||||
$CFG->httpswwwroot = $CFG->wwwroot;
|
$CFG->httpswwwroot = $CFG->wwwroot;
|
||||||
$CFG->httpsthemewww = $CFG->themewww;
|
$CFG->httpsthemewww = $CFG->themewww;
|
||||||
|
|
||||||
require_once($CFG->libdir .'/setuplib.php'); // Functions that MUST be loaded first
|
require_once($CFG->libdir .'/setuplib.php'); // Functions that MUST be loaded first
|
||||||
|
|
||||||
/// Time to start counting
|
// Time to start counting
|
||||||
init_performance_info();
|
init_performance_info();
|
||||||
|
|
||||||
/// Put $OUTPUT in place, so errors can be displayed.
|
// Put $OUTPUT in place, so errors can be displayed.
|
||||||
$OUTPUT = new bootstrap_renderer();
|
$OUTPUT = new bootstrap_renderer();
|
||||||
|
|
||||||
/// set handler for uncought exceptions - equivalent to print_error() call
|
// set handler for uncought exceptions - equivalent to print_error() call
|
||||||
set_exception_handler('default_exception_handler');
|
set_exception_handler('default_exception_handler');
|
||||||
|
|
||||||
/// If there are any errors in the standard libraries we want to know!
|
// If there are any errors in the standard libraries we want to know!
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
/// Just say no to link prefetching (Moz prefetching, Google Web Accelerator, others)
|
// Just say no to link prefetching (Moz prefetching, Google Web Accelerator, others)
|
||||||
/// http://www.google.com/webmasters/faq.html#prefetchblock
|
// http://www.google.com/webmasters/faq.html#prefetchblock
|
||||||
if (!empty($_SERVER['HTTP_X_moz']) && $_SERVER['HTTP_X_moz'] === 'prefetch'){
|
if (!empty($_SERVER['HTTP_X_moz']) && $_SERVER['HTTP_X_moz'] === 'prefetch'){
|
||||||
header($_SERVER['SERVER_PROTOCOL'] . ' 404 Prefetch Forbidden');
|
header($_SERVER['SERVER_PROTOCOL'] . ' 404 Prefetch Forbidden');
|
||||||
echo('Prefetch request forbidden.');
|
echo('Prefetch request forbidden.');
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Define admin directory
|
// Define admin directory
|
||||||
if (!isset($CFG->admin)) { // Just in case it isn't defined in config.php
|
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
|
$CFG->admin = 'admin'; // This is relative to the wwwroot and dirroot
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($CFG->prefix)) { // Just in case it isn't defined in config.php
|
if (!isset($CFG->prefix)) { // Just in case it isn't defined in config.php
|
||||||
$CFG->prefix = '';
|
$CFG->prefix = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load up standard libraries
|
// Load up standard libraries
|
||||||
require_once($CFG->libdir .'/textlib.class.php'); // Functions to handle multibyte strings
|
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 .'/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 .'/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 .'/weblib.php'); // Functions relating to HTTP and content
|
||||||
require_once($CFG->libdir .'/outputlib.php'); // Functions for generating output
|
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 .'/navigationlib.php'); // Class for generating Navigation structure
|
||||||
require_once($CFG->libdir .'/dmllib.php'); // Database access
|
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 .'/datalib.php'); // Legacy lib with a big-mix of functions.
|
||||||
require_once($CFG->libdir .'/accesslib.php'); // Access control 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 .'/deprecatedlib.php'); // Deprecated functions included for backward compatibility
|
||||||
require_once($CFG->libdir .'/moodlelib.php'); // Other general-purpose functions
|
require_once($CFG->libdir .'/moodlelib.php'); // Other general-purpose functions
|
||||||
require_once($CFG->libdir .'/pagelib.php'); // Library that defines the moodle_page class, used for $PAGE
|
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 .'/blocklib.php'); // Library for controlling blocks
|
||||||
require_once($CFG->libdir .'/eventslib.php'); // Events functions
|
require_once($CFG->libdir .'/eventslib.php'); // Events functions
|
||||||
require_once($CFG->libdir .'/grouplib.php'); // Groups 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 .'/sessionlib.php'); // All session and cookie related stuff
|
||||||
require_once($CFG->libdir .'/editorlib.php'); // All text editor related functions and classes
|
require_once($CFG->libdir .'/editorlib.php'); // All text editor related functions and classes
|
||||||
|
|
||||||
//point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else
|
//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 :-(
|
//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'));
|
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
|
//point zend include path to moodles lib/zend so that includes and requires will search there for files before anywhere else
|
||||||
ini_set('include_path', $CFG->libdir.'/zend' . PATH_SEPARATOR . ini_get('include_path'));
|
ini_set('include_path', $CFG->libdir.'/zend' . PATH_SEPARATOR . ini_get('include_path'));
|
||||||
|
|
||||||
/// make sure PHP is not severly misconfigured
|
// make sure PHP is not severly misconfigured
|
||||||
setup_validate_php_configuration();
|
setup_validate_php_configuration();
|
||||||
|
|
||||||
/// Increase memory limits if possible
|
// Increase memory limits if possible
|
||||||
raise_memory_limit('96M'); // We should never NEED this much but just in case...
|
raise_memory_limit('96M'); // We should never NEED this much but just in case...
|
||||||
|
|
||||||
/// Connect to the database
|
// Connect to the database
|
||||||
setup_DB();
|
setup_DB();
|
||||||
|
|
||||||
/// Disable errors for now - needed for installation when debug enabled in config.php
|
// Disable errors for now - needed for installation when debug enabled in config.php
|
||||||
if (isset($CFG->debug)) {
|
if (isset($CFG->debug)) {
|
||||||
$originalconfigdebug = $CFG->debug;
|
$originalconfigdebug = $CFG->debug;
|
||||||
unset($CFG->debug);
|
unset($CFG->debug);
|
||||||
} else {
|
} else {
|
||||||
$originalconfigdebug = -1;
|
$originalconfigdebug = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load up any configuration from the config table
|
// Load up any configuration from the config table
|
||||||
try {
|
try {
|
||||||
$CFG = get_config();
|
$CFG = get_config();
|
||||||
} catch (dml_read_exception $e) {
|
} catch (dml_read_exception $e) {
|
||||||
// most probably empty db, going to install soon
|
// most probably empty db, going to install soon
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Verify upgrade is not running unless we are in a script that needs to execute in any case
|
// 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 (!defined('NO_UPGRADE_CHECK') and isset($CFG->upgraderunning)) {
|
||||||
if ($CFG->upgraderunning < time()) {
|
if ($CFG->upgraderunning < time()) {
|
||||||
unset_config('upgraderunning');
|
unset_config('upgraderunning');
|
||||||
} else {
|
} else {
|
||||||
print_error('upgraderunning');
|
print_error('upgraderunning');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Turn on SQL logging if required
|
// Turn on SQL logging if required
|
||||||
if (!empty($CFG->logsql)) {
|
if (!empty($CFG->logsql)) {
|
||||||
$DB->set_logging(true);
|
$DB->set_logging(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Prevent warnings from roles when upgrading with debug on
|
// Prevent warnings from roles when upgrading with debug on
|
||||||
if (isset($CFG->debug)) {
|
if (isset($CFG->debug)) {
|
||||||
$originaldatabasedebug = $CFG->debug;
|
$originaldatabasedebug = $CFG->debug;
|
||||||
unset($CFG->debug);
|
unset($CFG->debug);
|
||||||
} else {
|
} else {
|
||||||
$originaldatabasedebug = -1;
|
$originaldatabasedebug = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// For now, only needed under apache (and probably unstable in other contexts)
|
// For now, only needed under apache (and probably unstable in other contexts)
|
||||||
if (function_exists('register_shutdown_function')) {
|
if (function_exists('register_shutdown_function')) {
|
||||||
register_shutdown_function('moodle_request_shutdown');
|
register_shutdown_function('moodle_request_shutdown');
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Defining the site
|
// Defining the site
|
||||||
try {
|
try {
|
||||||
$SITE = get_site();
|
$SITE = get_site();
|
||||||
} catch (dml_read_exception $e) {
|
} catch (dml_read_exception $e) {
|
||||||
$SITE = null;
|
$SITE = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($SITE) {
|
if ($SITE) {
|
||||||
/**
|
/**
|
||||||
* If $SITE global from {@link get_site()} is set then SITEID to $SITE->id, otherwise set to 1.
|
* If $SITE global from {@link get_site()} is set then SITEID to $SITE->id, otherwise set to 1.
|
||||||
*/
|
*/
|
||||||
define('SITEID', $SITE->id);
|
define('SITEID', $SITE->id);
|
||||||
/// And the 'default' course
|
// And the 'default' course
|
||||||
$COURSE = clone($SITE); // For now. This will usually get reset later in require_login() etc.
|
$COURSE = clone($SITE); // For now. This will usually get reset later in require_login() etc.
|
||||||
} else {
|
} else {
|
||||||
/**
|
/**
|
||||||
* @ignore
|
* @ignore
|
||||||
*/
|
*/
|
||||||
define('SITEID', 1);
|
define('SITEID', 1);
|
||||||
/// And the 'default' course
|
// And the 'default' course
|
||||||
$COURSE = new object; // no site created yet
|
$COURSE = new object; // no site created yet
|
||||||
$COURSE->id = 1;
|
$COURSE->id = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// define SYSCONTEXTID in config.php if you want to save some queries (after install or upgrade!)
|
// define SYSCONTEXTID in config.php if you want to save some queries (after install or upgrade!)
|
||||||
if (!defined('SYSCONTEXTID')) {
|
if (!defined('SYSCONTEXTID')) {
|
||||||
get_system_context();
|
get_system_context();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set error reporting back to normal
|
// Set error reporting back to normal
|
||||||
if ($originaldatabasedebug == -1) {
|
if ($originaldatabasedebug == -1) {
|
||||||
$CFG->debug = DEBUG_MINIMAL;
|
$CFG->debug = DEBUG_MINIMAL;
|
||||||
} else {
|
} else {
|
||||||
$CFG->debug = $originaldatabasedebug;
|
$CFG->debug = $originaldatabasedebug;
|
||||||
}
|
}
|
||||||
if ($originalconfigdebug !== -1) {
|
if ($originalconfigdebug !== -1) {
|
||||||
$CFG->debug = $originalconfigdebug;
|
$CFG->debug = $originalconfigdebug;
|
||||||
}
|
}
|
||||||
unset($originalconfigdebug);
|
unset($originalconfigdebug);
|
||||||
unset($originaldatabasedebug);
|
unset($originaldatabasedebug);
|
||||||
error_reporting($CFG->debug);
|
error_reporting($CFG->debug);
|
||||||
|
|
||||||
// find out if PHP cofigured to display warnings,
|
// find out if PHP cofigured to display warnings,
|
||||||
// this is a security problem because some moodle scripts may
|
// this is a security problem because some moodle scripts may
|
||||||
// disclose sensitive information
|
// disclose sensitive information
|
||||||
if (ini_get_bool('display_errors')) {
|
if (ini_get_bool('display_errors')) {
|
||||||
define('WARN_DISPLAY_ERRORS_ENABLED', true);
|
define('WARN_DISPLAY_ERRORS_ENABLED', true);
|
||||||
}
|
}
|
||||||
// If we want to display Moodle errors, then try and set PHP errors to match
|
// If we want to display Moodle errors, then try and set PHP errors to match
|
||||||
if (!isset($CFG->debugdisplay)) {
|
if (!isset($CFG->debugdisplay)) {
|
||||||
// keep it "as is" during installation
|
// keep it "as is" during installation
|
||||||
} else if (NO_DEBUG_DISPLAY) {
|
} else if (NO_DEBUG_DISPLAY) {
|
||||||
// some parts of Moodle cannot display errors and debug at all.
|
// some parts of Moodle cannot display errors and debug at all.
|
||||||
@ini_set('display_errors', '0');
|
@ini_set('display_errors', '0');
|
||||||
@ini_set('log_errors', '1');
|
@ini_set('log_errors', '1');
|
||||||
} else if (empty($CFG->debugdisplay)) {
|
} else if (empty($CFG->debugdisplay)) {
|
||||||
@ini_set('display_errors', '0');
|
@ini_set('display_errors', '0');
|
||||||
@ini_set('log_errors', '1');
|
@ini_set('log_errors', '1');
|
||||||
} else {
|
} else {
|
||||||
// This is very problematic in XHTML strict mode!
|
// This is very problematic in XHTML strict mode!
|
||||||
@ini_set('display_errors', '1');
|
@ini_set('display_errors', '1');
|
||||||
}
|
}
|
||||||
|
|
||||||
/// detect unsupported upgrade jump as soon as possible - do not change anything, do not use system functions
|
// 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) {
|
if (!empty($CFG->version) and $CFG->version < 2007101509) {
|
||||||
print_error('upgraderequires19', 'error');
|
print_error('upgraderequires19', 'error');
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shared-Memory cache init -- will set $MCACHE
|
// Shared-Memory cache init -- will set $MCACHE
|
||||||
/// $MCACHE is a global object that offers at least add(), set() and delete()
|
// $MCACHE is a global object that offers at least add(), set() and delete()
|
||||||
/// with similar semantics to the memcached PHP API http://php.net/memcache
|
// with similar semantics to the memcached PHP API http://php.net/memcache
|
||||||
/// Ensure we define rcache - so we can later check for it
|
// Ensure we define rcache - so we can later check for it
|
||||||
/// with a really fast and unambiguous $CFG->rcache === false
|
// with a really fast and unambiguous $CFG->rcache === false
|
||||||
if (!empty($CFG->cachetype)) {
|
if (!empty($CFG->cachetype)) {
|
||||||
if (empty($CFG->rcache)) {
|
if (empty($CFG->rcache)) {
|
||||||
$CFG->rcache = false;
|
$CFG->rcache = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -422,73 +420,72 @@ if (!isset($CFG->wwwroot)) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else { // just make sure it is defined
|
} else { // just make sure it is defined
|
||||||
$CFG->cachetype = '';
|
$CFG->cachetype = '';
|
||||||
$CFG->rcache = false;
|
$CFG->rcache = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set a default enrolment configuration (see bug 1598)
|
// Set a default enrolment configuration (see bug 1598)
|
||||||
if (!isset($CFG->enrol)) {
|
if (!isset($CFG->enrol)) {
|
||||||
$CFG->enrol = 'manual';
|
$CFG->enrol = 'manual';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set default enabled enrolment plugins
|
// Set default enabled enrolment plugins
|
||||||
if (!isset($CFG->enrol_plugins_enabled)) {
|
if (!isset($CFG->enrol_plugins_enabled)) {
|
||||||
$CFG->enrol_plugins_enabled = 'manual';
|
$CFG->enrol_plugins_enabled = 'manual';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// File permissions on created directories in the $CFG->dataroot
|
// File permissions on created directories in the $CFG->dataroot
|
||||||
|
if (empty($CFG->directorypermissions)) {
|
||||||
if (empty($CFG->directorypermissions)) {
|
|
||||||
$CFG->directorypermissions = 0777; // Must be octal (that's why it's here)
|
$CFG->directorypermissions = 0777; // Must be octal (that's why it's here)
|
||||||
}
|
}
|
||||||
if (empty($CFG->filepermissions)) {
|
if (empty($CFG->filepermissions)) {
|
||||||
$CFG->filepermissions = ($CFG->directorypermissions & 0666); // strip execute flags
|
$CFG->filepermissions = ($CFG->directorypermissions & 0666); // strip execute flags
|
||||||
}
|
}
|
||||||
/// better also set default umask because recursive mkdir() does not apply permissions recursively otherwise
|
// better also set default umask because recursive mkdir() does not apply permissions recursively otherwise
|
||||||
umask(0000);
|
umask(0000);
|
||||||
|
|
||||||
/// Calculate and set $CFG->ostype to be used everywhere. Possible values are:
|
// Calculate and set $CFG->ostype to be used everywhere. Possible values are:
|
||||||
/// - WINDOWS: for any Windows flavour.
|
// - WINDOWS: for any Windows flavour.
|
||||||
/// - UNIX: for the rest
|
// - UNIX: for the rest
|
||||||
/// Also, $CFG->os can continue being used if more specialization is required
|
// Also, $CFG->os can continue being used if more specialization is required
|
||||||
if (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) {
|
if (stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'darwin')) {
|
||||||
$CFG->ostype = 'WINDOWS';
|
$CFG->ostype = 'WINDOWS';
|
||||||
} else {
|
} else {
|
||||||
$CFG->ostype = 'UNIX';
|
$CFG->ostype = 'UNIX';
|
||||||
}
|
}
|
||||||
$CFG->os = PHP_OS;
|
$CFG->os = PHP_OS;
|
||||||
|
|
||||||
/// Set up default frame target string, based on $CFG->framename
|
// Set up default frame target string, based on $CFG->framename
|
||||||
$CFG->frametarget = frametarget();
|
$CFG->frametarget = frametarget();
|
||||||
|
|
||||||
/// Setup cache dir for Smarty and others
|
// Setup cache dir for Smarty and others
|
||||||
if (!file_exists($CFG->dataroot .'/cache')) {
|
if (!file_exists($CFG->dataroot .'/cache')) {
|
||||||
make_upload_directory('cache');
|
make_upload_directory('cache');
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Configure ampersands in URLs
|
// Configure ampersands in URLs
|
||||||
@ini_set('arg_separator.output', '&');
|
@ini_set('arg_separator.output', '&');
|
||||||
|
|
||||||
/// Work around for a PHP bug see MDL-11237
|
// Work around for a PHP bug see MDL-11237
|
||||||
@ini_set('pcre.backtrack_limit', 20971520); // 20 MB
|
@ini_set('pcre.backtrack_limit', 20971520); // 20 MB
|
||||||
|
|
||||||
/// Location of standard files
|
// Location of standard files
|
||||||
$CFG->wordlist = $CFG->libdir .'/wordlist.txt';
|
$CFG->wordlist = $CFG->libdir .'/wordlist.txt';
|
||||||
$CFG->moddata = 'moddata';
|
$CFG->moddata = 'moddata';
|
||||||
|
|
||||||
/// Create the $PAGE global.
|
// Create the $PAGE global.
|
||||||
if (!empty($CFG->moodlepageclass)) {
|
if (!empty($CFG->moodlepageclass)) {
|
||||||
$classname = $CFG->moodlepageclass;
|
$classname = $CFG->moodlepageclass;
|
||||||
} else {
|
} else {
|
||||||
$classname = 'moodle_page';
|
$classname = 'moodle_page';
|
||||||
}
|
}
|
||||||
$PAGE = new $classname();
|
$PAGE = new $classname();
|
||||||
unset($classname);
|
unset($classname);
|
||||||
|
|
||||||
/// A hack to get around magic_quotes_gpc being turned on
|
// A hack to get around magic_quotes_gpc being turned on
|
||||||
/// It is strongly recommended to disable "magic_quotes_gpc"!
|
// It is strongly recommended to disable "magic_quotes_gpc"!
|
||||||
if (ini_get_bool('magic_quotes_gpc')) {
|
if (ini_get_bool('magic_quotes_gpc')) {
|
||||||
function stripslashes_deep($value) {
|
function stripslashes_deep($value) {
|
||||||
$value = is_array($value) ?
|
$value = is_array($value) ?
|
||||||
array_map('stripslashes_deep', $value) :
|
array_map('stripslashes_deep', $value) :
|
||||||
|
@ -517,47 +514,47 @@ if (!isset($CFG->wwwroot)) {
|
||||||
if (!empty($_SERVER['PATH_TRANSLATED'])) {
|
if (!empty($_SERVER['PATH_TRANSLATED'])) {
|
||||||
$_SERVER['PATH_TRANSLATED'] = stripslashes($_SERVER['PATH_TRANSLATED']);
|
$_SERVER['PATH_TRANSLATED'] = stripslashes($_SERVER['PATH_TRANSLATED']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// neutralise nasty chars in PHP_SELF
|
// neutralise nasty chars in PHP_SELF
|
||||||
if (isset($_SERVER['PHP_SELF'])) {
|
if (isset($_SERVER['PHP_SELF'])) {
|
||||||
$phppos = strpos($_SERVER['PHP_SELF'], '.php');
|
$phppos = strpos($_SERVER['PHP_SELF'], '.php');
|
||||||
if ($phppos !== false) {
|
if ($phppos !== false) {
|
||||||
$_SERVER['PHP_SELF'] = substr($_SERVER['PHP_SELF'], 0, $phppos+4);
|
$_SERVER['PHP_SELF'] = substr($_SERVER['PHP_SELF'], 0, $phppos+4);
|
||||||
}
|
}
|
||||||
unset($phppos);
|
unset($phppos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// initialise ME's
|
// initialise ME's
|
||||||
initialise_fullme();
|
initialise_fullme();
|
||||||
|
|
||||||
/// start session and prepare global $SESSION, $USER
|
// start session and prepare global $SESSION, $USER
|
||||||
session_get_instance();
|
session_get_instance();
|
||||||
$SESSION = &$_SESSION['SESSION'];
|
$SESSION = &$_SESSION['SESSION'];
|
||||||
$USER = &$_SESSION['USER'];
|
$USER = &$_SESSION['USER'];
|
||||||
|
|
||||||
/// Process theme change in the URL.
|
// Process theme change in the URL.
|
||||||
if (!empty($CFG->allowthemechangeonurl) && ($urlthemename = optional_param('theme', '', PARAM_SAFEDIR)) && confirm_sesskey()) {
|
if (!empty($CFG->allowthemechangeonurl) && ($urlthemename = optional_param('theme', '', PARAM_SAFEDIR)) && confirm_sesskey()) {
|
||||||
try {
|
try {
|
||||||
theme_config::load($urlthemename); // Makes sure the theme can be loaded without errors.
|
theme_config::load($urlthemename); // Makes sure the theme can be loaded without errors.
|
||||||
$SESSION->theme = $urlthemename;
|
$SESSION->theme = $urlthemename;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
debugging('Failed to set the theme from the URL.', DEBUG_DEVELOPER, $e->getTrace());
|
debugging('Failed to set the theme from the URL.', DEBUG_DEVELOPER, $e->getTrace());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unset($urlthemename);
|
unset($urlthemename);
|
||||||
|
|
||||||
/// Ensure a valid theme is set.
|
// Ensure a valid theme is set.
|
||||||
if (!isset($CFG->theme)) {
|
if (!isset($CFG->theme)) {
|
||||||
$CFG->theme = 'standardwhite';
|
$CFG->theme = 'standardwhite';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set language/locale of printed times. If user has chosen a language that
|
// 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
|
// 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
|
// 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
|
// then use the one from the default language. Otherwise (and this is the
|
||||||
/// majority of cases), use the stored locale specified by admin.
|
// majority of cases), use the stored locale specified by admin.
|
||||||
if (($lang = optional_param('lang', '', PARAM_SAFEDIR))) {
|
if (($lang = optional_param('lang', '', PARAM_SAFEDIR))) {
|
||||||
if (file_exists($CFG->dataroot .'/lang/'. $lang) or
|
if (file_exists($CFG->dataroot .'/lang/'. $lang) or
|
||||||
file_exists($CFG->dirroot .'/lang/'. $lang)) {
|
file_exists($CFG->dirroot .'/lang/'. $lang)) {
|
||||||
$SESSION->lang = $lang;
|
$SESSION->lang = $lang;
|
||||||
|
@ -565,26 +562,26 @@ if (!isset($CFG->wwwroot)) {
|
||||||
file_exists($CFG->dirroot .'/lang/'.$lang.'_utf8')) {
|
file_exists($CFG->dirroot .'/lang/'.$lang.'_utf8')) {
|
||||||
$SESSION->lang = $lang.'_utf8';
|
$SESSION->lang = $lang.'_utf8';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unset($lang);
|
unset($lang);
|
||||||
|
|
||||||
setup_lang_from_browser();
|
setup_lang_from_browser();
|
||||||
|
|
||||||
if (empty($CFG->lang)) {
|
if (empty($CFG->lang)) {
|
||||||
if (empty($SESSION->lang)) {
|
if (empty($SESSION->lang)) {
|
||||||
$CFG->lang = 'en_utf8';
|
$CFG->lang = 'en_utf8';
|
||||||
} else {
|
} else {
|
||||||
$CFG->lang = $SESSION->lang;
|
$CFG->lang = $SESSION->lang;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We used to call moodle_setlocale() and theme_setup() here, even though they
|
// We used to call moodle_setlocale() and theme_setup() here, even though they
|
||||||
// would be called again from require_login or $PAGE->set_course. As an experiment
|
// would be called again from require_login or $PAGE->set_course. As an experiment
|
||||||
// I am going to try removing those calls. With luck it will help us find and
|
// I am going to try removing those calls. With luck it will help us find and
|
||||||
// fix a few bugs where scripts do not initialise thigns properly, wihtout causing
|
// fix a few bugs where scripts do not initialise thigns properly, wihtout causing
|
||||||
// too much grief.
|
// too much grief.
|
||||||
|
|
||||||
if (!empty($CFG->debugvalidators) and !empty($CFG->guestloginbutton)) {
|
if (!empty($CFG->debugvalidators) and !empty($CFG->guestloginbutton)) {
|
||||||
if ($CFG->theme == 'standard' or $CFG->theme == 'standardwhite') { // Temporary measure to help with XHTML validation
|
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 (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
|
if ((strpos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') !== false) or
|
||||||
|
@ -598,11 +595,11 @@ if (!isset($CFG->wwwroot)) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Apache log intergration. In apache conf file one can use ${MOODULEUSER}n in
|
// Apache log intergration. In apache conf file one can use ${MOODULEUSER}n in
|
||||||
/// LogFormat to get the current logged in username in moodle.
|
// LogFormat to get the current logged in username in moodle.
|
||||||
if ($USER && function_exists('apache_note')
|
if ($USER && function_exists('apache_note')
|
||||||
&& !empty($CFG->apacheloguser) && isset($USER->username)) {
|
&& !empty($CFG->apacheloguser) && isset($USER->username)) {
|
||||||
$apachelog_userid = $USER->id;
|
$apachelog_userid = $USER->id;
|
||||||
$apachelog_username = clean_filename($USER->username);
|
$apachelog_username = clean_filename($USER->username);
|
||||||
|
@ -632,24 +629,24 @@ if (!isset($CFG->wwwroot)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
apache_note('MOODLEUSER', $logname);
|
apache_note('MOODLEUSER', $logname);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adjust ALLOWED_TAGS
|
// Adjust ALLOWED_TAGS
|
||||||
adjust_allowed_tags();
|
adjust_allowed_tags();
|
||||||
|
|
||||||
/// Use a custom script replacement if one exists
|
// Use a custom script replacement if one exists
|
||||||
if (!empty($CFG->customscripts)) {
|
if (!empty($CFG->customscripts)) {
|
||||||
if (($customscript = custom_script_path()) !== false) {
|
if (($customscript = custom_script_path()) !== false) {
|
||||||
require ($customscript);
|
require ($customscript);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// in the first case, ip in allowed list will be performed first
|
// in the first case, ip in allowed list will be performed first
|
||||||
// for example, client IP is 192.168.1.1
|
// for example, client IP is 192.168.1.1
|
||||||
// 192.168 subnet is an entry in allowed list
|
// 192.168 subnet is an entry in allowed list
|
||||||
// 192.168.1.1 is banned in blocked list
|
// 192.168.1.1 is banned in blocked list
|
||||||
// This ip will be banned finally
|
// This ip will be banned finally
|
||||||
if (!empty($CFG->allowbeforeblock)) { // allowed list processed before blocked list?
|
if (!empty($CFG->allowbeforeblock)) { // allowed list processed before blocked list?
|
||||||
if (!empty($CFG->allowedip)) {
|
if (!empty($CFG->allowedip)) {
|
||||||
if (!remoteip_in_list($CFG->allowedip)) {
|
if (!remoteip_in_list($CFG->allowedip)) {
|
||||||
die(get_string('ipblocked', 'admin'));
|
die(get_string('ipblocked', 'admin'));
|
||||||
|
@ -664,7 +661,7 @@ if (!isset($CFG->wwwroot)) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// in this case, IPs in blocked list will be performed first
|
// in this case, IPs in blocked list will be performed first
|
||||||
// for example, client IP is 192.168.1.1
|
// for example, client IP is 192.168.1.1
|
||||||
// 192.168 subnet is an entry in blocked list
|
// 192.168 subnet is an entry in blocked list
|
||||||
|
@ -692,8 +689,7 @@ if (!isset($CFG->wwwroot)) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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
|
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue