2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
5 // $Id: vote.inc.php,v 1.14 2003/07/03 05:28:04 arino Exp $
8 function plugin_vote_action()
10 global $post,$vars,$script,$cols,$rows;
11 global $_title_collided,$_msg_collided,$_title_updated;
12 global $_vote_plugin_choice, $_vote_plugin_votes;
14 $postdata_old = get_source($post['refer']);
16 $title = $body = $postdata = '';
18 foreach($postdata_old as $line)
20 if (!preg_match("/^#vote\((.*)\)\s*$/",$line,$arg))
26 if ($vote_no++ != $post['vote_no'])
31 $args = explode(',',$arg[1]);
33 foreach($args as $arg)
36 if (preg_match("/^(.+)\[(\d+)\]$/",$arg,$match))
41 $e_arg = encode($arg);
42 if (!empty($post["vote_$e_arg"]) and $post["vote_$e_arg"] == $_vote_plugin_votes)
47 $votes[] = $arg.'['.$cnt.']';
50 $vote_str = '#vote('.@join(',',$votes).")\n";
52 $postdata_input = $vote_str;
53 $postdata .= $vote_str;
56 if (md5(@join('',get_source($post['refer']))) != $post['digest'])
58 $title = $_title_collided;
60 $s_refer = htmlspecialchars($post['refer']);
61 $s_digest = htmlspecialchars($post['digest']);
62 $s_postdata_input = htmlspecialchars($postdata_input);
65 <form action="$script?cmd=preview" method="post">
67 <input type="hidden" name="refer" value="$s_refer" />
68 <input type="hidden" name="digest" value="$s_digest" />
69 <textarea name="msg" rows="$rows" cols="$cols" id="textarea">$s_postdata_input</textarea><br />
77 page_write($post['refer'],$postdata);
79 $title = $_title_updated;
82 $retvars['msg'] = $title;
83 $retvars['body'] = $body;
85 $post['page'] = $post['refer'];
86 $vars['page'] = $post['refer'];
90 function plugin_vote_convert()
92 global $script,$vars,$digest;
93 global $_vote_plugin_choice, $_vote_plugin_votes;
94 static $numbers = array();
96 if (!array_key_exists($vars['page'],$numbers))
98 $numbers[$vars['page']] = 0;
100 $vote_no = $numbers[$vars['page']]++;
102 if (!func_num_args())
107 $args = func_get_args();
108 $s_page = htmlspecialchars($vars['page']);
109 $s_digest = htmlspecialchars($digest);
112 <form action="$script" method="post">
113 <table cellspacing="0" cellpadding="2" class="style_table" summary="vote">
115 <td align="left" class="vote_label" style="padding-left:1em;padding-right:1em"><strong>$_vote_plugin_choice</strong>
116 <input type="hidden" name="plugin" value="vote" />
117 <input type="hidden" name="refer" value="$s_page" />
118 <input type="hidden" name="vote_no" value="$vote_no" />
119 <input type="hidden" name="digest" value="$s_digest" />
121 <td align="center" class="vote_label"><strong>$_vote_plugin_votes</strong></td>
127 foreach($args as $arg)
131 if (preg_match("/^(.+)\[(\d+)\]$/",$arg,$match))
136 $e_arg = encode($arg);
138 $link = make_link($arg);
140 $cls = ($tdcnt++ % 2) ? 'vote_td1' : 'vote_td2';
144 <td align="left" class="$cls" style="padding-left:1em;padding-right:1em;">$link</td>
145 <td align="right" class="$cls">$cnt
146 <input type="submit" name="vote_$e_arg" value="$_vote_plugin_votes" class="submit" />