OSDN Git Service

ぱんだ:開発日記/2002-11-29参照
[pukiwiki/pukiwiki.git] / plugin / vote.inc.php
1 <?php
2 // $Id: vote.inc.php,v 1.8 2002/11/29 00:09:01 panda Exp $
3
4 function plugin_vote_init()
5 {
6   $_plugin_vote_messages = array(
7     '_vote_plugin_choice' => 'ÁªÂò»è',
8     '_vote_plugin_votes' => 'Åêɼ',
9     );
10   set_plugin_messages($_plugin_vote_messages);
11 }
12
13 function plugin_vote_action()
14 {
15         global $post,$vars,$script,$cols,$rows,$del_backup,$do_backup;
16         global $_title_collided,$_msg_collided,$_title_updated;
17         global $_vote_plugin_choice, $_vote_plugin_votes;
18
19         $postdata_old  = file(get_filename(encode($post["refer"])));
20         $vote_no = 0;
21
22         foreach($postdata_old as $line)
23         {
24                 if(preg_match("/^#vote\((.*)\)$/",$line,$arg))
25                 {
26                         if($vote_no == $post["vote_no"])
27                         {
28                                 $args = explode(",",$arg[1]);
29
30                                 foreach($args as $arg)
31                                 {
32                                         if(preg_match("/^(.+)\[(\d+)\]$/",$arg,$match))
33                                         {
34                                                 $arg = $match[1];
35                                                 $cnt = $match[2];
36                                         }
37                                         else
38                                         {
39                                                 $cnt = 0;
40                                         }
41
42                                         if($post["vote_$arg"]==$_vote_plugin_votes) $cnt++;
43
44                                         $votes[] = $arg.'['.$cnt.']';
45                                 }
46
47                                 $vote_str = "#vote(" . @join(",",$votes) . ")\n";
48
49                                 $postdata_input = $vote_str;
50                                 $postdata .= $vote_str;
51                                 $line = "";
52                         }
53                         $vote_no++;
54                 }
55                 $postdata .= $line;
56         }
57
58         if(md5(@join("",@file(get_filename(encode($post["refer"]))))) != $post["digest"])
59         {
60                 $title = $_title_collided;
61
62                 $body = "$_msg_collided\n";
63
64                 $body .= "<form action=\"$script?cmd=preview\" method=\"post\">\n"
65                         ."<div>\n"
66                         ."<input type=\"hidden\" name=\"refer\" value=\"".htmlspecialchars($post["refer"])."\" />\n"
67                         ."<input type=\"hidden\" name=\"digest\" value=\"".htmlspecialchars($post["digest"])."\" />\n"
68                         ."<textarea name=\"msg\" rows=\"$rows\" cols=\"$cols\" wrap=\"virtual\" id=\"textarea\">".htmlspecialchars($postdata_input)."</textarea><br />\n"
69                         ."</div>\n"
70                         ."</form>\n";
71         }
72         else
73         {
74                 if(is_page($post["refer"]))
75                         $oldpostdata = join("",file(get_filename(encode($post["refer"]))));
76                 else
77                         $oldpostdata = "\n";
78                 if($postdata)
79                         $diffdata = do_diff($oldpostdata,$postdata);
80                 file_write(DIFF_DIR,$post["refer"],$diffdata);
81
82                 if(is_page($post["refer"]))
83                         $oldposttime = filemtime(get_filename(encode($post["refer"])));
84                 else
85                         $oldposttime = time();
86
87                 if(!$postdata && $del_backup)
88                         backup_delete(BACKUP_DIR.encode($post["refer"]).".txt");
89                 else if($do_backup && is_page($post["refer"]))
90                         make_backup(encode($post["refer"]).".txt",$oldpostdata,$oldposttime);
91
92                 file_write(DATA_DIR,$post["refer"],$postdata);
93
94                 is_page($post["refer"],true);
95
96                 $title = $_title_updated;
97         }
98
99         $retvars["msg"] = $title;
100         $retvars["body"] = $body;
101
102         $post["page"] = $post["refer"];
103         $vars["page"] = $post["refer"];
104
105         return $retvars;
106 }
107 function plugin_vote_convert()
108 {
109         global $script,$vars,$vote_no,$digest;
110         global $_vote_plugin_choice, $_vote_plugin_votes;
111
112         $args = func_get_args();
113
114         if(!func_num_args()) return FALSE;
115
116         $string = ""
117                 . "<form action=\"$script\" method=\"post\">\n"
118                 . "<table cellspacing=\"0\" cellpadding=\"2\" class=\"style_table\">\n"
119                 . "<tr>\n"
120                 . "<td align=\"left\" class=\"vote_label\" style=\"padding-left:1em;padding-right:1em\"><strong>$_vote_plugin_choice</strong>"
121                 . "<input type=\"hidden\" name=\"plugin\" value=\"vote\" />\n"
122                 . "<input type=\"hidden\" name=\"refer\" value=\"".htmlspecialchars($vars["page"])."\" />\n"
123                 . "<input type=\"hidden\" name=\"vote_no\" value=\"".htmlspecialchars($vote_no)."\" />\n"
124                 . "<input type=\"hidden\" name=\"digest\" value=\"".htmlspecialchars($digest)."\" />\n"
125                 . "</td>\n"
126                 . "<td align=\"center\" class=\"vote_label\"><strong>$_vote_plugin_votes</strong></td>\n"
127                 . "</tr>\n";
128
129         $tdcnt = 0;
130         foreach($args as $arg)
131         {
132                 $cnt = 0;
133
134                 if(preg_match("/^(.+)\[(\d+)\]$/",$arg,$match))
135                 {
136                         $arg = $match[1];
137                         $cnt = $match[2];
138                 }
139
140                 $link = make_link($arg);
141
142                 if($tdcnt++ % 2) $cls = "vote_td1";
143                 else           $cls = "vote_td2";
144
145                 $string .= "<tr>"
146                         .  "<td align=\"left\" class=\"$cls\" style=\"padding-left:1em;padding-right:1em;\" nowrap=\"nowrap\">$link</td>"
147                         .  "<td align=\"right\" class=\"$cls\" nowrap=\"nowrap\">$cnt&nbsp;&nbsp;<input type=\"submit\" name=\"vote_".htmlspecialchars($arg)."\" value=\"$_vote_plugin_votes\" class=\"submit\" /></td>"
148                         .  "</tr>\n";
149         }
150
151         $string .= "</table></form>\n";
152
153         $vote_no++;
154
155         return $string;
156 }
157 ?>