This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/contrib/downtime/main.php
shish 96a37605e4 port page_matches from score to trunk
git-svn-id: file:///home/shish/svn/shimmie2/trunk@1028 7f39781d-f577-437e-ae19-be835c7a54ca
2008-09-06 17:48:03 +00:00

48 lines
1.2 KiB
PHP

<?php
/**
* Name: Downtime
* Author: Shish <webmaster@shishnet.org>
* License: GPLv2
* Description: Show a "down for maintenance" page
*/
class Downtime implements Extension {
var $theme;
public function receive_event(Event $event) {
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof SetupBuildingEvent) {
$sb = new SetupBlock("Downtime");
$sb->add_bool_option("downtime", "Disable non-admin access: ");
$sb->add_longtext_option("downtime_message", "<br>");
$event->panel->add_block($sb);
}
if($event instanceof PageRequestEvent) {
global $config;
if($config->get_bool("downtime")) {
$this->check_downtime($event);
$this->theme->display_notification($event->page);
}
}
}
private function check_downtime($event) {
global $user;
global $config;
if($config->get_bool("downtime") && !$user->is_admin() &&
($event instanceof PageRequestEvent) && !$this->is_safe_page($event)) {
$msg = $config->get_string("downtime_message");
$this->theme->display_message($msg);
}
}
private function is_safe_page($event) {
if($event->page_matches("user_admin/login")) return true;
else return false;
}
}
add_event_listener(new Downtime(), 10);
?>