<?php
+// PukiWiki - Yet another WikiWikiWeb clone
+// $Id: popular.inc.php,v 1.15 2005/10/04 14:31:22 henoheno Exp $
+//
+// Popular pages plugin: Show an access ranking of this wiki
+// -- like recent plugin, using counter plugin's count --
+
/*
- * PukiWiki popular ¥×¥é¥°¥¤¥ó
- * (C) 2002, Kazunori Mizushima <kazunori@uc.netyou.jp>
+ * (C) 2003-2005 PukiWiki Developers Team
+ * (C) 2002 Kazunori Mizushima <kazunori@uc.netyou.jp>
*
- * ¿Íµ¤¤Î¤¢¤ë(¥¢¥¯¥»¥¹¿ô¤Î¿¤¤)¥Ú¡¼¥¸¤Î°ìÍ÷¤ò recent ¥×¥é¥°¥¤¥ó¤Î¤è¤¦¤Ëɽ¼¨¤·¤Þ¤¹¡£
* ÄÌ»»¤ª¤è¤Óº£Æü¤ËÊ̤±¤Æ°ìÍ÷¤òºî¤ë¤³¤È¤¬¤Ç¤¤Þ¤¹¡£
- * counter ¥×¥é¥°¥¤¥ó¤Î¥¢¥¯¥»¥¹¥«¥¦¥ó¥È¾ðÊó¤ò»È¤Ã¤Æ¤¤¤Þ¤¹¡£
*
- * [»ÈÍÑÎã]
- * #popular
- * #popular(20)
- * #popular(20,FrontPage|MenuBar)
- * #popular(20,FrontPage|MenuBar,true)
+ * [Usage]
+ * #popular
+ * #popular(20)
+ * #popular(20,FrontPage|MenuBar)
+ * #popular(20,FrontPage|MenuBar,true)
*
- * [°ú¿ô]
- * 1 - ɽ¼¨¤¹¤ë·ï¿ô default 10
- * 2 - ɽ¼¨¤µ¤»¤Ê¤¤¥Ú¡¼¥¸¤ÎÀµµ¬É½¸½ default ¤Ê¤·
- * 3 - ÄÌ»»(true)¤«º£Æü(false)¤Î°ìÍ÷¤«¤Î¥Õ¥é¥° default false
+ * [Arguments]
+ * 1 - ɽ¼¨¤¹¤ë·ï¿ô default 10
+ * 2 - ɽ¼¨¤µ¤»¤Ê¤¤¥Ú¡¼¥¸¤ÎÀµµ¬É½¸½ default ¤Ê¤·
+ * 3 - ÄÌ»»(true)¤«º£Æü(false)¤Î°ìÍ÷¤«¤Î¥Õ¥é¥° default false
*/
-// counter file : counter ¥×¥é¥°¥¤¥ó¤ÇÀßÄꤷ¤Æ¤¤¤ë¤â¤Î¤ÈƱ¤¸¤Ë¤·¤Æ²¼¤µ¤¤¡£
-if (!defined('COUNTER_DIR'))
- define('COUNTER_DIR', './counter/');
-
-function plugin_popular_init()
-{
- if (LANG == 'ja')
- $messages = array(
- '_popular_plugin_frame' => '<h5>¿Íµ¤¤Î%d·ï</h5><div>%s</div>',
- '_popular_plugin_today_frame' => '<h5>º£Æü¤Î%d·ï</h5><div>%s</div>',
- );
- else
- $messages = array(
- '_popular_plugin_frame' => '<h5>popular(%d)</h5><div>%s</div>',
- '_popular_plugin_today_frame' => '<h5>today\'s(%d)</h5><div>%s</div>',
- );
- set_plugin_messages($messages);
-}
+define('PLUGIN_POPULAR_DEFAULT', 10);
function plugin_popular_convert()
{
+ global $vars, $whatsnew, $non_list;
global $_popular_plugin_frame, $_popular_plugin_today_frame;
- global $script,$whatsnew,$non_list;
-
- $max = 10;
+
+ $max = PLUGIN_POPULAR_DEFAULT;
$except = '';
$array = func_get_args();
$today = FALSE;
-
switch (func_num_args()) {
- case 3:
- if ($array[2])
- $today = get_date('Y/m/d');
- case 2:
- $except = $array[1];
- case 1:
- $max = $array[0];
+ case 3: if ($array[2]) $today = get_date('Y/m/d');
+ case 2: $except = $array[1];
+ case 1: $max = $array[0];
}
+ $non_list_pattern = '/' . $non_list . '/';
$counters = array();
-
- foreach (get_existpages(COUNTER_DIR,'.count') as $page) {
- if ($except != '' and ereg($except,$page)) {
- continue;
- }
- if ($page == $whatsnew or preg_match("/$non_list/",$page) or !is_page($page)) {
+ foreach (get_existpages(COUNTER_DIR, '.count') as $file=>$page) {
+ if (($except != '' && ereg($except, $page)) ||
+ $page == $whatsnew || preg_match($non_list_pattern, $page) ||
+ ! is_page($page))
continue;
- }
-
- $array = file(COUNTER_DIR.encode($page).'.count');
+
+ $array = file(COUNTER_DIR . $file);
$count = rtrim($array[0]);
- $date = rtrim($array[1]);
+ $date = rtrim($array[1]);
$today_count = rtrim($array[2]);
- $yesterday_count = rtrim($array[3]);
-
+
if ($today) {
- if ($today == $date) {
- // $page¤¬¿ôÃͤ˸«¤¨¤ë(¤¿¤È¤¨¤Ðencode('BBS')=424253)¤È¤¡¢
- // array_splice()¤Ë¤è¤Ã¤Æ¥¡¼Ãͤ¬Êѹ¹¤µ¤ì¤Æ¤·¤Þ¤¦¤Î¤òËɤ°
- $counters["_$page"] = $today_count;
- }
- }
- else {
- $counters["_$page"] = $count;
+ // $page¤¬¿ôÃͤ˸«¤¨¤ë(¤¿¤È¤¨¤Ðencode('BBS')=424253)¤È¤¡¢
+ // array_splice()¤Ë¤è¤Ã¤Æ¥¡¼Ãͤ¬Êѹ¹¤µ¤ì¤Æ¤·¤Þ¤¦¤Î¤òËɤ°
+ // ¤¿¤á¡¢¥¡¼¤Ë '_' ¤òÏ¢·ë¤¹¤ë
+ if ($today == $date) $counters['_' . $page] = $today_count;
+ } else {
+ $counters['_' . $page] = $count;
}
}
-
+
asort($counters, SORT_NUMERIC);
- $counters = array_splice(array_reverse($counters,TRUE),0,$max);
-
+
+ // BugTrack2/106: Only variables can be passed by reference from PHP 5.0.5
+ $counters = array_reverse($counters, TRUE); // with array_splice()
+ $counters = array_splice($counters, 0, $max);
+
$items = '';
- if (count($counters)) {
- $items = '<ul class="recent_list">';
-
+ if (! empty($counters)) {
+ $items = '<ul class="popular_list">' . "\n";
+
foreach ($counters as $page=>$count) {
- $page = substr($page,1);
-
+ $page = substr($page, 1);
+
$s_page = htmlspecialchars($page);
- $items .= " <li>".make_pagelink($page,"$s_page<span class=\"counter\">($count)</span>")."</li>\n";
+ if ($page == $vars['page']) {
+ // No need to link itself, notifies where you just read
+ $pg_passage = get_pg_passage($page,FALSE);
+ $items .= ' <li><span title="' . $s_page . ' ' . $pg_passage . '">' .
+ $s_page . '<span class="counter">(' . $count .
+ ')</span></span></li>' . "\n";
+ } else {
+ $items .= ' <li>' . make_pagelink($page,
+ $s_page . '<span class="counter">(' . $count . ')</span>') .
+ '</li>' . "\n";
+ }
}
- $items .= '</ul>';
+ $items .= '</ul>' . "\n";
}
- return sprintf($today ? $_popular_plugin_today_frame : $_popular_plugin_frame,count($counters),$items);
-}
-?>
\ No newline at end of file
+ return sprintf($today ? $_popular_plugin_today_frame : $_popular_plugin_frame, count($counters), $items);
+}
+?>