*/
global $USER;
+/**
+ * Frontpage course record
+ */
+global $SITE;
+
/**
* A central store of information about the current page we are
* generating in response to the user's request.
register_shutdown_function('moodle_request_shutdown');
}
-// Defining the site
-try {
- $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);
- // And the 'default' course - this will usually get reset later in require_login() etc.
- $COURSE = clone($SITE);
-} catch (dml_exception $e) {
- $SITE = null;
- if (empty($CFG->version)) {
- // we are just installing
- /**
- * @ignore
- */
- define('SITEID', 1);
- // And the 'default' course
- $COURSE = new stdClass(); // no site created yet
- $COURSE->id = 1;
- } else {
- throw $e;
- }
-}
-
-// define SYSCONTEXTID in config.php if you want to save some queries (after install or upgrade!)
-if (!defined('SYSCONTEXTID')) {
- get_system_context();
-}
-
// Set error reporting back to normal
if ($originaldatabasedebug == -1) {
$CFG->debug = DEBUG_MINIMAL;
$CFG->wordlist = $CFG->libdir .'/wordlist.txt';
$CFG->moddata = 'moddata';
-// Create the $PAGE global.
-if (!empty($CFG->moodlepageclass)) {
- $classname = $CFG->moodlepageclass;
-} else {
- $classname = 'moodle_page';
-}
-$PAGE = new $classname();
-unset($classname);
-
// 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')) {
// initialise ME's - this must be done BEFORE starting of session!
initialise_fullme();
+// 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);
+
// init session prevention flag - this is defined on pages that do not want session
if (CLI_SCRIPT) {
// no sessions in CLI scripts possible
// it is definitely too late to call this first in require_login()!
moodle_setlocale();
+// 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)) {
+ $classname = $CFG->moodlepageclass;
+} else {
+ $classname = 'moodle_page';
+}
+$PAGE = new $classname();
+unset($classname);
+
+
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)
* setup.php.
*/
function initialise_fullme() {
- global $CFG, $FULLME, $ME, $SCRIPT, $FULLSCRIPT, $USER;
+ global $CFG, $FULLME, $ME, $SCRIPT, $FULLSCRIPT;
// Detect common config error.
if (substr($CFG->wwwroot, -1) == '/') {
return;
}
- $wwwroot = parse_url($CFG->wwwroot);
- if (!isset($wwwroot['path'])) {
- $wwwroot['path'] = '';
- }
- $wwwroot['path'] .= '/';
-
$rurl = setup_get_remote_url();
+ $wwwroot = parse_url($CFG->wwwroot.'/');
+
+ if (empty($rurl['host'])) {
+ // missing host in request header, probably not a real browser, let's ignore them
+
+ } else if (!empty($CFG->reverseproxy)) {
+ // $CFG->reverseproxy specifies if reverse proxy server used
+ // Used in load balancing scenarios.
+ // Do not abuse this to try to solve lan/wan access problems!!!!!
+
+ } else {
+ if (($rurl['host'] !== $wwwroot['host']) or (!empty($wwwroot['port']) and $rurl['port'] != $wwwroot['port'])) {
+ // Explain the problem and redirect them to the right URL
+ if (!defined('NO_MOODLE_COOKIES')) {
+ define('NO_MOODLE_COOKIES', true);
+ }
+ redirect($CFG->wwwroot, get_string('wwwrootmismatch', 'error', $CFG->wwwroot), 3);
+ }
+ }
// Check that URL is under $CFG->wwwroot.
if (strpos($rurl['path'], $wwwroot['path']) === 0) {
$rurl['scheme'] = 'https'; // make moodle believe it runs on https, squid or something else it doing it
}
- // $CFG->reverseproxy specifies if reverse proxy server used.
- // Used in load balancing scenarios.
- // Do not abuse this to try to solve lan/wan access problems!!!!!
- if (empty($CFG->reverseproxy)) {
- if (empty($rurl['host'])) {
- // missing host in request header, probably not a real browser, let's ignore them
- } else if (($rurl['host'] !== $wwwroot['host']) or
- (!empty($wwwroot['port']) and $rurl['port'] != $wwwroot['port'])) {
- // Explain the problem and redirect them to the right URL
- if (!defined('NO_MOODLE_COOKIES')) {
- define('NO_MOODLE_COOKIES', true);
- }
- if (!isset($USER->id)) {
- // MDL-27899 workaround
- $USER = new stdClass();
- $USER->id = 0;
- }
- redirect($CFG->wwwroot, get_string('wwwrootmismatch', 'error', $CFG->wwwroot), 3);
- }
- }
-
// hopefully this will stop all those "clever" admins trying to set up moodle
// with two different addresses in intranet and Internet
if (!empty($CFG->reverseproxy) && $rurl['host'] === $wwwroot['host']) {
/**
* Returns nicely formatted error message in a div box.
+ * @static
+ * @param string $message error message
+ * @param string $moreinfourl ignored
+ * @param string $link ignored
+ * @param array $backtrace
+ * @param string $debuginfo
* @return string
*/
public static function early_error_content($message, $moreinfourl, $link, $backtrace, $debuginfo = null) {
/**
* This function should only be called by this class, or from exception handlers
+ * @static
+ * @param string $message error message
+ * @param string $moreinfourl
+ * @param string $link
+ * @param array $backtrace
+ * @param string $debuginfo
* @return string
*/
public static function early_error($message, $moreinfourl, $link, $backtrace, $debuginfo = null) {
return self::plain_page($strerror, $content);
}
+ /**
+ * Early notification message
+ * @static
+ * @param $message
+ * @param string $classes
+ * @return string
+ */
public static function early_notification($message, $classes = 'notifyproblem') {
return '<div class="' . $classes . '">' . $message . '</div>';
}
+ /**
+ * Page should redirect message.
+ * @static
+ * @param $encodedurl
+ * @return string
+ */
public static function plain_redirect_message($encodedurl) {
- $message = '<p>' . get_string('pageshouldredirect') . '</p><p><a href="'.
- $encodedurl .'">'. get_string('continue') .'</a></p>';
+ $message = '<div style="margin-top: 3em; margin-left:auto; margin-right:auto; text-align:center;">' . get_string('pageshouldredirect') . '</p><p><a href="'.
+ $encodedurl .'">'. get_string('continue') .'</a></div>';
return self::plain_page(get_string('redirect'), $message);
}
- protected static function plain_page($title, $content) {
+ /**
+ * Early redirection page, used before full init of $PAGE global
+ * @static
+ * @param $encodedurl
+ * @param $message
+ * @param $delay
+ * @return string
+ */
+ public static function early_redirect_message($encodedurl, $message, $delay) {
+ $meta = '<meta http-equiv="refresh" content="'. $delay .'; url='. $encodedurl .'" />';
+ $content = self::early_error_content($message, null, null, null);
+ $content .= self::plain_redirect_message($encodedurl);
+
+ return self::plain_page(get_string('redirect'), $content, $meta);
+ }
+
+ /**
+ * Output basic html page.
+ * @static
+ * @param $title
+ * @param $content
+ * @param string $meta
+ * @return string
+ */
+ protected static function plain_page($title, $content, $meta = '') {
if (function_exists('get_string') && function_exists('get_html_lang')) {
$htmllang = get_html_lang();
} else {
<html xmlns="http://www.w3.org/1999/xhtml" ' . $htmllang . '>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+'.$meta.'
<title>' . $title . '</title>
</head><body>' . $content . '</body></html>';
}