• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision47ddff85c9c70967d7c6b3ea4c91a64495c05bf3 (tree)
Zeit2022-01-24 02:08:09
Autorhai-fun <haifun129@gmai...>
Commiterhai-fun

Log Message

Ändern Zusammenfassung

Diff

--- /dev/null
+++ b/vote2.inc.php
@@ -0,0 +1,507 @@
1+<?php
2+/////////////////////////////////////////////////
3+// PukiWiki - Yet another WikiWikiWeb clone.
4+//
5+// $Id: vote2.inc.php,v 0.12 2003/10/05 17:55:04 sha Exp $
6+// based on vote.inc.php v1.14
7+//
8+// v0.2はインラインのリンクにtitleを付けた。
9+
10+function plugin_vote2_init()
11+{
12+ $messages = array(
13+ '_vote2_messages' => array(
14+ 'arg_notimestamp' => 'notimestamp',
15+ 'arg_nonumber' => 'nonumber',
16+ 'arg_nolabel' => 'nolabel',
17+ 'arg_notitle' => 'notitle',
18+ 'title_error' => 'Error in vote2',
19+ 'no_page_error' => '$1 のページは存在しません',
20+ 'update_failed' => '投票失敗:$1において投票先が無いか項目が合致しませんでした。',
21+ 'body_error' => 'あるべき引数が渡されていないか、引数にエラーがあります。',
22+ 'msg_collided' => '<h3>あなたが投票している間に、他の人が同じページの内容を更新してしまったようです。<br />従って、投票する位置を間違える可能性があります。<br /><br />
23+あなたの更新を無効にしました。前のページをリロードしてやり直してください。</h3>'
24+
25+ ),
26+ );
27+ set_plugin_messages($messages);
28+}
29+function plugin_vote2_action()
30+{
31+ global $vars, $_vote2_messages;
32+ $vote_no = 0;
33+ $block_flag = 0;
34+
35+ if ( ! is_page($vars['refer']) ){
36+ $error = str_replace('$1', $vars['refer'], $_vote2_messages['no_page_error']);
37+ return array(
38+ 'msg' => $_vote2_messages['title_error'],
39+ 'body' => $error,
40+ );
41+ }
42+ if ( array_key_exists('vote_no', $vars) ) {
43+ $vote_no = $vars['vote_no'];
44+ $block_flag = 1;
45+ }
46+ else if ( array_key_exists('vote_inno', $vars) ){
47+ $vote_no = $vars['vote_inno'];
48+ $block_flag = 0;
49+ }
50+ if ( preg_match('/^(\d+)([ib]?)$/', $vote_no, $match) ){
51+ $vote_no = $match[1];
52+ switch ( $match[2] ){
53+ case 'i': $block_flag = 0; break;
54+ case 'b': $block_flag = 1; break;
55+ default: break;
56+ }
57+ switch ( $block_flag ) {
58+ case 1:
59+ return plugin_vote2_action_block($vote_no);
60+ break;
61+ case 0:
62+ default:
63+ return plugin_vote2_action_inline($vote_no);
64+ break;
65+ }
66+ }
67+ return array(
68+ 'msg' => $_vote2_messages['title_error'],
69+ 'body' => $_vote2_messages['body_error'],
70+ );
71+}
72+function plugin_vote2_inline()
73+{
74+ global $script,$vars,$digest, $_vote2_messages, $_vote_plugin_votes;
75+ global $_vote_plugin_choice, $_vote_plugin_votes;
76+ static $numbers = array();
77+ static $notitle = FALSE;
78+ $str_notimestamp = $_vote2_messages['arg_notimestamp'];
79+ $str_nonumber = $_vote2_messages['arg_nonumber'];
80+ $str_nolabel = $_vote2_messages['arg_nolabel'];
81+ $str_notitle = $_vote2_messages['arg_notitle'];
82+
83+ $args = func_get_args();
84+ array_pop($args); // {}内の要素の削除
85+ $page = $vars['page'];
86+ if (!array_key_exists($page,$numbers)) $numbers[$page] = 0;
87+ $vote_inno = $numbers[$page]++;
88+ $o_vote_inno = $f_vote_inno = $vote_inno;
89+
90+ $ndigest = $digest;
91+ $arg = '';
92+ $cnt = 0;
93+ $nonumber = $nolabel = FALSE;
94+ foreach ( $args as $opt ){
95+ $opt = trim($opt);
96+ if ( $opt == $str_notimestamp || $opt == '' ){
97+ }
98+ else if ( $opt == $str_nonumber ){
99+ $nonumber = TRUE;
100+ }
101+ else if ( $opt == $str_nolabel ){
102+ $nolabel = TRUE;
103+ }
104+ else if ( $opt == $str_notitle ){
105+ $notitle = TRUE;
106+ }
107+ else if ( preg_match('/^(.+(?==))=([+-]?\d+)([ibr]?)$/',$opt,$match) ){
108+ list($page,$vote_inno,$f_vote_inno,$ndigest)
109+ = plugin_vote2_address($match,$vote_inno,$page,$ndigest);
110+ }
111+ else if ( $arg == '' and preg_match("/^(.*)\[(\d+)\]$/",$opt,$match)){
112+ $arg = $match[1];
113+ $cnt = $match[2];
114+ }
115+ else if ( $arg == '' ) {
116+ $arg = $opt;
117+ }
118+ }
119+// if ( $arg == '' ) return '';
120+ $link = make_link($arg);
121+ $e_arg = encode($arg);
122+ $f_page = rawurlencode($page);
123+ $f_digest = rawurlencode($ndigest);
124+ $f_vote_plugin_votes = rawurlencode($_vote_plugin_votes);
125+ $f_cnf = '';
126+ if ( $nonumber == FALSE ) {
127+ $title = $notitle ? '' : "title=\"$o_vote_inno\"";
128+ $f_cnt = "<span $title>&nbsp;" . $cnt . "&nbsp;</span>";
129+ }
130+ if ( $nolabel == FALSE ) {
131+ $title = $notitle ? '' : "title=\"$f_vote_inno\"";
132+ return <<<EOD
133+<a href="$script?plugin=vote2&amp;refer=$f_page&amp;vote_inno=$vote_inno&amp;vote_$e_arg=$f_vote_plugin_votes&amp;digest=$f_digest" $title>$link</a>$f_cnt
134+EOD;
135+ }
136+ else {
137+ return $f_cnt;
138+ }
139+}
140+function plugin_vote2_address($match, $vote_no, $page, $ndigest)
141+{
142+ global $digests;
143+
144+ $this_flag = FALSE;
145+ $npage = trim($match[1]);
146+ $vote2_no_arg = $match[2];
147+ $vote2_attr_arg = $match[3];
148+
149+ if ( $npage == 'this' ) {
150+ $npage = $page;
151+ $this_flag = TRUE;
152+ }
153+ else {
154+ $npage = preg_replace('/^\[\[(.*)\]\]$/','$1', $npage);
155+ if ( $npage == $page ){
156+ $this_flag = TRUE;
157+ }
158+ else if ( ! is_page($npage) ) {
159+ $vote2_attr_arg = 'error';
160+ }
161+ else if ( array_key_exists($npage, $digests) ) {
162+ $ndigest = $digests[$npage];
163+ }
164+ else {
165+ $ndigest = md5(join('',get_source($npage)));
166+ $digests[$npage] = $ndigest;
167+ }
168+ }
169+ switch ( $vote2_attr_arg ){
170+ case '':
171+ case 'i':
172+ case 'b': $vote_no = $vote2_no_arg . $vote2_attr_arg; break;
173+ case 'r':
174+ if ( $this_flag ) {
175+ $vote_no += $vote2_no_arg;
176+ }
177+ else {
178+ $vote_no = 'error';
179+ }
180+ break;
181+ default: $vote_no = 'error'; break;
182+ }
183+ $f_vote_no = htmlspecialchars($npage . '=' . $vote_no);
184+ return array($npage, $vote_no, $f_vote_no, $ndigest);
185+}
186+function plugin_vote2_convert()
187+{
188+ global $script,$vars,$digest, $_vote2_messages;
189+ global $_vote_plugin_choice, $_vote_plugin_votes, $digests;
190+ static $numbers = array();
191+ static $notitle = FALSE;
192+ $str_notimestamp = $_vote2_messages['arg_notimestamp'];
193+ $str_nonumber = $_vote2_messages['arg_nonumber'];
194+ $str_nolabel = $_vote2_messages['arg_nolabel'];
195+ $str_notitle = $_vote2_messages['arg_notitle'];
196+
197+ if (!array_key_exists($vars['page'],$numbers))
198+ {
199+ $numbers[$vars['page']] = 0;
200+ }
201+ $o_vote_no = $f_vote_no = $vote_no = $numbers[$vars['page']]++;
202+
203+ if (!func_num_args())
204+ {
205+ return '';
206+ }
207+
208+ $args = func_get_args();
209+ $page = $vars['page'];
210+
211+ $ndigest = $digest;
212+ $tdcnt = 0;
213+ $body2 = '';
214+ $nonumber = $nolabel = FALSE;
215+ $options = array();
216+ foreach($args as $arg)
217+ {
218+ $arg = trim($arg);
219+ if ( $arg == $str_nonumber ){
220+ $nonumber = TRUE;
221+ continue;
222+ }
223+ else if ( $arg == $str_nolabel ){
224+ $nolabel = TRUE;
225+ continue;
226+ }
227+ else if ( $arg == $str_notitle ){
228+ $notitle = TRUE;
229+ continue;
230+ }
231+ $options[] = $arg;
232+ }
233+ foreach($options as $arg)
234+ {
235+ $cnt = 0;
236+ if ( $arg == $str_notimestamp ){
237+ continue;
238+ }
239+ else if ( preg_match('/^(.+(?==))=([+-]?\d+)([bir]?)$/',$arg,$match) ){
240+ list($page,$vote_no,$f_vote_no,$ndigest)
241+ = plugin_vote2_address($match,$vote_no,$page,$ndigest);
242+ continue;
243+ }
244+ else if (preg_match("/^(.*)\[(\d+)\]$/",$arg,$match))
245+ {
246+ $arg = $match[1];
247+ $cnt = $match[2];
248+ }
249+ $e_arg = encode($arg);
250+ $f_cnf = '';
251+ if ( $nonumber == FALSE ) {
252+ $title = $notitle ? '' : "title=\"$o_vote_no\"";
253+ $f_cnt = "<span $title>&nbsp;" . $cnt . "&nbsp;</span>";
254+ }
255+ $link = make_link($arg);
256+
257+ switch ( $tdcnt++ % 3){
258+ case 0: $cls = 'vote_td1'; break;
259+ case 1: $cls = 'vote_td2'; break;
260+ case 2: $cls = 'vote_td3'; break;
261+ }
262+ $cls = ($tdcnt++ % 2) ? 'vote_td1' : 'vote_td2';
263+
264+ if ( $nolabel == FALSE ){
265+ $body2 .= <<<EOD
266+ <tr>
267+ <td align="left" class="$cls" style="padding-left:1em;padding-right:1em;">$link</td>
268+ <td align="right" class="$cls">$f_cnt
269+ <input type="submit" name="vote_$e_arg" value="$_vote_plugin_votes" class="submit" />
270+ </td>
271+ </tr>
272+
273+EOD;
274+ }
275+ else {
276+ $body2 .= <<<EOD
277+ <tr>
278+ <td align="left" class="$cls" style="padding-left:1em;padding-right:1em;">$link</td>
279+ <td align="right" class="$cls">$f_cnt
280+ </td>
281+ </tr>
282+
283+EOD;
284+ }
285+ }
286+
287+ $s_page = htmlspecialchars($page);
288+ $s_digest = htmlspecialchars($ndigest);
289+ $title = $notitle ? '' : "title=\"$f_vote_no\"";
290+ $body = <<<EOD
291+<form action="$script" method="post">
292+ <table cellspacing="0" cellpadding="2" class="style_table" summary="vote" $title>
293+ <tr>
294+ <td align="left" class="vote_label" style="padding-left:1em;padding-right:1em"><strong>$_vote_plugin_choice</strong>
295+ <input type="hidden" name="plugin" value="vote2" />
296+ <input type="hidden" name="refer" value="$s_page" />
297+ <input type="hidden" name="digest" value="$s_digest" />
298+ <input type="hidden" name="vote_no" value="$vote_no" />
299+ </td>
300+ <td align="center" class="vote_label"><strong>$_vote_plugin_votes</strong></td>
301+ </tr>
302+
303+EOD;
304+
305+ $body .= <<<EOD
306+$body2
307+ </table>
308+</form>
309+
310+EOD;
311+
312+ return $body;
313+}
314+function plugin_vote2_action_inline($vote_no)
315+{
316+ global $get,$vars,$script,$cols,$rows, $_vote2_messages;
317+ global $_title_collided,$_msg_collided,$_title_updated;
318+ global $_vote_plugin_choice, $_vote_plugin_votes;
319+ $str_notimestamp = $_vote2_messages['arg_notimestamp'];
320+ $str_nonumber = $_vote2_messages['arg_nonumber'];
321+ $str_nolabel = $_vote2_messages['arg_nolabel'];
322+ $str_notitle = $_vote2_messages['arg_notitle'];
323+
324+ $str_plugin = 'vote2';
325+ $len_plugin = strlen($str_plugin) + 1;
326+ $title = $body = $postdata = '';
327+ $vote_ct = $skipflag = 0;
328+ $page = $vars['page'];
329+ $postdata_old = get_source($vars['refer']);
330+
331+ $ic = new InlineConverter(array('plugin'));
332+ $notimestamp = $update_flag = FALSE;
333+ foreach($postdata_old as $line)
334+ {
335+ if ( $skipflag || substr($line,0,1) == ' ' || substr($line,0,2) == '//' ){
336+ $postdata .= $line;
337+ continue;
338+ }
339+ $pos = 0;
340+ $arr = $ic->get_objects($line,$page);
341+ while ( count($arr) ){
342+ $obj = array_shift($arr);
343+ if ( $obj->name != $str_plugin ) continue;
344+ $pos = strpos($line, '&' . $str_plugin, $pos);
345+ if ( $vote_ct++ < $vote_no ) {
346+ $pos += $len_plugin;
347+ continue;
348+ }
349+ $l_line = substr($line,0,$pos);
350+ $r_line = substr($line,$pos + strlen($obj->text));
351+ $options = explode(',', $obj->param);
352+ $cnt = 0;
353+ $name = '';
354+ $vote = array();
355+ foreach ( $options as $opt ){
356+ $arg = trim($opt);
357+ if ( $arg == $str_notimestamp ){
358+ $notimestamp = TRUE;
359+ }
360+ else if ( $arg == '' ){
361+ continue;
362+ }
363+ else if ( $arg == $str_nonumber || $arg == $str_nolabel || $arg == $str_notitle ) {
364+ }
365+ else if (preg_match("/^.+(?==)=[+-]?\d+[bir]?$/",$arg,$match)){
366+ }
367+ else if ( $name == '' and preg_match("/^(.*)\[(\d+)\]$/",$arg,$match)){
368+ $name = $match[1];
369+ $cnt = $match[2];
370+ continue;
371+ }
372+ else if ( $name == '' ){
373+ $name = $arg;
374+ continue;
375+ }
376+ $vote[] = $arg;
377+ }
378+ array_unshift($vote, $name .'['.($cnt+1).']');
379+ $vote_str = "&$str_plugin(".join(',',$vote).');';
380+ $pline = $l_line . $vote_str . $r_line;
381+ if ( $pline !== $line ) $update_flag = TRUE;
382+ $postdata_input = $line = $pline;
383+ $skipflag = 1;
384+ break;
385+ }
386+ $postdata .= $line;
387+ }
388+
389+ if ( md5(@join('',get_source($vars['refer']))) != $vars['digest'])
390+ {
391+ $title = $_title_collided;
392+ $body = $_vote2_messages['msg_collided'] . make_pagelink($vars['refer']) .
393+ "<hr />\n $postdata_input";
394+ }
395+ else if ( $update_flag == TRUE )
396+ {
397+ page_write($vars['refer'],$postdata,$notimestamp);
398+ $title = $_title_updated;
399+
400+//$body = convert_html($postdata . "\n----\n"). $postdata_input . "/" . $vote_str . "/" . $vote . "/" . $name;
401+//$title = "debug for vote2";
402+ }
403+ else {
404+ $title = $_vote2_messages['update_failed'];
405+ }
406+
407+ $retvars['msg'] = $title;
408+ $retvars['body'] = $body;
409+
410+ $get['page'] = $vars['refer'];
411+ $vars['page'] = $vars['refer'];
412+
413+ return $retvars;
414+}
415+function plugin_vote2_action_block($vote_no)
416+{
417+ global $post,$vars,$script,$cols,$rows, $_vote2_messages;
418+ global $_title_collided,$_msg_collided,$_title_updated;
419+ global $_vote_plugin_choice, $_vote_plugin_votes;
420+ $str_notimestamp = $_vote2_messages['arg_notimestamp'];
421+ $str_nonumber = $_vote2_messages['arg_nonumber'];
422+ $str_nolabel = $_vote2_messages['arg_nolabel'];
423+ $str_notitle = $_vote2_messages['arg_notitle'];
424+ $notimestamp = $update_flag = FALSE;
425+
426+ $postdata_old = get_source($vars['refer']);
427+ $vote_ct = 0;
428+ $title = $body = $postdata = '';
429+
430+ foreach($postdata_old as $line)
431+ {
432+ if (!preg_match("/^#vote2\((.*)\)\s*$/",$line,$arg))
433+ {
434+ $postdata .= $line;
435+ continue;
436+ }
437+
438+ if ($vote_ct++ != $vote_no)
439+ {
440+ $postdata .= $line;
441+ continue;
442+ }
443+ $args = explode(',',$arg[1]);
444+
445+ foreach($args as $arg)
446+ {
447+ $arg = trim($arg);
448+ $cnt = 0;
449+ if ( $arg == $str_notimestamp ){
450+ $notimestamp = TRUE;
451+ $votes[] = $arg;
452+ continue;
453+ }
454+ else if ( $arg == '' ) {
455+ continue;
456+ }
457+ else if ( $arg == $str_nonumber || $arg == $str_nolabel || $arg == $str_notitle ){
458+ $votes[] = $arg;
459+ continue;
460+ }
461+ else if (preg_match("/^.+(?==)=[+-]?\d+[bir]?$/",$arg,$match)){
462+ $votes[] = $arg;
463+ continue;
464+ }
465+ else if (preg_match("/^(.*)\[(\d+)\]$/",$arg,$match))
466+ {
467+ $arg = $match[1];
468+ $cnt = $match[2];
469+ }
470+ $e_arg = encode($arg);
471+ if (!empty($vars["vote_$e_arg"]) and $vars["vote_$e_arg"] == $_vote_plugin_votes)
472+ {
473+ $cnt++;
474+ $update_flag = TRUE;
475+ }
476+ $votes[] = $arg.'['.$cnt.']';
477+ }
478+ $vote_str = '#vote2('.@join(',',$votes).")\n";
479+
480+ $postdata_input = $vote_str;
481+ $postdata .= $vote_str;
482+ }
483+
484+ if ( md5(@join('',get_source($vars['refer']))) != $vars['digest'] )
485+ {
486+ $title = $_title_collided;
487+ $body = $_vote2_messages['msg_collided'] . make_pagelink($vars['refer']) .
488+ "<hr />\n $postdata_input";
489+ }
490+ else if ( $update_flag == TRUE )
491+ {
492+ $title = $_title_updated;
493+ page_write($vars['refer'],$postdata,$notimestamp);
494+ }
495+ else {
496+ $title = $_vote2_messages['update_failed'];
497+ }
498+
499+ $retvars['msg'] = $title;
500+ $retvars['body'] = $body;
501+
502+ $post['page'] = $vars['refer'];
503+ $vars['page'] = $vars['refer'];
504+
505+ return $retvars;
506+}
507+?>