1 | <?php |
---|
2 | /** |
---|
3 | * @copyright 2005-2008 OpenPNE Project |
---|
4 | * @license http://www.php.net/license/3_01.txt PHP License 3.01 |
---|
5 | */ |
---|
6 | |
---|
7 | /** |
---|
8 | * Smarty t_url2a_ktai modifier plugin |
---|
9 | * |
---|
10 | * @param string $string |
---|
11 | * @return string |
---|
12 | */ |
---|
13 | function smarty_modifier_t_url2a_ktai($string) |
---|
14 | { |
---|
15 | $url_pattern = '/https?:\/\/(?:[a-zA-Z0-9_\-\/.,:;~?@=+$%#!()]|&)+/'; |
---|
16 | return preg_replace_callback($url_pattern, 'smarty_modifier_t_url2a_ktai_callback', $string); |
---|
17 | } |
---|
18 | |
---|
19 | function smarty_modifier_t_url2a_ktai_callback($matches) |
---|
20 | { |
---|
21 | $raw_url = $matches[0]; |
---|
22 | |
---|
23 | $openpne_url = ''; |
---|
24 | if (strpos($raw_url, OPENPNE_URL) === 0) { |
---|
25 | $openpne_url = OPENPNE_URL; |
---|
26 | } elseif (OPENPNE_USE_PARTIAL_SSL && strpos($raw_url, OPENPNE_SSL_URL) === 0) { |
---|
27 | $openpne_url = OPENPNE_SSL_URL; |
---|
28 | } |
---|
29 | |
---|
30 | if (!$openpne_url) { |
---|
31 | return $raw_url; |
---|
32 | } |
---|
33 | |
---|
34 | $url_pattern = sprintf('/^%s(?:index.php)?\?m=pc&a=(\w+)((?:[a-zA-Z0-9_=]|&)*)$/', preg_quote($openpne_url, '/')); |
---|
35 | |
---|
36 | $openpne_url_matches = array(); |
---|
37 | if (!preg_match($url_pattern, $raw_url, $openpne_url_matches)) { |
---|
38 | return $raw_url; |
---|
39 | } |
---|
40 | $action = $openpne_url_matches[1]; |
---|
41 | $param = $openpne_url_matches[2]; |
---|
42 | |
---|
43 | //自動リンクのアクションリストにない場合は変換なし |
---|
44 | if (empty($GLOBALS['_OPENPNE_PC2KTAI_LINK_ACTION_LIST'][$action])) { |
---|
45 | return $raw_url; |
---|
46 | } |
---|
47 | |
---|
48 | $converted_action = $GLOBALS['_OPENPNE_PC2KTAI_LINK_ACTION_LIST'][$action]; |
---|
49 | $param = str_replace('&', '&', $param); |
---|
50 | |
---|
51 | // 携帯用URLに置換、ksid 追加 |
---|
52 | $ktai_url = $host . '?m=ktai&a=' . $converted_action . $param . '&' . $GLOBALS['KTAI_URL_TAIL']; |
---|
53 | |
---|
54 | // page_ より後ろを最大50文字に縮めて表示 |
---|
55 | $urlstr = $converted_action . $param; |
---|
56 | $urlstr = preg_replace('/^page_/', '', $urlstr); |
---|
57 | |
---|
58 | $length = 50; |
---|
59 | $etc = '..'; |
---|
60 | |
---|
61 | if (strlen($urlstr) > $length) { |
---|
62 | $length -= strlen($etc); |
---|
63 | $urlstr = substr($urlstr, 0, $length) . $etc; |
---|
64 | } |
---|
65 | |
---|
66 | $ktai_url = htmlspecialchars($ktai_url, ENT_QUOTES, 'UTF-8'); |
---|
67 | $urlstr = htmlspecialchars($urlstr, ENT_QUOTES, 'UTF-8'); |
---|
68 | |
---|
69 | return sprintf('<a href="%s">%s</a>', $ktai_url, $urlstr); |
---|
70 | } |
---|
71 | |
---|
72 | ?> |
---|