diff options
Diffstat (limited to 'lib/threads.pm')
| -rw-r--r-- | lib/threads.pm | 411 |
1 files changed, 411 insertions, 0 deletions
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(<tr><td><img src="/blank.gif" height=5></td></tr>); + } +# print qq(<tr><td><img src="/blank.gif" height=2></td></tr>); + } + +print qq(<tr><td colspan=666>); + index_photostream(); +print qq(</td></tr>); + + 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(<tr><td><img src="/blank.gif" height=1></td></tr>); + } + + thread_box({ threads => $organized{"unsorted"}, dosum => 0, dohead => 1 }) if ($BUCKY_CONFIG->{UNSORTED_POSITION} eq "bottom"); + + if ($i >= $limit) + { + print qq(<tr><td align="right" colspan=7 style="padding-top: 15px;"><big>); + print qq(<a href="$BUCKY/index?limit=10000">show all >></a></big></td></tr>); + } + } + +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(<tr><td align="right" valign="bottom"><big>); + print qq[<span style="font-weight: bold;">]; + print qq[tag: ]; + print qq(</span></a>); + print qq(</big>); + print qq(</td><td align="left" valign="bottom" colspan=4>); + print qq(<big>); + print qq[<span style="font-weight: bold;">]; + print qq($tag->{tag}); + print qq(</span>); + print qq(</big>); + print qq(</td></tr>); + } + if ($dohead && $latest) + { + print qq(<tr><td align="right" valign="bottom"><big>); + print qq[<span style="font-weight: bold;">]; + print qq(<i>the latest</i> </span></a>); + print qq(</big>); + print qq(·); + print qq(</td><td align="left" valign="bottom" colspan=4>); + print qq(welcome back to $BUCKY_NAME!! <a href="$BUCKY/post">Start a new thread...</a></td></tr>); + print_boxtop(1); + } + elsif ($dohead && (!defined($kw) || $kw == -1)) + { + my $unsorted_keyword = get_random_line("keywords"); + print qq(<tr><td align="right" valign="bottom"><big>); + print qq[<a href="$BUCKY/$BUCKY_LEXICON_KEYWORD/unsorted" class="quietlink">]; + print qq[<span style="font-weight: bold;">]; + print $unsorted_keyword; + print qq(</span></a>); + print qq(</big><small> · </small>); + print qq(</td><td align="left" valign="bottom" colspan=4>); + print qq(<small>); + print qq(<a href="$BUCKY/$BUCKY_LEXICON_KEYWORD/unsorted">show all</a>); + print qq( · <a href="$BUCKY/post">post</a>); + print qq( · <a href="$BUCKY/import">ftp</a>); + print qq(</small>); + print qq(</td></tr>); + } + 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(<tr><td align="right" valign="bottom"><big>); + print qq[<a href="$BUCKY/$BUCKY_LEXICON_KEYWORD/$th->{keyword}" class="quietlink">]; + print qq[<span style="font-weight: bold;">]; + print $polite_keyword; + print qq(</span></a>); + print qq(</big><small> · </small>); + print qq(</td><td align="left" valign="bottom" colspan=4>); + print qq(<small>); + if ($kw->{public} == 1 || $isop) + { + # print qq(<a href="$BUCKY/index?keyword=$th->{keyword}">show all</a>); + # print qq( · ); + + print qq(<a href="$BUCKY/post/$th->{keyword}">post</a>) if ($USER != -1); + + # 20070903 - marc - no more ftp + print qq( · <a href="$BUCKY/import?keyword=$th->{keyword}">ftp</a>); + } + if ($isop || $USER->{ulevel} == 3) + { + print qq( · ); + print qq(<a href="$BUCKY/$BUCKY_LEXICON_KEYWORD/$th->{keyword}?c=edit">settings</a>); + } + print qq(</small>); + print qq(</td></tr>); + } + $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(<tr><td colspan=2 align=right><small><b>$line</b> thread$s); + print qq(, ).hushsize($sum,1.7).qq(</small></td></tr>); + } + } + } + +sub print_boxtop + { + print qq!<tr><td></td><td style="border-bottom: 1px solid #b6aeab;"><img src="/blank.gif" width=1 height=1></td></tr>!; + } + +sub print_boxbottom + { + print qq!<tr><td></td><td style="border-top: 1px solid #b6aeab;"><img src="/blank.gif" width=1 height=2></td></tr>!; + } + +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!<div align="left">Displaying post $t->{id} -- $t->{title}</div>\n!; + } + + print qq[<tr>]; + + print qq[<td align="right" valign="middle" nowrap>]; + print "<small>"; + print qq[<a href="$BUCKY/profile/$t->{username}" class="quietlink">$t->{username}</a> ]; + + if ($t->{private} == 2) + { print qq[.:]; } + elsif ($t->{private} == 1) + { print qq[:]; } + else + { print qq[·]; } + print " </small>"; + print "</td>"; + + if ($box > 0) + { + $rcolor = "tan" if ($rcolor eq "plain"); + print qq(<td align="left" valign="middle" nowrap class="$rcolor$r" style="border-left: 1px solid #b6aeab; border-right: 1px solid #b6aeab;">); + } + else + { + print qq[<td align="left" valign="middle" nowrap class="$rcolor$r">]; + } + my $thread_link_class; + if ($t->{date} > (time - 209828) && $t->{date} > 1168910000) + { $thread_link_class = "threadname newthread"; } + else + { $thread_link_class = "threadname"; } + + print qq(<a class="$thread_link_class" style="display: block;" href="$BUCKY/).details_link().qq(/$t->{id}); + print get_revision($t) if ($USER != -1); + print qq(">); + print qq($t->{title}); + print qq(</a>); + print "</td>"; + + my ($age) = get_age($t->{date}); + + print qq(<td align="right" valign="middle" nowrap>); + print "<small>"; + print qq(<span class="$color"> $age </span>); + print "</small>"; + print "</td>"; + +# my ($tddate, $tdtime) = verbosedatetime($t->{date}); +# print qq[<td align="right" valign="middle" nowrap style="padding-right: 0px; margin-right: 0px;">]; +# print qq[<span class="$color"> $tddate </span>]; +# print "</td>"; +# if ($0 !~ /(details|profile)/) +# { +# print qq[<td align="left" valign="middle" nowrap style="padding-left: 0px; margin-left: 0px; padding-top: 2px;">]; +# print qq[<span class="$color"><small>$tdtime</small></span>]; +# print "</td>"; +# } + + print qq[<td align="right" valign="middle" nowrap>]; + print "<small> "; + if ($t->{viewed} > 0) + { print hushview($t->{viewed}, "v") . "</small></td>"; } + else + { print "</small></td>"; } + # decrement comments count here so we treat the first comment" as the body of the post + if (($t->{comments} - 1) > 0) + { print "<td align=right valign=middle nowrap><small> ".hushnull($t->{comments} - 1, "c") . "</small></td>"; } + else + { print "<td align=right valign=middle nowrap><small> </small></td>"; } + +# print qq[<a href="$BUCKY/index?keyword=$th->{keyword}" class="quietlink">]; +# if (!ref($t->{tags})) +# { print "<td><small> </small></td>"; } +# else +# { print "<td align=left valign=middle nowrap><span class=\"quiet\"><small> ". tags_stringify_links ( $t, 3 ). "</small></span></td>"; } +# if ($t->{files} > 0) +# { print "<td align=right valign=middle nowrap><small>" .hushnull($t->{files}, "f") . "</small></td>"; } +# else +# { print "<td><small> </small></td>"; } + +# print "</td>"; + + print qq[<td align="right" valign="middle" nowrap>]; + if ($t->{files} > 0) + { + print "<small> ".hushsize($t->{size},1.2,$old),qq[</small></td>]; + if ($0 !~ /(details|profile)/) + { + print qq[<td align="left"><small><span class="old">in</span> ]; + print hushnull($t->{files}, "f"); + print "</small>"; + } + } + print "</td>"; + + print qq[</tr>\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; + |
