2 // $Id: referer.inc.php,v 1.10 2005/01/23 05:20:02 henoheno Exp $
4 * PukiWiki Referer ¥×¥é¥°¥¤¥ó(¥ê¥ó¥¯¸µÉ½¼¨¥×¥é¥°¥¤¥ó)
5 * (C) 2003, Katsumi Saito <katsumi@jo1upk.ymt.prug.or.jp>
9 define('CONFIG_REFERER', 'plugin/referer/config');
11 function plugin_referer_action()
13 global $vars, $referer;
17 if (! $referer) return array('msg'=>'','body'=>'');
19 if (isset($vars['page']) && is_page($vars['page'])) {
20 $sort = (empty($vars['sort'])) ? '0d' : $vars['sort'];
22 'msg' => $_referer_msg['msg_H0_Refer'],
23 'body' => plugin_referer_body($vars['page'], $sort));
25 $pages = get_existpages(TRACKBACK_DIR, '.ref');
28 return array('msg'=>'', 'body'=>'');
31 'msg' => 'referer list',
32 'body' => page_list($pages, 'referer', FALSE));
37 function plugin_referer_body($page, $sort)
39 global $script, $_referer_msg;
41 $data = tb_get(tb_get_filename($page, '.ref'));
42 if (empty($data)) return '<p>no data.</p>';
44 $bg = plugin_referer_set_color();
46 $arrow_last = $arrow_1st = $arrow_ctr = '';
47 $color_last = $color_1st = $color_ctr = $color_ref = $bg['etc'];
53 case '0d': // 0d ºÇ½ª¹¹¿·Æü»þ(¿·Ãå½ç)
54 usort($data, create_function('$a,$b', 'return $b[0] - $a[0];'));
55 $color_last = $bg['cur'];
56 $arrow_last = $_referer_msg['msg_Chr_darr'];
59 case '0a': // 0a ºÇ½ª¹¹¿·Æü»þ(ÆüÉÕ½ç)
60 usort($data, create_function('$a,$b', 'return $a[0] - $b[0];'));
61 $color_last = $bg['cur'];
62 $arrow_last = $_referer_msg['msg_Chr_uarr'];
65 case '1d': // 1d ½é²óÅÐÏ¿Æü»þ(¿·Ãå½ç)
66 usort($data, create_function('$a,$b', 'return $b[1] - $a[1];'));
67 $color_1st = $bg['cur'];
68 $arrow_1st = $_referer_msg['msg_Chr_darr'];
71 case '1a': // 1a ½é²óÅÐÏ¿Æü»þ(ÆüÉÕ½ç)
72 usort($data, create_function('$a,$b', 'return $a[1] - $b[1];'));
73 $color_1st = $bg['cur'];
74 $arrow_1st = $_referer_msg['msg_Chr_uarr'];
77 case '2d': // 2d ¥«¥¦¥ó¥¿(Â礤¤½ç)
78 usort($data, create_function('$a,$b', 'return $b[2] - $a[2];'));
79 $color_ctr = $bg['cur'];
80 $arrow_ctr = $_referer_msg['msg_Chr_darr'];
83 case '2a': // 2a ¥«¥¦¥ó¥¿(¾®¤µ¤¤½ç)
84 usort($data, create_function('$a,$b', 'return $a[2] - $b[2];'));
85 $color_ctr = $bg['cur'];
86 $arrow_ctr = $_referer_msg['msg_Chr_uarr'];
89 case '3': // 3 Referer
90 usort($data, create_function('$a,$b',
91 'return ($a[3] == $b[3]) ? 0 : (($a[3] > $b[3]) ? 1 : -1);'));
92 $color_ref = $bg['cur'];
97 foreach ($data as $arr) {
98 // 0:ºÇ½ª¹¹¿·Æü»þ, 1:½é²óÅÐÏ¿Æü»þ, 2:»²¾È¥«¥¦¥ó¥¿, 3:Referer ¥Ø¥Ã¥À, 4:ÍøÍѲÄÈݥե饰(1¤Ï͸ú)
99 list($ltime, $stime, $count, $url, $enable) = $arr;
101 // ÈóASCII¥¥ã¥é¥¯¥¿(¤À¤±)¤òURL¥¨¥ó¥³¡¼¥É¤·¤Æ¤ª¤¯ BugTrack/440
102 $e_url = htmlspecialchars(preg_replace('/([" \x80-\xff]+)/e', 'rawurlencode("$1")', $url));
103 $s_url = htmlspecialchars(mb_convert_encoding(rawurldecode($url), SOURCE_ENCODING, 'auto'));
105 $lpass = get_passage($ltime, FALSE); // ºÇ½ª¹¹¿·Æü»þ¤«¤é¤Î·Ð²á»þ´Ö
106 $spass = get_passage($stime, FALSE); // ½é²óÅÐÏ¿Æü»þ¤«¤é¤Î·Ð²á»þ´Ö
107 $ldate = get_date($_referer_msg['msg_Fmt_Date'], $ltime); // ºÇ½ª¹¹¿·Æü»þʸ»úÎó
108 $sdate = get_date($_referer_msg['msg_Fmt_Date'], $stime); // ½é²óÅÐÏ¿Æü»þʸ»úÎó
112 ' <td>' . $ldate . '</td>' . "\n" .
113 ' <td>' . $lpass . '</td>' . "\n";
115 $body .= ($count == 1) ?
116 ' <td colspan="2">N/A</td>' . "\n" :
117 ' <td>' . $sdate . '</td>' . "\n" .
118 ' <td>' . $spass . '</td>' . "\n";
120 $body .= ' <td style="text-align:right;">' . $count . '</td>' . "\n";
122 // ŬÍÑÉԲĥǡ¼¥¿¤Î¤È¤¤Ï¥¢¥ó¥«¡¼¤ò¤Ä¤±¤Ê¤¤
123 $body .= plugin_referer_ignore_check($url) ?
124 ' <td>' . $s_url . '</td>' . "\n" :
125 ' <td><a href="' . $e_url . '" rel="nofollow">' . $s_url . '</a></td>' . "\n";
127 $body .= ' </tr>' . "\n";
129 $href = $script . '?plugin=referer&page=' . rawurlencode($page);
131 <table border="1" cellspacing="1" summary="Referer">
133 <td style="background-color:$color_last" colspan="2">
134 <a href="$href&sort=$sort_last">{$_referer_msg['msg_Hed_LastUpdate']}$arrow_last</a>
136 <td style="background-color:$color_1st" colspan="2">
137 <a href="$href&sort=$sort_1st">{$_referer_msg['msg_Hed_1stDate']}$arrow_1st</a>
139 <td style="background-color:$color_ctr;text-align:right">
140 <a href="$href&sort=$sort_ctr">{$_referer_msg['msg_Hed_RefCounter']}$arrow_ctr</a>
142 <td style="background-color:$color_ref">
143 <a href="$href&sort=3">{$_referer_msg['msg_Hed_Referer']}</a>
151 function plugin_referer_set_color()
155 if (! isset($color)) {
157 $color = array('cur' => '#88ff88', 'etc' => '#cccccc');
159 $config = new Config(CONFIG_REFERER);
161 $pconfig_color = $config->get('COLOR');
166 foreach ($pconfig_color as $x)
167 $color[$x[0]] = htmlspecialchars(
168 preg_match('/BGCOLOR\(([^)]+)\)/si', $x[1], $matches) ?
169 $matches[1] : $x[1]);
174 function plugin_referer_ignore_check($url)
179 if (! isset($ignore_url)) {
180 $config = new Config(CONFIG_REFERER);
182 $ignore_url = $config->get('IGNORE');
186 foreach ($ignore_url as $x)
187 if (strpos($url, $x) !== FALSE)