OSDN Git Service

07bf2faa41cc1e5bb691d94410eabd6ee028c14f
[pukiwiki/pukiwiki.git] / plugin / popular.inc.php
1 <?php
2 // PukiWiki - Yet another WikiWikiWeb clone
3 // popular.inc.php
4 // Copyright
5 //   2003-2017 PukiWiki Development Team
6 //   2002 Kazunori Mizushima <kazunori@uc.netyou.jp>
7 // License: WHERE IS THE RECORD?
8 //
9 // Popular pages plugin: Show an access ranking of this wiki
10 // -- like recent plugin, using counter plugin's count --
11
12 /**
13  *
14  * 通算および今日に別けて一覧を作ることができます。
15  *
16  * [Usage]
17  *   #popular
18  *   #popular(20)
19  *   #popular(20,FrontPage|MenuBar)
20  *   #popular(20,FrontPage|MenuBar,true)
21  *
22  * [Arguments]
23  *   1 - 表示する件数                             default 10
24  *   2 - 表示させないページの正規表現             default なし
25  *   3 - 通算(true)か今日(false)の一覧かのフラグ  default false
26  */
27
28 define('PLUGIN_POPULAR_DEFAULT', 10);
29
30 require_once(PLUGIN_DIR . 'counter.inc.php');
31
32 function plugin_popular_convert()
33 {
34         global $vars;
35         global $_popular_plugin_frame, $_popular_plugin_today_frame;
36
37         $max    = PLUGIN_POPULAR_DEFAULT;
38         $except = '';
39
40         $array = func_get_args();
41         $today = FALSE;
42         $today_param = $array[2];
43         switch (func_num_args()) {
44         case 3: if ($today_param && $today_param !== 'false') $today = get_date('Y/m/d');
45         case 2: $except = $array[1];
46         case 1: $max    = (int)$array[0];
47         }
48         $counters = plugin_counter_get_popular_list($today, $except, $max);
49
50         $items = '';
51         if (! empty($counters)) {
52                 $items = '<ul class="popular_list">' . "\n";
53
54                 foreach ($counters as $page=>$count) {
55                         $page = substr($page, 1);
56
57                         $s_page = htmlsc($page);
58                         if ($page === $vars['page']) {
59                                 // No need to link itself, notifies where you just read
60                                 $attrs = get_page_link_a_attrs($page);
61                                 $items .= ' <li><span class="' .
62                                         $attrs['class'] . '" data-mtime="' . $attrs['data_mtime'] .
63                                         '">' . $s_page . '<span class="counter">(' . $count .
64                                         ')</span></span></li>' . "\n";
65                         } else {
66                                 $items .= ' <li>' . make_pagelink($page,
67                                         $s_page . '<span class="counter">(' . $count . ')</span>') .
68                                         '</li>' . "\n";
69                         }
70                 }
71                 $items .= '</ul>' . "\n";
72         }
73
74         return sprintf($today ? $_popular_plugin_today_frame : $_popular_plugin_frame, count($counters), $items);
75 }