| ############################################################################### |
| ############################################################################### |
| # RemoveOldTopics.pl # |
| # RemoveOldTopics.pm # |
| |
| # $Date: 01.05.16 $ # |
| ############################################################################### |
| ############################################################################### |
| # YaBB: Yet another Bulletin Board # |
| # YaBB: Yet another Bulletin Board # |
| # Open-Source Community Software for Webmasters # |
| # Open-Source Community Software for Webmasters # |
| # Version: YaBB 2.5.2 # |
| # Version: YaBB 2.6.12 # |
| # Packaged: October 21, 2012 # |
| # Packaged: January 5, 2016 # |
| # Distributed by: http://www.yabbforum.com # |
| # Distributed by: http://www.yabbforum.com # |
| # =========================================================================== # |
| # =========================================================================== # |
| # Copyright (c) 2000-2012 YaBB (www.yabbforum.com) - All Rights Reserved. # |
| # Copyright (c) 2000-2016 YaBB (www.yabbforum.com) - All Rights Reserved. # |
| # Software by: The YaBB Development Team # |
| # Software by: The YaBB Development Team # |
| # with assistance from the YaBB community. # |
| # with assistance from the YaBB community. # |
| ############################################################################### |
| ############################################################################### |
| |
| use CGI::Carp qw(fatalsToBrowser); |
| |
| our $VERSION = '2.6.12'; |
| |
| |
| $removeoldtopicsplver = 'YaBB 2.5.2 $Revision: 1.0 $'; |
| $removeoldtopicspmver = 'YaBB 2.6.12 $Revision: 1710 $'; |
| if ($action eq 'detailedversion') { return 1; } |
| if ( $action eq 'detailedversion' ) { return 1; } |
| |
| |
| sub RemoveOldThreads { |
| sub RemoveOldThreads { |
| &is_admin_or_gmod; |
| is_admin_or_gmod(); |
| my $maxdays = $FORM{'maxdays'} || $INFO{'maxdays'}; |
| my $maxdays = $FORM{'maxdays'} || $INFO{'maxdays'}; |
| if ($maxdays !~ /\A[0-9]+\Z/) { &admin_fatal_error("only_numbers_allowed"); } |
| if ( $maxdays !~ /\A[0-9]+\Z/xsm ) { |
| |
| fatal_error('only_numbers_allowed'); |
| &automaintenance('on'); |
| } |
| |
| |
| # Set up the multi-step action |
| automaintenance('on'); |
| $time_to_jump = time() + $max_process_time; |
| |
| |
| # Set up the multi-step action |
| my (@threads,$num,$status,$keep_sticky,%attachfile); |
| $time_to_jump = time() + $max_process_time; |
| $date1; |
| |
| $date2 = $date; |
| my ( @threads, $num, $status, $keep_sticky, %attachfile ); |
| |
| $date1; |
| $yytitle = "$removemess_txt{'120'} $maxdays"; |
| $date2 = $date; |
| $action_area = "deleteoldthreads"; |
| |
| $yymain .= qq~<br /><b>$removemess_txt{'1'} $maxdays $removemess_txt{'2'}</b><br />~; |
| $yytitle = "$removemess_txt{'120'} $maxdays"; |
| |
| $action_area = 'deleteoldthreads'; |
| fopen(FILE, ">$vardir/oldestmes.txt"); |
| $yymain .= |
| print FILE $maxdays; |
| qq~<br /><b>$removemess_txt{'1'} $maxdays $removemess_txt{'2'}</b><br />~; |
| fclose(FILE); |
| |
| |
| fopen( FILE, ">$vardir/oldestmes.txt" ); |
| require "$boardsdir/forum.master"; |
| print {FILE} $maxdays or croak "$croak{'print'} oldestmes"; |
| require "$admindir/Attachments.pl"; |
| fclose(FILE); |
| |
| |
| my @boards = sort( keys %board ); |
| require "$boardsdir/forum.master"; |
| for (my $j = ($INFO{'nextboard'} || 0); $j < @boards; $j++) { |
| require Admin::Attachments; |
| my $checkboard = $FORM{ $boards[$j] . 'check' } || $INFO{ $boards[$j] . 'check' }; |
| |
| if ($checkboard == 1) { |
| my @boards = sort keys %board; |
| $keep_sticky = ($FORM{'keep_them'} || $INFO{'keep_them'}) ? 1 : 0; |
| my $inp = $INFO{'nextboard'} || 0; |
| |
| foreach my $j ( $inp .. ( @boards - 1 ) ) { |
| fopen(BOARDFILE, "$boardsdir/$boards[$j].txt"); |
| my $checkboard = $FORM{ $boards[$j] . 'check' } |
| @threads = <BOARDFILE>; |
| || $INFO{ $boards[$j] . 'check' }; |
| fclose(BOARDFILE); |
| if ( $checkboard == 1 ) { |
| |
| $keep_sticky = ( $FORM{'keep_them'} || $INFO{'keep_them'} ) ? 1 : 0; |
| my $totalthreads = @threads; |
| |
| my ($boardname) = split(/\|/, $board{$boards[$j]}, 2); |
| fopen( BOARDFILE, "$boardsdir/$boards[$j].txt" ); |
| $yymain .= qq~<br />$removemess_txt{'3'} <b>$boardname</b> ($totalthreads $removemess_txt{'6'})<br />~; |
| @threads = <BOARDFILE>; |
| |
| fclose(BOARDFILE); |
| next if !$totalthreads; |
| |
| |
| my $totalthreads = @threads; |
| my @temparray_1 = (); |
| my ($boardname) = split /\|/xsm, $board{ $boards[$j] }, 2; |
| my $tempcount = 0; |
| $yymain .= |
| for (my $i = 0; $i < $totalthreads; $i++) { |
| qq~<br />$removemess_txt{'3'} <b>$boardname</b> ($totalthreads $removemess_txt{'6'})<br />~; |
| ($num, undef, undef, undef, $date1, undef, undef, undef, $status) = split(/\|/, $threads[$i]); |
| |
| $date1 = sprintf("%010d", $date1); |
| next if !$totalthreads; |
| |
| |
| if ($i < $INFO{'nextthread'}) { |
| my @temparray_1 = (); |
| push(@temparray_1, "$date1|$threads[$i]"); |
| my $tempcount = 0; |
| next; |
| for my $i ( 0 .. ( $totalthreads - 1 ) ) { |
| } |
| ( |
| |
| $num, undef, undef, undef, $date1, |
| # Check if original thread was sticky |
| undef, undef, undef, $status |
| if ($keep_sticky && $status =~ /s/i) { |
| ) = split /\|/xsm, $threads[$i]; |
| push(@temparray_1, "$date1|$threads[$i]"); |
| $date1 = sprintf '%010d', $date1; |
| $yymain .= "$num : $removemess_txt{'4'} <br />"; |
| |
| } else { |
| if ( $i < $INFO{'nextthread'} ) { |
| &calcdifference(); |
| push @temparray_1, "$date1|$threads[$i]"; |
| if ($result <= $maxdays) { # If the message is not too old |
| next; |
| push(@temparray_1, "$date1|$threads[$i]"); |
| } |
| $yymain .= "$num = $result $removemess_txt{'122'}<br />"; |
| |
| |
| # Check if original thread was sticky |
| } else { |
| if ( $keep_sticky && $status =~ /s/ism ) { |
| # remove thread files |
| push @temparray_1, "$date1|$threads[$i]"; |
| unlink("$datadir/$num.txt"); |
| $yymain .= "$num : $removemess_txt{'4'} <br />"; |
| unlink("$datadir/$num.ctb"); |
| } |
| unlink("$datadir/$num.mail"); |
| else { |
| unlink("$datadir/$num.poll"); |
| calcdifference(); |
| unlink("$datadir/$num.polled"); |
| if ( $result <= $maxdays ) { # If the message is not too old |
| |
| push @temparray_1, "$date1|$threads[$i]"; |
| # delete all attachments of removed topic later |
| $yymain .= |
| $attachfile{$num} = undef; |
| "$num = $result $removemess_txt{'122'}<br />"; |
| |
| |
| $tempcount++; |
| } |
| |
| else { |
| $yymain .= "$num = $result $removemess_txt{'122'} ($removemess_txt{'123'})<br /> $num : $removemess_txt{'7'}<br />"; |
| |
| } |
| # remove thread files |
| } |
| unlink "$datadir/$num.txt"; |
| |
| unlink "$datadir/$num.ctb"; |
| if (time() > $time_to_jump && ($i + 1) < $totalthreads) { |
| unlink "$datadir/$num.mail"; |
| $i++; |
| unlink "$datadir/$num.poll"; |
| for (my $x = $i; $x < $totalthreads; $x++) { |
| unlink "$datadir/$num.polled"; |
| (undef, undef, undef, undef, $date1, undef) = split(/\|/, $threads[$x], 6); |
| |
| $date1 = sprintf("%010d", $date1); |
| # delete all attachments of removed topic later |
| push(@temparray_1, "$date1|$threads[$x]"); |
| $attachfile{$num} = undef; |
| } |
| |
| fopen(BOARDFILE, ">$boardsdir/$boards[$j].txt", 1) || &admin_fatal_error('cannot_open', "$boardsdir/$boards[$j].txt", 1); |
| $tempcount++; |
| print BOARDFILE map({ s/^.*?\|//; $_; } sort({ lc($b) cmp lc($a) } @temparray_1) ); |
| |
| fclose(BOARDFILE); |
| $yymain .= |
| |
| "$num = $result $removemess_txt{'122'} ($removemess_txt{'123'})<br /> $num : $removemess_txt{'7'}<br />"; |
| # remove attachments of removed topics |
| } |
| &RemoveAttachments(\%attachfile); |
| } |
| |
| |
| $i -= $tempcount; |
| if ( time() > $time_to_jump && ( $i + 1 ) < $totalthreads ) { |
| $INFO{'total_rem_count'} += $tempcount; |
| $i++; |
| &RemoveOldThreadsText($j,$i,$INFO{'total_rem_count'}); |
| for my $x ( $i .. ( $totalthreads - 1 ) ) { |
| } |
| ( undef, undef, undef, undef, $date1, undef ) = |
| } |
| split /\|/xsm, $threads[$x], 6; |
| |
| $date1 = sprintf '%010d', $date1; |
| fopen(BOARDFILE, ">$boardsdir/$boards[$j].txt", 1) || &admin_fatal_error('cannot_open', "$boardsdir/$boards[$j].txt", 1); |
| push @temparray_1, "$date1|$threads[$x]"; |
| print BOARDFILE map({ s/^.*?\|//; $_; } sort({ lc($b) cmp lc($a) } @temparray_1) ); |
| } |
| fclose(BOARDFILE); |
| fopen( BOARDFILE, ">$boardsdir/$boards[$j].txt", 1 ) |
| |
| || fatal_error( 'cannot_open', |
| &BoardCountTotals($boards[$j]); |
| "$boardsdir/$boards[$j].txt", 1 ); |
| $INFO{'total_rem_count'} += $tempcount; |
| print {BOARDFILE} map( { |
| $INFO{'nextthread'} = 0; |
| s/^.*?\|//xsm; |
| } |
| $_; |
| } |
| } reverse sort { lc($a) cmp lc $b } @temparray_1 ) |
| |
| or croak "$croak{'print'} BOARDFILE"; |
| # remove attachments of removed topics |
| fclose(BOARDFILE); |
| &RemoveAttachments(\%attachfile); |
| |
| |
| # remove attachments of removed topics |
| &automaintenance('off'); |
| RemoveAttachments( \%attachfile ); |
| |
| |
| $yymain .= qq~<br /><b>$removemess_txt{'5'} $INFO{'total_rem_count'} $removemess_txt{'6'}.</b>~; |
| $i -= $tempcount; |
| &AdminTemplate; |
| $INFO{'total_rem_count'} += $tempcount; |
| |
| RemoveOldThreadsText( $j, $i, $INFO{'total_rem_count'} ); |
| |
| } |
| |
| } |
| |
| |
| |
| fopen( BOARDFILE, ">$boardsdir/$boards[$j].txt", 1 ) |
| |
| || fatal_error( 'cannot_open', "$boardsdir/$boards[$j].txt", |
| |
| 1 ); |
| |
| print {BOARDFILE} map( { |
| |
| s/^.*?\|//xsm; |
| |
| $_; |
| |
| } reverse sort { lc($a) cmp lc $b } @temparray_1 ) |
| |
| or croak "$croak{'print'} BOARDFILE"; |
| |
| fclose(BOARDFILE); |
| |
| |
| |
| BoardCountTotals( $boards[$j] ); |
| |
| $INFO{'total_rem_count'} += $tempcount; |
| |
| $INFO{'nextthread'} = 0; |
| |
| } |
| |
| } |
| |
| |
| |
| # remove attachments of removed topics |
| |
| RemoveAttachments( \%attachfile ); |
| |
| |
| |
| automaintenance('off'); |
| |
| |
| |
| $yymain .= |
| |
| qq~<br /><b>$removemess_txt{'5'} $INFO{'total_rem_count'} $removemess_txt{'6'}.</b>~; |
| |
| AdminTemplate(); |
| |
| return; |
| } |
| } |
| |
| |
| sub RemoveOldThreadsText { |
| sub RemoveOldThreadsText { |
| my ($j,$i,$total) = @_; |
| my ( $j, $i, $total ) = @_; |
| |
| |
| |
| $INFO{'st'} = |
| |
| int( $INFO{'st'} + time() - $time_to_jump + $max_process_time ); |
| |
| |
| $INFO{'st'} = int($INFO{'st'} + time() - $time_to_jump + $max_process_time); |
| my $query; |
| |
| foreach ( keys %FORM ) { |
| |
| if ( $_ =~ /check$/xsm ) { $query .= qq~;$_=$FORM{$_}~; } |
| |
| } |
| |
| foreach ( keys %INFO ) { |
| |
| if ( $_ =~ /check$/xsm ) { $query .= qq~;$_=$INFO{$_}~; } |
| |
| } |
| |
| |
| |
| $yymain = |
| |
| qq~<b>$removemess_txt{'200'} <i>$max_process_time $admin_txt{'533'}</i>.<br /> |
| |
| $removemess_txt{'201'} <i>~ |
| |
| . ( time() - $time_to_jump + $max_process_time ) |
| |
| . qq~ $admin_txt{'533'}</i>.<br /> |
| |
| $removemess_txt{'202'} <i>~ |
| |
| . int( ( $INFO{'st'} + 60 ) / 60 ) . qq~ $admin_txt{'537'}</i>.<br /> |
| |
| <br />$total $removemess_txt{'203'}.</b><br /> |
| |
| <p id="memcontinued">$removemess_txt{'210'} <a href="$adminurl?action=removeoldthreads;maxdays=$FORM{'maxdays'}$INFO{'maxdays'};keep_them=$FORM{'keep_them'}$INFO{'keep_them'};nextboard=$j;st=$INFO{'st'};nextthread=$i;total_rem_count=$total$query" onclick="PleaseWait();">$removemess_txt{'211'}</a>...<br />$removemess_txt{'212'} |
| |
| </p> |
| |
| $yymain |
| |
| |
| |
| <script type="text/javascript"> |
| |
| function PleaseWait() { |
| |
| document.getElementById("memcontinued").innerHTML = '<span class="important"><b>$removemess_txt{'213'}</b></span>'; |
| |
| } |
| |
| |
| |
| function stoptick() { stop = 1; } |
| |
| |
| |
| stop = 0; |
| |
| function membtick() { |
| |
| if (stop != 1) { |
| |
| PleaseWait(); |
| |
| location.href="$adminurl?action=removeoldthreads;maxdays=$FORM{'maxdays'}$INFO{'maxdays'};keep_them=$FORM{'keep_them'}$INFO{'keep_them'};nextboard=$j;st=$INFO{'st'};nextthread=$i;total_rem_count=$total$query"; |
| |
| } |
| |
| } |
| |
| |
| my $query; |
| setTimeout("membtick()",2000); |
| foreach (keys %FORM) { |
| </script> |
| $query .= qq~;$_=$FORM{$_}~ if $_ =~ /check$/; |
| |
| } |
| |
| foreach (keys %INFO) { |
| |
| $query .= qq~;$_=$INFO{$_}~ if $_ =~ /check$/; |
| |
| } |
| |
| |
| |
| $yymain = qq~<b>$removemess_txt{'200'} <i>$max_process_time $admin_txt{'533'}</i>.<br /> |
| |
| $removemess_txt{'201'} <i>~ . (time() - $time_to_jump + $max_process_time) . qq~ $admin_txt{'533'}</i>.<br /> |
| |
| $removemess_txt{'202'} <i>~ . int(($INFO{'st'} + 60)/60) . qq~ $admin_txt{'537'}</i>.<br /> |
| |
| <br />$total $removemess_txt{'203'}.</b><br /> |
| |
| <p id="memcontinued">$removemess_txt{'210'} <a href="$adminurl?action=removeoldthreads;maxdays=$FORM{'maxdays'}$INFO{'maxdays'};keep_them=$FORM{'keep_them'}$INFO{'keep_them'};nextboard=$j;st=$INFO{'st'};nextthread=$i;total_rem_count=$total$query" onclick="PleaseWait();">$removemess_txt{'211'}</a>...<br />$removemess_txt{'212'} |
| |
| </p> |
| |
| $yymain |
| |
| |
| |
| <script type="text/javascript"> |
| |
| <!-- |
| |
| function PleaseWait() { |
| |
| document.getElementById("memcontinued").innerHTML = '<font color="red"><b>$removemess_txt{'213'}</b></font>'; |
| |
| } |
| |
| |
| |
| function stoptick() { stop = 1; } |
| |
| |
| |
| stop = 0; |
| |
| function membtick() { |
| |
| if (stop != 1) { |
| |
| PleaseWait(); |
| |
| location.href="$adminurl?action=removeoldthreads;maxdays=$FORM{'maxdays'}$INFO{'maxdays'};keep_them=$FORM{'keep_them'}$INFO{'keep_them'};nextboard=$j;st=$INFO{'st'};nextthread=$i;total_rem_count=$total$query"; |
| |
| } |
| |
| } |
| |
| |
| |
| setTimeout("membtick()",2000); |
| |
| // --> |
| |
| </script> |
| |
| |
| |
| ~; |
| ~; |
| |
| |
| &AdminTemplate; |
| AdminTemplate(); |
| |
| return; |
| } |
| } |
| |
| |
| 1; |
| 1; |
| |
| |