OSDN Git Service

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