OSDN Git Service

PukiWiki/1.4 first beta release
[pukiwiki/pukiwiki.git] / plugin / interwiki.inc.php
1 <?php
2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
4 //
5 // $Id: interwiki.inc.php,v 1.1 2003/01/27 05:38:46 panda Exp $
6 //
7 // InterWikiName¤ÎȽÊ̤ȥڡ¼¥¸¤Îɽ¼¨
8 function plugin_interwiki_action()
9 {
10         global $script,$vars,$interwiki,$WikiName,$InterWikiName;
11         global $_title_invalidiwn,$_msg_invalidiwn;
12         
13         $retvars = array();
14         
15         if (!preg_match("/^$InterWikiName$/",$vars['page'],$match)) {
16                 $retvars['msg'] = $_title_invalidiwn;
17                 $retvars['body'] = str_replace('$1',htmlspecialchars($name),str_replace('$2',"<a href=\"$script?InterWikiName\">InterWikiName</a>",$_msg_invalidiwn));
18                 return $retvars;
19         }
20         $name = $match[2];
21         $param = $match[3];
22         
23         $url = $opt = '';
24         $source = get_source($interwiki);
25         foreach($source as $line) {
26                 //                <1 url -------------------------------------------------------------->  <2 name>     <3 opt >
27                 if (preg_match('/\[((?:https?|ftp|news)(?:\:\/\/[[:alnum:]\+\$\;\?\.%,!#~\*\/\:@&=_\-]+))\s([^\]]+)\]\s?([^\s]*)/',$line,$match) and $match[2] == $name) {
28                         $url = $match[1];
29                         $opt = $match[3];
30                         break;
31                 }
32         }
33         
34         if ($url == '') {
35                 $retvars['msg'] = $_title_invalidiwn;
36                 $retvars['body'] = str_replace('$1',htmlspecialchars($name),str_replace('$2',"<a href=\"$script?InterWikiName\">InterWikiName</a>",$_msg_invalidiwn));
37                 return $retvars;
38         }
39         
40         $b_mb = function_exists('mb_convert_encoding');
41         
42         // Ê¸»ú¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°
43         if ($opt == 'yw')
44         {
45                 // YukiWiki·Ï
46                 if (!preg_match("/$WikiName/",$param))
47                         $param = $b_mb ? '[['.mb_convert_encoding($param,'SJIS',ENCODING).']]' : FALSE;
48         }
49         else if ($opt == 'moin')
50         {
51                 // moin·Ï
52                 $param = str_replace('%','_',rawurlencode($param));
53         }
54         else if ($opt == '' or $opt == 'std')
55         {
56                 // ÆâÉôʸ»ú¥¨¥ó¥³¡¼¥Ç¥£¥ó¥°¤Î¤Þ¤ÞURL¥¨¥ó¥³¡¼¥É
57                 $param = rawurlencode($param);
58         }
59         else if ($opt == 'asis' or $opt == 'raw')
60         {
61                 // URL¥¨¥ó¥³¡¼¥É¤·¤Ê¤¤
62 //                              $match[3] = $match[3];
63         }
64         else if ($opt != '')
65         {
66                 // ¥¨¥¤¥ê¥¢¥¹¤ÎÊÑ´¹
67                 if ($opt == 'sjis')
68                         $opt = 'SJIS';
69                 else if ($opt == 'euc')
70                         $opt = 'EUC-JP';
71                 else if ($opt == 'utf8')
72                         $opt = 'UTF-8';
73
74                 // ¤½¤Î¾¡¢»ØÄꤵ¤ì¤¿Ê¸»ú¥³¡¼¥É¤Ø¥¨¥ó¥³¡¼¥É¤·¤ÆURL¥¨¥ó¥³¡¼¥É
75                 $param = $b_mb ? rawurlencode(mb_convert_encoding($param,$opt,'auto')) : FALSE;
76         }
77
78         if ($param === FALSE)
79         {
80                 $retvars['msg'] = 'Not support mb_convert_encoding.';
81                 $retvars['body'] = 'This server\'s PHP does not have "mb_jstring" module. Cannot convert encoding.';
82                 return $retvars;
83         }
84
85         if (strpos($url,'$1') !== FALSE)
86                 $url = str_replace('$1',$param,$url);
87         else
88                 $url .= $param;
89
90         header("Location: $url");
91         die();
92 }
93 ?>