OSDN Git Service

Perl5.26以降における "{", "}" の正規表現検査時のエスケープ対応。
[fswiki/fswiki.git] / plugin / vote / Vote.pm
1 ############################################################
2
3 # <p>´Ê°×Ū¤ÊÅêɼ¥Õ¥©¡¼¥à¤ÈÅÓÃæ·Ð²á¤òɽ¼¨¤·¤Þ¤¹¡£</p>
4 # <pre>
5 # {{vote Åêɼ̾,¹àÌÜ1,¹àÌÜ2,}}
6 # </pre>
7 # <p>
8 #   Î㤨¤Ð°Ê²¼¤Î¤è¤¦¤Ë»ÈÍѤ·¤Þ¤¹¡£
9 #   Âè°ì°ú¿ô¤Ë¤Ï¤½¤ÎÅêɼ¤ò¼¨¤¹¤ï¤«¤ê¤ä¤¹¤¤Ì¾Á°¤ò¤Ä¤±¤Æ¤¯¤À¤µ¤¤¡£
10 #   ÂèÆó°ú¿ô°Ê¹ß¤¬¼ÂºÝ¤Ëɽ¼¨¤µ¤ì¤ëÁªÂò¹àÌܤˤʤê¤Þ¤¹¡£
11 # </p>
12 # <pre>
13 # {{vote FSWiki¤Î´¶ÁÛ,¤è¤¤,ÉáÄÌ,¥À¥á}}
14 # </pre>
15 #
16 ############################################################
17 package plugin::vote::Vote;
18 use strict;
19 #===========================================================
20 # ¥³¥ó¥¹¥È¥é¥¯¥¿
21 #===========================================================
22 sub new {
23         my $class = shift;
24         my $self = {};
25         return bless $self,$class;
26 }
27
28 #===========================================================
29 # Åêɼ¥Õ¥©¡¼¥à
30 #===========================================================
31 sub paragraph {
32         my $self     = shift;
33         my $wiki     = shift;
34         my $votename = shift;
35         my @itemlist = @_;
36         my $cgi      = $wiki->get_CGI;
37         my $page     = $cgi->param("page");
38         
39         # °ú¿ô¤Î¥¨¥é¡¼¥Á¥§¥Ã¥¯
40         if($votename eq ""){
41                 return &Util::paragraph_error("Åêɼ̾¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£","Wiki");
42         }
43         if($#itemlist == -1){
44                 return &Util::paragraph_error("¹àÌÜ̾¤¬»ØÄꤵ¤ì¤Æ¤¤¤Þ¤»¤ó¡£","Wiki");
45         }
46         
47         # Æɤ߹þ¤à
48         my $filename = &Util::make_filename($wiki->config('log_dir'),
49                                             &Util::url_encode($votename),"vote");
50         my $hash = &Util::load_config_hash(undef,$filename);
51         
52         # É½¼¨Íѥƥ­¥¹¥È¤òÁȤßΩ¤Æ¤ë
53         my $buf = ",¹àÌÜ,ÆÀɼ¿ô\n";
54         
55         foreach my $item (@itemlist) {
56                 my $count = $hash->{$item};
57                 unless(defined($count)){
58                         $count=0;
59                 }
60                 $buf .= ",$item,$countɼ - [Åêɼ|".$wiki->create_url({
61                         page=>$page,
62                         vote=>$votename,
63                         item=>$item,
64                         action=>'VOTE'
65                 })."]\n";
66         }
67         return $buf;
68 }
69
70 1;