1############################################################################### 2# AntispamQuestions.pm # 3# $Date: 12.02.14 $ # 4############################################################################### 5# YaBB: Yet another Bulletin Board # 6# Open-Source Community Software for Webmasters # 7# Version: YaBB 2.6.11 # 8# Packaged: December 2, 2014 # 9# Distributed by: http://www.yabbforum.com # 10# =========================================================================== # 11# Copyright (c) 2000-2014 YaBB (www.yabbforum.com) - All Rights Reserved. # 12# Software by: The YaBB Development Team # 13# with assistance from the YaBB community. # 14############################################################################### 15use CGI::Carp qw(fatalsToBrowser); 16our $VERSION = '2.6.11'; 17 18$antispamquestionspmver = 'YaBB 2.6.11 $Revision: 1611 $'; 19if ( $action eq 'detailedversion' ) { return 1; } 20 21my $questions_language = $FORM{'questions_language'} || $INFO{'questions_language'} || $lang; 22 23sub SpamQuestions { 24 25 is_admin_or_gmod(); 26 27 if ($en_spam_questions) { $chk_spam_question = q~ checked="checked"~; } 28 if ($spam_questions_send) { $chk_spam_question_send = q~ checked="checked"~; } 29 if ($spam_questions_gp) { $chk_spam_question_gp = q~ checked="checked"~; } 30 opendir LNGDIR, $langdir; 31 my @lfilesanddirs = readdir LNGDIR; 32 closedir LNGDIR; 33 34 foreach my $fld (sort {lc($a) cmp lc $b} @lfilesanddirs) { 35 if (-e "$langdir/$fld/Main.lng") { 36 my $displang = $fld; 37 $displang =~ s/(.+?)\_(.+?)$/$1 ($2)/gism; 38 if ($questions_language eq $fld) { $drawnldirs .= qq~<option value="$fld" selected="selected">$displang</option>~; } 39 else { $drawnldirs .= qq~<option value="$fld">$displang</option>~; } 40 } 41 } 42 43 if (-e "$langdir/$questions_language/spam.questions") { 44 fopen(SPAMQUESTIONS, "<$langdir/$questions_language/spam.questions") || fatal_error('cannot_open',"$langdir/$questions_language/spam.questions", 1); 45 @spam_questions = <SPAMQUESTIONS>; 46 fclose(SPAMQUESTIONS); 47 } 48 49 $total_questions = @spam_questions || 0; 50 51 if ($total_questions) { 52 $header_row = q~ colspan="5"~; 53 $show_questions = 54 qq~<tr class="catbg"> 55 <td><b>$spam_question_txt{'question'}</b></td> 56 <td><b>$spam_question_txt{'answer'}</b></td> 57 <td><b>$spam_question_txt{'image'}</b></td> 58 <td><b>$admin_txt{'edit'}</b></td> 59 <td><b>$admin_txt{'delete'}</b></td> 60</tr>~; 61 62 foreach my $question ( sort { $a <=> $b } @spam_questions ) { 63 chomp $question; 64 ( $spam_question_id, $spam_question, $spam_answer, undef, $spam_image ) = split /\|/xsm, 65 $question; 66 $spam_image = $spam_image ? qq~<a href="$defaultimagesdir/Spam_Img/$spam_image" target="_blank">$spam_image</a>~ : $spam_question_txt{'na'}; 67 $show_questions .= qq~<tr class="windowbg2"> 68 <td>$spam_question</td> 69 <td>$spam_answer</td> 70 <td>$spam_image</td> 71 <td> 72 <form action="$adminurl?action=spam_questions_edit" method="post"> 73 <input type="hidden" name="spam_question_id" value="$spam_question_id" /> 74 <input class="button" type="submit" value="$admin_txt{'edit'}" /> 75 <input type="hidden" name="questions_language" value="$questions_language" /> 76 </form> 77 </td> 78 <td> 79 <form action="$adminurl?action=spam_questions_delete" method="post"> 80 <input type="hidden" name="spam_question_id" value="$spam_question_id" /> 81 <input class="button" type="submit" value="$admin_txt{'delete'}" onclick="return confirm('$spam_question_txt{'confirm'}');"/> 82 <input type="hidden" name="questions_language" value="$questions_language" /> 83 </form> 84 </td> 85</tr>~; 86 } 87 } 88 else { 89 $header_row = q~ colspan="5"~; 90 $show_questions = qq~<tr class="windowbg2"> 91 <td colspan="5">$spam_question_txt{'no_questions'}</td> 92</tr>~; 93 } 94 95 $yymain = qq~ 96<form action="$adminurl?action=spam_questions2" method="post"> 97<div class="bordercolor rightboxdiv"> 98<table class="border-space pad-cell" style="margin-bottom: .5em;"> 99 <colgroup> 100 <col span="2" style="width: 50%" /> 101 </colgroup> 102 <tr> 103 <th class="titlebg" colspan="2">$admin_img{'prefimg'} $spam_question_txt{'question_settings'}</th> 104 </tr><tr class="windowbg2 vtop"> 105 <td><label for="en_spam_questions">$spam_question_txt{'enable_question'}</label></td> 106 <td><input type="checkbox" name="en_spam_questions" id="en_spam_questions" value="1"$chk_spam_question /></td> 107 </tr><tr class="windowbg2 vtop"> 108 <td><label for="spam_questions_send">$spam_question_txt{'enable_question_send'}</label></td> 109 <td><input type="checkbox" name="spam_questions_send" id="spam_questions_send" value="1"$chk_spam_question_send /></td> 110 </tr><tr class="windowbg2 vtop"> 111 <td><label for="spam_questions_gp">$spam_question_txt{'enable_question_gp'}</label></td> 112 <td><input type="checkbox" name="spam_questions_gp" id="spam_questions_gp" value="1"$chk_spam_question_gp /></td> 113 </tr> 114</table> 115</div> 116<div class="bordercolor rightboxdiv"> 117<table class="border-space pad-cell" style="margin-bottom: .5em;"> 118 <tr> 119 <th class="titlebg">$admin_img{'prefimg'} $admin_txt{'10'}</th> 120 </tr><tr> 121 <td class="catbg center"> 122 <input class="button" type="submit" value="$admin_txt{'10'}" /> 123 <input type="hidden" name="questions_language" value="$questions_language" /> 124 </td> 125 </tr> 126</table> 127</div> 128</form> 129<div class="bordercolor rightboxdiv" style="margin-bottom: .5em;"> 130<table class="border-space pad-cell"> 131 <colgroup> 132 <col span="2" style="width: 30%;" /> 133 <col span="1" style="width: 26%;" /> 134 <col span="2" style="width: 7%" /> 135 </colgroup> 136 <tr> 137 <th class="titlebg"$header_row>$admin_img{'prefimg'} $spam_question_txt{'questions'} ($total_questions) 138 <div style="display: inline; float: right;"> 139 <form action="$adminurl?action=spam_questions" method="post" enctype="application/x-www-form-urlencoded"> 140 <select name="questions_language" id="questions_language" size="1"> 141 $drawnldirs 142 </select> 143 <input type="submit" value="$admin_txt{'462'}" class="button" /> 144 </form> 145 </div> 146 </th> 147 </tr> 148$show_questions 149</table> 150</div> 151<form action="$adminurl?action=spam_questions_add" method="post" enctype="multipart/form-data" accept-charset="$yymycharset"> 152<div class="bordercolor rightboxdiv"> 153<table class="border-space pad-cell" style="margin-bottom: .5em;"> 154 <colgroup> 155 <col style="width: 25%" /> 156 <col style="width: 75%" /> 157 </colgroup> 158 <tr> 159 <th class="titlebg" colspan="2">$admin_img{'prefimg'} $spam_question_txt{'new_question'}</th> 160 </tr><tr class="windowbg2 vtop bold"> 161 <td><label for="spam_question">$spam_question_txt{'question'}:</label></td> 162 <td><input type="text" name="spam_question" id="spam_question" size="60" maxlength="100" /></td> 163 </tr><tr class="windowbg2 vtop bold"> 164 <td><label for="spam_answer">$spam_question_txt{'answer'}:<br /><span class="small" style="font-weight: normal;">$spam_question_txt{'answer_desc'}</span></label></td> 165 <td><input type="text" name="spam_answer" id="spam_answer" size="60" maxlength="50" /></td> 166 </tr><tr class="windowbg2 vtop bold"> 167 <td><label for="spam_case">$spam_question_txt{'case_sensitive'}:<br /><span class="small" style="font-weight: normal;">$spam_question_txt{'case_sensitive_desc'}</span></label></td> 168 <td><input type="checkbox" name="spam_case" id="spam_case" value="1" /></td> 169 </tr><tr class="windowbg2 vtop bold"> 170 <td><label for="spam_image">$spam_question_txt{'image'} $spam_question_txt{'optional'}:<br /><span class="small" style="font-weight: normal;">$spam_question_txt{'image_desc'}</span></label></td> 171 <td><input type="file" name="spam_image" id="spam_image" size="35" /> <span class="cursor small bold" title="$admin_txt{'remove_file'}" onclick="document.getElementById('spam_image').value='';">X</span></td> 172 </tr> 173</table> 174</div> 175<div class="bordercolor rightboxdiv"> 176<table class="border-space pad-cell" style="margin-bottom: .5em;"> 177 <tr> 178 <th class="titlebg">$admin_img{'prefimg'} $admin_txt{'10'}</th> 179 </tr><tr> 180 <td class="catbg center"> 181 <input class="button" type="submit" value="$spam_question_txt{'add_question'}" /> 182 <input type="hidden" name="questions_language" value="$questions_language" /> 183 </td> 184 </tr> 185</table> 186</div> 187</form> 188~; 189 190 $yytitle = $admintxt{'a3_sub6'}; 191 $action_area = 'spam_questions'; 192 AdminTemplate(); 193 exit; 194} 195 196sub SpamQuestions2 { 197 is_admin_or_gmod(); 198 199 $en_spam_questions = $FORM{'en_spam_questions'} || '0'; 200 $spam_questions_send = $FORM{'spam_questions_send'} || '0'; 201 $spam_questions_gp = $FORM{'spam_questions_gp'} || '0'; 202 203 require Admin::NewSettings; 204 SaveSettingsTo('Settings.pm'); 205 206 if ( $action eq 'spam_questions2' ) { 207 $yySetLocation = qq~$adminurl?action=spam_questions;questions_language=$FORM{'questions_language'}~; 208 redirectexit(); 209 } 210 return; 211} 212 213sub SpamQuestionsAdd { 214 is_admin_or_gmod(); 215 216 $spam_question = $FORM{'spam_question'}; 217 $spam_answer = $FORM{'spam_answer'}; 218 $spam_case = $FORM{'spam_case'} || '0'; 219 220 if ( $spam_question eq q{} ) { 221 fatal_error( 'invalid_value', "$spam_question_txt{'question'}" ); 222 } 223 if ( $spam_answer eq q{} ) { 224 fatal_error( 'invalid_value', "$spam_question_txt{'answer'}" ); 225 } 226 227 $spam_image = UploadFile('spam_image', 'Templates/Forum/default/Spam_Img', 'png jpg jpeg gif', '250', '0'); 228 229 fopen( SPAMQUESTIONS, ">>$langdir/$questions_language/spam.questions" ) 230 || fatal_error( 'cannot_open', "$langdir/$questions_language/spam.questions", 231 1 ); 232 print {SPAMQUESTIONS} "$date|$spam_question|$spam_answer|$spam_case|$spam_image\n" 233 or croak "$croak{'print'} SPAMQUESTIONS"; 234 fclose(SPAMQUESTIONS); 235 236 if ( $action eq 'spam_questions_add' ) { 237 $yySetLocation = qq~$adminurl?action=spam_questions;questions_language=$FORM{'questions_language'}~; 238 redirectexit(); 239 } 240 return; 241} 242 243sub SpamQuestionsEdit { 244 is_admin_or_gmod(); 245 246 $id = $FORM{'spam_question_id'}; 247 my $question_edit = q{}; 248 249 fopen( SPAMQUESTIONS, "<$langdir/$questions_language/spam.questions" ) 250 || fatal_error( 'cannot_open', "$langdir/$questions_language/spam.questions", 251 1 ); 252 @spam_questions = <SPAMQUESTIONS>; 253 fclose(SPAMQUESTIONS); 254 255 foreach my $question (@spam_questions) { 256 chomp $question; 257 if ( $question =~ /$id/xsm ) { 258 $question_edit = $question; 259 last; 260 } 261 } 262 ( $spam_question_id, $spam_question, $spam_answer, $spam_case, $spam_image ) = split /\|/xsm, 263 $question_edit; 264 if ($spam_case) { $chk_spam_case = q~ checked="checked"~; } 265 my $spam_image_value = q{}; 266 if ( $spam_image ) { 267 $spam_image_value = qq~<div class="small bold">$admin_txt{'current_img'}: <a href="$defaultimagesdir/Spam_Img/$spam_image" target="_blank">$spam_image</a><br /><input type="checkbox" name="del_spam_image" id="del_spam_image" value="1" /> <label for="del_spam_image">$admin_txt{'remove_img'}</label></div>~; 268 } 269 $yymain = qq~ 270<form action="$adminurl?action=spam_questions_edit2" method="post" enctype="multipart/form-data" accept-charset="$yymycharset"> 271<div class="bordercolor rightboxdiv"> 272<table class="border-space pad-cell" style="margin-bottom: .5em;"> 273 <colgroup> 274 <col style="width: 25%" /> 275 <col style="width: 75%" /> 276 </colgroup> 277 <tr> 278 <th class="titlebg" colspan="2">$admin_img{'prefimg'} $spam_question_txt{'edit_question'}</th> 279 </tr><tr class="windowbg2 vtop bold"> 280 <td><label for="spam_question">$spam_question_txt{'question'}:</label></td> 281 <td><input type="text" name="spam_question" id="spam_question" size="60" maxlength="100" value="$spam_question" /></td> 282 </tr><tr class="windowbg2 vtop bold"> 283 <td><label for="spam_answer">$spam_question_txt{'answer'}:<br /><span class="small" style="font-weight: normal;">$spam_question_txt{'answer_desc'}</span></label></td> 284 <td><input type="text" name="spam_answer" id="spam_answer" size="60" maxlength="50" value="$spam_answer" /><input type="hidden" name="spam_question_id" id="spam_question_id" value="$spam_question_id" /></td> 285 </tr><tr class="windowbg2 vtop bold"> 286 <td><label for="spam_case">$spam_question_txt{'case_sensitive'}:<br /><span class="small" style="font-weight: normal;">$spam_question_txt{'case_sensitive_desc'}</span></label></td> 287 <td><input type="checkbox" name="spam_case" id="spam_case" value="1"$chk_spam_case /></td> 288 </tr /> 289 <tr class="windowbg2 vtop bold"> 290 <td><label for="spam_image">$spam_question_txt{'image'} $spam_question_txt{'optional'}:<br /><span class="small" style="font-weight: normal;">$spam_question_txt{'image_desc'}</span></label></td> 291 <td><input type="file" name="spam_image" id="spam_image" size="35" /><input type="hidden" name="cur_spam_image" value="$spam_image" /> <span class="cursor small bold" title="$admin_txt{'remove_file'}" onclick="document.getElementById('spam_image').value='';">X</span>$spam_image_value</td> 292 </tr> 293</table> 294</div> 295<div class="bordercolor rightboxdiv"> 296<table class="border-space pad-cell"> 297 <tr> 298 <th class="titlebg">$admin_img{'prefimg'} $admin_txt{'10'}</th> 299 </tr><tr> 300 <td class="catbg center"> 301 <input class="button" type="submit" value="$admin_txt{'10'} $spam_question_txt{'question'}" /> <input type="button" class="button" value="$admin_txt{'cancel'}" onclick="location.href='$adminurl?action=spam_questions;questions_language=$FORM{'questions_language'}';" /> 302 <input type="hidden" name="questions_language" value="$questions_language" /> 303 </td> 304 </tr> 305</table> 306</div> 307</form>~; 308 309 $yytitle = $admintxt{'a3_sub6'}; 310 AdminTemplate(); 311 exit; 312} 313 314sub SpamQuestionsEdit2 { 315 is_admin_or_gmod(); 316 317 $spam_question_id = $FORM{'spam_question_id'}; 318 $spam_question = $FORM{'spam_question'}; 319 $spam_answer = $FORM{'spam_answer'}; 320 $spam_case = $FORM{'spam_case'} || '0'; 321 $spam_image = $FORM{'spam_image'}; 322 $cur_spam_image = $FORM{'cur_spam_image'}; 323 $del_spam_image = $FORM{'del_spam_image'}; 324 325 if ( $spam_question eq q{} ) { 326 fatal_error( 'invalid_value', "$spam_question_txt{'question'}" ); 327 } 328 if ( $spam_answer eq q{} ) { 329 fatal_error( 'invalid_value', "$spam_question_txt{'answer'}" ); 330 } 331 332 if ( $spam_image ne q{} ) { 333 $spam_image = UploadFile('spam_image', 'Templates/Forum/default/Spam_Img', 'png jpg jpeg gif', '250', '0'); 334 unlink "$htmldir/Templates/Forum/default/Spam_Img/$cur_spam_image"; 335 } 336 else { 337 $spam_image = $cur_spam_image; 338 } 339 if ( $del_spam_image ) { 340 unlink "$htmldir/Templates/Forum/default/Spam_Img/$cur_spam_image"; 341 $spam_image = q{}; 342 } 343 344 fopen( SPAMQUESTIONS, "<$langdir/$questions_language/spam.questions" ) 345 || fatal_error( 'cannot_open', "$langdir/$questions_language/spam.questions", 346 1 ); 347 @spam_questions = <SPAMQUESTIONS>; 348 fclose(SPAMQUESTIONS); 349 350 @question = grep { !/$spam_question_id/xsm } @spam_questions; 351 push @question, "$spam_question_id|$spam_question|$spam_answer|$spam_case|$spam_image"; 352 $question = join q{}, @question; 353 354 fopen( SPAMQUESTIONS, ">$langdir/$questions_language/spam.questions" ) 355 || fatal_error( 'cannot_open', "$langdir/$questions_language/spam.questions", 356 1 ); 357 print {SPAMQUESTIONS} "$question\n" or croak "$croak{'print'} SPAMQUESTIONS"; 358 fclose(SPAMQUESTIONS); 359 360 if ( $action eq 'spam_questions_edit2' ) { 361 $yySetLocation = qq~$adminurl?action=spam_questions;questions_language=$FORM{'questions_language'}~; 362 redirectexit(); 363 } 364 return; 365} 366 367sub SpamQuestionsDelete { 368 is_admin_or_gmod(); 369 370 fopen( SPAMQUESTIONS, "<$langdir/$questions_language/spam.questions" ) 371 || fatal_error( 'cannot_open', "$langdir/$questions_language/spam.questions", 372 1 ); 373 @spam_questions = <SPAMQUESTIONS>; 374 fclose(SPAMQUESTIONS); 375 376 fopen( SPAMQUESTIONS, ">$langdir/$questions_language/spam.questions" ) 377 || fatal_error( 'cannot_open', "$langdir/$questions_language/spam.questions", 378 1 ); 379 print {SPAMQUESTIONS} 380 grep { !/$FORM{'spam_question_id'}/xsm } @spam_questions 381 or croak "$croak{'print'} SPAMQUESTIONS"; 382 fclose(SPAMQUESTIONS); 383 384 foreach my $spam_image (@spam_questions) { 385 chomp $spam_image; 386 if ( $spam_image =~ /$FORM{'spam_question_id'}/xsm ) { 387 $spam_image_delete = $spam_image; 388 last; 389 } 390 } 391 ( undef, undef, undef, undef, $spam_image ) = split /\|/xsm, 392 $spam_image_delete; 393 394 if ( $spam_image ) { 395 unlink "$htmldir/Templates/Forum/default/Spam_Img/$spam_image"; 396 } 397 398 if ( $action eq 'spam_questions_delete' ) { 399 $yySetLocation = qq~$adminurl?action=spam_questions;questions_language=$FORM{'questions_language'}~; 400 redirectexit(); 401 } 402 return; 403} 404 4051; 406