| Versionen | |
|---|---|
| drupal6 – drupal7 | _menu_site_is_offline() |
Checks whether the site is offline for maintenance.
This function will log the current user out and redirect to front page if the current user has no 'administer site configuration' permission.
FALSE if the site is not offline or its the login page or the user has 'administer site configuration' permission. TRUE for anonymous users not on the login page if the site is offline.
includes/
<?php
function _menu_site_is_offline() {
// Check if site is set to maintenance mode.
if (variable_get('site_offline', 0)) {
// Check if the user has administration privileges.
if (user_access('administer site configuration')) {
// Ensure that the offline message is displayed only once [allowing for
// page redirects], and specifically suppress its display on the site
// maintenance page.
if (drupal_get_normal_path($_GET['q']) != 'admin/settings/maintenance-mode') {
drupal_set_message(t('Operating in maintenance mode. <a href="@url">Go online.</a>', array('@url' => url('admin/settings/maintenance-mode'))), 'status', FALSE);
}
}
else {
// Anonymous users get a FALSE at the login prompt, TRUE otherwise.
if (user_is_anonymous()) {
return $_GET['q'] != 'user' && $_GET['q'] != 'user/login';
}
// Logged in users are unprivileged here, so they are logged out.
require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'user') . '/user.pages.inc';
user_logout();
}
}
return FALSE;
}
?>
Kommentare
Kommentar hinzufügen