2 // $Id: vote.inc.php,v 1.8 2002/11/29 00:09:01 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 if($post["vote_$arg"]==$_vote_plugin_votes) $cnt++;
44 $votes[] = $arg.'['.$cnt.']';
47 $vote_str = "#vote(" . @join(",",$votes) . ")\n";
49 $postdata_input = $vote_str;
50 $postdata .= $vote_str;
58 if(md5(@join("",@file(get_filename(encode($post["refer"]))))) != $post["digest"])
60 $title = $_title_collided;
62 $body = "$_msg_collided\n";
64 $body .= "<form action=\"$script?cmd=preview\" method=\"post\">\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"
74 if(is_page($post["refer"]))
75 $oldpostdata = join("",file(get_filename(encode($post["refer"]))));
79 $diffdata = do_diff($oldpostdata,$postdata);
80 file_write(DIFF_DIR,$post["refer"],$diffdata);
82 if(is_page($post["refer"]))
83 $oldposttime = filemtime(get_filename(encode($post["refer"])));
85 $oldposttime = time();
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);
92 file_write(DATA_DIR,$post["refer"],$postdata);
94 is_page($post["refer"],true);
96 $title = $_title_updated;
99 $retvars["msg"] = $title;
100 $retvars["body"] = $body;
102 $post["page"] = $post["refer"];
103 $vars["page"] = $post["refer"];
107 function plugin_vote_convert()
109 global $script,$vars,$vote_no,$digest;
110 global $_vote_plugin_choice, $_vote_plugin_votes;
112 $args = func_get_args();
114 if(!func_num_args()) return FALSE;
117 . "<form action=\"$script\" method=\"post\">\n"
118 . "<table cellspacing=\"0\" cellpadding=\"2\" class=\"style_table\">\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"
126 . "<td align=\"center\" class=\"vote_label\"><strong>$_vote_plugin_votes</strong></td>\n"
130 foreach($args as $arg)
134 if(preg_match("/^(.+)\[(\d+)\]$/",$arg,$match))
140 $link = make_link($arg);
142 if($tdcnt++ % 2) $cls = "vote_td1";
143 else $cls = "vote_td2";
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 <input type=\"submit\" name=\"vote_".htmlspecialchars($arg)."\" value=\"$_vote_plugin_votes\" class=\"submit\" /></td>"
151 $string .= "</table></form>\n";