diff --git a/includes/common.inc b/includes/common.inc index 7af684578d799f241b53f3dc3c5b0edc6d80c443..513b6fc9fafc614a6f251bcd7922d48c3abb6378 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -320,6 +320,7 @@ function drupal_goto($path = '', $query = NULL, $fragment = NULL, $http_response * Generates a site off-line message */ function drupal_site_offline() { + drupal_maintenance_theme(); drupal_set_header('HTTP/1.1 503 Service unavailable'); drupal_set_title(t('Site off-line')); print theme('maintenance_page', filter_xss_admin(variable_get('site_offline_message', diff --git a/includes/menu.inc b/includes/menu.inc index 0750dddcccd5e2ba4cb6fdde358ffe340fc70452..3ab496bfd880a3bd391b0ea27a43a804e2f4a5df 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -305,6 +305,10 @@ function menu_get_item($path = NULL) { * Execute the page callback associated with the current path */ function menu_execute_active_handler() { + if (_menu_site_is_offline()) { + return MENU_SITE_OFFLINE; + } + if ($item = menu_get_item()) { if ($item->access) { if ($item->file) { @@ -1462,3 +1466,28 @@ function menu_path_is_external($path) { $colonpos = strpos($path, ':'); return $colonpos !== FALSE && !preg_match('![/?#]!', substr($path, 0, $colonpos)) && filter_xss_bad_protocol($path, FALSE) == check_plain($path); } + +/** + * Returns TRUE if the site is off-line for maintenance. + */ +function _menu_site_is_offline() { + // Check if site is set to off-line mode + if (variable_get('site_offline', 0)) { + // Check if the user has administration privileges + if (!user_access('administer site configuration')) { + // Check if this is an attempt to login + if (drupal_get_normal_path($_GET['q']) != 'user') { + return TRUE; + } + } + else { + $offline_message = t('Operating in off-line mode.'); + $messages = drupal_set_message(); + // Ensure that the off-line message is displayed only once [allowing for page redirects]. + if (!isset($messages) || !isset($messages['status']) || !in_array($offline_message, $messages['status'])) { + drupal_set_message($offline_message); + } + } + } + return FALSE; +}