OSDN Git Service

BugTrack/2420 AutoTicketLink - Improve regex and JSON encode
[pukiwiki/pukiwiki.git] / plugin / random.inc.php
1 <?php
2 // PukiWiki - Yet another WikiWikiWeb clone
3 // random.inc.php
4 // Copyright 2002-2017 PukiWiki Development Team
5 // License: GPL v2 or (at your option) any later version
6 //
7 // Show random page plugin
8
9 /*
10  *プラグイン random
11   配下のページをランダムに表示する
12
13  *Usage
14   #random(メッセージ)
15
16  *パラメータ
17  -メッセージ~
18  リンクに表示する文字列
19
20  */
21
22 function plugin_random_convert()
23 {
24         global $vars;
25
26         $script = $get_base_uri();
27         $title = '[Random Link]'; // default
28         if (func_num_args()) {
29                 $args  = func_get_args();
30                 $title = $args[0];
31         }
32
33         return "<p><a href=\"$script?plugin=random&amp;refer=" .
34                 pagename_urlencode($vars['page']) . '">' .
35                 htmlsc($title) . '</a></p>';
36 }
37
38 function plugin_random_action()
39 {
40         global $vars;
41
42         $pattern = strip_bracket($vars['refer']) . '/';
43         $pages = array();
44         foreach (get_existpages() as $_page) {
45                 if (strpos($_page, $pattern) === 0)
46                         $pages[$_page] = strip_bracket($_page);
47         }
48
49         srand((double)microtime() * 1000000);
50         $page = array_rand($pages);
51
52         if ($page != '') $vars['refer'] = $page;
53
54         return array('body'=>'','msg'=>'');
55 }