OSDN Git Service

Moved face images from face/ to image/face. default.ini.php shows bracketted alt...
[pukiwiki/pukiwiki.git] / html.php
1 <?php
2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
4 //
5 // $Id: html.php,v 1.100 2004/06/27 11:37:00 henoheno Exp $
6 //
7
8 // ËÜʸ¤ò½ÐÎÏ
9 function catbody($title,$page,$body)
10 {
11         global $script,$vars,$arg,$defaultpage,$whatsnew,$help_page,$hr;
12         global $related_link,$cantedit,$function_freeze,$search_word_color,$_msg_word;
13         global $foot_explain,$note_hr,$head_tags;
14         
15         global $html_transitional; // FALSE:XHTML1.1 TRUE:XHTML1.0 Transitional
16         global $page_title;        // ¥Û¡¼¥à¥Ú¡¼¥¸¤Î¥¿¥¤¥È¥ë
17         global $do_backup;         // ¥Ð¥Ã¥¯¥¢¥Ã¥×¤ò¹Ô¤¦¤«¤É¤¦¤«
18         global $modifier;          // ÊÔ½¸¼Ô¤Î¥Û¡¼¥à¥Ú¡¼¥¸
19         global $modifierlink;      // ÊÔ½¸¼Ô¤Î̾Á°
20
21         $_page = $vars['page'];
22         $r_page = rawurlencode($_page);
23         
24         $link_add      = "$script?cmd=add&amp;page=$r_page";
25         $link_edit     = "$script?cmd=edit&amp;page=$r_page";
26         $link_diff     = "$script?cmd=diff&amp;page=$r_page";
27         $link_top      = "$script?".rawurlencode($defaultpage);
28         $link_list     = "$script?cmd=list";
29         $link_filelist = "$script?cmd=filelist";
30         $link_search   = "$script?cmd=search";
31         $link_whatsnew = "$script?".rawurlencode($whatsnew);
32         $link_backup   = "$script?cmd=backup&amp;page=$r_page";
33         $link_help     = "$script?".rawurlencode($help_page);
34         $link_rss      = "$script?cmd=rss10";
35         $link_freeze   = "$script?cmd=freeze&amp;page=$r_page";
36         $link_unfreeze = "$script?cmd=unfreeze&amp;page=$r_page";
37         $link_upload   = "$script?plugin=attach&amp;pcmd=upload&amp;page=$r_page";
38         $link_template = "$script?plugin=template&amp;refer=$r_page";
39         $link_rename   = "$script?plugin=rename&amp;refer=$r_page";
40         
41         // ¥Ú¡¼¥¸¤Îɽ¼¨»þTRUE(¥Ð¥Ã¥¯¥¢¥Ã¥×¤Îɽ¼¨¡¢RecentChanges¤Îɽ¼¨¤ò½ü¤¯)
42         $is_page = (is_pagename($_page) and !arg_check('backup') and $_page != $whatsnew);
43         
44         // ¥Ú¡¼¥¸¤ÎÆɤ߽Ф·»þTRUE
45         $is_read = (arg_check('read') and is_page($_page));
46         
47         // ¥Ú¡¼¥¸¤¬Åà·ë¤µ¤ì¤Æ¤¤¤ë¤È¤­TRUE
48         $is_freeze = is_freeze($_page);
49         
50         // ¥Ú¡¼¥¸¤ÎºÇ½ª¹¹¿·»þ¹ï(ʸ»úÎó)
51         $lastmodified = $is_read ?
52                 get_date('D, d M Y H:i:s T',get_filetime($_page)).' '.get_pg_passage($_page,FALSE) : '';
53         
54         // ´ØÏ¢¤¹¤ë¥Ú¡¼¥¸¤Î¥ê¥¹¥È
55         $related = ($is_read and $related_link) ? make_related($_page) : '';
56         
57         // ÅºÉÕ¥Õ¥¡¥¤¥ë¤Î¥ê¥¹¥È
58         $attaches = ($is_read and exist_plugin_action('attach')) ? attach_filelist() : '';
59         
60         // Ãí¼á¤Î¥ê¥¹¥È
61         ksort($foot_explain,SORT_NUMERIC);
62         $notes = count($foot_explain) ? $note_hr.join("\n",$foot_explain) : '';
63         
64         // <head>Æâ¤ËÄɲ乤륿¥°
65         $head_tag = count($head_tags) ? join("\n",$head_tags)."\n" : '';
66         
67         // 1.3.x compat
68         // ¥Ú¡¼¥¸¤ÎºÇ½ª¹¹¿·»þ¹ï(UNIX timestamp)
69         $fmt = $is_read ? get_filetime($_page) + LOCALZONE : 0;
70
71         //ñ¸ì¸¡º÷
72         if ($search_word_color and array_key_exists('word',$vars))
73         {
74                 $body = '<div class="small">'.$_msg_word.htmlspecialchars($vars['word'])."</div>$hr\n$body";
75                 $words = array_flip(array_splice(preg_split('/\s+/',$vars['word'],-1,PREG_SPLIT_NO_EMPTY),0,10));
76                 $keys = array();
77                 foreach ($words as $word=>$id)
78                 {
79                         $keys[$word] = strlen($word);
80                 }
81                 arsort($keys,SORT_NUMERIC);
82                 $keys = get_search_words(array_keys($keys),TRUE);
83                 $id = 0;
84                 foreach ($keys as $key=>$pattern)
85                 {
86                         $s_key = htmlspecialchars($key);
87                         $pattern = "/<[^>]*>|($pattern)|&[^;]+;/";
88                         $callback = create_function(
89                                 '$arr',
90                                 'return (count($arr) > 1) ? "<strong class=\"word'.$id++.'\">{$arr[1]}</strong>" : $arr[0];'
91                         );
92                         $body = preg_replace_callback($pattern,$callback,$body);
93                         $notes = preg_replace_callback($pattern,$callback,$notes);
94                 }
95         }
96         
97         $longtaketime = getmicrotime() - MUTIME;
98         $taketime = sprintf('%01.03f',$longtaketime);
99         
100         if (!file_exists(SKIN_FILE)||!is_readable(SKIN_FILE))
101         {
102                 die_message(SKIN_FILE.'(skin file) is not found.');
103         }
104         require(SKIN_FILE);
105 }
106
107 // ¥¤¥ó¥é¥¤¥óÍ×ÁǤΥѡ¼¥¹ (obsolete)
108 function inline($line,$remove=FALSE)
109 {
110         global $NotePattern;
111         
112         $line = htmlspecialchars($line);
113         if ($remove)
114         {
115                 $line = preg_replace($NotePattern,'',$line);
116         }
117         return $line;
118 }
119
120 // ¥¤¥ó¥é¥¤¥óÍ×ÁǤΥѡ¼¥¹ (¥ê¥ó¥¯¡¢¸«½Ð¤·°ìÍ÷) (obsolete)
121 function inline2($str)
122 {
123         return make_link($str);
124 }
125
126 // ÊÔ½¸¥Õ¥©¡¼¥à¤Îɽ¼¨
127 function edit_form($page,$postdata,$digest = 0,$b_template = TRUE)
128 {
129         global $script,$vars,$rows,$cols,$hr,$function_freeze;
130         global $_btn_addtop,$_btn_preview,$_btn_repreview,$_btn_update,$_btn_freeze,$_msg_help,$_btn_notchangetimestamp;
131         global $whatsnew,$_btn_template,$_btn_load,$non_list,$load_template_func;
132         
133         $refer = $template = $addtag = $add_top = '';
134         
135         if ($digest == 0) {
136                 $digest = md5(join('',get_source($page)));
137         }
138         
139         $checked_top = array_key_exists('add_top',$vars) ? ' checked="checked"' : '';
140         $checked_time = array_key_exists('notimestamp',$vars) ? ' checked="checked"' : '';
141         
142         if(array_key_exists('add',$vars)) {
143                 $addtag = '<input type="hidden" name="add" value="true" />';
144                 $add_top = "<input type=\"checkbox\" name=\"add_top\" value=\"true\"$checked_top /><span class=\"small\">$_btn_addtop</span>";
145         }
146
147         if($load_template_func and $b_template) {
148                 $_pages = get_existpages();
149                 $pages = array();
150                 foreach($_pages as $_page) {
151                         if ($_page == $whatsnew or preg_match("/$non_list/",$_page)) {
152                                 continue;
153                         }
154                         $s_page = htmlspecialchars($_page);
155                         $pages[$_page] = "   <option value=\"$s_page\">$s_page</option>";
156                 }
157                 ksort($pages);
158                 $s_pages = join("\n",$pages);
159                 $template = <<<EOD
160   <select name="template_page">
161    <option value="">-- $_btn_template --</option>
162 $s_pages
163   </select>
164   <input type="submit" name="template" value="$_btn_load" accesskey="r" />
165   <br />
166 EOD;
167                 
168                 if (array_key_exists('refer',$vars) and $vars['refer'] != '') {
169                         $refer = '[['.strip_bracket($vars['refer'])."]]\n\n";
170                 }
171         }
172         
173         $r_page = rawurlencode($page);
174         $s_page = htmlspecialchars($page);
175         $s_digest = htmlspecialchars($digest);
176         $s_postdata = htmlspecialchars($refer.$postdata);
177         $s_original = array_key_exists('original',$vars) ? htmlspecialchars($vars['original']) : $s_postdata;
178         $b_preview = array_key_exists('preview',$vars); // ¥×¥ì¥Ó¥å¡¼ÃæTRUE
179         $btn_preview = $b_preview ? $_btn_repreview : $_btn_preview;
180         
181         $body = <<<EOD
182 <form action="$script" method="post">
183  <div class="edit_form">
184 $template
185   $addtag
186   <input type="hidden" name="cmd" value="edit" />
187   <input type="hidden" name="page" value="$s_page" />
188   <input type="hidden" name="digest" value="$s_digest" />
189   <textarea name="msg" rows="$rows" cols="$cols">$s_postdata</textarea>
190   <br />
191   <input type="submit" name="preview" value="$btn_preview" accesskey="p" />
192   <input type="submit" name="write" value="$_btn_update" accesskey="s" />
193   $add_top
194   <input type="checkbox" name="notimestamp" value="true"$checked_time />
195   <span style="small">$_btn_notchangetimestamp</span>
196   <textarea name="original" rows="1" cols="1" style="display:none">$s_original</textarea>
197  </div>
198 </form>
199 EOD;
200         
201         if (array_key_exists('help', $vars)) {
202                 $body .= $hr . catrule();
203         } else {
204                 $body .= 
205                 "<ul><li><a href=\"$script?cmd=edit&help=true&page=$r_page\">$_msg_help</a></li></ul>";
206         }
207         return $body;
208 }
209
210 // ´ØÏ¢¤¹¤ë¥Ú¡¼¥¸
211 function make_related($page,$tag='')
212 {
213         global $script,$vars,$related,$rule_related_str,$related_str,$non_list;
214         global $_ul_left_margin, $_ul_margin, $_list_pad_str;
215         
216         $links = links_get_related($page);
217         
218         if ($tag) {
219                 ksort($links);
220         }
221         else {
222                 arsort($links);
223         }
224         $_links = array();
225         foreach ($links as $page=>$lastmod)
226         {
227                 if (preg_match("/$non_list/",$page))
228                 {
229                         continue;
230                 }
231                 $r_page = rawurlencode($page);
232                 $s_page = htmlspecialchars($page);
233                 $passage = get_passage($lastmod);
234                 $_links[] = $tag ?
235                         "<a href=\"$script?$r_page\" title=\"$s_page $passage\">$s_page</a>" :
236                         "<a href=\"$script?$r_page\">$s_page</a>$passage";
237         }
238         
239         if (count($_links) == 0)
240         {
241                 return '';
242         }
243         
244         if ($tag == 'p') // ¹ÔƬ¤«¤é
245         {
246                 $margin = $_ul_left_margin + $_ul_margin;
247                 $style = sprintf($_list_pad_str,1,$margin,$margin);
248                 $retval =  "\n<ul$style>\n<li>".join($rule_related_str,$_links)."</li>\n</ul>\n";
249         }
250         else if ($tag)
251         {
252                 $retval = join($rule_related_str,$_links);
253         }
254         else
255         {
256                 $retval = join($related_str,$_links);
257         }
258         return $retval;
259 }
260
261 // ¥æ¡¼¥¶ÄêµÁ¥ë¡¼¥ë(¥½¡¼¥¹¤ÏÃÖ´¹¤»¤º¥³¥ó¥Ð¡¼¥È)
262 function make_line_rules($str)
263 {
264         global $line_rules;
265         static $pattern,$replace;
266         
267         if (!isset($pattern))
268         {
269                 $pattern = array_map(create_function('$a','return "/$a/";'),array_keys($line_rules));
270                 $replace = array_values($line_rules);
271                 unset($line_rules);
272         }
273         return preg_replace($pattern,$replace,$str);
274 }
275
276 // HTML¥¿¥°¤ò¼è¤ê½ü¤¯
277 function strip_htmltag($str)
278 {
279         global $_symbol_noexists;
280         
281         $noexists_pattern = '#<span class="noexists">([^<]*)<a[^>]+>'.
282                 preg_quote($_symbol_noexists,'#').
283                 '</a></span>#';
284         
285         $str = preg_replace($noexists_pattern,'$1',$str);
286         //$str = preg_replace('/<a[^>]+>\?<\/a>/','',$str);
287         return preg_replace('/<[^>]+>/','',$str);
288 }
289
290 // ¥Ú¡¼¥¸Ì¾¤«¤é¥Ú¡¼¥¸Ì¾¤ò¸¡º÷¤¹¤ë¥ê¥ó¥¯¤òºîÀ®
291 function make_search($page)
292 {
293         global $script,$WikiName;
294         
295         $s_page = htmlspecialchars($page);
296         $r_page = rawurlencode($page);
297         
298         //WikiWikiWeb like...
299         //if(preg_match("/^$WikiName$/",$page))
300         //      $name = preg_replace("/([A-Z][a-z]+)/","$1 ",$name);
301         
302         return "<a href=\"$script?cmd=search&amp;word=$r_page\">$s_page</a> ";
303 }
304
305 // ¸«½Ð¤·¤òÀ¸À® (Ãí¼á¤äHTML¥¿¥°¤ò½üµî)
306 function make_heading(&$str,$strip=TRUE)
307 {
308         global $NotePattern;
309         
310         // ¸«½Ð¤·¤Î¸ÇÍ­IDÉô¤òºï½ü
311         $id = '';
312         if (preg_match('/^(\*{0,3})(.*?)\[#([A-Za-z][\w-]+)\](.*?)$/m',$str,$matches))
313         {
314                 $str = $matches[2].$matches[4];
315                 $id = $matches[3];
316         }
317         else
318         {
319                 $str = preg_replace('/^\*{0,3}/','',$str);
320         }
321         if ($strip)
322         {
323                 $str = strip_htmltag(make_link(preg_replace($NotePattern,'',$str)));
324         } 
325         
326         return $id; 
327 }
328 ?>