2 // $Id: vote.inc.php,v 1.10 2002/12/19 11:33:49 panda Exp $
4 function plugin_vote_init()
6 $_plugin_vote_messages = array(
7 '_vote_plugin_choice' => 'ÁªÂò»è',
8 '_vote_plugin_votes' => 'Åêɼ',
10 set_plugin_messages($_plugin_vote_messages);
13 function plugin_vote_action()
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;
19 $postdata_old = file(get_filename(encode($post["refer"])));
22 foreach($postdata_old as $line)
24 if(preg_match("/^#vote\((.*)\)$/",$line,$arg))
26 if($vote_no == $post["vote_no"])
28 $args = explode(",",$arg[1]);
30 foreach($args as $arg)
32 if(preg_match("/^(.+)\[(\d+)\]$/",$arg,$match))
42 $e_arg = encode($arg);
43 if($post["vote_$e_arg"]==$_vote_plugin_votes) $cnt++;
45 $votes[] = $arg.'['.$cnt.']';
48 $vote_str = "#vote(" . @join(",",$votes) . ")\n";
50 $postdata_input = $vote_str;
51 $postdata .= $vote_str;
59 if(md5(@join("",@file(get_filename(encode($post["refer"]))))) != $post["digest"])
61 $title = $_title_collided;
63 $body = "$_msg_collided\n";
65 $body .= "<form action=\"$script?cmd=preview\" method=\"post\">\n"
67 ."<input type=\"hidden\" name=\"refer\" value=\"".htmlspecialchars($post["refer"])."\" />\n"
68 ."<input type=\"hidden\" name=\"digest\" value=\"".htmlspecialchars($post["digest"])."\" />\n"
69 ."<textarea name=\"msg\" rows=\"$rows\" cols=\"$cols\" wrap=\"virtual\" id=\"textarea\">".htmlspecialchars($postdata_input)."</textarea><br />\n"
75 if(is_page($post["refer"]))
76 $oldpostdata = join("",file(get_filename(encode($post["refer"]))));
80 $diffdata = do_diff($oldpostdata,$postdata);
81 file_write(DIFF_DIR,$post["refer"],$diffdata);
83 if(is_page($post["refer"]))
84 $oldposttime = filemtime(get_filename(encode($post["refer"])));
86 $oldposttime = time();
88 if(!$postdata && $del_backup)
89 backup_delete(BACKUP_DIR.encode($post["refer"]).".txt");
90 else if($do_backup && is_page($post["refer"]))
91 make_backup(encode($post["refer"]).".txt",$oldpostdata,$oldposttime);
93 file_write(DATA_DIR,$post["refer"],$postdata);
95 is_page($post["refer"],true);
97 $title = $_title_updated;
100 $retvars["msg"] = $title;
101 $retvars["body"] = $body;
103 $post["page"] = $post["refer"];
104 $vars["page"] = $post["refer"];
108 function plugin_vote_convert()
110 global $script,$vars,$digest;
111 global $_vote_plugin_choice, $_vote_plugin_votes;
114 $args = func_get_args();
116 if(!func_num_args()) return FALSE;
119 . "<form action=\"$script\" method=\"post\">\n"
120 . "<table cellspacing=\"0\" cellpadding=\"2\" class=\"style_table\">\n"
122 . "<td align=\"left\" class=\"vote_label\" style=\"padding-left:1em;padding-right:1em\"><strong>$_vote_plugin_choice</strong>"
123 . "<input type=\"hidden\" name=\"plugin\" value=\"vote\" />\n"
124 . "<input type=\"hidden\" name=\"refer\" value=\"".htmlspecialchars($vars["page"])."\" />\n"
125 . "<input type=\"hidden\" name=\"vote_no\" value=\"".htmlspecialchars($vote_no)."\" />\n"
126 . "<input type=\"hidden\" name=\"digest\" value=\"".htmlspecialchars($digest)."\" />\n"
128 . "<td align=\"center\" class=\"vote_label\"><strong>$_vote_plugin_votes</strong></td>\n"
132 foreach($args as $arg)
136 if(preg_match("/^(.+)\[(\d+)\]$/",$arg,$match))
142 $link = make_link($arg);
143 $e_arg = encode($arg);
145 if($tdcnt++ % 2) $cls = "vote_td1";
146 else $cls = "vote_td2";
149 . "<td align=\"left\" class=\"$cls\" style=\"padding-left:1em;padding-right:1em;\" nowrap=\"nowrap\">$link</td>"
150 . "<td align=\"right\" class=\"$cls\" nowrap=\"nowrap\">$cnt <input type=\"submit\" name=\"vote_".htmlspecialchars($e_arg)."\" value=\"$_vote_plugin_votes\" class=\"submit\" /></td>"
154 $string .= "</table></form>\n";