diff options
| author | Jules Laplace <carbon@melanarchy.org> | 2013-08-02 17:14:41 -0500 |
|---|---|---|
| committer | Jules Laplace <carbon@melanarchy.org> | 2013-08-02 17:14:41 -0500 |
| commit | e9192b3d42660a5781101df4357d276318151e8a (patch) | |
| tree | 059eb6ace6147cf9559af74ed1ab5e221c80e280 /lib/comments.pm | |
| parent | 79670053c7247d3a49b607960efd284e93f057e5 (diff) | |
cgi-bin & lib
Diffstat (limited to 'lib/comments.pm')
| -rw-r--r-- | lib/comments.pm | 287 |
1 files changed, 287 insertions, 0 deletions
diff --git a/lib/comments.pm b/lib/comments.pm new file mode 100644 index 0000000..1ccd469 --- /dev/null +++ b/lib/comments.pm @@ -0,0 +1,287 @@ + +sub sideshow_comments + { +# my ($thread, $keyword, $comments, $order) = @_; + my ($hash) = @_; +# print "YO COMMENTS WILL BE WORKING IN A SEC DUDES<br>"; + $thread = $hash->{'thread'}; + $keyword = $hash->{'keyword'}; + $comments = $hash->{'comments'}; + $order = $hash->{'order'}; + + return unless $comments; + + $shorturl = 0 unless (defined($shorturl)); + $color = get_color($thread, $keyword); + my %c; + my $shorturl = check_key($thread->{display}, "shorturl"); + my $r = 0; + + my @sorted; + if ($order && $order eq "asc") + { + @sorted = sort { $b <=> $a } (keys %$comments); + } + else + { + @sorted = sort { $a <=> $b } (keys %$comments); + } + my @basis = (); + my $firstpost = 1; + my $lastpost = undef; + my %tree; + +print qq(<!-- STARTING TABLE ) . scalar(keys(%$comments)) . qq( c. -->); + print qq(<tr><td colspan=2 height=1><img src="/blank.gif" width=1 height=1 vspace=0 hspace=0></td></tr>);# unless ($hash->{'hootbox'}); + $lastpost = undef; + foreach my $id (@sorted) + { + my $comment = $comments->{$id}; + # hide hidden comments from non-oper + if ($comment->{parent_id} != -1) + { push @{$tree{$comment->{parent_id}}}, $id; } + else + { push @basis, $comment; $lastpost = $comment->{id}; } + } + + my $args = $hash || {}; + $args->{thread} ||= $thread; + $args->{keyword} ||= $keyword; + $args->{shorturl} ||= $shorturl; + $args->{noreply} ||= 0; + + $args->{comment} = undef; + $args->{firstpost} = $firstpost; + $args->{lastpost} = 0; + $args->{r} = $sorted[0]->{id} % 2 ? "0" : "1"; + + foreach my $id (@sorted) + { + my $c = $comments->{$id}; + next if ($c->{parent_id} != -1); + next if hiding_hidden_posts($c); + + $args->{r} = $args->{r} ? "0" : "1"; + $args->{comment} = $c; + $args->{noreply} = exists($tree{$id}); + $args->{firstpost} = $firstpost; + if (display_comment($args)) + { $firstpost = 0; } + + if (exists($tree{$id})) + { + $firstpost = 1; + my $tail = $tree{$id}; + my $tailend = $tail->[-1]; + print qq(<tr>); + print qq(<td colspan=2 style="padding: 0px; margin: 0px;">\n); + print qq(<table cellpadding=0 cellspacing=0 border=0 width=100% style="padding: 0px; margin: 0px;">\n); + foreach my $subcomment_id ( @$tail ) + { + my $c = $comments->{$subcomment_id}; + next if hiding_hidden_posts($c); + $r = $r ? "0" : "1"; + $args->{r} = $args->{r} ? "0" : "1"; + $args->{comment} = $c; + $args->{noreply} = $subcomment_id != $tailend; + $args->{lastpost} = $subcomment_id == $tailend && $lastpost != $id; + display_subcomment($args); + } + print qq(</table>\n</td></tr>\n\n); + } + } + } + +sub hiding_hidden_posts + { + my ($c) = @_; + if ($c->{'hidden'} != 1) + { return 0; } + if ( $USER->{'ulevel'} == 3 && check_key($USER->{boxes}, "showhidden") ) + { return 0; } + return 1; + } + +sub display_comment + { + my ($args) = @_; + + my ($t) = $args->{thread} || -1; + my ($c) = $args->{comment} || -1; + + return 0 if ($c->{comment} eq undef); + + my $z_r = exists($args->{r}) ? $args->{r} : undef; + my $z_id = $c->{id}; + my $z_date = verbosedate($c->{date}); + my $z_age = get_age($c->{date}); +# $z_age .= " ago" unless $age eq "now"; + my $z_user = $c->{username}; + my $z_profile = qq($BUCKY/profile/$z_user); + my $z_comment = linebr($c->{comment}, $args->{shorturl}); + my $z_br = $z_comment =~ /<br>/ ? undef : "<br><br>"; + my $z_options = ($USER != -1) ? display_comment_options($args) : " "; + $z_options .= " ($z_id)" if $DEBUG; + + if ($args->{'hootbox'}) + { + my $z_width = $AVATAR_MED_WIDTH; + my $z_image = get_profile_image($c->{username}, $AVATAR_MED_PREFIX); + print qq(<tr>); + +print qq(<td style="padding:0px; width: $z_width; vertical-align: middle; text-align: right;); +print qq(border-top: 2px solid #000; ) if ($args->{firstpost}); + print qq(border-bottom: 2px solid #000; background-color: #666;); +print qq(">); + if ($z_image != -1) + { +print qq(<a href="$z_profile"><img src="$z_image" width="$z_width" height="$z_width" border=0></a>); + } +print qq(</td>); + + print qq(<td class="comment cc$z_r" style="vertical-align: middle; ); +print qq(border-top: 2px solid #000; ) if ($args->{firstpost}); + print qq(border-left: 2px solid #000; ); # if ($z_image == -1); + print qq(border-bottom: 2px solid #000;); +# print qq( border-right: 2px solid #ccc; padding: 0px;">); + print qq(">); + print qq(<table width="100%" border=0 cellpadding=0 cellspacing=0>); + print qq(<tr>); +# print qq(<td colspan=2 align=left><small>$z_comment <div class="quiet" style="float: right;">$z_age </div></small></td>); + print qq(<td colspan=2 align=left><small>$z_comment</small></td>); + print qq(</tr>); + print qq(</table>); + print qq(</td>); + +# print qq(<td style="text-align: left; vertical-align: top; ) . +# qq(border-right: 1px solid #ccc; ) . +# qq( padding: 3px 3px 3px 6px; width: 20px;">); +# print qq(<small><a href="$z_profile">$z_user</a><br>$z_age</small>); +## print qq(<a href="$z_profile">$z_user</a>); +# print qq(</td>); +## print qq(<tr>); +## print qq(<td colspan=2 align=right><small>$z_age</small></td>); +## print qq(</tr>); +# print qq(</tr>); + } + else + { + my $z_width = $AVATAR_BIG_WIDTH; + my $z_image = get_profile_image($c->{username}, $AVATAR_BIG_PREFIX); + print qq(<tr>); + print qq(<td style="text-align: center; vertical-align: top; ) . + qq(border-right: 1px solid #ccc; ) . + qq( padding: 3px 3px 1px 1px;" width=60>); + if ($z_image != -1) + { print qq(<a href="$z_profile"><img src="$z_image" width="$z_width" border=1></a>); } + print qq(<a href="$z_profile">$z_user</a>); + print qq(</td>); + print qq(<td class="comment c$z_r" style="vertical-align: top; ); + print qq(border-top: 1px solid #ccc; ) if ($args->{firstpost}); + print qq(border-bottom: 1px solid #ccc; border-right: 1px solid #ccc; padding: 3px 3px 3px 3px;">); + print qq(<table width="100%" height="" border=0 cellpadding=0 cellspacing=3>); + print qq(<tr>); + print qq(<td colspan=2 align=left>$z_comment$z_br</td>); + print qq(</tr>); + print qq(<tr>); + print qq(<td align=left>$z_options</td>); + print qq(<td align=right><small>$z_date</small></td>); + print qq(</tr>); + print qq(</table>); + print qq(</td></tr>); + } + + return 1; + } + +sub display_subcomment + { + my ($args) = @_; + + my ($t) = $args->{thread} || -1; + my ($c) = $args->{comment} || -1; + + return 0 if ($c->{comment} eq undef); + + my $z_r = exists($args->{r}) ? $args->{r} : undef; + my $z_date = verbosedate($c->{date}); + my $z_age = get_age($c->{date}); + $z_age .= " ago" unless $age eq "now"; + my $z_user = $c->{username}; + my $z_profile = qq($BUCKY/profile/$z_user); + my $z_comment = linebr($c->{comment}, $args->{shorturl}); + my $z_width = $AVATAR_MED_WIDTH; + my $z_image = get_profile_image($c->{username}, $AVATAR_MED_PREFIX); + my $z_options = ($USER != -1) ? display_comment_options($args) : " "; + $z_options .= " ($z_id)" if $DEBUG; + + print qq(<tr>); + + if ($z_image != -1) + { + print qq(<td style="text-align: right; vertical-align: top; ) . + qq(border-right: 1px solid #bbb; ) . + qq( padding: 3px 3px 1px 3px; width: 96px;">); + print qq(<a href="$z_profile"><img src="$z_image" width="$z_width" border=1></a><br>); + print qq(<a href="$z_profile">$z_user</a>); + print qq(</td>); + } + else + { + print qq(<td style="text-align: right; vertical-align: top; ) . + qq(border-right: 1px solid #ccc; ) . + qq( padding: 3px 3px 1px 3px; width: 94px;"> ); + print qq(<small><a href="$z_profile">$z_user</a></small>); + print qq(</td>); + } + + print qq(<td class="subcomment c$z_r" style="vertical-align: top; ); + print qq(border-bottom: 1px solid #ccc; ) unless ($args->{lastpost}); + print qq(border-right: 1px solid #ccc; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px;">); + print qq(<table width="100%" border=0 cellpadding=0 cellspacing=3>); + print qq(<tr>); + print qq(<td colspan=2 align=left>$z_comment</td>); + print qq(</tr>); + print qq(<tr>); + print qq(<td align=left>$z_options</td>); + print qq(<td align=right><small>$z_date</small></td>); + print qq(</tr>); + print qq(</table>); + print qq(</td></tr>); + + return 1; + } + +sub display_comment_options + { + my ($args) = @_; + + my ($thread) = $args->{thread} || -1; + my ($keyword) = $args->{keyword} || -1; + my ($c) = $args->{comment} || -1; + + my $out = ""; + my $age = time - $c->{date}; + my $z_id = $c->{id}; + my $z_link = qq($BUCKY/comment/$z_id); + + if ($c->{username} eq $USER->{username} || $USER->{ulevel} == 3 || + (check_key($thread->{display}, "editable") && check_privacy($thread, $keyword))) + { + $out .= qq(<small>); + $out .= $age < 86400 ? + qq(<span class="lite"><a href="$z_link?c=edit">edit</a></span>) + : qq(<a href="$z_link?c=edit">edit</a>); + $out .= middot(); + $out .= qq(<a href="$z_link?c=delete">remove</a>); + $out .= middot(); + $out .= qq(<a href="$z_link?c=reply">reply</a>); + $out .= qq(</small>); + } + else + { + $out .= qq(<small><a href="$z_link?c=reply">reply</a></small>); + } + } + +1; |
