OSDN Git Service

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