OSDN Git Service

[[pukiwiki:BugTrack/36]] <input>タグ内でページ名などがエスケープされていなかったのを修正
[pukiwiki/pukiwiki.git] / plugin / vote.inc.php
1 <?
2 // $Id: vote.inc.php,v 1.6 2002/07/02 04:20:20 masui Exp $
3
4 function plugin_vote_action()
5 {
6         global $post,$vars,$script,$cols,$rows,$del_backup,$do_backup;
7         global $_title_collided,$_msg_collided,$_title_updated;
8
9         $postdata_old  = file(get_filename(encode($post["refer"])));
10         $vote_no = 0;
11
12         foreach($postdata_old as $line)
13         {
14                 if(preg_match("/^#vote\((.*)\)$/",$line,$arg))
15                 {
16                         if($vote_no == $post["vote_no"])
17                         {
18                                 $args = explode(",",$arg[1]);
19
20                                 foreach($args as $arg)
21                                 {
22                                         if(preg_match("/^(.+)\[(\d+)\]$/",$arg,$match))
23                                         {
24                                                 $arg = $match[1];
25                                                 $cnt = $match[2];
26                                         }
27                                         else
28                                         {
29                                                 $cnt = 0;
30                                         }
31
32                                         if($post["vote"][preg_replace("/\]\]$/","",$arg)]) $cnt++;
33
34                                         $votes[] = $arg.'['.$cnt.']';
35                                 }
36
37                                 $vote_str = "#vote(" . @join(",",$votes) . ")\n";
38
39                                 $postdata_input = $vote_str;
40                                 $postdata .= $vote_str;
41                                 $line = "";
42                         }
43                         $vote_no++;
44                 }
45                 $postdata .= $line;
46         }
47
48         if(md5(@join("",@file(get_filename(encode($post["refer"]))))) != $post["digest"])
49         {
50                 $title = $_title_collided;
51
52                 $body = "$_msg_collided\n";
53
54                 $body .= "<form action=\"$script?cmd=preview\" method=\"post\">\n"
55                         ."<div>\n"
56                         ."<input type=\"hidden\" name=\"refer\" value=\"".htmlspecialchars($post["refer"])."\" />\n"
57                         ."<input type=\"hidden\" name=\"digest\" value=\"".htmlspecialchars($post["digest"])."\" />\n"
58                         ."<textarea name=\"msg\" rows=\"$rows\" cols=\"$cols\" wrap=\"virtual\" id=\"textarea\">".htmlspecialchars($postdata_input)."</textarea><br />\n"
59                         ."</div>\n"
60                         ."</form>\n";
61         }
62         else
63         {
64                 // ?¡¦?a?t?@?C???I?i?¢Ì
65                 if(is_page($post["refer"]))
66                         $oldpostdata = join("",file(get_filename(encode($post["refer"]))));
67                 else
68                         $oldpostdata = "\n";
69                 if($postdata)
70                         $diffdata = do_diff($oldpostdata,$postdata);
71                 file_write(DIFF_DIR,$post["refer"],$diffdata);
72
73                 // ?o?b?N?A?b?v?I?i?¢Ì
74                 if(is_page($post["refer"]))
75                         $oldposttime = filemtime(get_filename(encode($post["refer"])));
76                 else
77                         $oldposttime = time();
78
79                 // ?O?W¡Èa?e?a¢ó??a?¡Æ?c?e?A?¡ñ?E?¡ñ?A?o?b?N?A?b?v?a?i???¡¦?e??¦Ì?E?¡ñ?A?¡¦?a?E?B
80                 if(!$postdata && $del_backup)
81                         backup_delete(BACKUP_DIR.encode($post["refer"]).".txt");
82                 else if($do_backup && is_page($post["refer"]))
83                         make_backup(encode($post["refer"]).".txt",$oldpostdata,$oldposttime);
84
85                 // ?t?@?C???I?¡Æ?¢ã???Y
86                 file_write(DATA_DIR,$post["refer"],$postdata);
87
88                 // is_page?I?L???b?V?¡Ä?d?N???A?¡¦?e?B
89                 is_page($post["refer"],true);
90
91                 $title = $_title_updated;
92         }
93
94         $retvars["msg"] = $title;
95         $retvars["body"] = $body;
96
97         $post["page"] = $post["refer"];
98         $vars["page"] = $post["refer"];
99
100         return $retvars;
101 }
102 function plugin_vote_convert()
103 {
104         global $script,$vars,$vote_no,$digest;
105
106         $args = func_get_args();
107
108         if(!func_num_args()) return FALSE;
109
110         $string = ""
111                 . "<form action=\"$script\" method=\"post\">\n"
112                 . "<table cellspacing=\"0\" cellpadding=\"2\" border=\"0\">\n"
113                 . "<tr>\n"
114                 . "<td align=\"left\" class=\"vote_label\"><strong>The choices</strong>"
115                 . "<input type=\"hidden\" name=\"plugin\" value=\"vote\" />\n"
116                 . "<input type=\"hidden\" name=\"refer\" value=\"".htmlspecialchars($vars["page"])."\" />\n"
117                 . "<input type=\"hidden\" name=\"vote_no\" value=\"".htmlspecialchars($vote_no)."\" />\n"
118                 . "<input type=\"hidden\" name=\"digest\" value=\"".htmlspecialchars($digest)."\" />\n"
119                 . "</td>\n"
120                 . "<td align=\"center\" class=\"vote_label\"><strong>Votes</strong></td>\n"
121                 . "</tr>\n";
122
123         $tdcnt = 0;
124         foreach($args as $arg)
125         {
126                 $cnt = 0;
127
128                 if(preg_match("/^(.+)\[(\d+)\]$/",$arg,$match))
129                 {
130                         $arg = $match[1];
131                         $cnt = $match[2];
132                 }
133
134                 $link = make_link($arg);
135
136                 if($tdcnt++ % 2) $cls = "vote_td1";
137                 else           $cls = "vote_td2";
138
139                 $string .= "<tr>"
140                         .  "<td width=\"80%\" class=\"$cls\" nowrap>$link</td>"
141                         .  "<td class=\"$cls\" nowrap=\"nowrap\">$cnt&nbsp;&nbsp;<input type=\"submit\" name=\"vote[".htmlspecialchars($arg)."]\" value=\"Vote\" /></td>"
142                         .  "</tr>\n";
143         }
144
145         $string .= "</table></form>\n";
146
147         $vote_no++;
148
149         return $string;
150 }
151 ?>