check_downtime($event);
if(is_a($event, 'SetupBuildingEvent')) {
$sb = new SetupBlock("Downtime");
$sb->add_label("Disable non-admin access: ");
$sb->add_bool_option("downtime");
$sb->add_label("
");
$sb->add_longtext_option("downtime_message");
$event->panel->add_main_block($sb);
}
if(is_a($event, 'ConfigSaveEvent')) {
$event->config->set_bool("downtime", $_POST['downtime']);
$event->config->set_string("downtime_message", $_POST['downtime_message']);
}
if(is_a($event, 'PageRequestEvent')) {
global $config;
if($config->get_bool("downtime")) {
global $page;
$page->add_side_block(new Block("Downtime", "DOWNTIME MODE IS ON!"), 0);
}
}
}
// }}}
// do things {{{
private function check_downtime($event) {
global $user;
global $config;
if($config->get_bool("downtime") && !$user->is_admin() &&
is_a($event, 'PageRequestEvent') && !$this->is_safe_page($event)) {
$msg = $config->get_string("downtime_message");
print <<
Downtime
$msg