<?php
-// $Id: referer.inc.php,v 1.7 2004/07/31 03:09:20 henoheno Exp $
+// $Id: referer.inc.php,v 1.8 2005/01/23 04:47:52 henoheno Exp $
/*
* PukiWiki Referer ¥×¥é¥°¥¤¥ó(¥ê¥ó¥¯¸µÉ½¼¨¥×¥é¥°¥¤¥ó)
* (C) 2003, Katsumi Saito <katsumi@jo1upk.ymt.prug.or.jp>
* License: GPL
*/
-// ¹½À®ÄêµÁ¥Õ¥¡¥¤¥ë
-define('CONFIG_REFERER','plugin/referer/config');
+define('CONFIG_REFERER', 'plugin/referer/config');
function plugin_referer_action()
{
- global $vars,$referer;
+ global $vars, $referer;
global $_referer_msg;
- // Refererµ¡Ç½¤ò»ÈÍѤ·¤Æ¤¤¤Ê¤¤
- if (!$referer)
- {
- return array('msg'=>'','body'=>'');
- }
+ // Setting: Off
+ if (! $referer) return array('msg'=>'','body'=>'');
- if (array_key_exists('page',$vars) and is_page($vars['page']))
- {
- // À°Îó½ç
+ if (isset($vars['page']) && is_page($vars['page'])) {
$sort = (empty($vars['sort'])) ? '0d' : $vars['sort'];
-
return array(
'msg' => $_referer_msg['msg_H0_Refer'],
- 'body' => referer_body($vars['page'],$sort)
- );
+ 'body' => referer_body($vars['page'], $sort));
}
- $pages = get_existpages(TRACKBACK_DIR,'.ref');
+ $pages = get_existpages(TRACKBACK_DIR, '.ref');
- if (count($pages) == 0)
- {
- return array('msg'=>'','body'=>'');
+ if (empty($pages)) {
+ return array('msg'=>'', 'body'=>'');
+ } else {
+ return array(
+ 'msg' => 'referer list',
+ 'body' => page_list($pages, 'referer', FALSE));
}
-
- return array(
- 'msg' => 'referer list',
- 'body' => page_list($pages,'referer',FALSE)
- );
}
// Referer ÌÀºÙ¹ÔÊÔ½¸
-function referer_body($page,$sort)
+function referer_body($page, $sort)
{
- global $script,$_referer_msg;
+ global $script, $_referer_msg;
+
+ $data = tb_get(tb_get_filename($page, '.ref'));
+ if (empty($data)) return '<p>no data.</p>';
- $data = tb_get(tb_get_filename($page,'.ref'));
- if (count($data) == 0)
- {
- return '<p>no data.</p>';
- }
$bg = referer_set_color();
$arrow_last = $arrow_1st = $arrow_ctr = '';
$color_last = $color_1st = $color_ctr = $color_ref = $bg['etc'];
$sort_last = '0d';
- $sort_1st = '1d';
- $sort_ctr = '2d';
-
- switch ($sort)
- {
- case '0d': // 0d ºÇ½ª¹¹¿·Æü»þ(¿·Ãå½ç)
- usort($data,create_function('$a,$b','return $b[0] - $a[0];'));
- $color_last = $bg['cur'];
- $arrow_last = $_referer_msg['msg_Chr_darr'];
- $sort_last = '0a';
- break;
- case '0a': // 0a ºÇ½ª¹¹¿·Æü»þ(ÆüÉÕ½ç)
- usort($data,create_function('$a,$b','return $a[0] - $b[0];'));
- $color_last = $bg['cur'];
- $arrow_last = $_referer_msg['msg_Chr_uarr'];
-// $sort_last = '0d';
- break;
- case '1d': // 1d ½é²óÅÐÏ¿Æü»þ(¿·Ãå½ç)
- usort($data,create_function('$a,$b','return $b[1] - $a[1];'));
- $color_1st = $bg['cur'];
- $arrow_1st = $_referer_msg['msg_Chr_darr'];
- $sort_1st = '1a';
- break;
- case '1a': // 1a ½é²óÅÐÏ¿Æü»þ(ÆüÉÕ½ç)
- usort($data,create_function('$a,$b','return $a[1] - $b[1];'));
- $color_1st = $bg['cur'];
- $arrow_1st = $_referer_msg['msg_Chr_uarr'];
-// $sort_1st = '1d';
- break;
- case '2d': // 2d ¥«¥¦¥ó¥¿(Â礤¤½ç)
- usort($data,create_function('$a,$b','return $b[2] - $a[2];'));
- $color_ctr = $bg['cur'];
- $arrow_ctr = $_referer_msg['msg_Chr_darr'];
- $sort_ctr = '2a';
- break;
- case '2a': // 2a ¥«¥¦¥ó¥¿(¾®¤µ¤¤½ç)
- usort($data,create_function('$a,$b','return $a[2] - $b[2];'));
- $color_ctr = $bg['cur'];
- $arrow_ctr = $_referer_msg['msg_Chr_uarr'];
-// $sort_ctr = '2d';
- break;
- case '3': // 3 Referer
- usort($data,create_function('$a,$b','return ($a[3] == $b[3]) ? 0 : (($a[3] > $b[3]) ? 1 : -1);'));
- $color_ref = $bg['cur'];
- break;
+ $sort_1st = '1d';
+ $sort_ctr = '2d';
+
+ switch ($sort) {
+ case '0d': // 0d ºÇ½ª¹¹¿·Æü»þ(¿·Ãå½ç)
+ usort($data, create_function('$a,$b', 'return $b[0] - $a[0];'));
+ $color_last = $bg['cur'];
+ $arrow_last = $_referer_msg['msg_Chr_darr'];
+ $sort_last = '0a';
+ break;
+ case '0a': // 0a ºÇ½ª¹¹¿·Æü»þ(ÆüÉÕ½ç)
+ usort($data, create_function('$a,$b', 'return $a[0] - $b[0];'));
+ $color_last = $bg['cur'];
+ $arrow_last = $_referer_msg['msg_Chr_uarr'];
+// $sort_last = '0d';
+ break;
+ case '1d': // 1d ½é²óÅÐÏ¿Æü»þ(¿·Ãå½ç)
+ usort($data, create_function('$a,$b', 'return $b[1] - $a[1];'));
+ $color_1st = $bg['cur'];
+ $arrow_1st = $_referer_msg['msg_Chr_darr'];
+ $sort_1st = '1a';
+ break;
+ case '1a': // 1a ½é²óÅÐÏ¿Æü»þ(ÆüÉÕ½ç)
+ usort($data, create_function('$a,$b', 'return $a[1] - $b[1];'));
+ $color_1st = $bg['cur'];
+ $arrow_1st = $_referer_msg['msg_Chr_uarr'];
+// $sort_1st = '1d';
+ break;
+ case '2d': // 2d ¥«¥¦¥ó¥¿(Â礤¤½ç)
+ usort($data, create_function('$a,$b', 'return $b[2] - $a[2];'));
+ $color_ctr = $bg['cur'];
+ $arrow_ctr = $_referer_msg['msg_Chr_darr'];
+ $sort_ctr = '2a';
+ break;
+ case '2a': // 2a ¥«¥¦¥ó¥¿(¾®¤µ¤¤½ç)
+ usort($data, create_function('$a,$b', 'return $a[2] - $b[2];'));
+ $color_ctr = $bg['cur'];
+ $arrow_ctr = $_referer_msg['msg_Chr_uarr'];
+// $sort_ctr = '2d';
+ break;
+ case '3': // 3 Referer
+ usort($data, create_function('$a,$b',
+ 'return ($a[3] == $b[3]) ? 0 : (($a[3] > $b[3]) ? 1 : -1);'));
+ $color_ref = $bg['cur'];
+ break;
}
$body = '';
- foreach ($data as $arr)
- {
+ foreach ($data as $arr) {
// 0:ºÇ½ª¹¹¿·Æü»þ, 1:½é²óÅÐÏ¿Æü»þ, 2:»²¾È¥«¥¦¥ó¥¿, 3:Referer ¥Ø¥Ã¥À, 4:ÍøÍѲÄÈݥե饰(1¤Ï͸ú)
- list($ltime,$stime,$count,$url,$enable) = $arr;
+ list($ltime, $stime, $count, $url, $enable) = $arr;
// ÈóASCII¥¥ã¥é¥¯¥¿(¤À¤±)¤òURL¥¨¥ó¥³¡¼¥É¤·¤Æ¤ª¤¯ BugTrack/440
- $e_url = htmlspecialchars(preg_replace('/([" \x80-\xff]+)/e','rawurlencode("$1")',$url));
- $s_url = htmlspecialchars(mb_convert_encoding(rawurldecode($url),SOURCE_ENCODING,'auto'));
+ $e_url = htmlspecialchars(preg_replace('/([" \x80-\xff]+)/e', 'rawurlencode("$1")', $url));
+ $s_url = htmlspecialchars(mb_convert_encoding(rawurldecode($url), SOURCE_ENCODING, 'auto'));
- $lpass = get_passage($ltime,FALSE); // ºÇ½ª¹¹¿·Æü»þ¤«¤é¤Î·Ð²á»þ´Ö
- $spass = get_passage($stime,FALSE); // ½é²óÅÐÏ¿Æü»þ¤«¤é¤Î·Ð²á»þ´Ö
- $ldate = get_date($_referer_msg['msg_Fmt_Date'],$ltime); // ºÇ½ª¹¹¿·Æü»þʸ»úÎó
- $sdate = get_date($_referer_msg['msg_Fmt_Date'],$stime); // ½é²óÅÐÏ¿Æü»þʸ»úÎó
+ $lpass = get_passage($ltime, FALSE); // ºÇ½ª¹¹¿·Æü»þ¤«¤é¤Î·Ð²á»þ´Ö
+ $spass = get_passage($stime, FALSE); // ½é²óÅÐÏ¿Æü»þ¤«¤é¤Î·Ð²á»þ´Ö
+ $ldate = get_date($_referer_msg['msg_Fmt_Date'], $ltime); // ºÇ½ª¹¹¿·Æü»þʸ»úÎó
+ $sdate = get_date($_referer_msg['msg_Fmt_Date'], $stime); // ½é²óÅÐÏ¿Æü»þʸ»úÎó
- $body .= " <tr>\n <td>$ldate</td>\n <td>$lpass</td>\n";
- $body .= ($count == 1) ? " <td colspan=\"2\">N/A</td>\n" : " <td>$sdate</td>\n <td>$spass</td>\n";
- $body .= " <td style=\"text-align:right;\">$count</td>\n";
+ $body .=
+ ' <tr>' . "\n" .
+ ' <td>' . $ldate . '</td>' . "\n" .
+ ' <td>' . $lpass . '</td>' . "\n";
+
+ $body .= ($count == 1) ?
+ ' <td colspan="2">N/A</td>' . "\n" :
+ ' <td>' . $sdate . '</td>' . "\n" .
+ ' <td>' . $spass . '</td>' . "\n";
+
+ $body .= ' <td style="text-align:right;">' . $count . '</td>' . "\n";
// ŬÍÑÉԲĥǡ¼¥¿¤Î¤È¤¤Ï¥¢¥ó¥«¡¼¤ò¤Ä¤±¤Ê¤¤
$body .= referer_ignore_check($url) ?
- " <td>$s_url</td>\n" : " <td><a href=\"$e_url\">$s_url</a></td>\n";
- $body .= " </tr>\n";
+ ' <td>' . $s_url . '</td>' . "\n" :
+ ' <td><a href="' . $e_url . '">' . $s_url . '</a></td>' . "\n";
+
+ $body .= ' </tr>' . "\n";
}
- $href = $script.'?plugin=referer&page='.rawurlencode($page);
+ $href = $script . '?plugin=referer&page=' . rawurlencode($page);
return <<<EOD
<table border="1" cellspacing="1" summary="Referer">
<tr>
{
static $color;
- if (!isset($color))
- {
- // ¥Ç¥Õ¥©¥ë¥È¥«¥é¡¼
- $color = array(
- 'cur' => '#88ff88',
- 'etc' => '#cccccc'
- );
+ if (! isset($color)) {
+ // Default color
+ $color = array('cur' => '#88ff88', 'etc' => '#cccccc');
$config = new Config(CONFIG_REFERER);
$config->read();
$pconfig_color = $config->get('COLOR');
unset($config);
+
+ // BGCOLOR(#88ff88)
+ $matches = array();
foreach ($pconfig_color as $x)
- {
- // BGCOLOR(#88ff88)
$color[$x[0]] = htmlspecialchars(
- preg_match('/BGCOLOR\(([^)]+)\)/si',$x[1],$matches) ? $matches[1] : $x[1]
- );
- }
+ preg_match('/BGCOLOR\(([^)]+)\)/si', $x[1], $matches) ?
+ $matches[1] : $x[1]);
}
return $color;
}
static $ignore_url;
// config.php
- if (!isset($ignore_url))
- {
+ if (! isset($ignore_url)) {
$config = new Config(CONFIG_REFERER);
$config->read();
$ignore_url = $config->get('IGNORE');
}
foreach ($ignore_url as $x)
- {
- if (strpos($url,$x) !== FALSE)
- {
+ if (strpos($url, $x) !== FALSE)
return 1;
- }
- }
return 0;
}
?>