OSDN Git Service

Convert character code of the source code to UTF-8 from EUC-JP
[pukiwiki/pukiwiki.git] / plugin / random.inc.php
1 <?php
2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
4 //
5 // $Id: random.inc.php,v 1.9 2011/01/25 15:01:01 henoheno Exp $
6 //
7
8 /*
9  *プラグイン random
10   配下のページをランダムに表示する
11
12  *Usage
13   #random(メッセージ)
14
15  *パラメータ
16  -メッセージ~
17  リンクに表示する文字列
18
19  */
20
21 function plugin_random_convert()
22 {
23         global $script, $vars;
24
25         $title = '[Random Link]'; // default
26         if (func_num_args()) {
27                 $args  = func_get_args();
28                 $title = $args[0];
29         }
30
31         return "<p><a href=\"$script?plugin=random&amp;refer=" .
32                 rawurlencode($vars['page']) . '">' .
33                 htmlsc($title) . '</a></p>';
34 }
35
36 function plugin_random_action()
37 {
38         global $vars;
39
40         $pattern = strip_bracket($vars['refer']) . '/';
41         $pages = array();
42         foreach (get_existpages() as $_page) {
43                 if (strpos($_page, $pattern) === 0)
44                         $pages[$_page] = strip_bracket($_page);
45         }
46
47         srand((double)microtime() * 1000000);
48         $page = array_rand($pages);
49
50         if ($page != '') $vars['refer'] = $page;
51
52         return array('body'=>'','msg'=>'');
53 }
54 ?>