<?php
-// $Id: vote.inc.php,v 1.11 2003/01/27 05:38:47 panda Exp $
-
-function plugin_vote_init()
-{
- if (LANG == 'ja')
- $messages = array(
- '_vote_plugin_choice' => 'ÁªÂò»è',
- '_vote_plugin_votes' => 'Åêɼ',
- );
- else
- $messages = array(
- '_vote_plugin_choice' => 'Selection',
- '_vote_plugin_votes' => 'Vote',
- );
- set_plugin_messages($messages);
-}
+// PukiWiki - Yet another WikiWikiWeb clone.
+// vote.inc.php
+// Copyright 2002-2017 PukiWiki Development Team
+// License: GPL v2 or (at your option) any later version
+//
+// Vote box plugin
function plugin_vote_action()
{
- global $post,$vars,$script,$cols,$rows;
- global $_title_collided,$_msg_collided,$_title_updated;
- global $_vote_plugin_choice, $_vote_plugin_votes;
+ global $vars, $cols,$rows;
+ global $_title_collided, $_msg_collided, $_title_updated;
+ global $_vote_plugin_votes;
- $postdata_old = get_source($post['refer']);
- $vote_no = 0;
- $title = $body = $postdata = '';
+ $script = get_base_uri();
+ if (PKWK_READONLY) die_message('PKWK_READONLY prohibits editing');
+ $postdata_old = get_source($vars['refer']);
+
+ $vote_no = 0;
+ $title = $body = $postdata = $postdata_input = $vote_str = '';
+ $matches = array();
foreach($postdata_old as $line) {
- if (!preg_match("/^#vote\((.*)\)\s*$/",$line,$arg)) {
- $postdata .= $line;
- continue;
- }
-
- if (++$vote_no != $post['vote_no']) {
+
+ if (! preg_match('/^#vote(?:\((.*)\)(.*))?$/i', $line, $matches) ||
+ $vote_no++ != $vars['vote_no']) {
$postdata .= $line;
continue;
}
- $args = explode(',',$arg[1]);
-
+ $args = explode(',', $matches[1]);
+ $lefts = isset($matches[2]) ? $matches[2] : '';
+
foreach($args as $arg) {
$cnt = 0;
- if (preg_match("/^(.+)\[(\d+)\]$/",$arg,$match)) {
- $arg = $match[1];
- $cnt = $match[2];
+ if (preg_match('/^(.+)\[(\d+)\]$/', $arg, $matches)) {
+ $arg = $matches[1];
+ $cnt = $matches[2];
}
$e_arg = encode($arg);
- if (!empty($post["vote_$e_arg"]) and $post["vote_$e_arg"] == $_vote_plugin_votes) {
- $cnt++;
- }
-
- $votes[] = $arg.'['.$cnt.']';
+ if (! empty($vars['vote_' . $e_arg]) && $vars['vote_' . $e_arg] == $_vote_plugin_votes)
+ ++$cnt;
+
+ $votes[] = $arg . '[' . $cnt . ']';
}
-
- $vote_str = '#vote('.@join(',',$votes).")\n";
-
+
+ $vote_str = '#vote(' . @join(',', $votes) . ')' . $lefts . "\n";
$postdata_input = $vote_str;
- $postdata .= $vote_str;
+ $postdata .= $vote_str;
}
- if (md5(@join('',get_source($post['refer']))) != $post['digest']) {
+ if (md5(get_source($vars['refer'], TRUE, TRUE)) !== $vars['digest']) {
$title = $_title_collided;
-
- $s_refer = htmlspecialchars($post['refer']);
- $s_digest = htmlspecialchars($post['digest']);
- $s_postdata_input = htmlspecialchars($postdata_input);
+
+ $s_refer = htmlsc($vars['refer']);
+ $s_digest = htmlsc($vars['digest']);
+ $s_postdata_input = htmlsc($postdata_input);
$body = <<<EOD
$_msg_collided
<form action="$script?cmd=preview" method="post">
<div>
- <input type="hidden" name="refer" value="$s_refer" />
+ <input type="hidden" name="refer" value="$s_refer" />
<input type="hidden" name="digest" value="$s_digest" />
<textarea name="msg" rows="$rows" cols="$cols" id="textarea">$s_postdata_input</textarea><br />
</div>
</form>
EOD;
- }
- else
- {
- page_write($post['refer'],$postdata);
-
+ } else {
+ page_write($vars['refer'], $postdata);
$title = $_title_updated;
}
- $retvars['msg'] = $title;
- $retvars['body'] = $body;
+ $vars['page'] = $vars['refer'];
- $post['page'] = $post['refer'];
- $vars['page'] = $post['refer'];
-
- return $retvars;
+ return array('msg'=>$title, 'body'=>$body);
}
+
function plugin_vote_convert()
{
- global $script,$vars,$digest;
+ global $vars, $digest;
global $_vote_plugin_choice, $_vote_plugin_votes;
- static $vote_no = 0;
-
- $vote_no++;
+ static $number = array();
+
+ $page = isset($vars['page']) ? $vars['page'] : '';
- if (!func_num_args()) {
- return '';
+ // Vote-box-id in the page
+ if (! isset($number[$page])) $number[$page] = 0; // Init
+ $vote_no = $number[$page]++;
+
+ if (! func_num_args()) return '#vote(): No arguments<br />' . "\n";
+
+ if (PKWK_READONLY) {
+ $_script = '';
+ $_submit = 'hidden';
+ } else {
+ $_script = get_base_uri();
+ $_submit = 'submit';
}
- $args = func_get_args();
- $s_page = htmlspecialchars($vars['page']);
- $s_digest = htmlspecialchars($digest);
+ $args = func_get_args();
+ $s_page = htmlsc($page);
+ $s_digest = htmlsc($digest);
$body = <<<EOD
-<form action="$script" method="post">
+<form action="$_script" method="post">
<table cellspacing="0" cellpadding="2" class="style_table" summary="vote">
<tr>
<td align="left" class="vote_label" style="padding-left:1em;padding-right:1em"><strong>$_vote_plugin_choice</strong>
- <input type="hidden" name="plugin" value="vote" />
- <input type="hidden" name="refer" value="$s_page" />
+ <input type="hidden" name="plugin" value="vote" />
+ <input type="hidden" name="refer" value="$s_page" />
<input type="hidden" name="vote_no" value="$vote_no" />
- <input type="hidden" name="digest" value="$s_digest" />
+ <input type="hidden" name="digest" value="$s_digest" />
</td>
<td align="center" class="vote_label"><strong>$_vote_plugin_votes</strong></td>
</tr>
EOD;
-
+
$tdcnt = 0;
+ $matches = array();
foreach($args as $arg) {
$cnt = 0;
-
- if (preg_match("/^(.+)\[(\d+)\]$/",$arg,$match)) {
- $arg = $match[1];
- $cnt = $match[2];
+
+ if (preg_match('/^(.+)\[(\d+)\]$/', $arg, $matches)) {
+ $arg = $matches[1];
+ $cnt = $matches[2];
}
$e_arg = encode($arg);
-
+
$link = make_link($arg);
-
+
$cls = ($tdcnt++ % 2) ? 'vote_td1' : 'vote_td2';
-
+
$body .= <<<EOD
<tr>
- <td align="left" class="$cls" style="padding-left:1em;padding-right:1em;">$link</td>
+ <td align="left" class="$cls" style="padding-left:1em;padding-right:1em;">$link</td>
<td align="right" class="$cls">$cnt
- <input type="submit" name="vote_$e_arg" value="$_vote_plugin_votes" class="submit" />
+ <input type="$_submit" name="vote_$e_arg" value="$_vote_plugin_votes" class="submit" />
</td>
</tr>
EOD;
}
-
+
$body .= <<<EOD
</table>
</form>
EOD;
-
+
return $body;
}
-?>