OSDN Git Service

BugTrack2/62: Do remove the whole design, 'Showing TrackBack-ping list by html'.
[pukiwiki/pukiwiki.git] / plugin / popular.inc.php
1 <?php
2 // PukiWiki - Yet another WikiWikiWeb clone
3 // $Id: popular.inc.php,v 1.14 2005/04/09 03:18:06 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         $counters = array_splice(array_reverse($counters, TRUE), 0, $max);
69
70         $items = '';
71         if (! empty($counters)) {
72                 $items = '<ul class="popular_list">' . "\n";
73
74                 foreach ($counters as $page=>$count) {
75                         $page = substr($page, 1);
76
77                         $s_page = htmlspecialchars($page);
78                         if ($page == $vars['page']) {
79                                 // No need to link itself, notifies where you just read
80                                 $pg_passage = get_pg_passage($page,FALSE);
81                                 $items .= ' <li><span title="' . $s_page . ' ' . $pg_passage . '">' .
82                                         $s_page . '<span class="counter">(' . $count .
83                                         ')</span></span></li>' . "\n";
84                         } else {
85                                 $items .= ' <li>' . make_pagelink($page,
86                                         $s_page . '<span class="counter">(' . $count . ')</span>') .
87                                         '</li>' . "\n";
88                         }
89                 }
90                 $items .= '</ul>' . "\n";
91         }
92
93         return sprintf($today ? $_popular_plugin_today_frame : $_popular_plugin_frame, count($counters), $items);
94 }
95 ?>