-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelper.php
97 lines (83 loc) · 2.52 KB
/
helper.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
<?php
/**
* DokuWiki Plugin autologoff (Helper 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 helper_plugin_autologoff extends DokuWiki_Plugin {
private $configfile;
public function __construct() {
$this->configfile = DOKU_CONF . '/autologoff.conf';
}
/**
* Loads the configuration from config file
*
* @return array
*/
public function load_config() {
$conf = array();
foreach((array) confToHash($this->configfile) as $usergroup => $time) {
$conf[rawurldecode($usergroup)] = (int) $time;
}
ksort($conf);
return $conf;
}
/**
* Adds another entry to tend of the config file
*
* @param $usergroup
* @param $time
*/
public function add_entry($usergroup, $time) {
$time = (int) $time;
if ($usergroup == '') {
msg($this->getLang('groupCannotBeEmpty'), -1);
return;
}
if($time !== 0 && $time < 2) {
msg($this->getLang('mintime'), -1);
$time = 2;
}
$usergroup = auth_nameencode($usergroup, true);
io_saveFile($this->configfile, "$usergroup\t$time\n", true);
}
/**
* Removes an entry for the given group or user from config file
*
* @param $usergroup
*/
public function remove_entry($usergroup){
$grep = preg_quote(auth_nameencode($usergroup, true), '/');
$grep = '/^'.$grep.'\\t/';
io_deleteFromFile($this->configfile, $grep, true);
}
/**
* Returns the configured time for the current user (in minutes)
*
* @return int
*/
public function usertime() {
global $INFO;
global $auth;
if(!isset($_SERVER['REMOTE_USER'])) return 0;
// make sure we have group info on the current user
if(isset($INFO) && isset($INFO['userinfo'])){
$groups = $INFO['userinfo']['grps'];
}else{
$info = $auth->getUserData($_SERVER['REMOTE_USER']);
$groups = $info['grps'];
}
$config = $this->load_config();
$maxtime = 0;
foreach($config as $usergroup => $time) {
if(!auth_isMember($usergroup, $_SERVER['REMOTE_USER'], (array) $groups)) continue;
if($time == 0) return 0;
if($time > $maxtime) $maxtime = $time;
}
return $maxtime;
}
}
// vim:ts=4:sw=4:et: