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 | function smarty_modifier_t_url2cmd($string, $type = '', $target_c_member_id = '') |
---|
8 | { |
---|
9 | if (in_array($type, db_get_url2a_denied_list())) { |
---|
10 | // HTMLエスケープされていない場合 |
---|
11 | // ", ', </a> がURLの後に続く場合はマッチさせない |
---|
12 | $url_pattern = '/https?:\/\/([a-zA-Z0-9\-.]+)\/?(?:[a-zA-Z0-9_\-\/.,:;~?@=+$%#!()&])*(?!["\'a-zA-Z0-9_\-\/.,:;~?@=+$%#!()&]|<\/a>)/'; |
---|
13 | } else { |
---|
14 | $url_pattern = '/https?:\/\/([a-zA-Z0-9\-.]+)\/?(?:[a-zA-Z0-9_\-\/.,:;~?@=+$%#!()]|&)*/'; |
---|
15 | } |
---|
16 | |
---|
17 | $GLOBALS['_CMD']['type'] = $type; |
---|
18 | $GLOBALS['_CMD']['target_c_member_id'] = $target_c_member_id; |
---|
19 | |
---|
20 | return preg_replace_callback($url_pattern, '_smarty_modifier_t_cmd_make_url_js', $string); |
---|
21 | } |
---|
22 | |
---|
23 | function _smarty_modifier_t_cmd_make_url_js($matches) |
---|
24 | { |
---|
25 | $url = str_replace('&', '&', $matches[0]); |
---|
26 | $cmd = $matches[1]; |
---|
27 | |
---|
28 | // SNS内を指すURLの場合は cmd/openpne ディレクトリ以下の小窓を読み込む |
---|
29 | $openpne_url = ''; |
---|
30 | if (strpos($url, OPENPNE_URL) === 0) { |
---|
31 | $openpne_url = OPENPNE_URL; |
---|
32 | } elseif (OPENPNE_USE_PARTIAL_SSL && strpos($url, OPENPNE_SSL_URL) === 0) { |
---|
33 | $openpne_url = OPENPNE_SSL_URL; |
---|
34 | } |
---|
35 | |
---|
36 | if ($openpne_url) { |
---|
37 | $url_pattern = sprintf('/^%s(?:index.php)?\?m=(\w+)&a=(\w+)((?:[a-zA-Z0-9_=]|&)*)$/', preg_quote($openpne_url, '/')); |
---|
38 | |
---|
39 | $openpne_url_matches = array(); |
---|
40 | if (preg_match($url_pattern, $url, $openpne_url_matches)) { |
---|
41 | $module = $openpne_url_matches[1]; |
---|
42 | $action = $openpne_url_matches[2]; |
---|
43 | $cmd = 'openpne/' . $module . '_' . $action; |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | $file = $cmd . '.js'; |
---|
48 | $path = './cmd/' . $file; |
---|
49 | |
---|
50 | // ファイルが読み込めない場合は、小窓キャスト配信者のJavaScriptを読み込む |
---|
51 | if (!is_readable($path)) { |
---|
52 | $path = db_etc_c_cmd_url4name($cmd); |
---|
53 | } |
---|
54 | |
---|
55 | if (!OPENPNE_USE_CMD_TAG || !db_is_use_cmd($cmd, $GLOBALS['_CMD']['type']) || !$path) { |
---|
56 | if (in_array($GLOBALS['_CMD']['type'], db_get_url2a_denied_list())) { |
---|
57 | // t_url2aが無効: 何もせずに返す |
---|
58 | return $matches[0]; |
---|
59 | } else { |
---|
60 | // t_url2aが有効 |
---|
61 | return pne_url2a($url); |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | $url_html = str_replace('&', '&', $url); |
---|
66 | $result = <<<EOD |
---|
67 | <script type="text/javascript" src="{$path}"></script> |
---|
68 | <script type="text/javascript"> |
---|
69 | <!-- |
---|
70 | url2cmd('{$url_html}', '{$GLOBALS['_CMD']['target_c_member_id']}'); |
---|
71 | //--> |
---|
72 | </script> |
---|
73 | EOD; |
---|
74 | return $result; |
---|
75 | } |
---|
76 | |
---|
77 | ?> |
---|