OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / widgets / wiki_main / include / plugin / popular.inc.php
1 <?php
2 /**
3  * popularプラグイン
4  *
5  * PHP versions 5
6  *
7  * LICENSE: This source file is licensed under the terms of the GNU General Public License.
8  *
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
15  */
16 // Popular pages plugin: Show an access ranking of this wiki
17 // -- like recent plugin, using counter plugin's count --
18 /*
19  * (C) 2003-2005 PukiWiki Developers Team
20  * (C) 2002 Kazunori Mizushima <kazunori@uc.netyou.jp>
21  *
22  * 通算および今日に別けて一覧を作ることができます。
23  *
24  * [Usage]
25  *   #popular
26  *   #popular(20)
27  *   #popular(20,FrontPage|MenuBar)
28  *   #popular(20,FrontPage|MenuBar,true)
29  *
30  * [Arguments]
31  *   1 - 表示する件数                             default 10
32  *   2 - 表示させないページの正規表現             default なし
33  *   3 - 通算(true)か今日(false)の一覧かのフラグ  default false
34  */
35
36 define('PLUGIN_POPULAR_DEFAULT', 10);
37
38 function plugin_popular_convert()
39 {
40         //global $vars, $whatsnew;
41         global $_popular_plugin_frame, $_popular_plugin_today_frame;
42
43         $max    = PLUGIN_POPULAR_DEFAULT;
44         $except = '';
45
46         $array = func_get_args();
47         $today = FALSE;
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];
52         }
53
54         $counters = array();
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;
60
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]);
66
67                 if ($today) {
68                         // $pageが数値に見える(たとえばencode('BBS')=424253)とき、
69                         // array_splice()によってキー値が変更されてしまうのを防ぐ
70                         // ため、キーに '_' を連結する
71                         if ($today == $date) $counters['_' . $page] = $today_count;
72                 } else {
73                         $counters['_' . $page] = $count;
74                 }
75         }
76
77         asort($counters, SORT_NUMERIC);
78
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);
82
83         $items = '';
84         if (! empty($counters)) {
85                 $items = '<ul class="popular_list">' . "\n";
86
87                 foreach ($counters as $page=>$count) {
88                         $page = substr($page, 1);
89
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";
98                         } else {
99                                 $items .= ' <li>' . make_pagelink($page,
100                                         $s_page . '<span class="counter">(' . $count . ')</span>') .
101                                         '</li>' . "\n";
102                         }
103                 }
104                 $items .= '</ul>' . "\n";
105         }
106
107         return sprintf($today ? $_popular_plugin_today_frame : $_popular_plugin_frame, count($counters), $items);
108 }
109 ?>