7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
9 * @package Magic3 Framework
10 * @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11 * @copyright Copyright 2006-2008 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: popular.inc.php 1120 2008-10-25 03:20:42Z fishbone $
14 * @link http://www.magic3.org
16 // Popular pages plugin: Show an access ranking of this wiki
17 // -- like recent plugin, using counter plugin's count --
19 * (C) 2003-2005 PukiWiki Developers Team
20 * (C) 2002 Kazunori Mizushima <kazunori@uc.netyou.jp>
22 * 通算および今日に別けて一覧を作ることができます。
27 * #popular(20,FrontPage|MenuBar)
28 * #popular(20,FrontPage|MenuBar,true)
31 * 1 - 表示する件数 default 10
32 * 2 - 表示させないページの正規表現 default なし
33 * 3 - 通算(true)か今日(false)の一覧かのフラグ default false
36 define('PLUGIN_POPULAR_DEFAULT', 10);
38 function plugin_popular_convert()
40 //global $vars, $whatsnew;
41 global $_popular_plugin_frame, $_popular_plugin_today_frame;
43 $max = PLUGIN_POPULAR_DEFAULT;
46 $array = func_get_args();
48 switch (func_num_args()) {
49 case 3: if ($array[2]) $today = get_date('Y/m/d');
50 case 2: $except = $array[1];
51 case 1: $max = $array[0];
55 $pages = WikiPage::getCountPages();
56 foreach ($pages as $page){
57 //foreach (get_existpages(COUNTER_DIR, '.count') as $file=>$page) {
58 //if (($except != '' && ereg($except, $page)) || $page == $whatsnew || check_non_list($page) || ! is_page($page)) continue;
59 if (($except != '' && ereg($except, $page)) || $page == WikiConfig::getWhatsnewPage() || check_non_list($page) || ! is_page($page)) continue;
61 //$array = file(COUNTER_DIR . $file);
62 $array = WikiPage::getPageCount($page);
63 $count = rtrim($array[0]);
64 $date = rtrim($array[1]);
65 $today_count = rtrim($array[2]);
68 // $pageが数値に見える(たとえばencode('BBS')=424253)とき、
69 // array_splice()によってキー値が変更されてしまうのを防ぐ
71 if ($today == $date) $counters['_' . $page] = $today_count;
73 $counters['_' . $page] = $count;
77 asort($counters, SORT_NUMERIC);
79 // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5
80 $counters = array_reverse($counters, TRUE); // with array_splice()
81 $counters = array_splice($counters, 0, $max);
84 if (! empty($counters)) {
85 $items = '<ul class="popular_list">' . "\n";
87 foreach ($counters as $page=>$count) {
88 $page = substr($page, 1);
90 $s_page = htmlspecialchars($page);
91 //if ($page == $vars['page']) {
92 if ($page == WikiParam::getPage()){
93 // No need to link itself, notifies where you just read
94 $pg_passage = get_pg_passage($page,FALSE);
95 $items .= ' <li><span title="' . $s_page . ' ' . $pg_passage . '">' .
96 $s_page . '<span class="counter">(' . $count .
97 ')</span></span></li>' . "\n";
99 $items .= ' <li>' . make_pagelink($page,
100 $s_page . '<span class="counter">(' . $count . ')</span>') .
104 $items .= '</ul>' . "\n";
107 return sprintf($today ? $_popular_plugin_today_frame : $_popular_plugin_frame, count($counters), $items);