OSDN Git Service

(no commit message)
[fswiki/sandbox.git] / kgsoft / plugin / _ex_spam_filter_light / bbs.pm
1 ##########################################################################################
2 #
3 # ¥¹¥Ñ¥à¥Õ¥£¥ë¥¿¡¼¥×¥é¥°¥¤¥ó¡Ê³Ø½¬µ¡Ç½Ìµ¤·ÈÇ¡Ë
4 #¡Êbbs¥×¥é¥°¥¤¥ó¤Î¥ª¡¼¥Ð¡¼¥é¥¤¥É¡Ë
5 #
6 ##########################################################################################
7 use strict;
8
9 use plugin::bbs::BBSHandler;
10 use plugin::bbs::BBS2Handler;
11
12 # plugin::bbs::BBSHandler¤Îdo_action¥á¥½¥Ã¥É¤ÎÃÖ¤­´¹¤¨
13 package plugin::bbs::BBSHandler;
14
15 sub do_action {
16         my $self = shift;
17         my $wiki = shift;
18         my $cgi  = $wiki->get_CGI;
19         
20         my $name    = $cgi->param("name");
21         my $subject = $cgi->param("subject");
22         my $message = $cgi->param("message");
23         my $count   = $cgi->param("count");
24         my $page    = $cgi->param("page");
25         my $option  = $cgi->param("option");
26         
27         if($name eq ""){
28                 $name = "̵̾¤·¤µ¤ó";
29         } else {
30                 # post_name¤È¤¤¤¦¥­¡¼¤Ç¥¯¥Ã¥­¡¼¤ò¥»¥Ã¥È¤¹¤ë
31                 my $path   = &Util::cookie_path($wiki);
32                 my $cookie = $cgi->cookie(-name=>'post_name',-value=>$name,-expires=>'+1M',-path=>$path);
33                 print "Set-Cookie: ",$cookie->as_string,"\n";
34         }
35         
36         if($subject eq ""){
37                 $subject = "̵Âê";
38         }
39         
40         if($page eq "" || $count eq ""){
41                 return $wiki->error("¥Ñ¥é¥á¡¼¥¿¤¬ÉÔÀµ¤Ç¤¹");
42         } elsif($message eq ""){
43                 return $wiki->error("ËÜʸ¤òÆþÎϤ·¤Æ¤¯¤À¤µ¤¤¡£");
44         }
45         
46 #--------------------------------------------------------------------------------------------------
47   if($message){
48     unless(&plugin::_ex_spam_filter_light::Install::judgment_text($message)){
49       my $time = Util::format_date(time());
50       my $file = $wiki->config('log_dir')."/spam_bbs.txt";
51       if(open(SPAM_LOG, ">>$file")){
52         print SPAM_LOG "-" x 70 . "\n";
53         print SPAM_LOG "$page:$subject - $name ($time)\n";
54         print SPAM_LOG "-" x 70 . "\n";
55         print SPAM_LOG "$message\n";
56         close(SPAM_LOG);
57       }
58       my $error_message = $wiki->error("Åê¹Æ¤µ¤ì¤¿Ê¸¾Ï¤Ï¥¹¥Ñ¥à¥á¥Ã¥»¡¼¥¸¤ÈȽÄꤵ¤ì¤Þ¤·¤¿¡£\n");
59       $subject = Util::escapeHTML($subject);
60       $message = Util::escapeHTML($message);
61       $message =~ s/\n/<br>/g;
62       $error_message .= "<p>\n";
63       $error_message .= "<div>Åê¹Æ¤µ¤ì¤¿Ê¸¾Ï¡§</div>\n";
64       $error_message .= "<div>¡ã·ï̾¡ä</div>\n";
65       $error_message .= "<div>$subject</div>\n";
66       $error_message .= "<div>¡ãËÜʸ¡ä</div>\n";
67       $error_message .= "<div>$message</div>\n";
68       $error_message .= "</p>\n";
69       return $error_message;
70     }
71   }
72 #--------------------------------------------------------------------------------------------------
73
74         # ¥Õ¥©¡¼¥Þ¥Ã¥È¥×¥é¥°¥¤¥ó¤Ø¤ÎÂбþ
75         my $format = $wiki->get_edit_format();
76         $name    = $wiki->convert_to_fswiki($name   ,$format,1);
77         $subject = $wiki->convert_to_fswiki($subject,$format,1);
78         $message = $wiki->convert_to_fswiki($message,$format);
79         
80         my @lines = split(/\n/,$wiki->get_page($page));
81         my $flag       = 0;
82         my $form_count = 1;
83         my $content    = "";
84         
85         foreach(@lines){
86                 $content = $content.$_."\n";
87                 if(/^{{bbs\s*.*}}$/ && $flag==0){
88                         if($form_count==$count){
89                                 $content .= "!!$subject - $name (".&Util::format_date(time()).")\n".
90                                             "$message\n";
91                                 
92                                 # no_comment¥ª¥×¥·¥ç¥ó
93                                 if($option eq "no_comment"){
94                                         
95                                 # reverse_comment¥ª¥×¥·¥ç¥ó
96                                 } elsif($option eq "reverse_comment"){
97                                         $content .= "{{comment reverse}}\n";
98                                 # ¥Ç¥Õ¥©¥ë¥È
99                                 } else {
100                                         $content .= "{{comment}}\n";
101                                 }
102                                 $flag = 1;
103                                 
104                         } else {
105                                 $form_count++;
106                         }
107                 }
108         }
109         if($flag==1){
110                 $wiki->save_page($page,$content);
111         }
112         
113         # ¸µ¤Î¥Ú¡¼¥¸¤Ë¥ê¥À¥¤¥ì¥¯¥È¤¹¤ë
114         $wiki->redirect($page);
115 }
116
117
118 # plugin::bbs::BBS2Handler¤Îdo_action¥á¥½¥Ã¥É¤ÎÃÖ¤­´¹¤¨
119 package plugin::bbs::BBS2Handler;
120
121 sub do_action {
122         my $self = shift;
123         my $wiki = shift;
124         my $cgi  = $wiki->get_CGI;
125         
126         my $bbsname = $cgi->param("bbsname");
127         my $name    = $cgi->param("name");
128         my $subject = $cgi->param("subject");
129         my $message = $cgi->param("message");
130         my $page    = $cgi->param("page");
131         my $option  = $cgi->param("option");
132         
133         if($name    eq ""){
134                 $name    = "̵̾¤·¤µ¤ó";
135         } else {
136                 # post_name¤È¤¤¤¦¥­¡¼¤Ç¥¯¥Ã¥­¡¼¤ò¥»¥Ã¥È¤¹¤ë
137                 my $path   = &Util::cookie_path($wiki);
138                 my $cookie = $cgi->cookie(-name=>'post_name',-value=>$name,-expires=>'+1M',-path=>$path);
139                 print "Set-Cookie: ",$cookie->as_string,"\n";
140         }
141         
142         if($subject eq ""){
143                 $subject = "̵Âê";
144         }
145         
146         if($bbsname eq ""){
147                 return $wiki->error("¥Ñ¥é¥á¡¼¥¿¤¬ÉÔÀµ¤Ç¤¹¡£");
148         }
149         if($message eq ""){
150                 return $wiki->error("ËÜʸ¤òÆþÎϤ·¤Æ¤¯¤À¤µ¤¤¡£");
151         }
152         
153 #--------------------------------------------------------------------------------------------------
154   if($message){
155     unless(&plugin::_ex_spam_filter_light::Install::judgment_text($message)){
156       my $time = Util::format_date(time());
157       my $file = $wiki->config('log_dir')."/spam_bbs2.txt";
158       if(open(SPAM_LOG, ">>$file")){
159         print SPAM_LOG "-" x 70 . "\n";
160         print SPAM_LOG "$bbsname:$subject - $name ($time)\n";
161         print SPAM_LOG "-" x 70 . "\n";
162         print SPAM_LOG "$message\n";
163         close(SPAM_LOG);
164       }
165       my $error_message = $wiki->error("Åê¹Æ¤µ¤ì¤¿Ê¸¾Ï¤Ï¥¹¥Ñ¥à¥á¥Ã¥»¡¼¥¸¤ÈȽÄꤵ¤ì¤Þ¤·¤¿¡£\n");
166       $subject = Util::escapeHTML($subject);
167       $message = Util::escapeHTML($message);
168       $message =~ s/\n/<br>/g;
169       $error_message .= "<p>\n";
170       $error_message .= "<div>Åê¹Æ¤µ¤ì¤¿Ê¸¾Ï¡§</div>\n";
171       $error_message .= "<div>¡ã·ï̾¡ä</div>\n";
172       $error_message .= "<div>$subject</div>\n";
173       $error_message .= "<div>¡ãËÜʸ¡ä</div>\n";
174       $error_message .= "<div>$message</div>\n";
175       $error_message .= "</p>\n";
176       return $error_message;
177     }
178   }
179 #--------------------------------------------------------------------------------------------------
180
181         # ¥Õ¥©¡¼¥Þ¥Ã¥È¥×¥é¥°¥¤¥ó¤Ø¤ÎÂбþ
182         my $format = $wiki->get_edit_format();
183         $name    = $wiki->convert_to_fswiki($name   ,$format,1);
184         $subject = $wiki->convert_to_fswiki($subject,$format,1);
185         $message = $wiki->convert_to_fswiki($message,$format);
186         
187         my $pagename = $self->get_page_name($wiki,$bbsname);
188         my $content = "!![[$subject|$pagename]] - $name (".&Util::format_date(time()).")\n".
189                       "$message\n";
190         
191         # no_comment¥ª¥×¥·¥ç¥ó
192         if($option eq "no_comment"){
193                 
194         # reverse_comment¥ª¥×¥·¥ç¥ó
195         } elsif($option eq "reverse_comment"){
196                 $content .= "{{comment reverse}}\n";
197         # ¥Ç¥Õ¥©¥ë¥È
198         } else {
199                 $content .= "{{comment}}\n";
200         }
201         $wiki->save_page($pagename,$content);
202         
203         # ¸µ¤Î¥Ú¡¼¥¸¤Ë¥ê¥À¥¤¥ì¥¯¥È
204         $wiki->redirect($pagename);
205 }
206
207 1;