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: referer.inc.php 1141 2008-10-27 06:10:58Z fishbone $
14 * @link http://www.magic3.org
17 * PukiWiki Referer プラグイン(リンク元表示プラグイン)
18 * (C) 2003, Katsumi Saito <katsumi@jo1upk.ymt.prug.or.jp>
22 define('CONFIG_REFERER', 'plugin/referer/config');
24 function plugin_referer_action()
26 //global $vars, $referer;
31 if (! $referer) return array('msg'=>'','body'=>'');
33 $page = WikiParam::getPage();
34 //if (isset($vars['page']) && is_page($vars['page'])) {
36 //$sort = (empty($vars['sort'])) ? '0d' : $vars['sort'];
37 $sort = (WikiParam::getVar('sort') == '') ? '0d' : WikiParam::getVar('sort');
39 'msg' => $_referer_msg['msg_H0_Refer'],
40 'body' => plugin_referer_body($page, $sort));
41 //'body' => plugin_referer_body($vars['page'], $sort));
43 //$pages = get_existpages(TRACKBACK_DIR, '.ref');
44 $pages = WikiPage::getTrackbackPages();
47 return array('msg'=>'', 'body'=>'');
50 'msg' => 'referer list',
51 'body' => page_list($pages, 'referer', FALSE));
56 function plugin_referer_body($page, $sort)
58 global $script, $_referer_msg;
60 $data = tb_get(tb_get_filename($page, '.ref'));
61 if (empty($data)) return '<p>no data.</p>';
63 $bg = plugin_referer_set_color();
65 $arrow_last = $arrow_1st = $arrow_ctr = '';
66 $color_last = $color_1st = $color_ctr = $color_ref = $bg['etc'];
72 case '0d': // 0d 最終更新日時(新着順)
73 usort($data, create_function('$a,$b', 'return $b[0] - $a[0];'));
74 $color_last = $bg['cur'];
75 $arrow_last = $_referer_msg['msg_Chr_darr'];
78 case '0a': // 0a 最終更新日時(日付順)
79 usort($data, create_function('$a,$b', 'return $a[0] - $b[0];'));
80 $color_last = $bg['cur'];
81 $arrow_last = $_referer_msg['msg_Chr_uarr'];
84 case '1d': // 1d 初回登録日時(新着順)
85 usort($data, create_function('$a,$b', 'return $b[1] - $a[1];'));
86 $color_1st = $bg['cur'];
87 $arrow_1st = $_referer_msg['msg_Chr_darr'];
90 case '1a': // 1a 初回登録日時(日付順)
91 usort($data, create_function('$a,$b', 'return $a[1] - $b[1];'));
92 $color_1st = $bg['cur'];
93 $arrow_1st = $_referer_msg['msg_Chr_uarr'];
96 case '2d': // 2d カウンタ(大きい順)
97 usort($data, create_function('$a,$b', 'return $b[2] - $a[2];'));
98 $color_ctr = $bg['cur'];
99 $arrow_ctr = $_referer_msg['msg_Chr_darr'];
102 case '2a': // 2a カウンタ(小さい順)
103 usort($data, create_function('$a,$b', 'return $a[2] - $b[2];'));
104 $color_ctr = $bg['cur'];
105 $arrow_ctr = $_referer_msg['msg_Chr_uarr'];
108 case '3': // 3 Referer
109 usort($data, create_function('$a,$b',
110 'return ($a[3] == $b[3]) ? 0 : (($a[3] > $b[3]) ? 1 : -1);'));
111 $color_ref = $bg['cur'];
116 foreach ($data as $arr) {
117 // 0:最終更新日時, 1:初回登録日時, 2:参照カウンタ, 3:Referer ヘッダ, 4:利用可否フラグ(1は有効)
118 list($ltime, $stime, $count, $url, $enable) = $arr;
120 // 非ASCIIキャラクタ(だけ)をURLエンコードしておく BugTrack/440
121 $e_url = htmlspecialchars(preg_replace('/([" \x80-\xff]+)/e', 'rawurlencode("$1")', $url));
122 $s_url = htmlspecialchars(mb_convert_encoding(rawurldecode($url), SOURCE_ENCODING, 'auto'));
124 $lpass = get_passage($ltime, FALSE); // 最終更新日時からの経過時間
125 $spass = get_passage($stime, FALSE); // 初回登録日時からの経過時間
126 $ldate = get_date($_referer_msg['msg_Fmt_Date'], $ltime); // 最終更新日時文字列
127 $sdate = get_date($_referer_msg['msg_Fmt_Date'], $stime); // 初回登録日時文字列
131 ' <td>' . $ldate . '</td>' . "\n" .
132 ' <td>' . $lpass . '</td>' . "\n";
134 $body .= ($count == 1) ?
135 ' <td colspan="2">N/A</td>' . "\n" :
136 ' <td>' . $sdate . '</td>' . "\n" .
137 ' <td>' . $spass . '</td>' . "\n";
139 $body .= ' <td style="text-align:right;">' . $count . '</td>' . "\n";
141 // 適用不可データのときはアンカーをつけない
142 $body .= plugin_referer_ignore_check($url) ?
143 ' <td>' . $s_url . '</td>' . "\n" :
144 ' <td><a href="' . $e_url . '" rel="nofollow">' . $s_url . '</a></td>' . "\n";
146 $body .= ' </tr>' . "\n";
148 //$href = $script . '?plugin=referer&page=' . rawurlencode($page);
149 $href = $script . WikiParam::convQuery('?plugin=referer&page=' . rawurlencode($page));
151 <table border="1" cellspacing="1" summary="Referer">
153 <td style="background-color:$color_last" colspan="2">
154 <a href="$href&sort=$sort_last">{$_referer_msg['msg_Hed_LastUpdate']}$arrow_last</a>
156 <td style="background-color:$color_1st" colspan="2">
157 <a href="$href&sort=$sort_1st">{$_referer_msg['msg_Hed_1stDate']}$arrow_1st</a>
159 <td style="background-color:$color_ctr;text-align:right">
160 <a href="$href&sort=$sort_ctr">{$_referer_msg['msg_Hed_RefCounter']}$arrow_ctr</a>
162 <td style="background-color:$color_ref">
163 <a href="$href&sort=3">{$_referer_msg['msg_Hed_Referer']}</a>
171 function plugin_referer_set_color()
175 if (! isset($color)) {
177 $color = array('cur' => '#88ff88', 'etc' => '#cccccc');
179 $config = new Config(CONFIG_REFERER);
181 $pconfig_color = $config->get('COLOR');
186 foreach ($pconfig_color as $x)
187 $color[$x[0]] = htmlspecialchars(
188 preg_match('/BGCOLOR\(([^)]+)\)/si', $x[1], $matches) ?
189 $matches[1] : $x[1]);
194 function plugin_referer_ignore_check($url)
199 if (! isset($ignore_url)) {
200 $config = new Config(CONFIG_REFERER);
202 $ignore_url = $config->get('IGNORE');
206 foreach ($ignore_url as $x)
207 if (strpos($url, $x) !== FALSE)