OSDN Git Service

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