OSDN Git Service

BugTrack/399: 表示メッセージをen.lng/ja.lngに集約
[pukiwiki/pukiwiki.git] / plugin / vote.inc.php
1 <?php
2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
4 //
5 // $Id: vote.inc.php,v 1.14 2003/07/03 05:28:04 arino Exp $
6 //
7
8 function plugin_vote_action()
9 {
10         global $post,$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($post['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++ != $post['vote_no'])
27                 {
28                         $postdata .= $line;
29                         continue;
30                 }
31                 $args = explode(',',$arg[1]);
32                 
33                 foreach($args as $arg)
34                 {
35                         $cnt = 0;
36                         if (preg_match("/^(.+)\[(\d+)\]$/",$arg,$match))
37                         {
38                                 $arg = $match[1];
39                                 $cnt = $match[2];
40                         }
41                         $e_arg = encode($arg);
42                         if (!empty($post["vote_$e_arg"]) and $post["vote_$e_arg"] == $_vote_plugin_votes)
43                         {
44                                 $cnt++;
45                         }
46                         
47                         $votes[] = $arg.'['.$cnt.']';
48                 }
49                 
50                 $vote_str = '#vote('.@join(',',$votes).")\n";
51                 
52                 $postdata_input = $vote_str;
53                 $postdata .= $vote_str;
54         }
55
56         if (md5(@join('',get_source($post['refer']))) != $post['digest'])
57         {
58                 $title = $_title_collided;
59                 
60                 $s_refer = htmlspecialchars($post['refer']);
61                 $s_digest = htmlspecialchars($post['digest']);
62                 $s_postdata_input = htmlspecialchars($postdata_input);
63                 $body = <<<EOD
64 $_msg_collided
65 <form action="$script?cmd=preview" method="post">
66  <div>
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 />
70  </div>
71 </form>
72
73 EOD;
74         }
75         else
76         {
77                 page_write($post['refer'],$postdata);
78                 
79                 $title = $_title_updated;
80         }
81
82         $retvars['msg'] = $title;
83         $retvars['body'] = $body;
84
85         $post['page'] = $post['refer'];
86         $vars['page'] = $post['refer'];
87
88         return $retvars;
89 }
90 function plugin_vote_convert()
91 {
92         global $script,$vars,$digest;
93         global $_vote_plugin_choice, $_vote_plugin_votes;
94         static $numbers = array();
95         
96         if (!array_key_exists($vars['page'],$numbers))
97         {
98                 $numbers[$vars['page']] = 0;
99         }
100         $vote_no = $numbers[$vars['page']]++;
101         
102         if (!func_num_args())
103         {
104                 return '';
105         }
106
107         $args = func_get_args();
108         $s_page = htmlspecialchars($vars['page']);
109         $s_digest = htmlspecialchars($digest);
110
111         $body = <<<EOD
112 <form action="$script" method="post">
113  <table cellspacing="0" cellpadding="2" class="style_table" summary="vote">
114   <tr>
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" />
120    </td>
121    <td align="center" class="vote_label"><strong>$_vote_plugin_votes</strong></td>
122   </tr>
123
124 EOD;
125         
126         $tdcnt = 0;
127         foreach($args as $arg)
128         {
129                 $cnt = 0;
130                 
131                 if (preg_match("/^(.+)\[(\d+)\]$/",$arg,$match))
132                 {
133                         $arg = $match[1];
134                         $cnt = $match[2];
135                 }
136                 $e_arg = encode($arg);
137                 
138                 $link = make_link($arg);
139                 
140                 $cls = ($tdcnt++ % 2)  ? 'vote_td1' : 'vote_td2';
141                 
142                 $body .= <<<EOD
143   <tr>
144    <td align="left" class="$cls" style="padding-left:1em;padding-right:1em;">$link</td>
145    <td align="right" class="$cls">$cnt&nbsp;&nbsp;
146     <input type="submit" name="vote_$e_arg" value="$_vote_plugin_votes" class="submit" />
147    </td>
148   </tr>
149
150 EOD;
151         }
152         
153         $body .= <<<EOD
154  </table>
155 </form>
156
157 EOD;
158         
159         return $body;
160 }
161 ?>