OSDN Git Service

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