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/ext/downtime.ext.php
shish bed0e5260b use set_x_from_post
git-svn-id: file:///home/shish/svn/shimmie2/trunk@24 7f39781d-f577-437e-ae19-be835c7a54ca
2007-04-28 15:49:25 +00:00

59 lines
1.4 KiB
PHP

<?php
class Downtime extends Extension {
// event handler {{{
public function receive_event($event) {
$this->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("<br>");
$sb->add_longtext_option("downtime_message");
$event->panel->add_main_block($sb);
}
if(is_a($event, 'ConfigSaveEvent')) {
$event->config->set_bool_from_post("downtime");
$event->config->set_string_from_post("downtime_message");
}
if(is_a($event, 'PageRequestEvent')) {
global $config;
if($config->get_bool("downtime")) {
global $page;
$page->add_side_block(new Block("Downtime", "<span style='font-size: 1.5em'><b>DOWNTIME MODE IS ON!</b></span>"), 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 <<<EOD
<html>
<head>
<title>Downtime</title>
</head>
<body>
$msg
</body>
</html>
EOD;
exit;
}
}
private function is_safe_page($event) {
if($event->page == "user" && $event->get_arg(0) == "login") return true;
else return false;
}
// }}}
}
add_event_listener(new Downtime(), 10);
?>