OSDN Git Service

BugTrack2/236: If you compare two numerical strings, they are compared as integers
[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         foreach (get_existpages(COUNTER_DIR, '.count') as $file=>$page) {
50                 if (($except != '' && ereg($except, $page)) ||
51                     $page == $whatsnew || check_non_list($page) ||
52                     ! is_page($page))
53                         continue;
54
55                 $array = file(COUNTER_DIR . $file);
56                 $count = rtrim($array[0]);
57                 $date  = rtrim($array[1]);
58                 $today_count = rtrim($array[2]);
59
60                 if ($today) {
61                         // $page¤¬¿ôÃͤ˸«¤¨¤ë(¤¿¤È¤¨¤Ðencode('BBS')=424253)¤È¤­¡¢
62                         // array_splice()¤Ë¤è¤Ã¤Æ¥­¡¼Ãͤ¬Êѹ¹¤µ¤ì¤Æ¤·¤Þ¤¦¤Î¤òËɤ°
63                         // ¤¿¤á¡¢¥­¡¼¤Ë '_' ¤òÏ¢·ë¤¹¤ë
64                         if ($today == $date) $counters['_' . $page] = $today_count;
65                 } else {
66                         $counters['_' . $page] = $count;
67                 }
68         }
69
70         asort($counters, SORT_NUMERIC);
71
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);
75
76         $items = '';
77         if (! empty($counters)) {
78                 $items = '<ul class="popular_list">' . "\n";
79
80                 foreach ($counters as $page=>$count) {
81                         $page = substr($page, 1);
82
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";
90                         } else {
91                                 $items .= ' <li>' . make_pagelink($page,
92                                         $s_page . '<span class="counter">(' . $count . ')</span>') .
93                                         '</li>' . "\n";
94                         }
95                 }
96                 $items .= '</ul>' . "\n";
97         }
98
99         return sprintf($today ? $_popular_plugin_today_frame : $_popular_plugin_frame, count($counters), $items);
100 }
101 ?>