2007-04-16 11:58:25 +00:00
|
|
|
<?php
|
2009-08-20 22:37:17 +00:00
|
|
|
/*
|
2008-04-11 06:12:07 +00:00
|
|
|
* Name: Downtime
|
|
|
|
* Author: Shish <webmaster@shishnet.org>
|
|
|
|
* License: GPLv2
|
|
|
|
* Description: Show a "down for maintenance" page
|
2009-08-20 22:37:17 +00:00
|
|
|
* Documentation:
|
|
|
|
* Once installed there will be some more options on the config page --
|
|
|
|
* Ticking "disable non-admin access" will mean that regular and anonymous
|
|
|
|
* users will be blocked from accessing the site, only able to view the
|
|
|
|
* message specified in the box.
|
2008-04-11 06:12:07 +00:00
|
|
|
*/
|
2007-04-16 11:58:25 +00:00
|
|
|
|
2008-08-23 12:08:19 +00:00
|
|
|
class Downtime implements Extension {
|
2007-06-30 01:19:11 +00:00
|
|
|
var $theme;
|
|
|
|
|
2012-01-27 18:16:46 +00:00
|
|
|
public function get_priority() {return 10;}
|
|
|
|
|
2008-08-23 12:08:19 +00:00
|
|
|
public function receive_event(Event $event) {
|
2009-05-11 14:04:33 +00:00
|
|
|
global $config, $database, $page, $user;
|
2008-09-06 16:59:02 +00:00
|
|
|
if(is_null($this->theme)) $this->theme = get_theme_object($this);
|
2007-06-30 01:19:11 +00:00
|
|
|
|
2008-08-22 09:41:30 +00:00
|
|
|
if($event instanceof SetupBuildingEvent) {
|
2007-04-16 11:58:25 +00:00
|
|
|
$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-08-24 22:29:34 +00:00
|
|
|
|
2008-08-22 09:41:30 +00:00
|
|
|
if($event instanceof PageRequestEvent) {
|
2009-05-11 14:04:33 +00:00
|
|
|
if($config->get_bool("downtime")) {
|
2010-03-23 01:08:10 +00:00
|
|
|
if(!$user->is_admin() && !$this->is_safe_page($event)) {
|
|
|
|
$msg = $config->get_string("downtime_message");
|
|
|
|
$this->theme->display_message($msg);
|
|
|
|
exit;
|
|
|
|
}
|
2009-05-11 14:04:33 +00:00
|
|
|
$this->theme->display_notification($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
|
|
|
|
2009-01-04 16:30:46 +00:00
|
|
|
private function is_safe_page(PageRequestEvent $event) {
|
2008-09-06 17:48:03 +00:00
|
|
|
if($event->page_matches("user_admin/login")) return true;
|
2007-04-16 11:58:25 +00:00
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|