2007-04-16 11:58:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Downtime extends Extension {
|
2007-06-30 01:19:11 +00:00
|
|
|
var $theme;
|
|
|
|
|
2007-04-16 11:58:25 +00:00
|
|
|
public function receive_event($event) {
|
2007-06-30 01:19:11 +00:00
|
|
|
if(is_null($this->theme)) $this->theme = get_theme_object("downtime", "DowntimeTheme");
|
|
|
|
|
2007-04-16 11:58:25 +00:00
|
|
|
$this->check_downtime($event);
|
|
|
|
|
|
|
|
if(is_a($event, 'SetupBuildingEvent')) {
|
|
|
|
$sb = new SetupBlock("Downtime");
|
2007-05-08 20:36:02 +00:00
|
|
|
$sb->add_bool_option("downtime", "Disable non-admin access: ");
|
|
|
|
$sb->add_longtext_option("downtime_message", "<br>");
|
2007-06-30 01:19:11 +00:00
|
|
|
$event->panel->add_block($sb);
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
2007-04-21 13:55:11 +00:00
|
|
|
if(is_a($event, 'PageRequestEvent')) {
|
|
|
|
global $config;
|
|
|
|
if($config->get_bool("downtime")) {
|
2007-07-17 07:45:35 +00:00
|
|
|
$this->theme->display_notification($event->page);
|
2007-04-21 13:55:11 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
2007-06-30 01:19:11 +00:00
|
|
|
|
2007-04-16 11:58:25 +00:00
|
|
|
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");
|
2007-06-30 01:19:11 +00:00
|
|
|
$this->theme->display_message($msg);
|
2007-04-16 11:58:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function is_safe_page($event) {
|
2007-07-27 13:05:48 +00:00
|
|
|
if($event->page_name == "user_admin" && $event->get_arg(0) == "login") return true;
|
2007-04-16 11:58:25 +00:00
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_event_listener(new Downtime(), 10);
|
|
|
|
?>
|