OSDN Git Service

[[pukiwiki:BugTrack/71]] +, ++, +++という書式で<ol>〜</ol>を生成するように拡張
[pukiwiki/pukiwiki.git] / html.php
1 <?
2 // PukiWiki - Yet another WikiWikiWeb clone.
3 // $Id: html.php,v 1.24 2002/07/18 16:05:09 masui Exp $
4 /////////////////////////////////////////////////
5
6 // ËÜʸ¤ò¥Ú¡¼¥¸Ì¾¤«¤é½ÐÎÏ
7 function catbodyall($page,$title="",$pg="")
8 {
9         if($title === "") $title = strip_bracket($page);
10         if($pg === "") $pg = make_search($page);
11
12         $body = join("",get_source($page));
13         $body = convert_html($body);
14
15         header_lastmod($vars["page"]);
16         catbody($title,$pg,$body);
17         die();
18 }
19
20 // ËÜʸ¤ò½ÐÎÏ
21 function catbody($title,$page,$body)
22 {
23         global $script,$vars,$arg,$do_backup,$modifier,$modifierlink,$defaultpage,$whatsnew,$hr;
24         global $date_format,$weeklabels,$time_format,$longtaketime,$related_link;
25         global $HTTP_SERVER_VARS,$cantedit;
26
27         if($vars["page"] && !arg_check("backup") && $vars["page"] != $whatsnew)
28         {
29                 $is_page = 1;
30         }
31
32         $link_add = "$script?cmd=add&amp;page=".rawurlencode($vars["page"]);
33         $link_edit = "$script?cmd=edit&amp;page=".rawurlencode($vars["page"]);
34         $link_diff = "$script?cmd=diff&amp;page=".rawurlencode($vars["page"]);
35         $link_top = "$script?$defaultpage";
36         $link_list = "$script?cmd=list";
37         $link_filelist = "$script?cmd=filelist";
38         $link_search = "$script?cmd=search";
39         $link_whatsnew = "$script?$whatsnew";
40         $link_backup = "$script?cmd=backup&amp;page=".rawurlencode($vars["page"]);
41         $link_help = "$script?cmd=help";
42
43         if(is_page($vars["page"]) && $is_page)
44         {
45                 $fmt = @filemtime(get_filename(encode($vars["page"])));
46         }
47
48         if(is_page($vars["page"]) && $related_link && $is_page && !arg_check("edit") && !arg_check("freeze") && !arg_check("unfreeze"))
49         {
50                 $related = make_related($vars["page"],FALSE);
51         }
52
53         if(is_page($vars["page"]) && !in_array($vars["page"],$cantedit) && !arg_check("backup") && !arg_check("edit") && !$vars["preview"])
54         {
55                 $is_read = TRUE;
56         }
57
58         //if(!$longtaketime)
59                 $longtaketime = getmicrotime() - MUTIME;
60         $taketime = sprintf("%01.03f",$longtaketime);
61
62         require(SKIN_FILE);
63 }
64
65 // ¥Æ¥­¥¹¥ÈËÜÂΤòHTML¤ËÊÑ´¹¤¹¤ë
66 function convert_html($string)
67 {
68         global $result,$saved,$hr,$script,$page,$vars,$top;
69         global $note_id,$foot_explain,$digest,$note_hr;
70         global $user_rules,$str_rules,$line_rules,$strip_link_wall;
71         global $InterWikiName, $BracketName;
72
73         global $longtaketime;
74
75         $string = rtrim($string);
76         $string = preg_replace("/((\x0D\x0A)|(\x0D)|(\x0A))/","\n",$string);
77
78         $start_mtime = getmicrotime();
79
80         $digest = md5(@join("",get_source($vars["page"])));
81
82         $content_id = 0;
83         $user_rules = array_merge($str_rules,$line_rules);
84
85         $result = array();
86         $saved = array();
87         $arycontents = array();
88
89         $string = preg_replace("/^#freeze\n/","",$string);
90
91         $lines = split("\n", $string);
92         $note_id = 1;
93         $foot_explain = array();
94         // ³Æ¹Ô¤Î¹ÔƬ½ñ¼°¤ò³ÊǼ
95         $headform = array();
96         // ¸½ºß¤Î¹Ô¿ô¤òÆþ¤ì¤Æ¤ª¤³¤¦
97         $_cnt = 0;
98         // ¥Ö¥í¥Ã¥¯¤ÎȽÄê¥Õ¥é¥°
99         $_p = FALSE;
100         $_bq = FALSE;
101
102         $table = 0;
103
104         if(preg_match("/#contents/",$string))
105                 $top_link = "<a href=\"#contents\">$top</a>";
106
107         foreach ($lines as $line)
108         {
109                 if(!preg_match("/^\/\/(.*)/",$line,$comment_out) && $table != 0)
110                 {
111                         if(!preg_match("/^\|(.+)\|$/",$line,$out))
112                                 array_push($result, "</table></div>");
113                         if(!$out[1] || $table != count(explode("|",$out[1])))
114                                 $table = 0;
115                 }
116
117                 $comment_out = $comment_out[1];
118
119                 // ¹ÔƬ½ñ¼°¤«¤É¤¦¤«¤ÎȽÄê
120                 $line_head = substr($line,0,1);
121                 if(     $line_head == ' ' || 
122                         $line_head == ':' || 
123                         $line_head == '>' || 
124                         $line_head == '-' || 
125                         $line_head == '+' || 
126                         $line_head == '|' || 
127                         $line_head == '*' || 
128                         $line_head == '#' || 
129                         $line_head == '/'
130                 ) {
131                         if($headform[$_cnt-1] == '' && $_p){
132                                 array_push($result, "</p>");
133                                 $_p = FALSE;
134                         }
135                         if($line_head != '>' && $_bq){
136                                 array_push($result, "</p>");
137                                 $_bq = FALSE;
138                         }
139
140                         if(preg_match("/^\#([^\(]+)(.*)$/",$line,$out)){
141                                 if(exist_plugin_convert($out[1])) {
142                                         $result = array_merge($result,$saved); $saved = array();
143                                         
144                                         if($out[2]) {
145                                                 $_plugin = preg_replace("/^\#([^\(]+)\((.*)\)$/ex","do_plugin_convert('$1','$2')",$line);
146                                         } else {
147                                                 $_plugin = preg_replace("/^\#([^\(]+)$/ex","do_plugin_convert('$1','$2')",$line);
148                                         }
149                                         // ÀèƬ¤Ë¶õÇò¤òÆþ¤ì¤ë¤³¤È¤Ë¤è¤ê¤È¤ê¤¢¤¨¤ºpre¤Î°·¤¤¤ÈƱÍͤËinline2¤ÎƯ¤­¤òÍÞ¤¨¤ë¡¢¤¦¡Á¤ó¡¢ÌµÃã¡£
150                                         array_push($result,"\t$_plugin");
151                                 } else {
152                                         array_push($result, htmlspecialchars($line));
153                                 }
154                         }
155                         else if(preg_match("/^(\*{1,3})(.*)/",$line,$out))
156                         {
157                                 $result = array_merge($result,$saved); $saved = array();
158                                 $headform[$_cnt] = $out[1];
159                                 $str = inline($out[2]);
160                                 
161                                 $level = strlen($out[1]) + 1;
162
163                                 array_push($result, "<h$level><a name=\"content:$content_id\"></a>$str $top_link</h$level>");
164                                 $arycontents[] = str_repeat("-",$level-1)."<a href=\"#content:$content_id\">".strip_htmltag(make_user_rules($str))."</a>\n";
165                                 $content_id++;
166                         }
167                         else if(preg_match("/^(-{1,4})(.*)/",$line,$out))
168                         {
169                                 $headform[$_cnt] = $out[1];
170                                 if(strlen($out[1]) == 4)
171                                 {
172                                         $result = array_merge($result,$saved); $saved = array();
173                                         array_push($result, $hr);
174                                 }
175                                 else
176                                 {
177                                         back_push('ul', strlen($out[1]));
178                                         array_push($result, '<li>' . inline($out[2]) . '</li>');
179                                 }
180                         }
181                         else if(preg_match("/^(\+{1,4})(.*)/",$line,$out))
182                         {
183                                 $headform[$_cnt] = $out[1];
184                                 back_push('ol', strlen($out[1]));
185                                 array_push($result, '<li>' . inline($out[2]) . '</li>');
186                         }
187                         else if (preg_match("/^:([^:]+):(.*)/",$line,$out))
188                         {
189                                 $headform[$_cnt] = ':'.$out[1].':';
190                                 back_push('dl', 1);
191                                 array_push($result, '<dt>' . inline($out[1]) . '</dt>', '<dd>' . inline($out[2]) . '</dd>');
192                         }
193                         else if(preg_match("/^(>{1,3})(.*)/",$line,$out))
194                         {
195                                 $headform[$_cnt] = $out[1];
196                                 back_push('blockquote', strlen($out[1]));
197                                 // ¤³¤³¤Î¤¢¤¿¤ê¤Ç¼«Á°¤Çback_push¤«¤±¤Æ¤ë´¶¤¸¡£ÌµÃã¶ìÃã¡Ä
198                                 if($headform[$_cnt-1] != $headform[$_cnt] ) {
199                                         if(!$_bq) {
200                                                 array_push($result, "<p class=\"quotation\">");
201                                                 $_bq = TRUE;
202                                         }
203                                         else if(substr($headform[$_cnt-1],0,1) == '>'){
204                                                 $_level_diff = abs( strlen($out[1]) - strlen($headform[$_cnt-1]) );
205                                                 if( $_level_diff == 1 ){
206                                                         $i = array_pop($result);
207                                                         array_push($result, "</p>");
208                                                         array_push($result,$i);
209                                                         array_push($result, "<p class=\"quotation\">");
210                                                         $_bq = TRUE;
211                                                 } else {
212                                                         $i = array();
213                                                         $i[] = array_pop($result);
214                                                         $i[] = array_pop($result);
215                                                         array_push($result, "</p>");
216                                                         $result = array_merge($result,$i);
217                                                         array_push($result, "<p class=\"quotation\">");
218                                                         $_bq = TRUE;
219                                                 }
220                                         }
221                                 }
222                                 array_push($result, ltrim(inline($out[2])));
223                         }
224                         else if(preg_match("/^(\s+.*)/",$line,$out))
225                         {
226                                 $headform[$_cnt] = ' ';
227                                 back_push('pre', 1);
228                                 array_push($result, htmlspecialchars($out[1],ENT_NOQUOTES));
229                         }
230                         else if(preg_match("/^\|(.+)\|$/",$line,$out))
231                         {
232                                 $headform[$_cnt] = '|';
233                                 $arytable = explode("|",$out[1]);
234
235                                 if(!$table)
236                                 {
237                                         $result = array_merge($result,$saved); $saved = array();
238                                         array_push($result,"<div class=\"ie5\"><table class=\"style_table\" cellspacing=\"1\" border=\"0\">");
239                                         $table = count($arytable);
240                                 }
241
242                                 array_push($result,"<tr>");
243                                 foreach($arytable as $td)
244                                 {
245                                         array_push($result,"<td class=\"style_td\">");
246                                         array_push($result,ltrim(inline($td)));
247                                         array_push($result,"</td>");
248                                 }
249                                 array_push($result,"</tr>");
250
251                         }
252                         else if(strlen($comment_out) != 0)
253                         {
254                                 $headform[$_cnt] = '//';
255                                 array_push($result," <!-- ".htmlspecialchars($comment_out)." -->");
256                         }
257
258                 } else {
259
260                         $headform[$_cnt] = '';
261                         if($headform[$_cnt-1] != $headform[$_cnt]){
262                                 if(array_values($saved)){
263                                         if( $_bq ){
264                                                 array_unshift($saved, "</p>");
265                                                 $_bq = FALSE;
266                                         }
267                                         $i = array_pop($saved);
268                                         array_push($saved,$i);
269                                         $result = array_merge($result,$saved); $saved = array();
270                                 }
271                                 if( substr($line,0,1) == '' && !$_p){
272                                         array_push($result, "<p>");
273                                         $_p = TRUE;
274                                 }
275                                 else if( substr($line,0,1) != '' && $_p){
276                                         array_push($result, "</p>");
277                                         $_p = FALSE;
278                                 }
279                         }
280                         
281                         if( substr($line,0,1) == '' && $_p){
282                                 $_tmp = array_pop($result);
283                                 if($_tmp == "<p>") {
284                                         $_tmp = '<p class="empty">';
285                                 }
286                                 array_push($result, $_tmp, "</p>");
287                                 $_p = FALSE;
288                         }
289                         else if( substr($line,0,1) != '' && !$_p) {
290                                 array_push($result, "<p>");
291                                 $_p = TRUE;
292                         }
293                         if( substr($line,0,1) != '' ){
294                                 array_push($result, inline($line));
295                         }
296
297                 }
298
299                 $_cnt++;
300         }
301
302         if($_p) array_push($result, "</p>");
303         if($_bq) {
304                 array_push($result, "</p>");
305                 array_push($result, "</blockquote>");
306                 $saved = array();
307         }
308         if($table) array_push($result, "</table></div>");
309         
310         $result_last = $result = array_merge($result,$saved); $saved = array();
311
312         if($content_id != 0)
313         {
314                 $result = array();
315                 $saved = array();
316
317                 foreach($arycontents as $line)
318                 {
319                         if(preg_match("/^(-{1,3})(.*)/",$line,$out))
320                         {
321                                 back_push('ul', strlen($out[1]));
322                                 array_push($result, '<li>'.$out[2].'</li>');
323                         }
324                 }
325                 $result = array_merge($result,$saved); $saved = array();
326                 
327                 $contents = "<a name=\"contents\"></a>\n";
328                 $contents .= join("\n",$result);
329                 if($strip_link_wall)
330                 {
331                         $contents = preg_replace("/\[\[([^\]:]+):(.+)\]\]/","$1",$contents);
332                         $contents = preg_replace("/\[\[([^\]]+)\]\]/","$1",$contents);
333                 }
334         }
335
336         $result_last = inline2($result_last);
337         
338         $result_last = preg_replace("/^#contents/",$contents,$result_last);
339
340         $str = join("\n", $result_last);
341
342         if($foot_explain)
343         {
344                 $str .= "\n";
345                 $str .= "$note_hr\n";
346                 $str .= join("\n",inline2($foot_explain));
347         }
348
349         $longtaketime = getmicrotime() - $start_mtime;
350
351 #       $str = preg_replace("/&((amp)|(quot)|(nbsp)|(lt)|(gt));/","&$1;",$str);
352
353         return $str;
354 }
355
356 // $tag¤Î¥¿¥°¤ò$level¥ì¥Ù¥ë¤Þ¤ÇµÍ¤á¤ë¡£
357 function back_push($tag, $level)
358 {
359         global $result,$saved;
360         
361         while (count($saved) > $level) {
362                 array_push($result, array_shift($saved));
363         }
364         if ($saved[0] != "</$tag>") {
365                 $result = array_merge($result,$saved); $saved = array();
366         }
367         while (count($saved) < $level) {
368                 array_unshift($saved, "</$tag>");
369                 array_push($result, "<$tag>");
370         }
371 }
372
373 // ¥¤¥ó¥é¥¤¥óÍ×ÁǤΥѡ¼¥¹ (Ãí¼á)
374 function inline($line)
375 {
376         $line = htmlspecialchars($line);
377
378         $line = preg_replace("/\(\(((?:(?!\)\)).)*)\)\)/ex","make_note(\"$1\")",$line);
379
380         return $line;
381 }
382
383 // ¥¤¥ó¥é¥¤¥óÍ×ÁǤΥѡ¼¥¹ (¥ê¥ó¥¯¡¢´ØÏ¢°ìÍ÷¡¢¸«½Ð¤·°ìÍ÷)
384 function inline2($str)
385 {
386         global $WikiName,$BracketName,$InterWikiName,$vars,$related,$related_link,$script;
387         $cnts_plain = array();
388         $arykeep = array();
389
390         for($cnt=0;$cnt<count($str);$cnt++)
391         {
392                 if(preg_match("/^(\s)/",$str[$cnt]))
393                 {
394                         $arykeep[$cnt] = $str[$cnt];
395                         $str[$cnt] = "";
396                         $cnts_plain[] = $cnt;
397                 }
398         }
399
400         $str = preg_replace("/
401                 (
402                         (\[\[([^\]]+)\:(https?|ftp|news)(:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)\]\])
403                         |
404                         (\[(https?|ftp|news)(:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)\s([^\]]+)\])
405                         |
406                         (https?|ftp|news)(:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)
407                         |
408                         ([[:alnum:]\-_.]+@[[:alnum:]\-_]+\.[[:alnum:]\-_\.]+)
409                         |
410                         (\[\[([^\]]+)\:([[:alnum:]\-_.]+@[[:alnum:]\-_]+\.[[:alnum:]\-_\.]+)\]\])
411                         |
412                         ($InterWikiName)
413                         |
414                         ($BracketName)
415                         |
416                         ($WikiName)
417                 )/ex","make_link('$1')",$str);
418
419         $str = preg_replace("/#related/",make_related($vars["page"],TRUE),$str);
420
421         $str = make_user_rules($str);
422
423         $tmp = $str;
424         $str = preg_replace("/^#norelated$/","",$str);
425         if($tmp != $str)
426                 $related_link = 0;
427
428         foreach($cnts_plain as $cnt)
429                 $str[$cnt] = $arykeep[$cnt];
430
431         return $str;
432 }
433
434 // °ìÍ÷¤Î¼èÆÀ
435 function get_list($withfilename)
436 {
437         global $script,$list_index,$top,$non_list,$whatsnew;
438         global $_msg_symbol,$_msg_other;
439         
440         $retval = array();
441         $files = get_existpages();
442         foreach($files as $page) {
443                 if(preg_match("/$non_list/",$page) && !$withfilename) continue;
444                 if($page == $whatsnew) continue;
445                 $page_url = rawurlencode($page);
446                 $page2 = strip_bracket($page);
447                 $pg_passage = get_pg_passage($page);
448                 $file = encode($page).".txt";
449                 $retval[$page2] .= "<li><a href=\"$script?$page_url\">".htmlspecialchars($page2,ENT_QUOTES)."</a>$pg_passage</li>\n";
450                 if($withfilename)
451                 {
452                         $retval[$page2] .= "<ul><li>$file</li></ul>\n";
453                 }
454         }
455         
456         $retval = list_sort($retval);
457         
458         if($list_index)
459         {
460                 $head_str = "";
461                 $etc_sw = 0;
462                 $symbol_sw = 0;
463                 $top_link = "";
464                 $link_counter = 0;
465                 foreach($retval as $page => $link)
466                 {
467                         $head = substr($page,0,1);
468                         if($head_str != $head && !$etc_sw)
469                         {
470                                 $retval2[$page] = "";
471                                 
472                                 if(preg_match("/([A-Z])|([a-z])/",$head,$match))
473                                 {
474                                         if($match[1])
475                                                 $head_nm = "High:$head";
476                                         else
477                                                 $head_nm = "Low:$head";
478                                         
479                                         if($head_str) $retval2[$page] = "</ul>\n";
480                                         $retval2[$page] .= "<li><a href=\"#top:$head_nm\" name=\"$head_nm\"><strong>$head</strong></a></li>\n<ul>\n";
481                                         $head_str = $head;
482                                         if($link_counter) $top_link .= "|";
483                                         $link_counter = $link_counter + 1;
484                                         $top_link .= "<a href=\"#$head_nm\" name=\"top:$head_nm\"><strong>&nbsp;".$head."&nbsp;</strong></a>";
485                                         if($link_counter==16) {
486                                                 $top_link .= "<br />";
487                                                 $link_counter = 0;
488                                         }
489                                 }
490                                 else if(preg_match("/[ -~]/",$head))
491                                 {
492                                         if(!$symbol_sw)
493                                         {
494                                                 if($head_str) $retval2[$page] = "</ul>\n";
495                                                 $retval2[$page] .= "<li><a href=\"#top:symbol\" name=\"symbol\"><strong>$_msg_symbol</strong></a></li>\n<ul>\n";
496                                                 $head_str = $head;
497                                                 if($link_counter) $top_link .= "|";
498                                                 $link_counter = $link_counter + 1;
499                                                 $top_link .= "<a href=\"#symbol\" name=\"top:symbol\"><strong>$_msg_symbol</strong></a>";
500                                                 $symbol_sw = 1;
501                                         }
502                                 }
503                                 else
504                                 {
505                                         if($head_str) $retval2[$page] = "</ul>\n";
506                                         $retval2[$page] .= "<li><a href=\"#top:etc\" name=\"etc\"><strong>$_msg_other</strong></a></li>\n<ul>\n";
507                                         $etc_sw = 1;
508                                         if($link_counter) $top_link .= "|";
509                                         $link_counter = $link_counter + 1;
510                                         $top_link .= "<a href=\"#etc\" name=\"top:etc\"><strong>$_msg_other</strong></a>";
511                                 }
512                         }
513                         $retval2[$page] .= $link;
514                 }
515                 $retval2[] = "</ul>\n";
516                 
517                 $top_link = "<div style=\"text-align:center\"><a name=\"top\">$top_link</a></div><br />\n";
518                 
519                 array_unshift($retval2,$top_link);
520         }
521         else
522         {
523                 $retval2 = $retval;
524         }
525         
526         return join("",$retval2);
527 }
528
529 // ÊÔ½¸¥Õ¥©¡¼¥à¤Îɽ¼¨
530 function edit_form($postdata,$page,$add=0)
531 {
532         global $script,$rows,$cols,$hr,$vars,$function_freeze;
533         global $_btn_addtop,$_btn_preview,$_btn_update,$_btn_freeze,$_msg_help,$_btn_notchangetimestamp;
534         global $whatsnew,$_btn_template,$_btn_load,$non_list,$load_template_func;
535
536         $digest = md5(@join("",get_source($page)));
537
538         if($add)
539         {
540                 $addtag = '<input type="hidden" name="add" value="true" />';
541                 $add_top = '<input type="checkbox" name="add_top" value="true" /><span class="small">'.$_btn_addtop.'</span>';
542         }
543
544         if($vars["help"] == "true")
545                 $help = $hr.catrule();
546         else
547                 $help = "<br />\n<ul><li><a href=\"$script?cmd=edit&amp;help=true&amp;page=".rawurlencode($page)."\">$_msg_help</a></ul></li>\n";
548
549         if($function_freeze)
550                 $str_freeze = '<input type="submit" name="freeze" value="'.$_btn_freeze.'" accesskey="f" />';
551
552         if($load_template_func)
553         {
554                 $vals = array();
555
556                 $files = get_existpages();
557                 foreach($files as $pg_org) {
558                         if($pg_org == $whatsnew) continue;
559                         if(preg_match("/$non_list/",$pg_org)) continue;
560                         $name = strip_bracket($pg_org);
561                         $vals[$name] = "    <option value=\"$pg_org\">$name</option>";
562                 }
563                 @ksort($vals);
564                 
565                 $template = "   <select name=\"template_page\">\n"
566                            ."    <option value=\"\">-- $_btn_template --</option>\n"
567                            .join("\n",$vals)
568                            ."   </select>\n"
569                            ."   <input type=\"submit\" name=\"template\" value=\"$_btn_load\" accesskey=\"r\" /><br />\n";
570
571                 if($vars["refer"]) $refer = $vars["refer"]."\n\n";
572         }
573
574 return '
575 <form action="'.$script.'" method="post">
576 '.$addtag.'
577 <table cellspacing="3" cellpadding="0" border="0">
578  <tr>
579   <td align="right">
580 '.$template.'
581   </td>
582  </tr>
583  <tr>
584   <td align="right">
585    <input type="hidden" name="page" value="'.htmlspecialchars($page).'" />
586    <input type="hidden" name="digest" value="'.htmlspecialchars($digest).'" />
587    <textarea name="msg" rows="'.$rows.'" cols="'.$cols.'" wrap="virtual">
588 '.htmlspecialchars($refer.$postdata).'</textarea>
589   </td>
590  </tr>
591  <tr>
592   <td>
593    <input type="submit" name="preview" value="'.$_btn_preview.'" accesskey="p" />
594    <input type="submit" name="write" value="'.$_btn_update.'" accesskey="s" />
595    '.$add_top.'
596    <input type="checkbox" name="notimestamp" value="true" /><span style="small">'.$_btn_notchangetimestamp.'</span>
597   </td>
598  </tr>
599 </table>
600 </form>
601
602 <form action="'.$script.'?cmd=freeze" method="post">
603 <div>
604 <input type="hidden" name="page" value="'.htmlspecialchars($vars["page"]).'" />
605 '.$str_freeze.'
606 </div>
607 </form>
608
609 ' . $help;
610 }
611
612 // ´ØÏ¢¤¹¤ë¥Ú¡¼¥¸
613 function make_related($page,$_isrule)
614 {
615         global $related_str,$rule_related_str,$related,$_make_related,$vars;
616
617         $page_name = strip_bracket($vars["page"]);
618
619         if(!is_array($_make_related))
620         {
621                 $aryrelated = do_search($page,"OR",1);
622
623                 if(is_array($aryrelated))
624                 {
625                         foreach($aryrelated as $key => $val)
626                         {
627                                 $new_arylerated[$key.md5($val)] = $val;
628                         }
629                 }
630
631                 if(is_array($related))
632                 {
633                         foreach($related as $key => $val)
634                         {
635                                 $new_arylerated[$key.md5($val)] = $val;
636                         }
637                 }
638
639                 @krsort($new_arylerated);
640                 $_make_related = @array_unique($new_arylerated);
641         }
642
643         if($_isrule)
644         {
645                 if(is_array($_make_related))
646                 {
647                         foreach($_make_related as $str)
648                         {
649                                 preg_match("/<a\shref=\"([^\"]+)\">([^<]+)<\/a>(.*)/",$str,$out);
650                                 
651                                 if($out[3]) $title = " title=\"$out[2] $out[3]\"";
652                                 
653                                 $aryret[$out[2]] = "<a href=\"$out[1]\"$title>$out[2]</a>";
654                         }
655                         @ksort($aryret);
656                 }
657         }
658         else
659         {
660                 $aryret = $_make_related;
661         }
662
663         if($_isrule) $str = $rule_related_str;
664         else         $str = $related_str;
665
666         return @join($str,$aryret);
667 }
668
669 // Ãí¼á½èÍý
670 function make_note($str)
671 {
672         global $note_id,$foot_explain;
673
674         $str = preg_replace("/^\(\(/","",$str);
675         $str = preg_replace("/\)\)$/","",$str);
676
677         $str= str_replace("\\'","'",$str);
678
679         $str = make_user_rules($str);
680
681         $foot_explain[] = "<a name=\"notefoot:$note_id\" href=\"#notetext:$note_id\" class=\"note_super\">*$note_id</a> <span class=\"small\">$str</span><br />\n";
682         $note =  "<a name=\"notetext:$note_id\" href=\"#notefoot:$note_id\" class=\"note_super\">*$note_id</a>";
683         $note_id++;
684
685         return $note;
686 }
687
688 // ¥ê¥ó¥¯¤òÉղ乤ë
689 function make_link($name)
690 {
691         global $BracketName,$WikiName,$InterWikiName,$InterWikiNameNoBracket,$script,$link_target,$interwiki_target;
692         global $related,$show_passage,$vars,$defaultpage;
693
694         $aryconv_htmlspecial = array("&amp;","&lt;","&gt;");
695         $aryconv_html = array("&","<",">");
696
697         $page = $name;
698
699         if(preg_match("/^\[\[([^\]]+)\:((https?|ftp|news)([^\]]+))\]\]$/",$name,$match))
700         {
701                 return "<a href=\"$match[2]\" target=\"$link_target\">$match[1]</a>";
702         }
703         else if(preg_match("/^\[((https?|ftp|news)([^\]\s]+))\s([^\]]+)\]$/",$name,$match))
704         {
705                 return "<a href=\"$match[1]\" target=\"$link_target\">$match[4]</a>";
706         }
707         else if(preg_match("/^(https?|ftp|news).*?(\.gif|\.png|\.jpeg|\.jpg)?$/",$name,$match))
708         {
709                 if($match[2])
710                         return "<a href=\"$name\" target=\"$link_target\"><img src=\"$name\" border=\"0\"></a>";
711                 else
712                         return "<a href=\"$name\" target=\"$link_target\">$page</a>";
713         }
714         else if(preg_match("/^\[\[([^\]]+)\:([[:alnum:]\-_.]+@[[:alnum:]\-_]+\.[[:alnum:]\-_\.]+)\]\]/",$name,$match))
715         {
716                 return "<a href=\"mailto:$match[2]\">$match[1]</a>";
717         }
718         else if(preg_match("/^([[:alnum:]\-_]+@[[:alnum:]\-_]+\.[[:alnum:]\-_\.]+)/",$name))
719         {
720                 return "<a href=\"mailto:$name\">$page</a>";
721         }
722         else if(preg_match("/^(.+?)&gt;($InterWikiNameNoBracket)$/",strip_bracket($name),$match))
723         {
724                 $page = $match[1];
725                 $name = '[['.$match[2].']]';
726                 $percent_name = str_replace($aryconv_htmlspecial,$aryconv_html,$name);
727                 $percent_name = rawurlencode($percent_name);
728
729                 return "<a href=\"$script?$percent_name\" target=\"$interwiki_target\">$page</a>";
730         }
731         else if(preg_match("/^($InterWikiName)$/",$name))
732         {
733                 $page = strip_bracket($page);
734                 $percent_name = str_replace($aryconv_htmlspecial,$aryconv_html,$name);
735                 $percent_name = rawurlencode($percent_name);
736
737                 return "<a href=\"$script?$percent_name\" target=\"$interwiki_target\">$page</a>";
738         }
739         else if(preg_match("/^($BracketName)|($WikiName)$/",$name))
740         {
741                 if(preg_match("/^(.+?)&gt;(.+)$/",strip_bracket($name),$match))
742                 {
743
744                         $page = $match[1];
745                         $name = $match[2];
746                         if(!preg_match("/^($BracketName)|($WikiName)$/",$page))
747                                 $page = "[[$page]]";
748                         if(!preg_match("/^($BracketName)|($WikiName)$/",$name))
749                                 $name = "[[$name]]";
750                 }
751                 if(preg_match("/^\[\[\.\/([^\]]*)\]\]/",$name,$match))
752                 {
753                         if(!$match[1])
754                                 $name = $vars["page"];
755                         else
756                                 $name = "[[".strip_bracket($vars["page"])."/$match[1]]]";
757                 }
758                 else if(preg_match("/^\[\[\..\/([^\]]+)\]\]/",$name,$match))
759                 {
760                         for($i=0;$i<substr_count($name,"../");$i++)
761                                 $name = preg_replace("/(.+)\/([^\/]+)$/","$1",strip_bracket($vars["page"]));
762
763                         if(!preg_match("/^($BracketName)|($WikiName)$/",$name))
764                                 $name = "[[$name]]";
765                         
766                         if($vars["page"]==$name)
767                                 $name = "[[$match[1]]]";
768                         else
769                                 $name = "[[".strip_bracket($name)."/$match[1]]]";
770                 }
771                 else if($name == "[[../]]")
772                 {
773                         $name = preg_replace("/(.+)\/([^\/]+)$/","$1",strip_bracket($vars["page"]));
774                         
775                         if(!preg_match("/^($BracketName)|($WikiName)$/",$name))
776                                 $name = "[[$name]]";
777                         if($vars["page"]==$name)
778                                 $name = $defaultpage;
779                 }
780                 
781                 $page = strip_bracket($page);
782                 $pagename = htmlspecialchars(strip_bracket($name));
783                 $percent_name = str_replace($aryconv_htmlspecial,$aryconv_html,$name);
784                 $percent_name = rawurlencode($percent_name);
785
786                 $refer = rawurlencode($vars["page"]);
787                 if(is_page($name))
788                 {
789                         $str = get_pg_passage($name,FALSE);
790                         $tm = @filemtime(get_filename(encode($name)));
791                         if($vars["page"] != $name)
792                                 $related[$tm] = "<a href=\"$script?$percent_name\">$pagename</a>$str";
793                         if($show_passage)
794                         {
795                                 $str_title = "title=\"$pagename $str\"";
796                         }
797                         return "<a href=\"$script?$percent_name\" $str_title>$page</a>";
798                 }
799                 else
800                         return "<span class=\"noexists\">$page<a href=\"$script?cmd=edit&amp;page=$percent_name&amp;refer=$refer\">?</a></span>";
801         }
802         else
803         {
804                 return $page;
805         }
806 }
807
808 // ¥æ¡¼¥¶ÄêµÁ¥ë¡¼¥ë(¥½¡¼¥¹¤òÃÖ´¹¤¹¤ë)
809 function user_rules_str($str)
810 {
811         global $str_rules;
812
813         $arystr = split("\n",$str);
814
815         // ÆüÉÕ¡¦»þ¹ïÃÖ´¹½èÍý
816         foreach($arystr as $str)
817         {
818                 if(substr($str,0,1) != " ")
819                 {
820                         foreach($str_rules as $rule => $replace)
821                         {
822                                 $str = preg_replace("/$rule/",$replace,$str);
823                         }
824                 }
825                 $retvars[] = $str;
826         }
827
828         return join("\n",$retvars);
829 }
830
831 // ¥æ¡¼¥¶ÄêµÁ¥ë¡¼¥ë(¥½¡¼¥¹¤ÏÃÖ´¹¤»¤º¥³¥ó¥Ð¡¼¥È)
832 function make_user_rules($str)
833 {
834         global $user_rules;
835
836         foreach($user_rules as $rule => $replace)
837         {
838                 $str = preg_replace("/$rule/",$replace,$str);
839         }
840
841         return $str;
842 }
843
844 // HTML¥¿¥°¤ò¼è¤ê½ü¤¯
845 function strip_htmltag($str)
846 {
847         //$str = preg_replace("/<a[^>]+>\?<\/a>/","",$str);
848         return preg_replace("/<[^>]+>/","",$str);
849 }
850
851 // ¥Ú¡¼¥¸Ì¾¤«¤é¥Ú¡¼¥¸Ì¾¤ò¸¡º÷¤¹¤ë¥ê¥ó¥¯¤òºîÀ®
852 function make_search($page)
853 {
854         global $script,$WikiName;
855
856         $name = strip_bracket($page);
857         $url = rawurlencode($page);
858
859         //WikiWikiWeb like...
860         //if(preg_match("/^$WikiName$/",$page))
861         //      $name = preg_replace("/([A-Z][a-z]+)/","$1 ",$name);
862
863         return "<a href=\"$script?cmd=search&amp;word=$url\">".htmlspecialchars($name)."</a> ";
864 }
865
866 ?>