From e9192b3d42660a5781101df4357d276318151e8a Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 2 Aug 2013 17:14:41 -0500 Subject: cgi-bin & lib --- lib/threads.pm | 411 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 411 insertions(+) create mode 100644 lib/threads.pm (limited to 'lib/threads.pm') diff --git a/lib/threads.pm b/lib/threads.pm new file mode 100644 index 0000000..b20bbc6 --- /dev/null +++ b/lib/threads.pm @@ -0,0 +1,411 @@ +######################################### +# THREADS.PM + +my $r = 0; +my $firstbox = 1; +my %tk; + +our $our_keywords = {}; + +sub alpha_index + { + my ($keywords, $limit, $date) = @_; +$our_keywords = $keywords; + my %organized; + my $oldest = $date eq "now" ? time : $date; + my $recently = time - 86400 * $BUCKY_INDEX_LATEST; # two days ago + my $i = 0; + + while ($limit > $i) + { + my $threads = throttle_threads({ keyword => $keyword, limit => ($limit-$i), newest => $oldest, oldest => 0 }); + last if ($threads == -1); + foreach my $t (@$threads) + { + if ( check_privacy ( $t, $keywords->{ $t->{keyword} } ) ) + { + # If keyword is undefined, file it under "unsorted" + my $this_kw = $t->{keyword} ? $t->{keyword} : "unsorted"; + + # put newest (last 2 days) or unsorted posts in one place + if ( $t->{date} > $recently || ! length($t->{keyword}) ) + { + push @{ $organized{'latest'} }, $t; + } + + push @{$organized{$this_kw}}, $t; + $i++; + } + $oldest = $t->{date} if ($t->{date} < $oldest); + last if ($limit == $i); + } + print "Oldest: $oldest, i: $i\n" if ($DEBUG); + } + + if ($date eq "now") + { + foreach my $k (sort { lc($a) cmp lc($b) } keys %$keywords) + { + next unless (check_key($USER->{stickies}, $k)); + next if (check_key($USER->{sink}, $k)); + next unless (exists($organized{$k})); + thread_box({ threads => $organized{$k}, kw => $keywords->{$k}, dosum => 0, dohead => 1 }); +# print qq(); + } +# print qq(); + } + +print qq(); + index_photostream(); +print qq(); + + thread_box({ threads => $organized{"latest"}, kw => "LATEST", dosum => 0, dohead => 1 }); + + foreach my $k (sort { lc($a) cmp lc($b) } (keys(%organized))) + { + next if (check_key($USER->{stickies}, $k)); + next if (check_key($USER->{sink}, $k)); + next if ($k =~ /^(unsorted|latest)$/i); + thread_box({ threads => $organized{$k}, kw => $keywords->{$k}, dosum => 0, dohead => 1 }); + print qq(); + } + + thread_box({ threads => $organized{"unsorted"}, dosum => 0, dohead => 1 }) if ($BUCKY_CONFIG->{UNSORTED_POSITION} eq "bottom"); + + if ($i >= $limit) + { + print qq(); + print qq(show all >>); + } + } + +sub thread_box + { + my ($args) = @_; + my $threads = $args->{threads} || undef; + my $kw = $args->{kw} || undef; + my $tag = $args->{tag} || undef; + my $dosum = exists($args->{dosum}) ? $args->{dosum} : undef; + my $dohead = exists($args->{dohead}) ? $args->{dohead} : undef; + my $line = 0; + my $user = 0; + my $latest = 0; + $dosum = 1 unless (defined($dosum)); + $dohead = 1 unless (defined($dohead)); + my $sum = 0; + my $isop; + $firstbox = 1; + my $method = \&rsort_by_date; + if (exists($args->{sort_by}) && $arts->{sort_by} eq "name") + { $method = \&sort_by_name; } + if ($kw eq "USER") + { + $user = 1; + $isop = 1; + $kw = -1; + } + elsif ($kw eq "LATEST") + { + $latest = 1; + $isop = 1; + $kw = -1; + } + elsif ($kw != -1) + { $isop = check_op($kw); } + else + { $isop = 1; } + foreach my $th (&{$method}(@$threads)) + { + my $printed = 0; +# next if ($kw == -1 && defined($th->{keyword})); + if ($line == 0) + { + if ($dohead && $tag) + { + print qq(); + print qq[]; + print qq[tag: ]; + print qq(); + print qq(); + print qq(); + print qq(); + print qq[]; + print qq($tag->{tag}); + print qq(); + print qq(); + print qq(); + } + if ($dohead && $latest) + { + print qq(); + print qq[]; + print qq(the latest ); + print qq(); + print qq(·); + print qq(); + print qq(welcome back to $BUCKY_NAME!! Start a new thread...); + print_boxtop(1); + } + elsif ($dohead && (!defined($kw) || $kw == -1)) + { + my $unsorted_keyword = get_random_line("keywords"); + print qq(); + print qq[]; + print qq[]; + print $unsorted_keyword; + print qq(); + print qq( · ); + print qq(); + print qq(); + print qq(show all); + print qq( · post); + print qq( · ftp); + print qq(); + print qq(); + } + elsif ($user) + { + # this is all broken for some reason, is rewritten somewhere...! + print_boxtop(1); + } + elsif ($dohead) + { + $polite_keyword = $th->{keyword}; + $polite_keyword =~ s/ / /g; + print qq(); + print qq[]; + print qq[]; + print $polite_keyword; + print qq(); + print qq( · ); + print qq(); + print qq(); + if ($kw->{public} == 1 || $isop) + { + # print qq(show all); + # print qq( · ); + + print qq(post) if ($USER != -1); + + # 20070903 - marc - no more ftp + print qq( · ftp); + } + if ($isop || $USER->{ulevel} == 3) + { + print qq( · ); + print qq(settings); + } + print qq(); + print qq(); + } + $line++; + } + if ($dosum == -1) + { $printed = check_thread_row($th, $kw, 4, $line); } + else + { $printed = check_thread_row($th, $kw, 3, $line); } + $sum += $th->{size}; + $line++ if ($printed); + last if ($dosum == -1 && $line == 6); + } + if ($line != 0) + { + print_boxbottom(1); + if ($dosum > 0) + { + $line -= 1; + my $s = $line != 1 ? 's' : ''; + print qq($line thread$s); + print qq(, ).hushsize($sum,1.7).qq(); + } + } + } + +sub print_boxtop + { + print qq!!; + } + +sub print_boxbottom + { + print qq!!; + } + +sub check_thread_row + { + my ($thread, $keyword, $brief, $box) = @_; + my $priv = 0; +# uncomment to skip threads already printed +# return 1 if ($tk{$thread->{id}} == 1); + $tk{$thread->{id}} = 1; + return 1 if ($brief eq "NOPRINT"); + if ($thread->{private} != 0) + { + $priv = check_privacy($thread, $keyword); + if ($priv == 0) + { return 0; } + } + if ($box == 1 && $keyword != -1) + { + print_boxtop($firstbox); + } + if ($thread->{'keyword'} && $keyword == -1) { $keyword = $our_keywords->{$thread->{'keyword'}} } + display_thread($thread, $keyword, $r, $priv, $brief, $box); + $r = $r ? 0 : 1; + return 1; + } + +sub display_thread + { + my ($t, $k, $r, $priv, $brief, $box) = @_; + my $color = carbondate($t->{date}); + my $rcolor = get_color($t, $k, $box); + my $old = ((time - $t->{date}) > 2419200) ? 1 : 0; + my $box = (defined($box)) ? $box : 0; + + if ($DEBUG) + { + print qq!
Displaying post $t->{id} -- $t->{title}
\n!; + } + + print qq[]; + + print qq[]; + print ""; + print qq[$t->{username} ]; + + if ($t->{private} == 2) + { print qq[.:]; } + elsif ($t->{private} == 1) + { print qq[:]; } + else + { print qq[·]; } + print " "; + print ""; + + if ($box > 0) + { + $rcolor = "tan" if ($rcolor eq "plain"); + print qq(); + } + else + { + print qq[]; + } + my $thread_link_class; + if ($t->{date} > (time - 209828) && $t->{date} > 1168910000) + { $thread_link_class = "threadname newthread"; } + else + { $thread_link_class = "threadname"; } + + print qq(); + print qq($t->{title}); + print qq(); + print ""; + + my ($age) = get_age($t->{date}); + + print qq(); + print ""; + print qq(  $age ); + print ""; + print ""; + +# my ($tddate, $tdtime) = verbosedatetime($t->{date}); +# print qq[]; +# print qq[ $tddate ]; +# print ""; +# if ($0 !~ /(details|profile)/) +# { +# print qq[]; +# print qq[$tdtime]; +# print ""; +# } + + print qq[]; + print " "; + if ($t->{viewed} > 0) + { print hushview($t->{viewed}, "v") . ""; } + else + { print ""; } + # decrement comments count here so we treat the first comment" as the body of the post + if (($t->{comments} - 1) > 0) + { print " ".hushnull($t->{comments} - 1, "c") . ""; } + else + { print " "; } + +# print qq[]; +# if (!ref($t->{tags})) +# { print " "; } +# else +# { print "  ". tags_stringify_links ( $t, 3 ). ""; } +# if ($t->{files} > 0) +# { print "" .hushnull($t->{files}, "f") . ""; } +# else +# { print " "; } + +# print ""; + + print qq[]; + if ($t->{files} > 0) + { + print " ".hushsize($t->{size},1.2,$old),qq[]; + if ($0 !~ /(details|profile)/) + { + print qq[in ]; + print hushnull($t->{files}, "f"); + print ""; + } + } + print ""; + + print qq[\n]; + } + +# sort methods +# title, date, size, files, username + +sub get_sort_method + { + my ($s, $o) = @_; + + if ($o eq "a") + { + if ($s eq "t") { return \&sort_by_title; } + elsif ($s eq "s") { return \&sort_by_size; } + elsif ($s eq "d") { return \&sort_by_date; } + elsif ($s eq "c") { return \&sort_by_comments; } + elsif ($s eq "f") { return \&sort_by_files; } + elsif ($s eq "a") { return \&sort_by_author; } + } + elsif ($o eq "d") + { + if ($s eq "t") { return \&rsort_by_title; } + elsif ($s eq "s") { return \&rsort_by_size; } + elsif ($s eq "d") { return \&rsort_by_date; } + elsif ($s eq "c") { return \&rsort_by_comments; } + elsif ($s eq "f") { return \&rsort_by_files; } + elsif ($s eq "a") { return \&rsort_by_author; } + } + else + { return \&rsort_by_date; } + } + +sub sort_by_name { sort { uc($$a{title}) cmp uc($$b{title}) } @_; } +sub sort_by_title { sort { uc($$a{title}) cmp uc($$b{title}) } @_; } +sub rsort_by_title { sort { uc($$b{title}) cmp uc($$a{title}) } @_; } +sub sort_by_date { sort { $$a{date} <=> $$b{date} } @_; } +sub rsort_by_date { sort { $$b{date} <=> $$a{date} } @_; } +sub sort_by_size { sort { $$a{size} <=> $$b{size} } @_; } +sub rsort_by_size { sort { $$b{size} <=> $$a{size} } @_; } +sub sort_by_files { sort { $$a{files} <=> $$b{files} } @_; } +sub rsort_by_files { sort { $$b{files} <=> $$a{files} } @_; } +sub sort_by_comments { sort { $$a{comments} <=> $$b{comments} } @_; } +sub rsort_by_comments { sort { $$b{comments} <=> $$a{comments} } @_; } +sub sort_by_author { sort { uc($$a{username}) cmp uc($$b{username}) } @_; } +sub rsort_by_author { sort { uc($$b{username}) cmp uc($$a{username}) } @_; } + +1; + -- cgit v1.2.3-70-g09d2