OSDN Git Service

(no commit message)
[fswiki/sandbox.git] / kgsoft / plugin / _ex_spam_filter_light / comment.pm
1 ##########################################################################################
2 #
3 # ¥¹¥Ñ¥à¥Õ¥£¥ë¥¿¡¼¥×¥é¥°¥¤¥ó¡Ê³Ø½¬µ¡Ç½Ìµ¤·ÈÇ¡Ë
4 #¡Êcomment¥×¥é¥°¥¤¥ó¤Î¥ª¡¼¥Ð¡¼¥é¥¤¥É¡Ë
5 #
6 ##########################################################################################
7 use strict;
8
9 use plugin::comment::CommentHandler;
10
11 # plugin::comment::CommentHandler¤Îdo_action¥á¥½¥Ã¥É¤ÎÃÖ¤­´¹¤¨
12 package plugin::comment::CommentHandler;
13
14 sub do_action {
15         my $self = shift;
16         my $wiki = shift;
17         my $cgi  = $wiki->get_CGI;
18         
19         my $name    = $cgi->param("name");
20         my $message = $cgi->param("message");
21         my $count   = $cgi->param("count");
22         my $page    = $cgi->param("page");
23         my $option  = $cgi->param("option");
24         
25         if(!$wiki->can_show($page)){
26                 return $wiki->error("¥Ú¡¼¥¸¤Î»²¾È¸¢¸Â¤¬¤¢¤ê¤Þ¤»¤ó¡£");
27         }
28
29 #--------------------------------------------------------------------------------------------------
30   if($message){
31     unless(&plugin::_ex_spam_filter_light::Install::judgment_text($message)){
32       my $time = Util::format_date(time());
33       my $file = $wiki->config('log_dir')."/spam_comment.txt";
34       if(open(SPAM_LOG, ">>$file")){
35         print SPAM_LOG "$page:$message - $name($time)\n";
36         close(SPAM_LOG);
37       }
38       my $error_message = $wiki->error("Åê¹Æ¤µ¤ì¤¿Ê¸¾Ï¤Ï¥¹¥Ñ¥à¥á¥Ã¥»¡¼¥¸¤ÈȽÄꤵ¤ì¤Þ¤·¤¿¡£\n");
39       $error_message .= "<p>\n";
40       $error_message .= "<div>Åê¹Æ¤µ¤ì¤¿Ê¸¾Ï¡§</div>\n";
41       $error_message .= "<div>" . Util::escapeHTML("$message") . "</div>\n";
42       $error_message .= "</p>\n";
43       return $error_message;
44     }
45   }
46 #--------------------------------------------------------------------------------------------------
47
48         if($name eq ""){
49                 $name = "̵̾¤·¤µ¤ó";
50         } else {
51                 # fswiki_post_name¤È¤¤¤¦¥­¡¼¤Ç¥¯¥Ã¥­¡¼¤ò¥»¥Ã¥È¤¹¤ë
52                 my $path   = &Util::cookie_path($wiki);
53                 my $cookie = $cgi->cookie(-name=>'fswiki_post_name',-value=>Util::url_encode($name),-expires=>'+1M',-path=>$path);
54                 print "Set-Cookie: ",$cookie->as_string,"\n";
55         }
56         
57         # ¥Õ¥©¡¼¥Þ¥Ã¥È¥×¥é¥°¥¤¥ó¤Ø¤ÎÂбþ
58         my $format = $wiki->get_edit_format();
59         $name    = $wiki->convert_to_fswiki($name   ,$format,1);
60         $message = $wiki->convert_to_fswiki($message,$format,1);
61         
62         if($page ne "" && $message ne "" && $count ne ""){
63                 
64                 my @lines = split(/\n/,$wiki->get_page($page));
65                 my $flag       = 0;
66                 my $form_count = 1;
67                 my $content    = "";
68                 
69                 foreach(@lines){
70                         # ¿·Ãå½ç¤Î¾ì¹ç
71                         if($option eq "reverse"){
72                                 $content = $content.$_."\n";
73                                 if(/^\{\{comment\s*.*\}\}$/ && $flag==0){
74                                         if($form_count==$count){
75                                                 $content = $content."*$message - $name (".Util::format_date(time()).")\n";
76                                                 $flag = 1;
77                                         } else {
78                                                 $form_count++;
79                                         }
80                                 }
81                         # ¥Ú¡¼¥¸ËöÈø¤ËÄɲäξì¹ç
82                         } elsif($option eq "tail"){
83                                 $content = $content.$_."\n";
84                                 
85                         # Åê¹Æ½ç¤Î¾ì¹ç
86                         } else {
87                                 if(/^\{\{comment\s*.*\}\}$/ && $flag==0){
88                                         if($form_count==$count){
89                                                 $content = $content."*$message - $name (".Util::format_date(time()).")\n";
90                                                 $flag = 1;
91                                         } else {
92                                                 $form_count++;
93                                         }
94                                 }
95                                 $content = $content.$_."\n";
96                         }
97                 }
98                 
99                 # ¥Ú¡¼¥¸ËöÈø¤ËÄɲäξì¹ç¤ÏºÇ¸å¤ËÄɲÃ
100                 if($option eq "tail" && check_comment($wiki, 'Footer')){
101                         $content = $content."*$message - $name (".Util::format_date(time()).")\n";
102                         $flag = 1;
103                 }
104                 
105                 if($flag==1){
106                         $wiki->save_page($page,$content);
107                 }
108         }
109         
110         # ¸µ¤Î¥Ú¡¼¥¸¤Ë¥ê¥À¥¤¥ì¥¯¥È
111         $wiki->redirect($page);
112 }
113
114 1;