diff --git a/includes/common.inc b/includes/common.inc index 6f348500ba912ac053dc238b8438e8fc27d943f1..dc7a41afd1601d511583295e9b7bc400c897da00 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -252,6 +252,17 @@ function drupal_goto($path = '', $query = NULL, $fragment = NULL) { exit(); } + +/** + * Generates a site offline message + */ +function drupal_site_offline() { + header('HTTP/1.0 503 Service unavailable'); + drupal_set_title(t('Site offline')); + print theme('maintenance_page', variable_get('site_offline_message', + t('%site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('%site' => variable_get('site_name', t('This drupal site')))))); +} + /** * Generates a 404 error if the request can not be handled. */ diff --git a/includes/menu.inc b/includes/menu.inc index ee8875b22815ba13e37643230643cc1fd03a1da5..826d1c0ed458a19550e7be39f42b1829493ba157 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -164,6 +164,7 @@ define('MENU_FOUND', 1); define('MENU_NOT_FOUND', 2); define('MENU_ACCESS_DENIED', 3); +define('MENU_SITE_OFFLINE', 4); /** * @} End of "Menu status codes". @@ -324,6 +325,10 @@ function menu_set_location($location) { * act as if the user were in a different location on the site. */ function menu_execute_active_handler() { + if (_menu_site_is_offline()) { + return MENU_SITE_OFFLINE; + } + $menu = menu_get_menu(); // Determine the menu item containing the callback. @@ -1040,3 +1045,19 @@ function _menu_build_local_tasks($pid) { return $forked; } +/** + * Returns TRUE if the is offline for maintenance. + */ +function _menu_site_is_offline() { + // Check if site is set to offline 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/login') { + return TRUE; + } + } + } + return FALSE; +} diff --git a/index.php b/index.php index c77f84ba9bfb6ef2ec7836068dd0dfdb081fba80..df07fff6709b2491cad38d1bf714889d80f49553 100644 --- a/index.php +++ b/index.php @@ -20,6 +20,9 @@ case MENU_ACCESS_DENIED: drupal_access_denied(); break; + case MENU_SITE_OFFLINE: + drupal_site_offline(); + break; default: if (!empty($return)) { print theme('page', $return); diff --git a/modules/system.module b/modules/system.module index 387c3b19516b2494d2cf71a6ce89b424b31c9b0f..8be2b1749fbf650e841ee8d09091287fdcade3e2 100644 --- a/modules/system.module +++ b/modules/system.module @@ -412,6 +412,29 @@ function system_view_general() { ); + // Site offline/maintenance settings + $form['site_status'] = array( + type => 'fieldset', + title => t('Site maintenance'), + collapsible => TRUE, + collapsed => TRUE); + + $form['site_status']['site_offline'] = array( + type => 'radios', + title => t('Site status'), + default_value => variable_get('site_offline', 0), + options => array(t('Online'), t('Offline')), + description => t('When set to "Online", all visitors will be able to browse your site normally. When set to "Offline", only users with the "administer site configuration" permission will be able to access your site to perform maintenance, all other visitors will see the site offline message configured below.') + ); + + $form['site_status']['site_offline_message'] = array( + type => 'textarea', + rows => 5, + title => t('Site offline message'), + default_value => variable_get('site_offline_message', t('%site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('%site' => variable_get('site_name', t('This drupal site'))))), + description => t('Message to show visitors when site is offline.') + ); + // String handling: report status and errors. $form['strings'] = array(type => 'fieldset', title => t('String handling'), collapsible => TRUE, collapsed => TRUE); $form['strings'] = array_merge($form['strings'], unicode_settings()); @@ -638,7 +661,7 @@ function system_settings_form($form_id, $form) { $form['buttons']['reset'] = array(type => 'submit', value => t('Reset to defaults') ); if (!empty($_POST) && form_get_errors()) { - drupal_set_message(t('Your settings are not saved because of the errors above'), 'error'); + drupal_set_message(t('The settings have not been saved because of the errors.'), 'error'); } return drupal_get_form($form_id, $form, 'system_settings_form'); diff --git a/modules/system/system.module b/modules/system/system.module index 387c3b19516b2494d2cf71a6ce89b424b31c9b0f..8be2b1749fbf650e841ee8d09091287fdcade3e2 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -412,6 +412,29 @@ function system_view_general() { ); + // Site offline/maintenance settings + $form['site_status'] = array( + type => 'fieldset', + title => t('Site maintenance'), + collapsible => TRUE, + collapsed => TRUE); + + $form['site_status']['site_offline'] = array( + type => 'radios', + title => t('Site status'), + default_value => variable_get('site_offline', 0), + options => array(t('Online'), t('Offline')), + description => t('When set to "Online", all visitors will be able to browse your site normally. When set to "Offline", only users with the "administer site configuration" permission will be able to access your site to perform maintenance, all other visitors will see the site offline message configured below.') + ); + + $form['site_status']['site_offline_message'] = array( + type => 'textarea', + rows => 5, + title => t('Site offline message'), + default_value => variable_get('site_offline_message', t('%site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('%site' => variable_get('site_name', t('This drupal site'))))), + description => t('Message to show visitors when site is offline.') + ); + // String handling: report status and errors. $form['strings'] = array(type => 'fieldset', title => t('String handling'), collapsible => TRUE, collapsed => TRUE); $form['strings'] = array_merge($form['strings'], unicode_settings()); @@ -638,7 +661,7 @@ function system_settings_form($form_id, $form) { $form['buttons']['reset'] = array(type => 'submit', value => t('Reset to defaults') ); if (!empty($_POST) && form_get_errors()) { - drupal_set_message(t('Your settings are not saved because of the errors above'), 'error'); + drupal_set_message(t('The settings have not been saved because of the errors.'), 'error'); } return drupal_get_form($form_id, $form, 'system_settings_form');