OSDN Git Service

Remove charset selector, use UTF-8
[pukiwiki/pukiwiki.git] / plugin / popular.inc.php
1 <?php
2 // PukiWiki - Yet another WikiWikiWeb clone
3 // $Id: popular.inc.php,v 1.20 2011/01/25 15:01:01 henoheno Exp $
4 // Copyright (C)
5 //   2003-2005, 2007 PukiWiki Developers 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  * (C) 2003-2005 PukiWiki Developers Team
14  * (C) 2002 Kazunori Mizushima <kazunori@uc.netyou.jp>
15  *
16  * 通算および今日に別けて一覧を作ることができます。
17  *
18  * [Usage]
19  *   #popular
20  *   #popular(20)
21  *   #popular(20,FrontPage|MenuBar)
22  *   #popular(20,FrontPage|MenuBar,true)
23  *
24  * [Arguments]
25  *   1 - 表示する件数                             default 10
26  *   2 - 表示させないページの正規表現             default なし
27  *   3 - 通算(true)か今日(false)の一覧かのフラグ  default false
28  */
29
30 define('PLUGIN_POPULAR_DEFAULT', 10);
31
32 function plugin_popular_convert()
33 {
34         global $vars, $whatsnew;
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         switch (func_num_args()) {
43         case 3: if ($array[2]) $today = get_date('Y/m/d');
44         case 2: $except = $array[1];
45         case 1: $max    = $array[0];
46         }
47
48         $counters = array();
49         $except_quote = str_replace('#', '\#', $except);
50         foreach (get_existpages(COUNTER_DIR, '.count') as $file=>$page) {
51                 if (($except != '' && preg_match("#$except_quote#", $page)) ||
52                     $page == $whatsnew || check_non_list($page) ||
53                     ! is_page($page))
54                         continue;
55
56                 $array = file(COUNTER_DIR . $file);
57                 $count = rtrim($array[0]);
58                 $date  = rtrim($array[1]);
59                 $today_count = rtrim($array[2]);
60
61                 if ($today) {
62                         // $pageが数値に見える(たとえばencode('BBS')=424253)とき、
63                         // array_splice()によってキー値が変更されてしまうのを防ぐ
64                         // ため、キーに '_' を連結する
65                         if ($today == $date) $counters['_' . $page] = $today_count;
66                 } else {
67                         $counters['_' . $page] = $count;
68                 }
69         }
70
71         asort($counters, SORT_NUMERIC);
72
73         // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5
74         $counters = array_reverse($counters, TRUE); // with array_splice()
75         $counters = array_splice($counters, 0, $max);
76
77         $items = '';
78         if (! empty($counters)) {
79                 $items = '<ul class="popular_list">' . "\n";
80
81                 foreach ($counters as $page=>$count) {
82                         $page = substr($page, 1);
83
84                         $s_page = htmlsc($page);
85                         if ($page === $vars['page']) {
86                                 // No need to link itself, notifies where you just read
87                                 $pg_passage = get_pg_passage($page,FALSE);
88                                 $items .= ' <li><span title="' . $s_page . ' ' . $pg_passage . '">' .
89                                         $s_page . '<span class="counter">(' . $count .
90                                         ')</span></span></li>' . "\n";
91                         } else {
92                                 $items .= ' <li>' . make_pagelink($page,
93                                         $s_page . '<span class="counter">(' . $count . ')</span>') .
94                                         '</li>' . "\n";
95                         }
96                 }
97                 $items .= '</ul>' . "\n";
98         }
99
100         return sprintf($today ? $_popular_plugin_today_frame : $_popular_plugin_frame, count($counters), $items);
101 }
102