2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
5 // $Id: vote.inc.php,v 1.17 2004/08/15 01:29:19 henoheno Exp $
8 function plugin_vote_action()
10 global $vars, $script, $cols,$rows;
11 global $_title_collided, $_msg_collided, $_title_updated;
12 global $_vote_plugin_votes;
14 $postdata_old = get_source($vars['refer']);
17 $title = $body = $postdata = $postdata_input = $vote_str = '';
19 foreach($postdata_old as $line) {
21 if (preg_match("/^#vote\((.*)\)\s*$/", $line, $matches)) {
22 $args = explode(',', $matches[1]);
28 if ($vote_no++ != $vars['vote_no']) {
33 foreach($args as $arg) {
35 if (preg_match("/^(.+)\[(\d+)\]$/", $arg, $matches)) {
39 $e_arg = encode($arg);
40 if (! empty($vars["vote_$e_arg"]) and $vars["vote_$e_arg"] == $_vote_plugin_votes)
43 $votes[] = $arg . '[' . $cnt . ']';
46 $vote_str = '#vote(' . @join(',', $votes) . ")\n";
47 $postdata_input = $vote_str;
48 $postdata .= $vote_str;
51 if (md5(@join('', get_source($vars['refer']))) != $vars['digest']) {
52 $title = $_title_collided;
54 $s_refer = htmlspecialchars($vars['refer']);
55 $s_digest = htmlspecialchars($vars['digest']);
56 $s_postdata_input = htmlspecialchars($postdata_input);
59 <form action="$script?cmd=preview" method="post">
61 <input type="hidden" name="refer" value="$s_refer" />
62 <input type="hidden" name="digest" value="$s_digest" />
63 <textarea name="msg" rows="$rows" cols="$cols" id="textarea">$s_postdata_input</textarea><br />
69 page_write($vars['refer'], $postdata);
70 $title = $_title_updated;
73 $vars['page'] = $vars['refer'];
75 return array('msg'=>$title, 'body'=>$body);
78 function plugin_vote_convert()
80 global $script, $vars, $digest;
81 global $_vote_plugin_choice, $_vote_plugin_votes;
82 static $number = array();
84 $page = isset($vars['page']) ? $vars['page'] : '';
86 // Vote-box-id in the page
87 if (! isset($number[$page])) $number[$page] = 0; // Init
88 $vote_no = $number[$page]++;
90 if (! func_num_args()) return '#vote(): No arguments';
92 $args = func_get_args();
93 $s_page = htmlspecialchars($page);
94 $s_digest = htmlspecialchars($digest);
97 <form action="$script" method="post">
98 <table cellspacing="0" cellpadding="2" class="style_table" summary="vote">
100 <td align="left" class="vote_label" style="padding-left:1em;padding-right:1em"><strong>$_vote_plugin_choice</strong>
101 <input type="hidden" name="plugin" value="vote" />
102 <input type="hidden" name="refer" value="$s_page" />
103 <input type="hidden" name="vote_no" value="$vote_no" />
104 <input type="hidden" name="digest" value="$s_digest" />
106 <td align="center" class="vote_label"><strong>$_vote_plugin_votes</strong></td>
113 foreach($args as $arg) {
116 if (preg_match("/^(.+)\[(\d+)\]$/", $arg, $matches)) {
120 $e_arg = encode($arg);
122 $link = make_link($arg);
124 $cls = ($tdcnt++ % 2) ? 'vote_td1' : 'vote_td2';
128 <td align="left" class="$cls" style="padding-left:1em;padding-right:1em;">$link</td>
129 <td align="right" class="$cls">$cnt
130 <input type="submit" name="vote_$e_arg" value="$_vote_plugin_votes" class="submit" />