OSDN Git Service

convert_html()の引数を配列にしました
[pukiwiki/pukiwiki.git] / plugin / edit.inc.php
1 <?php
2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
4 //
5 // $Id: edit.inc.php,v 1.2 2003/01/31 01:49:35 panda Exp $
6 //
7 // ÊÔ½¸
8 // cmd=edit
9 function plugin_edit_action()
10 {
11         global $vars,$_title_edit;
12         
13         if (array_key_exists('preview',$vars) or array_key_exists('template',$vars)) {
14                 return plugin_edit_preview();
15         }
16         else if (array_key_exists('write',$vars)) {
17                 return plugin_edit_write();
18         }
19         
20         check_editable();
21         
22         $postdata = @join('',get_source($vars['page']));
23         if ($postdata == '') {
24                 $postdata = auto_template($vars['page']);
25         }
26         
27         return array('msg'=>$_title_edit,'body'=>edit_form($vars['page'],$postdata));
28 }
29 // ¥×¥ì¥Ó¥å¡¼
30 function plugin_edit_preview()
31 {
32         global $script,$post;
33         global $_title_preview,$_msg_preview,$_msg_preview_delete;
34
35         if (array_key_exists('template_page',$post) and is_page($post['template_page'])) {
36                 $post['msg'] = join('',get_source($post['template_page']));
37         }
38         
39         $post['msg'] = preg_replace("/^#freeze\n/",'',$post['msg']);
40         $postdata_input = $post['msg'];
41
42         if (!empty($post['add'])) {
43                 if ($post['add_top']) {
44                         $postdata  = $post['msg']."\n\n".@join('',get_source($post['page']));
45                 }
46                 else {
47                         $postdata  = @join('',get_source($post['page']))."\n\n".$post['msg'];
48                 }
49         }
50         else {
51                 $postdata = $post['msg'];
52         }
53
54         $body = "$_msg_preview<br />\n";
55         if ($postdata == '') {
56                 $body .= "<strong>$_msg_preview_delete</strong>";
57         }
58         $body .= "<br />\n";
59
60         if ($postdata != '') {
61                 $postdata = explode("\n",$postdata);
62                 $postdata = drop_submit(convert_html($postdata));
63                 
64                 if (!empty($post['viewtag'])) {
65                         $postdata = preg_replace("/(<[^\/][^>]*>)/e",'"$1".htmlspecialchars("$1")', $postdata);
66                         $postdata = preg_replace("/(<\/[^>]+>)/e",'htmlspecialchars("$1")."$1"', $postdata);
67                 }
68                 
69                 $body .= <<<EOD
70 <div id="preview">
71   $postdata
72 </div>
73 EOD;
74         }
75         $body .= edit_form($post['page'],$postdata_input,$post['digest'],FALSE);
76         
77         return array('msg'=>$_title_preview,'body'=>$body);
78 }
79
80 // ½ñ¤­¹þ¤ß¤â¤·¤¯¤ÏÄɲä⤷¤¯¤Ï¥³¥á¥ó¥È¤ÎÁÞÆþ
81 function plugin_edit_write()
82 {
83         global $script,$post,$vars;
84         global $_title_collided,$_msg_collided_auto,$_msg_collided,$_title_deleted;
85         
86         $retvars = array();
87         
88         // ¼ê½ñ¤­¤Î#freeze¤òºï½ü
89         $post['msg'] = preg_replace('/^#freeze\n/','',$post['msg']);
90         
91         $postdata_input = $post['msg'];
92         
93         if (!empty($post['add'])) {
94                 if (!empty($post['add_top'])) {
95                         $postdata  = $post['msg'];
96                         $postdata .= "\n\n";
97                         $postdata .= @join('',get_source($post['page']));
98                 }
99                 else {
100                         $postdata  = @join('',get_source($post['page']));
101                         $postdata .= "\n\n";
102                         $postdata .= $post['msg'];
103                 }
104         }
105         else {
106                 $postdata = $post['msg'];
107         }
108
109         $oldpagesrc = join('',get_source($post['page']));
110         $oldpagemd5 = md5($oldpagesrc);
111         
112         if ($oldpagemd5 != $post['digest']) {
113                 $retvars['msg'] = $_title_collided;
114                 
115                 $post['digest'] = $vars['digest'] = $oldpagemd5;
116                 list($postdata_input,$auto) = do_update_diff($oldpagesrc,$postdata_input,$post['original']);
117                 
118                 $retvars['body'] = ($auto ? $_msg_collided_auto : $_msg_collided)."\n";
119                 
120                 if (TRUE) {
121                         global $do_update_diff_table;
122                         $retvars['body'] .= $do_update_diff_table;
123                 }
124                 
125                 $retvars['body'] .= edit_form($post['page'],$postdata_input,$oldpagemd5,FALSE);
126         }
127         else {
128                 page_write($post['page'],$postdata);
129                 
130                 if ($postdata != '') {
131                         header("Location: $script?".rawurlencode($post['page']));
132                         exit;
133                 }
134                 
135                 $retvars['msg'] = $_title_deleted;
136                 $retvars['body'] = str_replace('$1',htmlspecialchars($post['page']),$_title_deleted);
137         }
138         
139         return $retvars;
140 }
141
142 ?>