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);
- }
- 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']) {
if (function_exists('posix_times')) {
$PERF->startposixtimes = posix_times();
}
- if (function_exists('apd_set_pprof_trace')) {
- // APD profiling
- if ($USER->id > 0 && $CFG->perfdebug >= 15) {
- $tempdir = $CFG->tempdir . '/profile/' . $USER->id;
- mkdir($tempdir);
- apd_set_pprof_trace($tempdir);
- $PERF->profiling = true;
- }
- }
}
/**
return false;
}
+ /**
+ * Constructor - to be used by core code only.
+ * @param $method
+ * @param $arguments
+ * @return string
+ */
public function __call($method, $arguments) {
global $OUTPUT, $PAGE;
/**
* Returns nicely formatted error message in a div box.
+ * @static
+ * @param string $message error message
+ * @param string $moreinfourl (ignored in early errors)
+ * @param string $link (ignored in early errors)
+ * @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 (ignored in early errors)
+ * @param string $link (ignored in early errors)
+ * @param array $backtrace
+ * @param string $debuginfo extra information for developers
* @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 usually notifyproblem or notifysuccess
+ * @return string
+ */
public static function early_notification($message, $classes = 'notifyproblem') {
return '<div class="' . $classes . '">' . $message . '</div>';
}
+ /**
+ * Page should redirect message.
+ * @static
+ * @param $encodedurl redirect url
+ * @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') . '<br /><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 redirect url
+ * @param $message redirect message
+ * @param $delay time in seconds
+ * @return string redirect page
+ */
+ 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 page title
+ * @param $content page content
+ * @param string $meta meta tag
+ * @return string html page
+ */
+ 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>';
}