OSDN Git Service

701fda5da0911e437a4fdf6c5f9a54798b91d90e
[fswiki/sandbox.git] / kgsoft / plugin / 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 #--------------------------------------------------------------------------------------------------
26   if($message){
27     unless(&plugin::_ex_spam_filter_light::Install::judgment_text($message)){
28       my $time = Util::format_date(time());
29       my $file = $wiki->config('log_dir')."/spam_comment.txt";
30       if(open(SPAM_LOG, ">>$file")){
31         print SPAM_LOG "$page:$message - $name($time)\n";
32         close(SPAM_LOG);
33       }
34       my $error_message = $wiki->error("Åê¹Æ¤µ¤ì¤¿Ê¸¾Ï¤Ï¥¹¥Ñ¥à¥á¥Ã¥»¡¼¥¸¤ÈȽÄꤵ¤ì¤Þ¤·¤¿¡£\n");
35       $error_message .= "<p>\n";
36       $error_message .= "<div>Åê¹Æ¤µ¤ì¤¿Ê¸¾Ï¡§</div>\n";
37       $error_message .= "<div>" . Util::escapeHTML("$message") . "</div>\n";
38       $error_message .= "</p>\n";
39       return $error_message;
40     }
41   }
42 #--------------------------------------------------------------------------------------------------
43
44         if($name eq ""){
45                 $name = "̵̾¤·¤µ¤ó";
46         } else {
47                 # post_name¤È¤¤¤¦¥­¡¼¤Ç¥¯¥Ã¥­¡¼¤ò¥»¥Ã¥È¤¹¤ë
48                 my $path   = &Util::cookie_path($wiki);
49                 my $cookie = $cgi->cookie(-name=>'post_name',-value=>$name,-expires=>'+1M',-path=>$path);
50                 print "Set-Cookie: ",$cookie->as_string,"\n";
51         }
52         
53         # ¥Õ¥©¡¼¥Þ¥Ã¥È¥×¥é¥°¥¤¥ó¤Ø¤ÎÂбþ
54         my $format = $wiki->get_edit_format();
55         $name    = $wiki->convert_to_fswiki($name   ,$format,1);
56         $message = $wiki->convert_to_fswiki($message,$format,1);
57         
58         if($page ne "" && $message ne "" && $count ne ""){
59                 
60                 my @lines = split(/\n/,$wiki->get_page($page));
61                 my $flag       = 0;
62                 my $form_count = 1;
63                 my $content    = "";
64                 
65                 foreach(@lines){
66                         # ¿·Ãå½ç¤Î¾ì¹ç
67                         if($option eq "reverse"){
68                                 $content = $content.$_."\n";
69                                 if(/^{{comment\s*.*}}$/ && $flag==0){
70                                         if($form_count==$count){
71                                                 $content = $content."*$message - $name (".Util::format_date(time()).")\n";
72                                                 $flag = 1;
73                                         } else {
74                                                 $form_count++;
75                                         }
76                                 }
77                         # ¥Ú¡¼¥¸ËöÈø¤ËÄɲäξì¹ç
78                         } elsif($option eq "tail"){
79                                 $content = $content.$_."\n";
80                                 
81                         # Åê¹Æ½ç¤Î¾ì¹ç
82                         } else {
83                                 if(/^{{comment\s*.*}}$/ && $flag==0){
84                                         if($form_count==$count){
85                                                 $content = $content."*$message - $name (".Util::format_date(time()).")\n";
86                                                 $flag = 1;
87                                         } else {
88                                                 $form_count++;
89                                         }
90                                 }
91                                 $content = $content.$_."\n";
92                         }
93                 }
94                 
95                 # ¥Ú¡¼¥¸ËöÈø¤ËÄɲäξì¹ç¤ÏºÇ¸å¤ËÄɲÃ
96                 if($option eq "tail"){
97                         $content = $content."*$message - $name (".Util::format_date(time()).")\n";
98                         $flag = 1;
99                 }
100                 
101                 if($flag==1){
102                         $wiki->save_page($page,$content);
103                 }
104         }
105         
106         # ¸µ¤Î¥Ú¡¼¥¸¤Ë¥ê¥À¥¤¥ì¥¯¥È
107         $wiki->redirect($page);
108 }
109
110 1;