2004-09-25 05:30:03 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* 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.
|
2004-09-25 05:30:03 +00:00
|
|
|
* @author Martin Dougiamas
|
|
|
|
* @version $Id$
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
|
* @package moodlecore
|
|
|
|
*/
|
|
|
|
|
|
|
|
////// DOCUMENTATION IN PHPDOC FORMAT FOR MOODLE GLOBALS AND COMMON OBJECT TYPES /////////////
|
|
|
|
/**
|
2005-12-13 02:21:02 +00:00
|
|
|
* $USER is a global instance of a typical $user record.
|
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->emailstop - Does the user want email sent to them?
|
|
|
|
* - $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.
|
|
|
|
*
|
2005-02-19 17:52:30 +00:00
|
|
|
* @global object(user) $USER
|
2004-09-25 05:30:03 +00:00
|
|
|
*/
|
2004-09-28 02:51:56 +00:00
|
|
|
global $USER;
|
2004-09-25 05:30:03 +00:00
|
|
|
/**
|
2005-12-13 02:21:02 +00:00
|
|
|
* This global variable is read in from the 'config' table.
|
2004-09-25 05:30:03 +00:00
|
|
|
*
|
2005-12-13 02:21:02 +00:00
|
|
|
* Some typical settings in the $CFG global:
|
2004-09-25 05:30:03 +00:00
|
|
|
* - $CFG->wwwroot - Path to moodle index directory in url format.
|
|
|
|
* - $CFG->dataroot - Path to moodle index directory on server's filesystem.
|
2006-08-28 09:00:38 +00:00
|
|
|
* - $CFG->libdir - Path to moodle's library folder on server's filesystem.
|
2004-09-25 05:30:03 +00:00
|
|
|
*
|
2004-09-28 02:51:56 +00:00
|
|
|
* @global object(cfg) $CFG
|
2004-09-25 05:30:03 +00:00
|
|
|
*/
|
2004-09-28 02:51:56 +00:00
|
|
|
global $CFG;
|
2004-09-25 05:30:03 +00:00
|
|
|
/**
|
|
|
|
* Definition of session type
|
2005-02-19 17:52:30 +00:00
|
|
|
* @global object(session) $SESSION
|
2004-09-25 05:30:03 +00:00
|
|
|
*/
|
|
|
|
global $SESSION;
|
2008-06-25 17:31:23 +00:00
|
|
|
/**
|
2006-12-27 22:44:39 +00:00
|
|
|
* Definition of shared memory cache
|
|
|
|
*/
|
|
|
|
global $MCACHE;
|
2004-09-25 05:30:03 +00:00
|
|
|
/**
|
|
|
|
* Definition of course type
|
2005-02-19 17:52:30 +00:00
|
|
|
* @global object(course) $COURSE
|
2004-09-25 05:30:03 +00:00
|
|
|
*/
|
|
|
|
global $COURSE;
|
2008-05-15 21:40:00 +00:00
|
|
|
/**
|
|
|
|
* Database instances
|
|
|
|
* @global object(mdb) $DB
|
|
|
|
*/
|
|
|
|
global $DB;
|
2004-09-25 05:30:03 +00:00
|
|
|
/**
|
|
|
|
* $THEME is a global that defines the site theme.
|
|
|
|
*
|
|
|
|
* Items found in the theme record:
|
|
|
|
* - $THEME->cellheading - Cell colors.
|
|
|
|
* - $THEME->cellheading2 - Alternate cell colors.
|
|
|
|
*
|
2005-02-19 17:52:30 +00:00
|
|
|
* @global object(theme) $THEME
|
2004-09-25 05:30:03 +00:00
|
|
|
*/
|
|
|
|
global $THEME;
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2005-07-14 20:11:29 +00:00
|
|
|
/**
|
2008-06-25 17:31:23 +00:00
|
|
|
* HTTPSPAGEREQUIRED is a global to define if the page being displayed must run under HTTPS.
|
|
|
|
*
|
2005-07-14 20:11:29 +00:00
|
|
|
* It's primary goal is to allow 100% HTTPS pages when $CFG->loginhttps is enabled. Default to false.
|
|
|
|
* It's enabled only by the httpsrequired() function and used in some pages to update some URLs
|
|
|
|
*/
|
|
|
|
global $HTTPSPAGEREQUIRED;
|
|
|
|
|
|
|
|
|
2005-11-14 22:53:44 +00:00
|
|
|
/// First try to detect some attacks on older buggy PHP versions
|
2005-12-13 02:21:02 +00:00
|
|
|
if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS']) || isset($_FILES['GLOBALS'])) {
|
2005-11-14 22:53:44 +00:00
|
|
|
die('Fatal: Illegal GLOBALS overwrite attempt detected!');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-20 04:04:15 +00:00
|
|
|
if (!isset($CFG->wwwroot)) {
|
2005-10-18 03:31:13 +00:00
|
|
|
trigger_error('Fatal: $CFG->wwwroot is not configured! Exiting.');
|
2004-03-20 04:04:15 +00:00
|
|
|
die;
|
|
|
|
}
|
2005-02-19 17:52:30 +00:00
|
|
|
|
2007-12-19 17:35:20 +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;
|
|
|
|
|
2005-07-14 20:11:29 +00:00
|
|
|
/// Set httpswwwroot default value (this variable will replace $CFG->wwwroot
|
|
|
|
/// inside some URLs used in HTTPSPAGEREQUIRED pages.
|
2006-01-05 07:08:10 +00:00
|
|
|
$CFG->httpswwwroot = $CFG->wwwroot;
|
|
|
|
|
|
|
|
$CFG->libdir = $CFG->dirroot .'/lib';
|
|
|
|
|
|
|
|
require_once($CFG->libdir .'/setuplib.php'); // Functions that MUST be loaded first
|
2005-07-14 20:11:29 +00:00
|
|
|
|
2008-06-25 17:31:23 +00:00
|
|
|
/// Time to start counting
|
|
|
|
init_performance_info();
|
|
|
|
|
2005-04-01 10:00:18 +00:00
|
|
|
|
2002-09-19 12:01:55 +00:00
|
|
|
/// If there are any errors in the standard libraries we want to know!
|
2003-01-01 06:40:31 +00:00
|
|
|
error_reporting(E_ALL);
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2005-05-07 03:07:08 +00:00
|
|
|
/// Just say no to link prefetching (Moz prefetching, Google Web Accelerator, others)
|
2005-05-07 08:20:34 +00:00
|
|
|
/// http://www.google.com/webmasters/faq.html#prefetchblock
|
2005-05-07 03:07:08 +00:00
|
|
|
if (!empty($_SERVER['HTTP_X_moz']) && $_SERVER['HTTP_X_moz'] === 'prefetch'){
|
2008-06-25 17:31:23 +00:00
|
|
|
header($_SERVER['SERVER_PROTOCOL'] . ' 404 Prefetch Forbidden');
|
2005-05-07 03:07:08 +00:00
|
|
|
trigger_error('Prefetch request forbidden.');
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2003-04-10 13:46:52 +00:00
|
|
|
/// Define admin directory
|
|
|
|
if (!isset($CFG->admin)) { // Just in case it isn't defined in config.php
|
2003-11-12 07:39:10 +00:00
|
|
|
$CFG->admin = 'admin'; // This is relative to the wwwroot and dirroot
|
2003-04-10 13:46:52 +00:00
|
|
|
}
|
|
|
|
|
2008-05-15 21:40:00 +00:00
|
|
|
if (!isset($CFG->prefix)) { // Just in case it isn't defined in config.php
|
|
|
|
$CFG->prefix = '';
|
|
|
|
}
|
2002-12-07 07:27:58 +00:00
|
|
|
|
2005-02-19 17:52:30 +00:00
|
|
|
/// Load up standard libraries
|
2006-01-04 08:23:42 +00:00
|
|
|
require_once($CFG->libdir .'/textlib.class.php'); // Functions to handle multibyte strings
|
2004-09-25 05:30:03 +00:00
|
|
|
require_once($CFG->libdir .'/weblib.php'); // Functions for producing HTML
|
2006-08-18 22:56:08 +00:00
|
|
|
require_once($CFG->libdir .'/datalib.php'); // Legacy lib with a big-mix of functions.
|
2006-09-03 08:10:10 +00:00
|
|
|
require_once($CFG->libdir .'/accesslib.php'); // Access control functions
|
|
|
|
require_once($CFG->libdir .'/deprecatedlib.php'); // Deprecated functions included for backward compatibility
|
2004-09-25 05:30:03 +00:00
|
|
|
require_once($CFG->libdir .'/moodlelib.php'); // Other general-purpose functions
|
2007-04-19 08:45:30 +00:00
|
|
|
require_once($CFG->libdir .'/eventslib.php'); // Events functions
|
2007-08-20 10:52:59 +00:00
|
|
|
require_once($CFG->libdir .'/grouplib.php'); // Groups functions
|
2008-06-25 17:31:23 +00:00
|
|
|
require_once($CFG->libdir .'/sessionlib.php'); // All session and cookie related stuff
|
2008-02-27 02:55:36 +00:00
|
|
|
|
2008-02-27 11:09:27 +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'));
|
2008-02-27 02:55:36 +00:00
|
|
|
|
2008-06-13 17:51:34 +00:00
|
|
|
/// set handler for uncought exceptions - equivalent to print_error() call
|
|
|
|
set_exception_handler('default_exception_handler');
|
|
|
|
|
2008-05-15 21:40:00 +00:00
|
|
|
/// Connect to the database
|
|
|
|
setup_DB();
|
|
|
|
|
|
|
|
/// Increase memory limits if possible
|
|
|
|
raise_memory_limit('96M'); // We should never NEED this much but just in case...
|
|
|
|
|
2006-09-10 21:10:48 +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 {
|
|
|
|
$originalconfigdebug = -1;
|
|
|
|
}
|
|
|
|
|
2002-09-19 12:01:55 +00:00
|
|
|
/// Load up any configuration from the config table
|
2005-06-02 05:39:41 +00:00
|
|
|
$CFG = get_config();
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2005-02-18 14:12:38 +00:00
|
|
|
/// Turn on SQL logging if required
|
|
|
|
if (!empty($CFG->logsql)) {
|
2008-05-15 21:40:00 +00:00
|
|
|
$DB->set_logging(true);
|
2005-02-18 14:12:38 +00:00
|
|
|
}
|
2002-08-17 13:01:06 +00:00
|
|
|
|
2006-09-10 21:10:48 +00:00
|
|
|
/// Prevent warnings from roles when upgrading with debug on
|
|
|
|
if (isset($CFG->debug)) {
|
|
|
|
$originaldatabasedebug = $CFG->debug;
|
|
|
|
unset($CFG->debug);
|
|
|
|
} else {
|
|
|
|
$originaldatabasedebug = -1;
|
2003-01-01 08:48:15 +00:00
|
|
|
}
|
2002-12-30 03:24:07 +00:00
|
|
|
|
|
|
|
|
2007-04-05 05:04:06 +00:00
|
|
|
/// For now, only needed under apache (and probably unstable in other contexts)
|
2007-09-12 02:57:26 +00:00
|
|
|
if (function_exists('register_shutdown_function')) {
|
2007-04-05 05:04:06 +00:00
|
|
|
register_shutdown_function('moodle_request_shutdown');
|
|
|
|
}
|
|
|
|
|
2007-09-21 04:55:14 +00:00
|
|
|
/// Defining the site
|
2006-03-29 23:38:46 +00:00
|
|
|
if ($SITE = get_site()) {
|
|
|
|
/**
|
|
|
|
* If $SITE global from {@link get_site()} is set then SITEID to $SITE->id, otherwise set to 1.
|
|
|
|
*/
|
|
|
|
define('SITEID', $SITE->id);
|
2006-05-29 20:33:12 +00:00
|
|
|
/// And the 'default' course
|
|
|
|
$COURSE = clone($SITE); // For now. This will usually get reset later in require_login() etc.
|
2006-03-29 23:38:46 +00:00
|
|
|
} else {
|
|
|
|
/**
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
define('SITEID', 1);
|
2006-05-29 20:33:12 +00:00
|
|
|
/// And the 'default' course
|
|
|
|
$COURSE = new object; // no site created yet
|
|
|
|
$COURSE->id = 1;
|
2006-03-29 23:38:46 +00:00
|
|
|
}
|
|
|
|
|
2007-10-05 15:06:38 +00:00
|
|
|
// define SYSCONTEXTID in config.php if you want to save some queries (after install or upgrade!)
|
|
|
|
if (!defined('SYSCONTEXTID')) {
|
|
|
|
get_system_context();
|
2007-09-19 07:02:18 +00:00
|
|
|
}
|
2006-03-29 23:38:46 +00:00
|
|
|
|
2006-09-10 21:10:48 +00:00
|
|
|
/// Set error reporting back to normal
|
|
|
|
if ($originaldatabasedebug == -1) {
|
2006-09-23 09:38:39 +00:00
|
|
|
$CFG->debug = DEBUG_MINIMAL;
|
2006-09-10 21:10:48 +00:00
|
|
|
} else {
|
|
|
|
$CFG->debug = $originaldatabasedebug;
|
|
|
|
}
|
|
|
|
if ($originalconfigdebug !== -1) {
|
2008-06-25 17:31:23 +00:00
|
|
|
$CFG->debug = $originalconfigdebug;
|
2006-09-10 21:10:48 +00:00
|
|
|
}
|
|
|
|
unset($originalconfigdebug);
|
|
|
|
unset($originaldatabasedebug);
|
|
|
|
error_reporting($CFG->debug);
|
|
|
|
|
2007-01-03 01:37:20 +00:00
|
|
|
|
2008-07-07 14:34:40 +00:00
|
|
|
/// find out if PHP cofigured to display warnings
|
|
|
|
if (ini_get_bool('display_errors')) {
|
|
|
|
define('WARN_DISPLAY_ERRORS_ENABLED', true);
|
|
|
|
}
|
2007-01-03 01:37:20 +00:00
|
|
|
/// If we want to display Moodle errors, then try and set PHP errors to match
|
2007-02-01 21:11:50 +00:00
|
|
|
if (!isset($CFG->debugdisplay)) {
|
|
|
|
//keep it as is during installation
|
|
|
|
} else if (empty($CFG->debugdisplay)) {
|
2007-01-03 01:37:20 +00:00
|
|
|
@ini_set('display_errors', '0');
|
|
|
|
@ini_set('log_errors', '1');
|
|
|
|
} else {
|
|
|
|
@ini_set('display_errors', '1');
|
|
|
|
}
|
2008-02-27 02:51:49 +00:00
|
|
|
// Even when users want to see errors in the output,
|
|
|
|
// some parts of Moodle cannot display them at all.
|
|
|
|
// (Once we are XHTML strict compliant, debugdisplay
|
|
|
|
// _must_ go away).
|
|
|
|
if (defined('MOODLE_SANE_OUTPUT')) {
|
|
|
|
@ini_set('display_errors', '0');
|
|
|
|
@ini_set('log_errors', '1');
|
|
|
|
}
|
2007-01-03 01:37:20 +00:00
|
|
|
|
2008-04-30 14:05:36 +00:00
|
|
|
/// detect unsupported upgrade jump as soon as possible - do not change anything, do not use system functions
|
2008-05-01 21:08:50 +00:00
|
|
|
if (!empty($CFG->version) and $CFG->version < 2007101509) {
|
2008-05-19 18:02:33 +00:00
|
|
|
print_error('upgraderequires19', 'error');
|
2008-04-30 14:05:36 +00:00
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
2006-12-27 22:44:39 +00:00
|
|
|
/// Shared-Memory cache init -- will set $MCACHE
|
|
|
|
/// $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
|
2007-12-23 13:10:35 +00:00
|
|
|
/// Ensure we define rcache - so we can later check for it
|
|
|
|
/// with a really fast and unambiguous $CFG->rcache === false
|
2007-01-14 23:02:13 +00:00
|
|
|
if (!empty($CFG->cachetype)) {
|
2008-01-06 22:56:07 +00:00
|
|
|
if (empty($CFG->rcache)) {
|
2007-12-23 13:10:35 +00:00
|
|
|
$CFG->rcache = false;
|
|
|
|
} else {
|
|
|
|
$CFG->rcache = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// do not try to initialize if cache disabled
|
|
|
|
if (!$CFG->rcache) {
|
|
|
|
$CFG->cachetype = '';
|
|
|
|
}
|
|
|
|
|
2007-01-14 23:02:13 +00:00
|
|
|
if ($CFG->cachetype === 'memcached' && !empty($CFG->memcachedhosts)) {
|
|
|
|
if (!init_memcached()) {
|
|
|
|
debugging("Error initialising memcached");
|
2008-03-11 09:05:20 +00:00
|
|
|
$CFG->cachetype = '';
|
|
|
|
$CFG->rcache = false;
|
2007-01-14 23:02:13 +00:00
|
|
|
}
|
2007-12-23 13:10:35 +00:00
|
|
|
} else if ($CFG->cachetype === 'eaccelerator') {
|
2007-01-14 23:02:13 +00:00
|
|
|
if (!init_eaccelerator()) {
|
|
|
|
debugging("Error initialising eaccelerator cache");
|
2008-03-11 09:05:20 +00:00
|
|
|
$CFG->cachetype = '';
|
2008-06-25 17:31:23 +00:00
|
|
|
$CFG->rcache = false;
|
2007-01-14 23:02:13 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-23 13:10:35 +00:00
|
|
|
|
2007-01-14 23:02:13 +00:00
|
|
|
} else { // just make sure it is defined
|
|
|
|
$CFG->cachetype = '';
|
2007-12-23 13:10:35 +00:00
|
|
|
$CFG->rcache = false;
|
2006-12-27 22:47:14 +00:00
|
|
|
}
|
2006-09-10 21:10:48 +00:00
|
|
|
|
2005-01-18 18:28:25 +00:00
|
|
|
/// Set a default enrolment configuration (see bug 1598)
|
|
|
|
if (!isset($CFG->enrol)) {
|
2006-03-09 03:19:10 +00:00
|
|
|
$CFG->enrol = 'manual';
|
2005-01-18 18:28:25 +00:00
|
|
|
}
|
|
|
|
|
2006-03-09 03:58:08 +00:00
|
|
|
/// Set default enabled enrolment plugins
|
|
|
|
if (!isset($CFG->enrol_plugins_enabled)) {
|
|
|
|
$CFG->enrol_plugins_enabled = 'manual';
|
|
|
|
}
|
|
|
|
|
2003-01-20 14:03:11 +00:00
|
|
|
/// File permissions on created directories in the $CFG->dataroot
|
|
|
|
|
|
|
|
if (empty($CFG->directorypermissions)) {
|
|
|
|
$CFG->directorypermissions = 0777; // Must be octal (that's why it's here)
|
|
|
|
}
|
|
|
|
|
2006-04-07 22:58:07 +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
|
2006-11-15 03:15:06 +00:00
|
|
|
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
|
|
|
|
2007-01-04 04:57:50 +00:00
|
|
|
/// Set up default frame target string, based on $CFG->framename
|
|
|
|
$CFG->frametarget = frametarget();
|
|
|
|
|
2005-04-20 07:29:28 +00:00
|
|
|
/// Setup cache dir for Smarty and others
|
|
|
|
if (!file_exists($CFG->dataroot .'/cache')) {
|
|
|
|
make_upload_directory('cache');
|
|
|
|
}
|
|
|
|
|
2004-09-07 09:49:41 +00:00
|
|
|
/// Configure ampersands in URLs
|
|
|
|
@ini_set('arg_separator.output', '&');
|
|
|
|
|
2007-09-13 06:42:49 +00:00
|
|
|
/// Work around for a PHP bug see MDL-11237
|
2008-06-25 17:31:23 +00:00
|
|
|
@ini_set('pcre.backtrack_limit', 20971520); // 20 MB
|
2007-09-13 06:42:49 +00:00
|
|
|
|
2002-09-19 12:01:55 +00:00
|
|
|
/// Location of standard files
|
2004-09-25 05:30:03 +00:00
|
|
|
$CFG->wordlist = $CFG->libdir .'/wordlist.txt';
|
|
|
|
$CFG->javascript = $CFG->libdir .'/javascript.php';
|
2003-11-12 07:39:10 +00:00
|
|
|
$CFG->moddata = 'moddata';
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2008-02-27 02:51:49 +00:00
|
|
|
// Alas, in some cases we cannot deal with magic_quotes.
|
|
|
|
if (defined('MOODLE_SANE_INPUT') && ini_get_bool('magic_quotes_gpc')) {
|
|
|
|
mdie("Facilities that require MOODLE_SANE_INPUT "
|
|
|
|
. "cannot work with magic_quotes_gpc. Please disable "
|
|
|
|
. "magic_quotes_gpc.");
|
|
|
|
}
|
2008-06-09 16:53:30 +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) {
|
2005-02-19 17:52:30 +00:00
|
|
|
$value = is_array($value) ?
|
2008-06-09 16:53:30 +00:00
|
|
|
array_map('stripslashes_deep', $value) :
|
|
|
|
stripslashes($value);
|
2005-02-19 17:52:30 +00:00
|
|
|
return $value;
|
2004-12-17 01:43:06 +00:00
|
|
|
}
|
2008-06-09 16:53:30 +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);
|
2005-11-14 22:53:44 +00:00
|
|
|
if (!empty($_SERVER['REQUEST_URI'])) {
|
2008-06-09 16:53:30 +00:00
|
|
|
$_SERVER['REQUEST_URI'] = stripslashes($_SERVER['REQUEST_URI']);
|
2005-11-14 22:53:44 +00:00
|
|
|
}
|
|
|
|
if (!empty($_SERVER['QUERY_STRING'])) {
|
2008-06-09 16:53:30 +00:00
|
|
|
$_SERVER['QUERY_STRING'] = stripslashes($_SERVER['QUERY_STRING']);
|
2005-11-14 22:53:44 +00:00
|
|
|
}
|
|
|
|
if (!empty($_SERVER['HTTP_REFERER'])) {
|
2008-06-09 16:53:30 +00:00
|
|
|
$_SERVER['HTTP_REFERER'] = stripslashes($_SERVER['HTTP_REFERER']);
|
2005-11-14 22:53:44 +00:00
|
|
|
}
|
|
|
|
if (!empty($_SERVER['PATH_INFO'])) {
|
2008-06-09 16:53:30 +00:00
|
|
|
$_SERVER['PATH_INFO'] = stripslashes($_SERVER['PATH_INFO']);
|
2005-11-14 22:53:44 +00:00
|
|
|
}
|
|
|
|
if (!empty($_SERVER['PHP_SELF'])) {
|
2008-06-09 16:53:30 +00:00
|
|
|
$_SERVER['PHP_SELF'] = stripslashes($_SERVER['PHP_SELF']);
|
2005-11-14 22:53:44 +00:00
|
|
|
}
|
|
|
|
if (!empty($_SERVER['PATH_TRANSLATED'])) {
|
2008-06-09 16:53:30 +00:00
|
|
|
$_SERVER['PATH_TRANSLATED'] = stripslashes($_SERVER['PATH_TRANSLATED']);
|
2005-11-14 22:53:44 +00:00
|
|
|
}
|
2003-07-28 16:37:12 +00:00
|
|
|
}
|
2002-07-02 07:02:28 +00:00
|
|
|
|
2008-06-25 17:31:23 +00:00
|
|
|
/// start session and prepare global $SESSION
|
|
|
|
$SESSION = new moodle_session();
|
2008-02-24 12:46:37 +00:00
|
|
|
|
2008-06-25 17:31:23 +00:00
|
|
|
/// set up global $USER
|
|
|
|
if (!NO_MOODLE_COOKIES) {
|
|
|
|
$USER = &$_SESSION['USER'];
|
|
|
|
} else {
|
2007-01-28 20:52:57 +00:00
|
|
|
$USER = new object();
|
|
|
|
$USER->id = 0; // user not logged in when session disabled
|
2007-10-07 13:46:46 +00:00
|
|
|
if (isset($CFG->mnet_localhost_id)) {
|
|
|
|
$USER->mnethostid = $CFG->mnet_localhost_id;
|
|
|
|
}
|
2004-12-17 01:43:06 +00:00
|
|
|
}
|
2003-02-27 02:38:55 +00:00
|
|
|
|
2004-12-12 06:49:26 +00:00
|
|
|
if (defined('FULLME')) { // Usually in command-line scripts like admin/cron.php
|
|
|
|
$FULLME = FULLME;
|
|
|
|
$ME = FULLME;
|
2002-12-29 04:17:32 +00:00
|
|
|
} else {
|
2002-12-20 14:44:14 +00:00
|
|
|
$FULLME = qualified_me();
|
2002-12-29 04:17:32 +00:00
|
|
|
$ME = strip_querystring($FULLME);
|
2002-12-20 14:44:14 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2005-02-01 08:00:58 +00:00
|
|
|
/// Load up theme variables (colours etc)
|
2005-03-14 13:23:38 +00:00
|
|
|
|
|
|
|
if (!isset($CFG->themedir)) {
|
2006-10-09 10:12:41 +00:00
|
|
|
$CFG->themedir = $CFG->dirroot.'/theme';
|
|
|
|
$CFG->themewww = $CFG->wwwroot.'/theme';
|
2005-03-14 13:23:38 +00:00
|
|
|
}
|
2008-06-25 17:31:23 +00:00
|
|
|
$CFG->httpsthemewww = $CFG->themewww;
|
2005-03-14 13:23:38 +00:00
|
|
|
|
2005-02-01 08:00:58 +00:00
|
|
|
if (isset($_GET['theme'])) {
|
2005-02-10 10:28:27 +00:00
|
|
|
if ($CFG->allowthemechangeonurl || confirm_sesskey()) {
|
2006-10-09 10:12:41 +00:00
|
|
|
$themename = clean_param($_GET['theme'], PARAM_SAFEDIR);
|
|
|
|
if (($themename != '') and file_exists($CFG->themedir.'/'.$themename)) {
|
|
|
|
$SESSION->theme = $themename;
|
2005-02-01 08:00:58 +00:00
|
|
|
}
|
2006-10-09 10:12:41 +00:00
|
|
|
unset($themename);
|
2005-02-01 08:00:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($CFG->theme)) {
|
2005-06-13 02:56:37 +00:00
|
|
|
$CFG->theme = 'standardwhite';
|
2005-02-01 08:00:58 +00:00
|
|
|
}
|
|
|
|
|
2005-12-28 19:05:46 +00:00
|
|
|
/// now do a session test to prevent random user switching - observed on some PHP/Apache combinations,
|
2008-06-25 17:31:23 +00:00
|
|
|
$SESSION->session_verify();
|
2005-02-01 08:00:58 +00:00
|
|
|
|
2005-02-19 17:52:30 +00:00
|
|
|
/// 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
|
2002-12-08 17:26:21 +00:00
|
|
|
/// in the language file. Otherwise, if the admin hasn't specified a locale
|
2005-02-19 17:52:30 +00:00
|
|
|
/// then use the one from the default language. Otherwise (and this is the
|
2002-12-08 17:26:21 +00:00
|
|
|
/// majority of cases), use the stored locale specified by admin.
|
2008-06-25 17:31:23 +00:00
|
|
|
if (isset($_GET['lang']) && ($lang = clean_param($_GET['lang'], PARAM_SAFEDIR))) {
|
2006-09-11 20:41:49 +00:00
|
|
|
if (file_exists($CFG->dataroot .'/lang/'. $lang) or file_exists($CFG->dirroot .'/lang/'. $lang)) {
|
2004-07-17 04:31:34 +00:00
|
|
|
$SESSION->lang = $lang;
|
2008-06-25 17:31:23 +00:00
|
|
|
} else if (file_exists($CFG->dataroot.'/lang/'.$lang.'_utf8') or
|
2006-09-23 13:14:25 +00:00
|
|
|
file_exists($CFG->dirroot .'/lang/'.$lang.'_utf8')) {
|
|
|
|
$SESSION->lang = $lang.'_utf8';
|
2004-07-17 04:31:34 +00:00
|
|
|
}
|
2003-01-20 08:09:25 +00:00
|
|
|
}
|
2007-02-12 14:58:44 +00:00
|
|
|
|
|
|
|
setup_lang_from_browser();
|
|
|
|
|
2006-09-11 20:41:49 +00:00
|
|
|
unset($lang);
|
2007-02-12 14:58:44 +00:00
|
|
|
|
2003-05-26 15:38:52 +00:00
|
|
|
if (empty($CFG->lang)) {
|
2006-09-11 20:41:49 +00:00
|
|
|
if (empty($SESSION->lang)) {
|
2006-11-11 17:23:20 +00:00
|
|
|
$CFG->lang = 'en_utf8';
|
2006-09-11 20:41:49 +00:00
|
|
|
} else {
|
|
|
|
$CFG->lang = $SESSION->lang;
|
|
|
|
}
|
2003-05-26 15:38:52 +00:00
|
|
|
}
|
2008-06-25 17:31:23 +00:00
|
|
|
|
2007-01-27 19:56:08 +00:00
|
|
|
// set default locale and themes - might be changed again later from require_login()
|
|
|
|
course_setup();
|
2003-11-12 07:39:10 +00:00
|
|
|
|
2004-01-25 09:37:28 +00:00
|
|
|
if (!empty($CFG->opentogoogle)) {
|
2008-06-25 17:31:23 +00:00
|
|
|
if (!NO_MOODLE_COOKIES and empty($USER->id)) { // Ignore anyone logged in, or scripts without cookies
|
2004-01-25 09:37:28 +00:00
|
|
|
if (!empty($_SERVER['HTTP_USER_AGENT'])) {
|
|
|
|
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Googlebot') !== false ) {
|
|
|
|
$USER = guest_user();
|
2007-09-13 08:59:31 +00:00
|
|
|
} else if (strpos($_SERVER['HTTP_USER_AGENT'], 'google.com') !== false ) { // Google
|
2006-03-25 07:09:40 +00:00
|
|
|
$USER = guest_user();
|
2007-09-13 08:59:31 +00:00
|
|
|
} else if (strpos($_SERVER['HTTP_USER_AGENT'], 'Yahoo! Slurp') !== false ) { // Yahoo
|
2006-03-25 07:09:40 +00:00
|
|
|
$USER = guest_user();
|
2007-09-13 08:59:31 +00:00
|
|
|
} else if (strpos($_SERVER['HTTP_USER_AGENT'], '[ZSEBOT]') !== false ) { // Zoomspider
|
|
|
|
$USER = guest_user();
|
|
|
|
} else if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSNBOT') !== false ) { // MSN Search
|
2004-05-16 14:19:35 +00:00
|
|
|
$USER = guest_user();
|
|
|
|
}
|
2004-01-25 09:37:28 +00:00
|
|
|
}
|
2006-03-25 07:09:40 +00:00
|
|
|
if (empty($USER) && !empty($_SERVER['HTTP_REFERER'])) {
|
2004-01-25 09:37:28 +00:00
|
|
|
if (strpos($_SERVER['HTTP_REFERER'], 'google') !== false ) {
|
|
|
|
$USER = guest_user();
|
2005-07-14 04:18:59 +00:00
|
|
|
} else if (strpos($_SERVER['HTTP_REFERER'], 'altavista') !== false ) {
|
|
|
|
$USER = guest_user();
|
2004-01-25 09:37:28 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-25 17:31:23 +00:00
|
|
|
if (!empty($USER->id)) {
|
2006-10-26 14:55:45 +00:00
|
|
|
load_all_capabilities();
|
|
|
|
}
|
2004-01-25 09:37:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-23 16:49:03 +00:00
|
|
|
if ($CFG->theme == 'standard' or $CFG->theme == 'standardwhite') { // Temporary measure to help with XHTML validation
|
2008-06-25 17:31:23 +00:00
|
|
|
if (isset($_SERVER['HTTP_USER_AGENT']) and empty($USER->id)) { // Allow W3CValidator in as user called w3cvalidator (or guest)
|
2005-02-19 17:52:30 +00:00
|
|
|
if ((strpos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') !== false) or
|
2004-09-07 08:04:02 +00:00
|
|
|
(strpos($_SERVER['HTTP_USER_AGENT'], 'Cynthia') !== false )) {
|
2005-04-17 12:08:46 +00:00
|
|
|
if ($USER = get_complete_user_data("username", "w3cvalidator")) {
|
2004-12-22 02:56:16 +00:00
|
|
|
$USER->ignoresesskey = true;
|
2004-09-07 08:23:11 +00:00
|
|
|
} else {
|
2004-09-07 07:38:44 +00:00
|
|
|
$USER = guest_user();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-16 02:51:05 +00:00
|
|
|
/// Apache log intergration. In apache conf file one can use ${MOODULEUSER}n in
|
|
|
|
/// LogFormat to get the current logged in username in moodle.
|
2007-09-19 07:55:46 +00:00
|
|
|
if ($USER && function_exists('apache_note')
|
|
|
|
&& !empty($CFG->apacheloguser) && isset($user->username)) {
|
2005-09-29 23:40:14 +00:00
|
|
|
$apachelog_userid = $USER->id;
|
2007-09-19 07:55:46 +00:00
|
|
|
$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);
|
|
|
|
}
|
2005-09-27 05:25:23 +00:00
|
|
|
if (isset($USER->realuser)) {
|
2008-05-15 21:40:00 +00:00
|
|
|
if ($realuser = $DB->get_record('user', array('id'=>$USER->realuser))) {
|
2005-09-29 23:40:14 +00:00
|
|
|
$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);
|
2005-09-27 05:25:23 +00:00
|
|
|
}
|
|
|
|
}
|
2005-05-17 04:03:48 +00:00
|
|
|
switch ($CFG->apacheloguser) {
|
|
|
|
case 3:
|
2005-09-29 23:40:14 +00:00
|
|
|
$logname = $apachelog_username;
|
2005-05-17 04:03:48 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2005-09-29 23:40:14 +00:00
|
|
|
$logname = $apachelog_name;
|
2005-05-17 04:03:48 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
default:
|
2005-09-29 23:40:14 +00:00
|
|
|
$logname = $apachelog_userid;
|
2005-05-17 04:03:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
apache_note('MOODLEUSER', $logname);
|
2005-05-16 02:51:05 +00:00
|
|
|
}
|
|
|
|
|
2005-06-25 15:42:44 +00:00
|
|
|
/// Adjust ALLOWED_TAGS
|
|
|
|
adjust_allowed_tags();
|
|
|
|
|
2005-07-14 15:35:23 +00:00
|
|
|
|
|
|
|
/// Use a custom script replacement if one exists
|
|
|
|
if (!empty($CFG->customscripts)) {
|
|
|
|
if (($customscript = custom_script_path()) !== false) {
|
2005-07-15 15:36:40 +00:00
|
|
|
require ($customscript);
|
2005-07-14 15:35:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-11 17:23:20 +00:00
|
|
|
/// note: we can not block non utf-8 installatrions here, because empty mysql database
|
|
|
|
/// might be converted to utf-8 in admin/index.php during installation
|
2006-01-05 07:08:10 +00:00
|
|
|
?>
|