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 --- cgi-bin/details | 275 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 275 insertions(+) create mode 100755 cgi-bin/details (limited to 'cgi-bin/details') diff --git a/cgi-bin/details b/cgi-bin/details new file mode 100755 index 0000000..35b34c7 --- /dev/null +++ b/cgi-bin/details @@ -0,0 +1,275 @@ +#!/usr/bin/perl +######################################## +# details +######################################### + +use localbucky; + +$dbh = DBI->connect ($dsn); + +our ($USER, $lastlog) = checkin(); +our $loggedin = ($USER != -1); + +our ($t, $kw, $files, $comments) = details_init(); +details_run($t, $kw, $files, $comments); + +sub details_init + { + $input->{id} ||= $input->{object_from_uri} if defined($input->{object_from_uri}); + my $id = exists($input->{id}) ? $input->{id} : error("No such thread!"); + + my $t = get_thread($id); + error("No such post.") if ($t == -1); + my $kw = get_keyword($t->{keyword}); + + my $files = get_files($t->{id}); + my $comments = get_comments ($t->{id}); + + if ( ! check_privacy($t, $kw) ) # || check_participation($files, $comments) ) + #unless ( check_privacy($t, $kw) || check_participation($files, $comments) ) + { error("No such post!"); } + + # Reset NULL viewed + if ( ! $t->{viewed} ) + { $t->{viewed} = 0; } + + # Increment viewed for this thread + $t->{viewed}++; + # Update thread viewed count + update_thread_viewed( $t->{id}, $t->{viewed} ); + + return ($t, $kw, $files, $comments); + } + +sub details_run + { + my ($t, $kw, $files, $comments) = @_; + my $header_args = + { + title => $t->{title}, + sticky => $t->{keyword}, + color => get_color($t, $kw, $comments) +# participation => check_participation($files, $comments) + }; + + my $age = get_age($t->{lastmodified}); + $age .= " ago" unless $age eq "now"; + + $header_args->{subtitle} = + qq!posted by $t->{username} on ! . + verbosedate($t->{createdate}) . " · active " . $age . + qq! · $t->{viewed} view! . courtesy_s($t->{viewed}); + + if ($t->{username} eq $USER->{username} || check_op($kw) || $header_args->{participation} == 2 || $USER->{ulevel} == 3) + { + $header_args->{subtitle} .= qq! · !; + $header_args->{subtitle} .= qq!options!; + } +# else +# { +# $header_args->{subtitle} .= +# qq! · go to index!; +# } + + $header_args->{subtitle} .= qq! · !; + $header_args->{subtitle} .= qq!download\!!; + + my @participants = get_participants($t, $files, $comments); + + $header_args->{sidetitle} = details_participation(@participants) + if (@participants > 0); + $header_args->{sidesubtitle} = "see also: ".details_tags_box($t, $kw)."" + if (@{$t->{tags}}); + + header($header_args); + + # 20070903 - marc - new menu args calling style + my $menu_args; + $menu_args->{keywords} = $kw if $kw; + $menu_args->{ftp} = 1 if ($t->{files}+$t->{comments} + 1); + menu( $menu_args ); + + details_view($t, $kw, $comments, $files); + footer(); + } + + +############################## + +sub details_view + { + my ($t, $kw, $comments, $files) = @_; + my ($many_jpgs, $flagged) = find_jpeg_v2($files, $t->{flagged}); + if ($many_jpgs > 6) + { + print qq(
); + } + else + { + print qq(
); + } + + print qq("; + + print qq(
); + print qq(); + + if ($flagged != -1 && $many_jpgs > 1) + { + print qq(); + } + + sideshow_comments({ thread => $t, keyword => $kw, comments => $comments }); + print qq(); + print qq(
); + print_flagged_jpeg($flagged); + print qq(
); + reply_form($t->{id}, $t); + print qq(
); + + if ($flagged != -1 && $many_jpgs == 1) + { + print qq(
); + print_flagged_jpeg($flagged); + } + elsif ($many_jpgs > 1 || @$files > $many_jpgs) + { + print qq(); + } + else + { + print qq(); + } + if ($many_jpgs > 1) + { + if ($many_jpgs < 6) # && @$files == $many_jpgs) + { image_column($files, $flagged, $many_jpgs); } + else + { image_gallery($files, $flagged, $many_jpgs); } + } + if (@$files > $many_jpgs) + { + if (find_mp3($files)) + { + my $z_playlist = "/cgi-bin/bucky/playlist/$t->{id}"; + my $z_autoplay = "false"; + if (check_key($USER->{boxes}, "autoplay")) + { $z_autoplay = "true"; } + print <<__PLAYLIST__; +
LOADING MP3 PLAYER ...
+ + + +__PLAYLIST__ + } + if (check_key($t->{display}, "nfl")) # no file list + { ; } + elsif (check_key($t->{display}, "ffl")) # full file list + { + file_list($files, 0, 1, 0); + } + else # "terse" file list + { + file_list($files, 0, 1, $many_jpgs); + } + } + if ($ZIP_BUTTON_ENABLED && @$files > 4) + { + zip_this_button($t); + } + + details_keywords_box($t, $kw); + print "
); + } + +sub find_mp3 + { + my ($q) = @_; + foreach my $f (@$q) + { return 1 if $f->{filename} =~ /mp3$/i; } + return 0; + } + +sub details_tags_box + { + my ($t, $kw) = @_; +# my $tags = $t->{tags}; + return tags_stringify_links ( $t ); +# return join(", ", @$tags); + } + +sub details_participation + { + my (@participants) = @_; + my $pcount = 0; + my $out; + + foreach my $p (@participants) + { + $pcount++; + next if ($pcount > 6); + my $image = get_profile_image($p, $AVATAR_MED_PREFIX); + if ($image != -1) + { + $out .= qq( ); + $out .= qq(); + $out .= qq(); + $out .= qq(); + } + } + if ($pcount > 6) + { + $out .= " + ".($pcount - 4); + $out .= " $BUCKY_DUDER_NOUN"; + $out .= courtesy_s($pcount - 4); + $out .= ""; + } + return $out; + } + +# get list of unique users posting in thread +sub get_participants + { + my ($t, $files, $comments) = @_; + my %participant; + $participant{$t->{username}} = 1000; + + foreach my $f (@$files) + { $participant{$f->{username}}++; } + foreach my $c (keys %$comments) + { $participant{$comments->{$c}->{username}}++; } + + return (sort { $participant{$b} <=> $participant{$a} } (keys(%participant))); + } + +sub details_keywords_box + { + my ($t, $kw) = @_; + if (defined($t->{keyword}) && !check_key($t->{display}, "kws")) + { + my $t = get_threads_by_keyword($t->{keyword}); + if ($t != -1) + { + print qq(); + thread_box({ threads => $t, kw => $kw }); + print qq(
); + } + } + } + +############################## + +print "Details: " . &report_time() . "\n" if $timer; -- cgit v1.2.3-70-g09d2