7 * LICENSE: This source file is licensed under the terms of the GNU General Public License.
9 * @package Magic3 Framework
10 * @author 平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
11 * @copyright Copyright 2006-2009 Magic3 Project.
12 * @license http://www.gnu.org/copyleft/gpl.html GPL License
13 * @version SVN: $Id: vote.inc.php 1601 2009-03-21 05:51:06Z fishbone $
14 * @link http://www.magic3.org
16 function plugin_vote_action()
18 //global $vars, $script, $cols,$rows;
19 global $script, $cols,$rows;
20 global $_title_collided, $_msg_collided, $_title_updated;
21 global $_vote_plugin_votes;
23 if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing');
25 //$postdata_old = get_source($vars['refer']);
26 $postdata_old = get_source(WikiParam::getRefer());
29 $title = $body = $postdata = $postdata_input = $vote_str = '';
31 foreach($postdata_old as $line) {
32 //if (! preg_match('/^#vote(?:\((.*)\)(.*))?$/i', $line, $matches) || $vote_no++ != $vars['vote_no']) {
33 if (!preg_match('/^#vote(?:\((.*)\)(.*))?$/i', $line, $matches) || $vote_no++ != WikiParam::getVar('vote_no')){
37 $args = explode(',', $matches[1]);
38 $lefts = isset($matches[2]) ? $matches[2] : '';
40 foreach($args as $arg) {
42 if (preg_match('/^(.+)\[(\d+)\]$/', $arg, $matches)) {
46 $e_arg = encode($arg);
47 //if (! empty($vars['vote_' . $e_arg]) && $vars['vote_' . $e_arg] == $_vote_plugin_votes)
48 if (WikiParam::getVar('vote_' . $e_arg) == $_vote_plugin_votes)
51 $votes[] = $arg . '[' . $cnt . ']';
54 $vote_str = '#vote(' . @join(',', $votes) . ')' . $lefts . "\n";
55 $postdata_input = $vote_str;
56 $postdata .= $vote_str;
59 //if (md5(@join('', get_source($vars['refer']))) != $vars['digest']) {
60 if (md5(get_source(WikiParam::getRefer(), true)) != WikiParam::getVar('digest')) {
61 $title = $_title_collided;
63 /* $s_refer = htmlspecialchars($vars['refer']);
64 $s_digest = htmlspecialchars($vars['digest']);*/
65 $s_refer = htmlspecialchars(WikiParam::getRefer());
66 $s_digest = htmlspecialchars(WikiParam::getVar('digest'));
68 $postScript = $script . WikiParam::convQuery("?cmd=preview");
69 $s_postdata_input = htmlspecialchars($postdata_input);
72 <form action="$postScript" method="post" class="form">
74 <input type="hidden" name="refer" value="$s_refer" />
75 <input type="hidden" name="digest" value="$s_digest" />
76 <textarea name="msg" class="wiki_edit" rows="$rows" cols="$cols">$s_postdata_input</textarea><br />
81 //page_write($vars['refer'], $postdata);
82 page_write(WikiParam::getRefer(), $postdata);
83 $title = $_title_updated;
86 //$vars['page'] = $vars['refer'];
87 WikiParam::setPage(WikiParam::getRefer());
89 return array('msg'=>$title, 'body'=>$body);
92 function plugin_vote_convert()
94 //global $script, $vars, $digest;
96 global $_vote_plugin_choice, $_vote_plugin_votes;
97 static $number = array();
99 //$page = isset($vars['page']) ? $vars['page'] : '';
100 $page = WikiParam::getPage();
102 // Vote-box-id in the page
103 if (! isset($number[$page])) $number[$page] = 0; // Init
104 $vote_no = $number[$page]++;
106 if (! func_num_args()) return '#vote(): No arguments<br />' . "\n";
112 //$_script = $script;
113 $_script = $script . WikiParam::convQuery("?");
117 $args = func_get_args();
118 $s_page = htmlspecialchars($page);
119 //$s_digest = htmlspecialchars($digest);
120 $s_digest = htmlspecialchars(WikiParam::getDigest());
123 <form action="$_script" method="post" class="form">
124 <table cellspacing="0" cellpadding="2" class="style_table" summary="vote">
126 <td align="left" class="vote_label" style="padding-left:1em;padding-right:1em"><strong>$_vote_plugin_choice</strong>
127 <input type="hidden" name="plugin" value="vote" />
128 <input type="hidden" name="refer" value="$s_page" />
129 <input type="hidden" name="vote_no" value="$vote_no" />
130 <input type="hidden" name="digest" value="$s_digest" />
132 <td align="center" class="vote_label"><strong>$_vote_plugin_votes</strong></td>
138 foreach($args as $arg) {
141 if (preg_match('/^(.+)\[(\d+)\]$/', $arg, $matches)) {
145 $e_arg = encode($arg);
147 $link = make_link($arg);
149 $cls = ($tdcnt++ % 2) ? 'vote_td1' : 'vote_td2';
153 <td align="left" class="$cls" style="padding-left:1em;padding-right:1em;">$link</td>
154 <td align="right" class="$cls">$cnt
155 <input type="$_submit" name="vote_$e_arg" class="button" value="$_vote_plugin_votes" />