OSDN Git Service

BugTrack2/139: Correct. Deleted a first space at preview.
[pukiwiki/pukiwiki.git] / plugin / popular.inc.php
1 <?php
2 // PukiWiki - Yet another WikiWikiWeb clone
3 // $Id: popular.inc.php,v 1.15 2005/10/04 14:31:22 henoheno Exp $
4 //
5 // Popular pages plugin: Show an access ranking of this wiki
6 // -- like recent plugin, using counter plugin's count --
7
8 /*
9  * (C) 2003-2005 PukiWiki Developers Team
10  * (C) 2002 Kazunori Mizushima <kazunori@uc.netyou.jp>
11  *
12  * ÄÌ»»¤ª¤è¤Óº£Æü¤ËÊ̤±¤Æ°ìÍ÷¤òºî¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
13  *
14  * [Usage]
15  *   #popular
16  *   #popular(20)
17  *   #popular(20,FrontPage|MenuBar)
18  *   #popular(20,FrontPage|MenuBar,true)
19  *
20  * [Arguments]
21  *   1 - É½¼¨¤¹¤ë·ï¿ô                             default 10
22  *   2 - É½¼¨¤µ¤»¤Ê¤¤¥Ú¡¼¥¸¤ÎÀµµ¬É½¸½             default ¤Ê¤·
23  *   3 - ÄÌ»»(true)¤«º£Æü(false)¤Î°ìÍ÷¤«¤Î¥Õ¥é¥°  default false
24  */
25
26 define('PLUGIN_POPULAR_DEFAULT', 10);
27
28 function plugin_popular_convert()
29 {
30         global $vars, $whatsnew, $non_list;
31         global $_popular_plugin_frame, $_popular_plugin_today_frame;
32
33         $max    = PLUGIN_POPULAR_DEFAULT;
34         $except = '';
35
36         $array = func_get_args();
37         $today = FALSE;
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];
42         }
43
44         $non_list_pattern = '/' . $non_list . '/';
45         $counters = array();
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) ||
49                     ! is_page($page))
50                         continue;
51
52                 $array = file(COUNTER_DIR . $file);
53                 $count = rtrim($array[0]);
54                 $date  = rtrim($array[1]);
55                 $today_count = rtrim($array[2]);
56
57                 if ($today) {
58                         // $page¤¬¿ôÃͤ˸«¤¨¤ë(¤¿¤È¤¨¤Ðencode('BBS')=424253)¤È¤­¡¢
59                         // array_splice()¤Ë¤è¤Ã¤Æ¥­¡¼Ãͤ¬Êѹ¹¤µ¤ì¤Æ¤·¤Þ¤¦¤Î¤òËɤ°
60                         // ¤¿¤á¡¢¥­¡¼¤Ë '_' ¤òÏ¢·ë¤¹¤ë
61                         if ($today == $date) $counters['_' . $page] = $today_count;
62                 } else {
63                         $counters['_' . $page] = $count;
64                 }
65         }
66
67         asort($counters, SORT_NUMERIC);
68
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);
72
73         $items = '';
74         if (! empty($counters)) {
75                 $items = '<ul class="popular_list">' . "\n";
76
77                 foreach ($counters as $page=>$count) {
78                         $page = substr($page, 1);
79
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";
87                         } else {
88                                 $items .= ' <li>' . make_pagelink($page,
89                                         $s_page . '<span class="counter">(' . $count . ')</span>') .
90                                         '</li>' . "\n";
91                         }
92                 }
93                 $items .= '</ul>' . "\n";
94         }
95
96         return sprintf($today ? $_popular_plugin_today_frame : $_popular_plugin_frame, count($counters), $items);
97 }
98 ?>