OSDN Git Service

Cleanup and correct secret 'x*y' view
[pukiwiki/pukiwiki.git] / plugin / vote.inc.php
1 <?php
2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
4 //
5 // $Id: vote.inc.php,v 1.16 2004/07/31 03:09:20 henoheno Exp $
6 //
7
8 function plugin_vote_action()
9 {
10         global $vars, $script, $cols,$rows;
11         global $_title_collided, $_msg_collided, $_title_updated;
12         global $_vote_plugin_choice, $_vote_plugin_votes;
13
14         $postdata_old  = get_source($vars['refer']);
15         $vote_no = 0;
16         $title = $body = $postdata = '';
17
18         foreach($postdata_old as $line)
19         {
20                 if (! preg_match("/^#vote\((.*)\)\s*$/", $line, $arg))
21                 {
22                         $postdata .= $line;
23                         continue;
24                 }
25
26                 if ($vote_no++ != $vars['vote_no'])
27                 {
28                         $postdata .= $line;
29                         continue;
30                 }
31                 $args = explode(',', $arg[1]);
32
33                 $match = array();
34                 foreach($args as $arg)
35                 {
36                         $cnt = 0;
37                         if (preg_match("/^(.+)\[(\d+)\]$/", $arg, $match))
38                         {
39                                 $arg = $match[1];
40                                 $cnt = $match[2];
41                         }
42                         $e_arg = encode($arg);
43                         if (! empty($vars["vote_$e_arg"]) and $vars["vote_$e_arg"] == $_vote_plugin_votes)
44                         {
45                                 ++$cnt;
46                         }
47
48                         $votes[] = $arg . '[' . $cnt . ']';
49                 }
50
51                 $vote_str = '#vote(' . @join(',', $votes) . ")\n";
52
53                 $postdata_input = $vote_str;
54                 $postdata      .= $vote_str;
55         }
56
57         if (md5(@join('', get_source($vars['refer']))) != $vars['digest'])
58         {
59                 $title = $_title_collided;
60
61                 $s_refer  = htmlspecialchars($vars['refer']);
62                 $s_digest = htmlspecialchars($vars['digest']);
63                 $s_postdata_input = htmlspecialchars($postdata_input);
64                 $body = <<<EOD
65 $_msg_collided
66 <form action="$script?cmd=preview" method="post">
67  <div>
68   <input type="hidden" name="refer"  value="$s_refer" />
69   <input type="hidden" name="digest" value="$s_digest" />
70   <textarea name="msg" rows="$rows" cols="$cols" id="textarea">$s_postdata_input</textarea><br />
71  </div>
72 </form>
73
74 EOD;
75         }
76         else
77         {
78                 page_write($vars['refer'], $postdata);
79
80                 $title = $_title_updated;
81         }
82
83         $retvars['msg'] = $title;
84         $retvars['body'] = $body;
85
86         $vars['page'] = $vars['refer'];
87
88         return $retvars;
89 }
90
91 function plugin_vote_convert()
92 {
93         global $script, $vars,  $digest;
94         global $_vote_plugin_choice, $_vote_plugin_votes;
95         static $numbers = array();
96
97         if (! isset($numbers[$vars['page']]))
98         {
99                 $numbers[$vars['page']] = 0;
100         }
101         $vote_no = $numbers[$vars['page']]++;
102
103         if (!func_num_args())
104         {
105                 return '';
106         }
107
108         $args = func_get_args();
109         $s_page   = htmlspecialchars($vars['page']);
110         $s_digest = htmlspecialchars($digest);
111
112         $body = <<<EOD
113 <form action="$script" method="post">
114  <table cellspacing="0" cellpadding="2" class="style_table" summary="vote">
115   <tr>
116    <td align="left" class="vote_label" style="padding-left:1em;padding-right:1em"><strong>$_vote_plugin_choice</strong>
117     <input type="hidden" name="plugin"  value="vote" />
118     <input type="hidden" name="refer"   value="$s_page" />
119     <input type="hidden" name="vote_no" value="$vote_no" />
120     <input type="hidden" name="digest"  value="$s_digest" />
121    </td>
122    <td align="center" class="vote_label"><strong>$_vote_plugin_votes</strong></td>
123   </tr>
124
125 EOD;
126
127         $tdcnt = 0;
128         $match = array();
129         foreach($args as $arg)
130         {
131                 $cnt = 0;
132
133                 if (preg_match("/^(.+)\[(\d+)\]$/", $arg, $match))
134                 {
135                         $arg = $match[1];
136                         $cnt = $match[2];
137                 }
138                 $e_arg = encode($arg);
139
140                 $link = make_link($arg);
141
142                 $cls = ($tdcnt++ % 2)  ? 'vote_td1' : 'vote_td2';
143
144                 $body .= <<<EOD
145   <tr>
146    <td align="left" class="$cls" style="padding-left:1em;padding-right:1em;">$link</td>
147    <td align="right" class="$cls">$cnt&nbsp;&nbsp;
148     <input type="submit" name="vote_$e_arg" value="$_vote_plugin_votes" class="submit" />
149    </td>
150   </tr>
151
152 EOD;
153         }
154
155         $body .= <<<EOD
156  </table>
157 </form>
158
159 EOD;
160
161         return $body;
162 }
163 ?>