1<?php
2/**
3 * Example Action Plugin:   Example Component.
4 *
5 * @author     Samuele Tognini <samuele@cli.di.unipi.it>
6 */
7
8if(!defined('DOKU_INC')) die();
9if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
10require_once(DOKU_PLUGIN.'action.php');
11
12class action_plugin_maintenancemessage extends DokuWiki_Action_Plugin {
13
14	/**
15	 * return some info
16	 */
17	function getInfo(){
18		return confToHash(dirname(__FILE__).'/INFO.txt');
19	}
20
21	/**
22	 * Register its handlers with the DokuWiki's event controller
23	 */
24	function register(&$controller) {
25		$controller->register_hook('TPL_CONTENT_DISPLAY', 'BEFORE',  $this, '_printmaintenance');
26		$controller->register_hook('AUTH_LOGIN_CHECK', 'BEFORE',  $this, '_denylogin');
27		$controller->register_hook('TPL_ACT_RENDER', 'BEFORE',  $this, '_denyediting');
28	}
29
30	/**
31	 * Print Maintenance Message.
32	 *
33	 * @author Thomas Hawkins <thawkins@mun.ca>
34	 */
35	function _printmaintenance(&$event, $param){
36		$html = &$event->data;
37		if($this->getConf('maintenance_message_on') == true){
38			$message = $this->getConf('maintenance_message_text');
39			$html = '<div class="maintenancemessage">' . $message . '</div>' . $html;
40		}
41	}
42	/**
43	 * Denies login for all users.
44	 *
45	 * @author Thomas Hawkins <thawkins@mun.ca>
46	 */
47	function _denylogin(&$event, $param){
48		$html = &$event->data;
49		if($this->getConf('deny_all_logins') == true){
50			$event->preventDefault();
51			$message = $this->getConf('deny_login_message');
52			$html = '<div class="maintenancemessage">' . $message . '</div>';
53		}
54	}
55	/**
56	 * Denies a user from editing any pages.
57	 *
58	 * @author Thomas Hawkins <thawkins@mun.ca>
59	 */
60	function _denyediting(&$event, $param){
61		if($event->data != 'edit') return;
62		if($this->getConf('deny_editing') == true){
63			$message = $this->getConf('deny_editing_message');
64			echo '<div class="denyeditmessage">' . $message . '</div>';
65			$event->preventDefault();
66		}
67	}
68}