2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
5 // $Id: html.php,v 1.1 2004/08/01 01:54:35 henoheno Exp $
9 function catbody($title,$page,$body)
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;
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; // ÊÔ½¸¼Ô¤Î̾Á°
21 $_page = $vars['page'];
22 $r_page = rawurlencode($_page);
24 $link_add = "$script?cmd=add&page=$r_page";
25 $link_edit = "$script?cmd=edit&page=$r_page";
26 $link_diff = "$script?cmd=diff&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&page=$r_page";
33 $link_help = "$script?".rawurlencode($help_page);
34 $link_rss = "$script?cmd=rss10";
35 $link_freeze = "$script?cmd=freeze&page=$r_page";
36 $link_unfreeze = "$script?cmd=unfreeze&page=$r_page";
37 $link_upload = "$script?plugin=attach&pcmd=upload&page=$r_page";
38 $link_template = "$script?plugin=template&refer=$r_page";
39 $link_rename = "$script?plugin=rename&refer=$r_page";
41 // ¥Ú¡¼¥¸¤Îɽ¼¨»þTRUE(¥Ð¥Ã¥¯¥¢¥Ã¥×¤Îɽ¼¨¡¢RecentChanges¤Îɽ¼¨¤ò½ü¤¯)
42 $is_page = (is_pagename($_page) and !arg_check('backup') and $_page != $whatsnew);
44 // ¥Ú¡¼¥¸¤ÎÆɤ߽Ф·»þTRUE
45 $is_read = (arg_check('read') and is_page($_page));
47 // ¥Ú¡¼¥¸¤¬Åà·ë¤µ¤ì¤Æ¤¤¤ë¤È¤TRUE
48 $is_freeze = is_freeze($_page);
50 // ¥Ú¡¼¥¸¤ÎºÇ½ª¹¹¿·»þ¹ï(ʸ»úÎó)
51 $lastmodified = $is_read ?
52 get_date('D, d M Y H:i:s T',get_filetime($_page)).' '.get_pg_passage($_page,FALSE) : '';
54 // ´ØÏ¢¤¹¤ë¥Ú¡¼¥¸¤Î¥ê¥¹¥È
55 $related = ($is_read and $related_link) ? make_related($_page) : '';
57 // źÉÕ¥Õ¥¡¥¤¥ë¤Î¥ê¥¹¥È
58 $attaches = ($is_read and exist_plugin_action('attach')) ? attach_filelist() : '';
61 ksort($foot_explain,SORT_NUMERIC);
62 $notes = count($foot_explain) ? $note_hr.join("\n",$foot_explain) : '';
64 // <head>Æâ¤ËÄɲ乤륿¥°
65 $head_tag = count($head_tags) ? join("\n",$head_tags)."\n" : '';
68 // ¥Ú¡¼¥¸¤ÎºÇ½ª¹¹¿·»þ¹ï(UNIX timestamp)
69 $fmt = $is_read ? get_filetime($_page) + LOCALZONE : 0;
72 if ($search_word_color and array_key_exists('word',$vars))
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));
77 foreach ($words as $word=>$id)
79 $keys[$word] = strlen($word);
81 arsort($keys,SORT_NUMERIC);
82 $keys = get_search_words(array_keys($keys),TRUE);
84 foreach ($keys as $key=>$pattern)
86 $s_key = htmlspecialchars($key);
87 $pattern = "/<[^>]*>|($pattern)|&[^;]+;/";
88 $callback = create_function(
90 'return (count($arr) > 1) ? "<strong class=\"word'.$id++.'\">{$arr[1]}</strong>" : $arr[0];'
92 $body = preg_replace_callback($pattern,$callback,$body);
93 $notes = preg_replace_callback($pattern,$callback,$notes);
97 $longtaketime = getmicrotime() - MUTIME;
98 $taketime = sprintf('%01.03f',$longtaketime);
100 if (!file_exists(SKIN_FILE)||!is_readable(SKIN_FILE))
102 die_message(SKIN_FILE.'(skin file) is not found.');
107 // ¥¤¥ó¥é¥¤¥óÍ×ÁǤΥѡ¼¥¹ (obsolete)
108 function inline($line,$remove=FALSE)
112 $line = htmlspecialchars($line);
115 $line = preg_replace($NotePattern,'',$line);
120 // ¥¤¥ó¥é¥¤¥óÍ×ÁǤΥѡ¼¥¹ (¥ê¥ó¥¯¡¢¸«½Ð¤·°ìÍ÷) (obsolete)
121 function inline2($str)
123 return make_link($str);
126 // ÊÔ½¸¥Õ¥©¡¼¥à¤Îɽ¼¨
127 function edit_form($page,$postdata,$digest = 0,$b_template = TRUE)
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;
133 $refer = $template = $addtag = $add_top = '';
136 $digest = md5(join('',get_source($page)));
139 $checked_top = array_key_exists('add_top',$vars) ? ' checked="checked"' : '';
140 $checked_time = array_key_exists('notimestamp',$vars) ? ' checked="checked"' : '';
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>";
147 if($load_template_func and $b_template) {
148 $_pages = get_existpages();
150 foreach($_pages as $_page) {
151 if ($_page == $whatsnew or preg_match("/$non_list/",$_page)) {
154 $s_page = htmlspecialchars($_page);
155 $pages[$_page] = " <option value=\"$s_page\">$s_page</option>";
158 $s_pages = join("\n",$pages);
160 <select name="template_page">
161 <option value="">-- $_btn_template --</option>
164 <input type="submit" name="template" value="$_btn_load" accesskey="r" />
168 if (array_key_exists('refer',$vars) and $vars['refer'] != '') {
169 $refer = '[['.strip_bracket($vars['refer'])."]]\n\n";
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;
182 <form action="$script" method="post">
183 <div class="edit_form">
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>
191 <input type="submit" name="preview" value="$btn_preview" accesskey="p" />
192 <input type="submit" name="write" value="$_btn_update" accesskey="s" />
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>
201 if (array_key_exists('help', $vars)) {
202 $body .= $hr . catrule();
205 "<ul><li><a href=\"$script?cmd=edit&help=true&page=$r_page\">$_msg_help</a></li></ul>";
211 function make_related($page,$tag='')
213 global $script,$vars,$related,$rule_related_str,$related_str,$non_list;
214 global $_ul_left_margin, $_ul_margin, $_list_pad_str;
216 $links = links_get_related($page);
225 foreach ($links as $page=>$lastmod)
227 if (preg_match("/$non_list/",$page))
231 $r_page = rawurlencode($page);
232 $s_page = htmlspecialchars($page);
233 $passage = get_passage($lastmod);
235 "<a href=\"$script?$r_page\" title=\"$s_page $passage\">$s_page</a>" :
236 "<a href=\"$script?$r_page\">$s_page</a>$passage";
239 if (count($_links) == 0)
244 if ($tag == 'p') // ¹ÔƬ¤«¤é
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";
252 $retval = join($rule_related_str,$_links);
256 $retval = join($related_str,$_links);
261 // ¥æ¡¼¥¶ÄêµÁ¥ë¡¼¥ë(¥½¡¼¥¹¤ÏÃÖ´¹¤»¤º¥³¥ó¥Ð¡¼¥È)
262 function make_line_rules($str)
265 static $pattern,$replace;
267 if (!isset($pattern))
269 $pattern = array_map(create_function('$a','return "/$a/";'),array_keys($line_rules));
270 $replace = array_values($line_rules);
273 return preg_replace($pattern,$replace,$str);
276 // HTML¥¿¥°¤ò¼è¤ê½ü¤¯
277 function strip_htmltag($str)
279 global $_symbol_noexists;
281 $noexists_pattern = '#<span class="noexists">([^<]*)<a[^>]+>'.
282 preg_quote($_symbol_noexists,'#').
285 $str = preg_replace($noexists_pattern,'$1',$str);
286 //$str = preg_replace('/<a[^>]+>\?<\/a>/','',$str);
287 return preg_replace('/<[^>]+>/','',$str);
290 // ¥Ú¡¼¥¸Ì¾¤«¤é¥Ú¡¼¥¸Ì¾¤ò¸¡º÷¤¹¤ë¥ê¥ó¥¯¤òºîÀ®
291 function make_search($page)
293 global $script,$WikiName;
295 $s_page = htmlspecialchars($page);
296 $r_page = rawurlencode($page);
298 //WikiWikiWeb like...
299 //if(preg_match("/^$WikiName$/",$page))
300 // $name = preg_replace("/([A-Z][a-z]+)/","$1 ",$name);
302 return "<a href=\"$script?cmd=search&word=$r_page\">$s_page</a> ";
305 // ¸«½Ð¤·¤òÀ¸À® (Ãí¼á¤äHTML¥¿¥°¤ò½üµî)
306 function make_heading(&$str,$strip=TRUE)
310 // ¸«½Ð¤·¤Î¸ÇÍIDÉô¤òºï½ü
312 if (preg_match('/^(\*{0,3})(.*?)\[#([A-Za-z][\w-]+)\](.*?)$/m',$str,$matches))
314 $str = $matches[2].$matches[4];
319 $str = preg_replace('/^\*{0,3}/','',$str);
323 $str = strip_htmltag(make_link(preg_replace($NotePattern,'',$str)));