-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaction.php
100 lines (83 loc) · 3.11 KB
/
action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* DokuWiki Plugin autologoff (Action Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <[email protected]>
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
class action_plugin_autologoff extends DokuWiki_Action_Plugin {
/** @var helper_plugin_autologoff */
private $helper;
public function __construct(){
$this->helper = $this->loadHelper('autologoff', false);
}
/**
* Registers a callback function for a given event
*
* @param Doku_Event_Handler $controller DokuWiki's event controller object
* @return void
*/
public function register(Doku_Event_Handler $controller) {
$controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'handle_dokuwiki_started');
$controller->register_hook('DETAIL_STARTED', 'BEFORE', $this, 'handle_dokuwiki_started');
$controller->register_hook('MEDIAMANAGER_STARTED', 'BEFORE', $this, 'handle_dokuwiki_started');
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax');
}
/**
* Check for timeouts, remember last activity
*
* @param Doku_Event $event event object by reference
* @param mixed $param [the parameters passed as fifth argument to register_hook() when this
* handler was registered]
* @return void
*/
public function handle_dokuwiki_started(Doku_Event &$event, $param) {
global $ID;
global $JSINFO;
$time = $this->helper->usertime();
if(!$time) return;
// check if the time has expired meanwhile
if(isset($_SESSION[DOKU_COOKIE]['autologoff'])) {
/** @var int $idle_time */
$idle_time = time() - $_SESSION[DOKU_COOKIE]['autologoff'];
if( $idle_time >= $time * 60) {
msg(sprintf($this->getLang('loggedoff'), hsc($_SERVER['REMOTE_USER'])));
unset($_SESSION[DOKU_COOKIE]['autologoff']);
$event = new Doku_Event('ACTION_AUTH_AUTOLOGOUT', $idle_time);
$event->advise_before(false);
auth_logoff();
$event->advise_after();
send_redirect(wl($ID, '', true, '&'));
}
}
// update the time
$_SESSION[DOKU_COOKIE]['autologoff'] = time();
$JSINFO['autologoff'] = $time;
}
/**
* Ajax function returning the remaining time
*
* @param Doku_Event $event
* @param $param
*/
public function handle_ajax(Doku_Event &$event, $param) {
if($event->data != 'autologoff') return;
$event->preventDefault();
header('Content-Type: text/plain');
$time = $this->helper->usertime();
if(!$time){
echo 0;
exit;
}
// user hit button to stay logged in
if(isset($_REQUEST['refresh'])){
session_start();
$_SESSION[DOKU_COOKIE]['autologoff'] = time();
session_write_close();
}
echo(($time * 60) - (time() - $_SESSION[DOKU_COOKIE]['autologoff']));
}
}
// vim:ts=4:sw=4:et: