############################################################################### # ModifyMessage.pl # ############################################################################### # YaBB: Yet another Bulletin Board # # Open-Source Community Software for Webmasters # # Version: YaBB 1 Gold - SP 1.3 # # Released: December 2001; Updated April 6, 2003 # # Distributed by: http://www.yabbforum.com # # =========================================================================== # # Copyright (c) 2000-2003 YaBB (www.yabbforum.com) - All Rights Reserved. # # Software by: The YaBB Development Team # # with assistance from the YaBB community. # # Sponsored by: Xnull Internet Media, Inc. - http://www.ximinc.com # ############################################################################### $modifymessageplver = "1 Gold - SP 1.3"; sub ModifyMessage { if($username eq 'Guest') { &fatal_error($txt{'223'}); } if( $currentboard eq '' ) { &fatal_error($txt{'1'}); } my( $mnum, $msub, $mname, $memail, $mdate, $mreplies, $musername, $micon, $mstate, @messages, $curmessage, $msubject, $mattach, $mip, $mmessage, $mns, $mlm, $mlmb); $threadid = $INFO{'thread'}; $postid = int( $INFO{'message'} ); ($mnum, $msub, $mname, $memail, $mdate, $mreplies, $musername, $micon, $mstate) = split(/\|/,$yyThreadLine); if( $mstate == 1 ) { &fatal_error($txt{'90'}); } if ($INFO{'message'} eq $polltxt{'15'}) { unless (-e "$datadir/$threadid.poll") {&fatal_error("$polltxt{'13'}");} fopen (FILE, "$datadir/$threadid.poll"); @poll_data = ; fclose (FILE); chomp $poll_data[0]; ($poll_question, $poll_locked, $poll_uname, $poll_name, $poll_email, $poll_date, $guest_vote, $hide_results, $multi_choice, $poll_mod, $poll_modname, $poll_comment) = split(/\|/, $poll_data[0]); for(my $i = 0; $i < @poll_data; $i++) { chomp $poll_data[$i]; ($votes[$i], $options[$i]) = split(/\|/, $poll_data[$i]); } unless($poll_uname eq $username || exists $moderators{$username} || $settings[7] eq 'Administrator' || $settings[7] eq 'Global Moderator') { &fatal_error("$polltxt{'13'}"); } $poll_comment =~ s~
~\n~g; $pollthread = 2; $settofield = "question"; } else { fopen(FILE, "$datadir/$threadid.txt") || &fatal_error("$txt{'23'} $threadid.txt"); @messages = ; fclose(FILE); $curmessage = $messages[$postid]; chomp $curmessage; ($sub, $mname, $memail, $mdate, $musername, $micon, $mattach, $mip, $message, $mns, $mlm, $mlmb) = split(/\|/,$messages[$postid]); $messagedate = stringtotime($mdate); $registrationdate = stringtotime($settings[14]); if ($registrationdate > $messagedate) {&fatal_error("$txt{'67'}");} unless($musername eq $username || exists $moderators{$username} || $settings[7] eq 'Administrator' || $settings[7] eq 'Global Moderator' ) { &fatal_error("$txt{'73'}"); } else { unless($musername eq $username || exists $moderators{$username} || $settings[7] eq 'Administrator' || $settings[7] eq 'Global Moderator') { &fatal_error("$txt{'67'}"); } $lastmod = $mlm ? &timeformat($mlm) : '-'; $nscheck = $mns ? ' checked' : ''; $lastmod = qq~ $txt{'211'}: $lastmod ~; $icon = $micon; if($icon eq "xx") { $ic1 = " selected"; } elsif($icon eq "thumbup") { $ic2 = " selected"; } elsif($icon eq "thumbdown") { $ic3 = " selected"; } elsif($icon eq "exclamation") { $ic4 = " selected"; } elsif($icon eq "question") { $ic5 = " selected"; } elsif($icon eq "lamp") { $ic6 = " selected"; } elsif($icon eq "smiley") { $ic7 = " selected"; } elsif($icon eq "angry") { $ic8 = " selected"; } elsif($icon eq "cheesy") { $ic9 = " selected"; } elsif($icon eq "laugh") { $ic10 = " selected"; } elsif($icon eq "sad") { $ic11 = " selected"; } elsif($icon eq "wink") { $ic12 = " selected"; } $message =~ s/
/\n/ig; $settofield = "message"; } $submittxt = "$txt{'10'}"; $destination = "modify2"; $is_preview = 0; $post = "postmodify"; $preview = "previewmodify"; require "$sourcedir/Post.pl"; $yytitle = "$txt{'66'}"; &Postpage; &template; exit; } sub ModifyMessage2 { if($username eq 'Guest') { &fatal_error($txt{'223'}); } if( $FORM{'previewmodify'} ) { require "$sourcedir/Post.pl"; &Preview; } my( $deletepost, $threadid, $postid, @messages, $msub, $mname, $memail, $mdate, $musername, $micon, $mattach, $mip, $mmessage, $mns, $mlm, $mlmb, $tnum, $tsub, $tname, $temail, $tdate, $treplies, $tusername, $ticon, $tstate, @threads, $tmpa, $tmpb, $tnum2, $tdate2, $newlastposttime, $newlastposter, $lastpostid, $views, $name, $email, $subject, $message, $ns, $postkilled, $threadkilled ); $deletepost = $INFO{'d'} eq '1'; if($deletepost) { $threadid = $INFO{'thread'}; $postid = $INFO{'id'}; if ($postid eq $polltxt{'15'} ) {$pollthread = 1;} } else { $threadid = $FORM{'threadid'}; $postid = $FORM{'postid'}; $pollthread = $FORM{'pollthread'}; } if ($pollthread) { $maxpq ||= 60; $maxpo ||= 50; $maxpc ||= 0; $numpolloptions ||= 8; unless (-e "$datadir/$threadid.poll") {&fatal_error("$polltxt{'13'}");} fopen (FILE, "$datadir/$threadid.poll"); @poll_data = ; fclose (FILE); chomp $poll_data[0]; ($poll_question, $poll_locked, $poll_uname, $poll_name, $poll_email, $poll_date, $guest_vote, $hide_results, $multi_choice, $poll_mod, $poll_modname, $poll_comment) = split(/\|/, $poll_data[0]); unless($poll_uname eq $username || exists $moderators{$username} || $settings[7] eq 'Administrator' || $settings[7] eq 'Global Moderator') { &fatal_error("$polltxt{'13'}"); } if ( $deletepost ) { # Delete Poll unlink("$datadir/$threadid.poll"); unlink("$datadir/$threadid.polled"); } else { # Modify Poll $numcount = 0; unless ($FORM{"question"}) { &fatal_error("$polltxt{'37'}"); } if ( length($FORM{"question"} ) > $maxpq) { &fatal_error("$polltxt{'40'} $polltxt{'34a'} $maxpq $polltxt{'34b'} $polltxt{'36'}"); } $poll_question = $FORM{"question"}; &ToHTML($poll_question); $guest_vote = $FORM{'guest_vote'} || 0; $hide_results = $FORM{'hide_results'} || 0; $multi_choice = $FORM{'multi_choice'} || 0; $poll_comment = $FORM{'poll_comment'} || ""; if ( length($poll_comment ) > $maxpc) { &fatal_error("$polltxt{'57'} $polltxt{'34a'} $maxpc $polltxt{'34b'} $polltxt{'36'}"); } &ToHTML($poll_comment); $poll_comment =~ s~\n~
~g; $poll_comment =~ s~\r~~g; my @new_poll_data; push @new_poll_data, qq~$poll_question|$poll_locked|$poll_uname|$poll_name|$poll_email|$poll_date|$guest_vote|$hide_results|$multi_choice|$date|$username|$poll_comment\n~; for ($i = 1; $i <= $numpolloptions; $i++){ chomp $poll_data[$i]; ($votes, $dummy) = split(/\|/, $poll_data[$i]); if (!$votes) {$votes = "0";} if ($FORM{"option$i"}) { if (length($FORM{"option$i"}) > $maxpo) { &fatal_error("$polltxt{'7'} $i $polltxt{'34a'} $maxpo $polltxt{'34b'} $polltxt{'36'}"); } &ToHTML($FORM{"option$i"}); $numcount++; push @new_poll_data, qq~$votes|$FORM{"option$i"}\n~; } } if ($numcount < 2) { &fatal_error("$polltxt{'38'}"); } fopen (POLL, ">$datadir/$threadid.poll"); print POLL @new_poll_data; fclose (POLL); } $yySetLocation = qq~$cgi;action=display;num=$threadid~; &redirectexit; } fopen(FILE, "$datadir/$threadid.txt") || &fatal_error("$txt{'23'} $threadid.txt"); @messages = ; fclose(FILE); # Make sure the user is allowed to edit this post. if( $postid >= 0 && $postid < @messages ) { chomp $messages[$postid]; ($msub, $mname, $memail, $mdate, $musername, $micon, $mattach, $mip, $mmessage, $mns, $mlm, $mlmb) = split( /\|/, $messages[$postid]); } else { &fatal_error("$txt{'580'} $postid"); } # Look for the current thread in the current board. fopen(FILE, "$boardsdir/$currentboard.txt"); @threads = ; fclose(FILE); ($tnum, $tsub, $tname, $temail, $tdate, $treplies, $tusername, $ticon, $tstate) = split( /\|/, $yyThreadLine ); $threadnum = $yyThreadPosition; if( $tstate == 1 ) { &fatal_error($txt{'90'}); } if( $deletepost ) { if( $musername ne 'Guest' ) { fopen(FILE, "$memberdir/$musername.dat"); @userprofile = ; fclose(FILE); chomp $userprofile[6]; if ($userprofile[6] > 0) { --$userprofile[6]; $userprofile[6] .= "\n"; fopen(FILE, ">$memberdir/$musername.dat", 1); print FILE @userprofile; fclose(FILE); } } --$treplies; $postkilled = 1; if( $treplies < 0 ) { # If the post is the only one in the thread, # then delete the thread as well. $threads[$threadnum] = ''; $threadkilled = 1; unlink("$datadir/$tnum.txt"); unlink("$datadir/$tnum.mail"); unlink("$datadir/$tnum.data"); unlink("$datadir/$tnum.poll"); unlink("$datadir/$tnum.polled"); &Sticky_remove($tnum); if( $threadnum == 0 ) { ($tnum2, $tmpa, $tmpa, $tmpa, $tdate2) = split( /\|/, $threads[1] ); if( $tnum2 ) { $newlastposttime = $tdate2; fopen(FILE, "$datadir/$tnum2.data"); $tmpa = ; fclose(FILE); ($views,$newlastposter) = split(/\|/, $tmpa); } else { $newlastposttime = 'N/A'; $newlastposter = 'N/A'; } } } else { # If the post is not the only one in the thread... if( $postid == $#messages ) { ($tmpa,$tmpa,$tmpa,$tdate) = split( /\|/, $messages[$postid-1] ); } elsif( $postid == 0 ) { $_ = $messages[1]; chomp; ($msub, $mname, $memail, $mdate, $musername, $micon, $mattach, $mip, $mmessage, $mns, $mlm, $mlmb) = split( /\|/, $_ ); $tsub = $msub; $ticon = $micon; } $threads[$threadnum] = qq~$tnum|$tsub|$tname|$temail|$tdate|$treplies|$tusername|$ticon|$tstate\n~; if( $postid == $#messages ) { # If the post is the last one in the thread, then make sure # all the lastposter/lastposttime stuff is correct for the thread. $lastpostid = $postid - 1; $_ = $messages[$lastpostid]; chomp; ($msub, $mname, $memail, $mdate, $musername, $micon, $mattach, $mip, $mmessage, $mns, $mlm, $mlmb) = split( /\|/, $_ ); # Changed from->if( $threadnum == 0 ) { $newlastposttime = $mdate; if($musername ne "Guest") { $newlastposter = $musername; } else { $newlastposter = $mname; } fopen(FILE, "$datadir/$tnum.data"); $tmpa = ; fclose(FILE); ($views,$tmpa) = split(/\|/, $tmpa); fopen(FILE, "+>$datadir/$tnum.data"); print FILE qq~$views|$newlastposter~; fclose(FILE); } $messages[$postid] = ''; # Save thread without the deleted post. fopen(FILE, ">$datadir/$threadid.txt", 1) || &fatal_error("$txt{'23'} $threadid.txt"); print FILE @messages; fclose(FILE); } } else { # If the post is to be modified... $name = $FORM{'name'}; $email = $FORM{'email'}; $subject = $FORM{'subject'}; $message = $FORM{'message'}; $icon = $FORM{'icon'}; $ns = $FORM{'ns'}; &CheckIcon; &fatal_error($txt{'78'}) unless($message); if (length($message)>$MaxMessLen) { &fatal_error($txt{'499'}); } &ToHTML($name); $email =~ s/\|//g; &ToHTML($email); &fatal_error($txt{'77'}) unless($subject && $subject !~ m~\A[\s_.,]+\Z~ ); $message =~ s/\cM//g; $message =~ s~\[([^\]]{0,30})\n([^\]]{0,30})\]~\[$1$2\]~g; $message =~ s~\[/([^\]]{0,30})\n([^\]]{0,30})\]~\[/$1$2\]~g; $message =~ s~(\w+://[^<>\s\n\"\]\[]+)\n([^<>\s\n\"\]\[]+)~$1\n$2~g; &ToHTML($message); $message =~ s/\t/ \  \  \ /g; $message =~ s/\n/
/g; if( $postid == 0 ) { $tsub = $subject; $ticon = $icon; } $threads[$threadnum] = qq~$tnum|$tsub|$tname|$temail|$tdate|$treplies|$tusername|$ticon|$tstate\n~; if ( $mip =~ /$user_ip/) {$useredit_ip = $mip;} else {$useredit_ip = "$mip $user_ip";} $messages[$postid] = qq~$subject|$mname|$memail|$mdate|$musername|$icon|0|$useredit_ip|$message|$ns|$date|$username\n~; fopen(FILE, ">$datadir/$threadid.txt", 1) || &fatal_error("$txt{'23'} $threadid.txt"); print FILE @messages; fclose(FILE); } # Save the current board. fopen(FILE, "+<$boardsdir/$currentboard.txt", 1) || &fatal_error("$txt{'23'} $currentboard.txt"); seek FILE, 0, 0; my @buffer = ; truncate FILE, 0; for ($a = 0; $a < @buffer; $a++) { if ( $buffer[$a] =~ m~\A$threadid\|~o ) { $buffer[$a] = $threads[$threadnum]; last; } } seek FILE, 0, 0; print FILE @buffer; fclose(FILE); if( $postkilled ) { # If post was killed, update the current board. my( $threadcount, $messagecount, $lastposttime, $lastposter ) = &BoardCountGet($currentboard); --$messagecount; if( $threadkilled ) { --$threadcount; } &BoardCountSet( $currentboard, $threadcount, $messagecount, $newlastposttime || $lastposttime, $newlastposter || $lastposter ); } &dumplog($currentboard); if( $threadkilled ) { $yySetLocation = qq~$cgi~; &redirectexit; } else { # Let's figure out what page number to show my $pageindex = int($postid / $maxmessagedisplay); my $start = $pageindex * $maxmessagedisplay; $yySetLocation = qq~$cgi;action=display;num=$threadid;start=$start#$postid~; &redirectexit; } } } sub MultiDel { $yySetLocation = qq~$cgi;action=display;num=$INFO{'thread'};start=$INFO{'start'}~; $mkill = 0; $topickill = 0; fopen(FILE, "$datadir/$INFO{'thread'}.txt", 1) || &fatal_error("$txt{'23'} $INFO{'thread'}.txt"); @mess = ; fclose(FILE); $count = $#mess; $tnum = $INFO{'thread'}; fopen(AMV, "$vardir/attachments.txt"); my @attachments = ; fclose(AMV); # Find thread position in message index fopen(FILE, "$boardsdir/$currentboard.txt"); @threads = ; fclose(FILE); $tmpcount = 0; $threadpos = ''; foreach $curentry (@threads) { ($tmpa, $dummy) = split(/\|/, $curentry); if($INFO{'thread'} eq $tmpa) { $threadpos = $tmpcount; } $tmpcount++; } # check all checkboxes, delete posts if checkbox is ticked while (0 <= $count) { if ($FORM{"del$count"} ne '' && $threadpos ne ''){ ($msub, $mname, $memail, $mdate, $musername, $micon, $mattach, $mip, $mmessage, $mns, $mlm, $mlmb, $msf, $mfn) = split( /\|/, $mess[$count] ); chomp $mfn; if(-e("$upload_dir/$mfn")) { $attachpos = $#attachments; while (0 <= $attachpos) { my ($amthreadid, $amreplies, $amthreadsub, $amposter, $amcurrentboard, $amkb, $amdate, $amfn) = split(/\|/,$attachments[$attachpos]); chomp $amfn; if($tnum eq $amthreadid) { if($amreplies eq $count) { splice(@attachments, $attachpos, 1); } elsif ($amreplies > $count) { $amreplies--; $attachments[$attachpos] = "$amthreadid|$amreplies|$amthreadsub|$amposter|$currentboard|$amkb|$amdate|$amfn\n"; } } $attachpos--; } unlink("$upload_dir/$mfn"); } if ($mess[1] eq '' || $mess[1] eq "\n"){ # if this is the only post, delete the files unlink("$datadir/$tnum.txt"); unlink("$datadir/$tnum.mail"); unlink("$datadir/$tnum.data"); unlink("$datadir/$tnum.poll"); unlink("$datadir/$tnum.polled"); unlink("$datadir/$tnum.polll"); splice(@threads, $threadpos, 1); $topickill = 1; $yySetLocation = qq~$cgi~; } else { # if this is not the only post, delete post splice(@mess, $count, 1); $mkill++; } } $count--; } # if thread has not been deleted from message index, update message index details ($msub, $mname, $memail, $mdate, $musername, $micon, $mattach, $mip, $mmessage, $mns, $mlm, $mlmb) = split( /\|/, $mess[$#mess]); if ($topickill != 1 && $threadpos ne ''){ ($tnum, $tsub, $tname, $temail, $tdate, $treplies, $tusername, $ticon, $tstate) = split( /\|/, $threads[$threadpos] ); $treplies = $treplies - $mkill; $threads[$threadpos] = qq~$tnum|$tsub|$tname|$temail|$mdate|$treplies|$tusername|$ticon|$tstate~; # Save updated posts fopen(FILE, ">$datadir/$INFO{'thread'}.txt", 1) || &fatal_error("$txt{'23'} $threadid.txt"); print FILE @mess; fclose(FILE); # Update last poster information if( -e "$datadir/$INFO{'thread'}.data" ) { fopen(FILE, "$datadir/$INFO{'thread'}.data"); $tmpa = ; fclose(FILE); ($views,$dummy) = split(/\|/, $tmpa); fopen(FILE, "+>$datadir/$INFO{'thread'}.data"); print FILE qq~$views|$musername~; fclose(FILE); } } # Save updated attachments file fopen(FILE, ">$vardir/attachments.txt", 1) || &fatal_error("$txt{'23'} $threadid.txt"); foreach $row(@attachments) { chomp $row; print FILE qq~$row\n~; } fclose(FILE); # Save updated message index fopen(FILE, ">$boardsdir/$currentboard.txt", 1) || &fatal_error("$txt{'23'} $currentboard.txt"); print FILE @threads; fclose(FILE); # update board index details ($latestnum, $dummy) = split( /\|/, $threads[0] ); fopen(FILE, "$datadir/$latestnum.txt", 1) || &fatal_error("$txt{'23'} $latestnum.txt"); @mess = ; fclose(FILE); ($msub, $mname, $memail, $mdate, $musername, $micon, $mattach, $mip, $mmessage, $mns, $mlm, $mlmb) = split( /\|/, $mess[$#mess]); my( $threadcount, $messagecount, $lastposttime, $lastposter ) = &BoardCountGet($currentboard); $messagecount = $messagecount - $mkill; if( $topickill == 1) { --$threadcount; --$messagecount; } &BoardCountSet( $currentboard, $threadcount, $messagecount, $mdate, $musername ); &redirectexit; } 1;