#!/usr/bin/perl ######################################### # maintain # - thread administration ######################################### use localbucky; our $id; our $files; $dbh = DBI->connect ($dsn); our ($USER, $lastlog) = checkin(); logout() unless ($USER != -1); $input->{id} ||= $input->{object_from_uri} if defined($input->{object_from_uri}); if (exists($input->{id}) && $input->{id} > 0) { $id = $input->{id}; } elsif (exists($input->{keyword}) ) { $keyword = $input->{keyword}; } else { error("No post specified."); } my $t = get_thread($id); my $k = get_keyword($t->{keyword}); if ($t == -1) { error("No such post."); } $files = get_files($t->{id}); $comments = get_comments($t->{id}); #my ($participation) = check_participation($files, $comments); my ($participation) = 0; if (exists($input->{c}) && $input->{c} eq "zip") { if ($t->{zipped} == 0) { my $cleantitle = generate_zip_filename($t); update_thread_zipped($t->{id}, -1); $t->{zipped} = -1; system(qq!$NOHUP_PATH $ZIP_PATH -jr "$data_path/$t->{id}/$cleantitle" $data_path/$t->{id}/* >$temp_path/.zip.out -x "$cleantitle" 2>&1 &!); redirect("$BUCKY/".details_link($t)."/$t->{id}"); } elsif ($t->{zipped} == 1) { my $cleantitle = generate_zip_filename($t); update_thread_zipped($t->{id}, -1); $t->{zipped} = -1; system(qq!$NOHUP_PATH $ZIP_PATH -jr "$data_path/$t->{id}/$cleantitle" $data_path/$t->{id}/* >$temp_path/.zip.out -x "$cleantitle" 2>&1 &!); redirect("$BUCKY/".details_link($t)."/$t->{id}"); } } elsif ($t->{username} eq $USER->{username} || check_op($k) || $participation == 2 || (check_key($t->{display}, "opset") && check_privacy($t, $k)) || $USER->{ulevel} == 3) { header( { title => "settings for \"$t->{title}\"", subtitle => qq!posted by $t->{username} on ! . (verbosedate($t->{createdate})) . qq! · view post!, color => get_color($t, $k) } ); menu(); if (exists($input->{c})) { if ($input->{c} eq "display") { if ($t->{title} ne $input->{title}) { update_thread_title($t->{id}, $input->{title}); $t->{title} = $input->{title}; print "Changed title to: $t->{title}
\n"; } if (($t->{color} ne $input->{color}) && is_color($input->{color})) { update_thread_color($t->{id}, $input->{color}); $t->{color} = $input->{color}; print "Set color to: $t->{color}
\n"; print qq(); } my (@display) = qw[hoot ren "no-upload" shorturl editable opset "no-zip-button" hidekws]; my $newdisplay = ' '; foreach my $key (@display) { if (exists($input->{$key}) && $input->{$key} == 1) { $newdisplay = add_key($newdisplay, $key); } } if ($input->{filelist} == 2) { $newdisplay = add_key($newdisplay, "ffl"); } if ($input->{filelist} == 0) { $newdisplay = add_key($newdisplay, "nfl"); } if ($t->{display} ne $newdisplay) { update_thread_display($t->{id}, $newdisplay); $t->{display} = $newdisplay; print "New display settings: $t->{display}
\n"; } # touch_thread($t); admin_form($t->{id}, $t, $files, $k); } elsif ($input->{c} eq "p") { if ($input->{private} == 2) { print "Thread is now " . $BUCKY_CONFIG->{PRIVACY_OWNER} . ".
"; switch_thread_privacy($t->{id}, 2); $t->{allowed} = update_whitelist(); $t->{private} = 2; } elsif ($input->{private} == 1) { print "Thread is now viewable by " . $BUCKY_CONFIG->{PRIVACY_BBS} || "other users" . ".
"; switch_thread_privacy($t->{id}, 1); $t->{allowed} = update_whitelist(); $t->{private} = 1; } else { print "Thread is now viewable by " . $BUCKY_CONFIG->{PRIVACY_WORLD} . ".
"; switch_thread_privacy($t->{id}, 0); $t->{private} = 0; } admin_form($t->{id}, $t, $files, $k); } # change tags elsif ($input->{c} eq "t") { my $new_tags = 0; if ($input->{tags} ne $input->{tags_saved}) { print "Changed Tag to " . $input->{tags} . "
" if ($DEBUG); # First: add new tags my $tags = get_tags_from_string( $input->{tags} ); foreach my $tag (@$tags) { print "Assigning tag $tag
\n" if ($DEBUG); print tag_assign_mechanism( $tag, $t ) || ""; $new_tags++; } # Second: remove deleted tags my $old_tags = get_tags_from_string( $input->{tags_saved} ); foreach my $old_tag (@$old_tags) { # If the new tags list does not contain this old tag, remove it if ( ! grep ( /^$old_tag$/, @$tags ) ) { print tag_remove_mechanism( $old_tag, $t ) || ""; $new_tags++; } } } # touch_thread($t); $t = get_thread( $t->{id} ) if $new_tags; admin_form($t->{id}, $t, $files, $k); } elsif ($input->{c} eq "f") { my @flagged = corral($input, "file"); if ($DEBUG) { print "
\nfiles flagged: "; foreach (@flagged) { print; print " "; } print "
\n"; } if ($input->{verb} eq "flag") { print "Flagged file $flagged[0]
"; update_flagged($t->{id}, $flagged[0]); $t->{flagged} = $flagged[0]; touch_thread($t); admin_form($t->{id}, $t, $files, $k); } elsif ($input->{verb} eq "move") { print "When this works it will be like this:!
\n"; print "Where do you want to move these files here
\n"; print "Moving files...
\n"; # system("mv", $data_path/$oldpid/$filenamea ..., "$data_path/$newpid/"); print "Moving ids...
\n"; print "Recalculating post sizes...
\n"; } elsif ($input->{verb} eq "rm") { if (!$input->{ok}) { print qq(

Are you sure you want to delete these files?

\n); print qq(

); print qq(\n); print qq(\n); print qq(\n) if ($DEBUG); print qq(\n); print qq(\n); my $i = 0; my $fid = shift(@flagged); foreach my $fh (sort_by_id(@$files)) { next if ($fid != $fh->{id}); $i++; print qq{\n}; print $fh->{id}.": " if ($DEBUG); print $fh->{filename}."
\n"; $fid = shift(@flagged); } print qq{
}; } else { my $i = 0; my $fid = shift(@flagged); foreach my $fh (sort_by_id(@$files)) { next if ($fid != $fh->{id}); $i++; next if -d qq!$data_path/$t->{id}/$$fh{filename}!; delete_file_record($fid); system($RM_PATH, "-f", qq!$data_path/$t->{id}/$$fh{filename}!); system($RM_PATH, "-f", qq!$data_path/$t->{id}/.thumb/s.$$fh{filename}!); system($RM_PATH, "-f", qq!$data_path/$t->{id}/.thumb/t.$$fh{filename}!); system($RM_PATH, "-f", qq!$data_path/$t->{id}/.thumb/b.$$fh{filename}!); print qq!deleted $$fh{filename}
\n!; $fid = shift(@flagged); } print "Recalculating post size...
\n"; update_thread_size($t->{id}); $files = get_files($t->{id}); touch_thread($t); admin_form($t->{id}, $t, $files, $k); } } } elsif ($input->{c} eq "clobber") { if ($input->{okay}) { delete_thread($t->{id}); print qq!

POST DELETED\!
\n!; } else { my $fs = $t->{files} != 1 ? "s" : ""; my $cs = $t->{comments} != 1 ? "s" : ""; my $par = get_participation($t->{id}); my $ps = $par != 1 ? "s" : ""; print qq(

); print qq(Are you sure you want to delete:
$t->{title}


); print qq(Doing so will delete $t->{files} file$fs and $t->{comments} comment$cs,
); print qq(destroying the hard work of $par duder$ps\!
); print qq(
); print qq(
\n); print qq(\n) if ($DEBUG); print qq(\n); print qq(\n); print qq(\n); print qq(
); print qq!
!; } } } else { admin_form($t->{id}, $t, $files, $k); } footer(); } else { error("Unable to access $id!"); } sub sort_by_username { sort { lc($a->{username}) cmp lc($b->{username}) } @_; } sub sort_by_id { sort { $a->{id} <=> $b->{id} } @_; } print "Maintain: " . &report_time() . "\n" if $timer;