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/comments.pm | 287 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 287 insertions(+) create mode 100644 lib/comments.pm (limited to 'lib/comments.pm') 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
"; + $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(); + print qq();# 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(); + print qq(\n); + print qq(\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(
\n\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 =~ /
/ ? undef : "

"; + 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(); + +print qq(); + if ($z_image != -1) + { +print qq(); + } +print qq(); + + print qq(); + print qq(">); + print qq(); + print qq(); +# print qq(); + print qq(); + print qq(); + print qq(
$z_comment
$z_age 
$z_comment
); + print qq(); + +# print qq(); +# print qq($z_user
$z_age
); +## print qq($z_user); +# print qq(); +## print qq(); +## print qq($z_age); +## print qq(); +# print qq(); + } + else + { + my $z_width = $AVATAR_BIG_WIDTH; + my $z_image = get_profile_image($c->{username}, $AVATAR_BIG_PREFIX); + print qq(); + print qq(); + if ($z_image != -1) + { print qq(); } + print qq($z_user); + print qq(); + print qq(); + print qq(); + print qq(); + print qq(); + print qq(); + print qq(); + print qq(); + print qq(); + print qq(); + print qq(
$z_comment$z_br
$z_options$z_date
); + print qq(); + } + + 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(); + + if ($z_image != -1) + { + print qq(); + print qq(
); + print qq($z_user); + print qq(); + } + else + { + print qq( ); + print qq($z_user); + print qq(); + } + + print qq(); + print qq(); + print qq(); + print qq(); + print qq(); + print qq(); + print qq(); + print qq(); + print qq(); + print qq(
$z_comment
$z_options$z_date
); + print qq(); + + 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(); + $out .= $age < 86400 ? + qq(edit) + : qq(edit); + $out .= middot(); + $out .= qq(remove); + $out .= middot(); + $out .= qq(reply); + $out .= qq(); + } + else + { + $out .= qq(reply); + } + } + +1; -- cgit v1.2.3-70-g09d2