2 // PukiWiki - Yet another WikiWikiWeb clone
3 // $Id: popular.inc.php,v 1.20 2011/01/25 15:01:01 henoheno Exp $
5 // 2003-2005, 2007 PukiWiki Developers Team
6 // 2002 Kazunori Mizushima <kazunori@uc.netyou.jp>
7 // License: WHERE IS THE RECORD?
9 // Popular pages plugin: Show an access ranking of this wiki
10 // -- like recent plugin, using counter plugin's count --
13 * (C) 2003-2005 PukiWiki Developers Team
14 * (C) 2002 Kazunori Mizushima <kazunori@uc.netyou.jp>
16 * 通算および今日に別けて一覧を作ることができます。
21 * #popular(20,FrontPage|MenuBar)
22 * #popular(20,FrontPage|MenuBar,true)
25 * 1 - 表示する件数 default 10
26 * 2 - 表示させないページの正規表現 default なし
27 * 3 - 通算(true)か今日(false)の一覧かのフラグ default false
30 define('PLUGIN_POPULAR_DEFAULT', 10);
32 function plugin_popular_convert()
34 global $vars, $whatsnew;
35 global $_popular_plugin_frame, $_popular_plugin_today_frame;
37 $max = PLUGIN_POPULAR_DEFAULT;
40 $array = func_get_args();
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];
49 foreach (get_existpages(COUNTER_DIR, '.count') as $file=>$page) {
50 if (($except != '' && ereg($except, $page)) ||
51 $page == $whatsnew || check_non_list($page) ||
55 $array = file(COUNTER_DIR . $file);
56 $count = rtrim($array[0]);
57 $date = rtrim($array[1]);
58 $today_count = rtrim($array[2]);
61 // $pageが数値に見える(たとえばencode('BBS')=424253)とき、
62 // array_splice()によってキー値が変更されてしまうのを防ぐ
64 if ($today == $date) $counters['_' . $page] = $today_count;
66 $counters['_' . $page] = $count;
70 asort($counters, SORT_NUMERIC);
72 // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5
73 $counters = array_reverse($counters, TRUE); // with array_splice()
74 $counters = array_splice($counters, 0, $max);
77 if (! empty($counters)) {
78 $items = '<ul class="popular_list">' . "\n";
80 foreach ($counters as $page=>$count) {
81 $page = substr($page, 1);
83 $s_page = htmlsc($page);
84 if ($page === $vars['page']) {
85 // No need to link itself, notifies where you just read
86 $pg_passage = get_pg_passage($page,FALSE);
87 $items .= ' <li><span title="' . $s_page . ' ' . $pg_passage . '">' .
88 $s_page . '<span class="counter">(' . $count .
89 ')</span></span></li>' . "\n";
91 $items .= ' <li>' . make_pagelink($page,
92 $s_page . '<span class="counter">(' . $count . ')</span>') .
96 $items .= '</ul>' . "\n";
99 return sprintf($today ? $_popular_plugin_today_frame : $_popular_plugin_frame, count($counters), $items);