OSDN Git Service

MASUI'z Edition first beta release
[pukiwiki/pukiwiki.git] / plugin / comment.inc.php
1 <?
2 global $name_cols, $comment_cols, $msg_format, $name_format;
3 global $msg_format, $now_format, $comment_format;
4 global $comment_ins, $comment_mail, $comment_no;
5
6
7 /////////////////////////////////////////////////
8 // ¥³¥á¥ó¥È¤Î̾Á°¥Æ¥­¥¹¥È¥¨¥ê¥¢¤Î¥«¥é¥à¿ô
9 $name_cols = 15;
10 /////////////////////////////////////////////////
11 // ¥³¥á¥ó¥È¤Î¥Æ¥­¥¹¥È¥¨¥ê¥¢¤Î¥«¥é¥à¿ô
12 $comment_cols = 70;
13 /////////////////////////////////////////////////
14 // ¥³¥á¥ó¥È¤ÎÁÞÆþ¥Õ¥©¡¼¥Þ¥Ã¥È
15 $name_format = '[[$name]]';
16 $msg_format = '$msg';
17 $now_format = 'SIZE(1):$now';
18 /////////////////////////////////////////////////
19 // ¥³¥á¥ó¥È¤ÎÁÞÆþ¥Õ¥©¡¼¥Þ¥Ã¥È(¥³¥á¥ó¥ÈÆâÍÆ)
20 $comment_format = '$msg -- $name $now';
21 /////////////////////////////////////////////////
22 // ¥³¥á¥ó¥È¤òÁÞÆþ¤¹¤ë°ÌÃÖ 1:Íó¤ÎÁ° 0:Íó¤Î¸å
23 $comment_ins = 1;
24 /////////////////////////////////////////////////
25 // ¥³¥á¥ó¥È¤¬Åê¹Æ¤µ¤ì¤¿¾ì¹ç¡¢ÆâÍƤò¥á¡¼¥ë¤ÇÁ÷¤ëÀè
26 $comment_mail = FALSE;
27
28 // initialize
29 $comment_no = 0;
30
31 function plugin_comment_action()
32 {
33         global $post,$vars,$script,$cols,$rows,$del_backup,$do_backup,$update_exec,$now;
34         global $name_cols,$comment_cols,$name_format,$msg_format,$now_format,$comment_format,$comment_ins;
35         global $_title_collided,$_msg_collided,$_title_updated;
36         global $_msg_comment_collided,$_title_comment_collided;
37
38         $_comment_format = $comment_format;
39         if($post["nodate"]=="1") {
40                 $_comment_format = str_replace('$now','',$_comment_format);
41         }
42         if($post["msg"]=="") {
43                 $retvars["msg"] = $name;
44                 $post["page"] = $post["refer"];
45                 $vars["page"] = $post["refer"];
46                 $retvars["body"] = convert_html(join("",file(get_filename(encode($post["refer"])))));
47                 return $retvars;
48         }
49         if($post["msg"])
50         {
51                 $post["msg"] = preg_replace("/\n/","",$post["msg"]);
52
53                 $postdata = "";
54                 $postdata_old  = file(get_filename(encode($post["refer"])));
55                 $comment_no = 0;
56
57                 if($post["name"])
58                 {
59                         $name = str_replace('$name',$post["name"],$name_format);
60                 }
61                 if($post["msg"])
62                 {
63                         if(preg_match("/^(-{1,2})(.*)/",$post["msg"],$match))
64                         {
65                                 $head = $match[1];
66                                 $post["msg"] = $match[2];
67                         }
68                         
69                         $comment = str_replace('$msg',str_replace('$msg',$post["msg"],$msg_format),$_comment_format);
70                         $comment = str_replace('$name',$name,$comment);
71                         $comment = str_replace('$now',str_replace('$now',$now,$now_format),$comment);
72                         $comment = $head.$comment;
73                 }
74
75                 foreach($postdata_old as $line)
76                 {
77                         if(!$comment_ins) $postdata .= $line;
78                         if(preg_match("/^#comment/",$line))
79                         {
80                                 if($comment_no == $post["comment_no"] && $post[msg]!="")
81                                 {
82                                         $postdata .= "-$comment\n";
83                                 }
84                                 $comment_no++;
85                         }
86                         if($comment_ins) $postdata .= $line;
87                 }
88
89                 $postdata_input = "-$comment\n";
90         }
91
92         $title = $_title_updated;
93         if(md5(@join("",@file(get_filename(encode($post["refer"]))))) != $post["digest"])
94         {
95                 $title = $_title_comment_collided;
96                 $body = $_msg_comment_collided . make_link($post["refer"]);
97         }
98         
99         $postdata = user_rules_str($postdata);
100
101         // º¹Ê¬¥Õ¥¡¥¤¥ë¤ÎºîÀ®
102         if(is_page($post["refer"]))
103                 $oldpostdata = join("",file(get_filename(encode($post["refer"]))));
104         else
105                 $oldpostdata = "\n";
106         if($postdata)
107                 $diffdata = do_diff($oldpostdata,$postdata);
108         file_write(DIFF_DIR,$post["refer"],$diffdata);
109                 // ¥Ð¥Ã¥¯¥¢¥Ã¥×¤ÎºîÀ®
110         if(is_page($post["refer"]))
111                 $oldposttime = filemtime(get_filename(encode($post["refer"])));
112         else
113                 $oldposttime = time();
114
115         // ÊÔ½¸ÆâÍƤ¬²¿¤â½ñ¤«¤ì¤Æ¤¤¤Ê¤¤¤È¥Ð¥Ã¥¯¥¢¥Ã¥×¤âºï½ü¤¹¤ë?¤·¤Ê¤¤¤Ç¤¹¤è¤Í¡£
116         if(!$postdata && $del_backup)
117                 backup_delete(BACKUP_DIR.encode($post["refer"]).".txt");
118         else if($do_backup && is_page($post["refer"]))
119         make_backup(encode($post["refer"]).".txt",$oldpostdata,$oldposttime);
120
121         // ¥Õ¥¡¥¤¥ë¤Î½ñ¤­¹þ¤ß
122         file_write(DATA_DIR,$post["refer"],$postdata);
123
124         // is_page¤Î¥­¥ã¥Ã¥·¥å¤ò¥¯¥ê¥¢¤¹¤ë¡£
125         is_page($post["refer"],true);
126
127         $retvars["msg"] = $title;
128         $retvars["body"] = $body;
129         
130         $post["page"] = $post["refer"];
131         $vars["page"] = $post["refer"];
132         
133         return $retvars;
134 }
135 function plugin_comment_convert()
136 {
137         global $script,$comment_no,$vars,$name_cols,$comment_cols,$digest;
138         global $_btn_comment,$_btn_name,$_msg_comment,$vars;
139
140         $options = func_get_args();
141         
142         $nametags = "$_btn_name<input type=\"text\" name=\"name\" size=\"$name_cols\">\n";
143         if(is_array($options) && in_array("noname",$options)) {
144                 $nametags = $_msg_comment;
145         }
146
147         $nodate = '0';
148         if(is_array($options) && in_array("nodate",$options)) {
149                 $nodate = '1';
150         }
151
152         if((arg_check("read")||$vars["cmd"] == ""||arg_check("unfreeze")||arg_check("freeze")||$vars["write"]||$vars["comment"]))
153                 $button = "<input type=\"submit\" name=\"comment\" value=\"$_btn_comment\">\n";
154
155         $string = "<p><form action=\"$script\" method=\"post\">\n"
156                  ."<input type=\"hidden\" name=\"comment_no\" value=\"$comment_no\">\n"
157                  ."<input type=\"hidden\" name=\"refer\" value=\"$vars[page]\">\n"
158                  ."<input type=\"hidden\" name=\"plugin\" value=\"comment\">\n"
159                  ."<input type=\"hidden\" name=\"nodate\" value=\"$nodate\">\n"
160                  ."<input type=\"hidden\" name=\"digest\" value=\"$digest\">\n"
161                  ."$nametags"
162                  ."<input type=\"text\" name=\"msg\" size=\"$comment_cols\">\n"
163                  .$button
164                  ."</form>";
165
166         $comment_no++;
167
168         return $string;
169 }
170 ?>