2 // PukiWiki - Yet another WikiWikiWeb clone
3 // $Id: popular.inc.php,v 1.15 2005/10/04 14:31:22 henoheno Exp $
5 // Popular pages plugin: Show an access ranking of this wiki
6 // -- like recent plugin, using counter plugin's count --
9 * (C) 2003-2005 PukiWiki Developers Team
10 * (C) 2002 Kazunori Mizushima <kazunori@uc.netyou.jp>
12 * ÄÌ»»¤ª¤è¤Óº£Æü¤ËÊ̤±¤Æ°ìÍ÷¤òºî¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
17 * #popular(20,FrontPage|MenuBar)
18 * #popular(20,FrontPage|MenuBar,true)
21 * 1 - ɽ¼¨¤¹¤ë·ï¿ô default 10
22 * 2 - ɽ¼¨¤µ¤»¤Ê¤¤¥Ú¡¼¥¸¤ÎÀµµ¬É½¸½ default ¤Ê¤·
23 * 3 - ÄÌ»»(true)¤«º£Æü(false)¤Î°ìÍ÷¤«¤Î¥Õ¥é¥° default false
26 define('PLUGIN_POPULAR_DEFAULT', 10);
28 function plugin_popular_convert()
30 global $vars, $whatsnew, $non_list;
31 global $_popular_plugin_frame, $_popular_plugin_today_frame;
33 $max = PLUGIN_POPULAR_DEFAULT;
36 $array = func_get_args();
38 switch (func_num_args()) {
39 case 3: if ($array[2]) $today = get_date('Y/m/d');
40 case 2: $except = $array[1];
41 case 1: $max = $array[0];
44 $non_list_pattern = '/' . $non_list . '/';
46 foreach (get_existpages(COUNTER_DIR, '.count') as $file=>$page) {
47 if (($except != '' && ereg($except, $page)) ||
48 $page == $whatsnew || preg_match($non_list_pattern, $page) ||
52 $array = file(COUNTER_DIR . $file);
53 $count = rtrim($array[0]);
54 $date = rtrim($array[1]);
55 $today_count = rtrim($array[2]);
58 // $page¤¬¿ôÃͤ˸«¤¨¤ë(¤¿¤È¤¨¤Ðencode('BBS')=424253)¤È¤¡¢
59 // array_splice()¤Ë¤è¤Ã¤Æ¥¡¼Ãͤ¬Êѹ¹¤µ¤ì¤Æ¤·¤Þ¤¦¤Î¤òËɤ°
60 // ¤¿¤á¡¢¥¡¼¤Ë '_' ¤òÏ¢·ë¤¹¤ë
61 if ($today == $date) $counters['_' . $page] = $today_count;
63 $counters['_' . $page] = $count;
67 asort($counters, SORT_NUMERIC);
69 // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5
70 $counters = array_reverse($counters, TRUE); // with array_splice()
71 $counters = array_splice($counters, 0, $max);
74 if (! empty($counters)) {
75 $items = '<ul class="popular_list">' . "\n";
77 foreach ($counters as $page=>$count) {
78 $page = substr($page, 1);
80 $s_page = htmlspecialchars($page);
81 if ($page == $vars['page']) {
82 // No need to link itself, notifies where you just read
83 $pg_passage = get_pg_passage($page,FALSE);
84 $items .= ' <li><span title="' . $s_page . ' ' . $pg_passage . '">' .
85 $s_page . '<span class="counter">(' . $count .
86 ')</span></span></li>' . "\n";
88 $items .= ' <li>' . make_pagelink($page,
89 $s_page . '<span class="counter">(' . $count . ')</span>') .
93 $items .= '</ul>' . "\n";
96 return sprintf($today ? $_popular_plugin_today_frame : $_popular_plugin_frame, count($counters), $items);