OSDN Git Service

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