/
action.php
executable file
·88 lines (66 loc) · 2.01 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
<?php
/**
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Pete Prodoehl <pete@2xlnetworks.com> and Jean Marc Massou <massou@gmail.com>
*/
require_once(DOKU_PLUGIN.'action.php');
class action_plugin_randompage extends Dokuwiki_Action_Plugin {
/**
* Register its handlers with the dokuwiki's event controller
*/
function register(Doku_Event_Handler $controller) {
$controller->register_hook('ACTION_HEADERS_SEND', 'BEFORE', $this, 'init', 'header');
}
function init(Doku_Event $event, $args)
{
// Catch the good request
if ($_REQUEST['do'] == 'randompage'|| $_REQUEST['do'] == 'nsrandompage' ) {
// On efface les headers par defaut
if ($args == 'header') {
$this->action_randompage($event, $args);
}
}
}
function action_randompage(Doku_Event $event, $args) {
global $conf;
global $ID;
global $INFO;
$data = array();
$dir = $conf['savedir'];
$data = file ($dir.'/index/page.idx');
//if current page is in
function isCurNS($value){
global $INFO;
return stripos($value, $INFO['namespace'])===0 ? true : false;
}
if ($INFO['namespace']!=null && $_REQUEST['do'] == 'nsrandompage' ) {
$data=array_filter($data,"isCurNS" );
}
//We loops through ten random page...
$i = 1;
while ($i <= 10 & $i <> "ok"):
//echo $i;
$i++;
$id = rtrim($data[array_rand($data, 1)]);
$testACL = auth_aclcheck($id,$_SERVER['REMOTE_USER'],$USERINFO['grps']);
if (($testACL > 1) and (file_exists(wikiFN($id)))){
$i="ok";
//echo $id;
}
endwhile;
if ($testACL < 1){
$id = $ID;
}
header("Location: ".wl($id,'',true));
//echo wl($page,'',true);
exit();
}
//Function from Php manual to get a random number in a Array
function array_rand($array, $lim=1) {
mt_srand((double) microtime() * 1000000);
for($a=0; $a<=$lim; $a++) {
$num[] = mt_srand(0, count($array)-1);
}
return @$num;
}
}