X-Git-Url: https://git.sesse.net/?p=pr0n;a=blobdiff_plain;f=perl%2FSesse%2Fpr0n%2FIndex.pm;h=22d233b1d26276cfe0e3ae94eb408a13af79b21b;hp=30794557e868b2d4de43aa1b0927f63bd61fba06;hb=060aaacf0d15a03ed7287cf81169f630a1a1f95b;hpb=29546c334313d9ade7fd708b04f86c567696d471 diff --git a/perl/Sesse/pr0n/Index.pm b/perl/Sesse/pr0n/Index.pm index 3079455..22d233b 100644 --- a/perl/Sesse/pr0n/Index.pm +++ b/perl/Sesse/pr0n/Index.pm @@ -17,15 +17,13 @@ sub handler { $abspath = 1; $tag = undef; - # augh, this needs 8.3, so we'll have to fiddle around a bit instead - # $datesort = 'DESC NULLS LAST'; - $datesort = 'DESC'; + $datesort = 'DESC NULLS LAST'; } elsif ($r->uri =~ /^\/\+tags\/([a-zA-Z0-9-]+)\/?$/) { $tag = $1; $event = "+tags/$tag"; $abspath = 1; - $datesort = 'DESC'; + $datesort = 'DESC NULLS LAST'; } else { # Find the event $r->uri =~ /^\/([a-zA-Z0-9-]+)\/?$/ @@ -33,7 +31,7 @@ sub handler { $event = $1; $abspath = 0; $tag = undef; - $datesort = 'ASC'; + $datesort = 'ASC NULLS LAST'; } # Fix common error: pr0n.sesse.net/event -> pr0n.sesse.net/event/ @@ -79,7 +77,7 @@ sub handler { } # Any NEF files => default to processing - my $ref = $dbh->selectrow_hashref("SELECT * FROM images WHERE vhost=? $where AND LOWER(filename) LIKE '%.nef' LIMIT 1", + my $ref = $dbh->selectrow_hashref("SELECT * FROM images WHERE vhost=? $where AND ( LOWER(filename) LIKE '%.nef' OR LOWER(filename) LIKE '%.cr2' ) LIMIT 1", undef, $r->get_server_name) and $defsettings{'xres'} = $defsettings{'yres'} = undef; @@ -90,15 +88,18 @@ sub handler { my %settings = %defsettings; - for my $s qw(thumbxres thumbyres xres yres start num all infobox rot sel fullscreen model lens author) { + for my $s (qw(thumbxres thumbyres xres yres start num all infobox rot sel fullscreen model lens author)) { my $val = $apr->param($s); if (defined($val) && $val =~ /^(\d+)$/) { $settings{$s} = $val; } - if (($s eq "num" || $s eq "xres" || $s eq "yres") && defined($val) && $val == -1) { + if ($s eq "num" && defined($val) && $val == -1) { $settings{$s} = $val; } - if ($s eq "model" || $s eq "lens" || $s eq "author") { + if (($s eq "xres" || $s eq "yres") && defined($val) && ($val == -1 || $val == -2)) { + $settings{$s} = $val; + } + if (($s eq "model" || $s eq "lens" || $s eq "author") && defined($val)) { $settings{$s} = Sesse::pr0n::Common::pretty_unescape($val); } } @@ -127,17 +128,16 @@ sub handler { if ($model eq '') { # no defined model - $where .= " AND id NOT IN ( SELECT image FROM exif_info WHERE key='Model' AND TRIM(value)<>'' )"; + $where .= " AND model IS NULL"; } else { - $where .= " AND id IN ( SELECT image FROM exif_info WHERE key='Model' AND TRIM(value)=$mq )"; + $where .= " AND model=$mq"; } - # This doesn't match 1:1 if there's both lens and lensspec, but it should be OK in practice if ($lens eq '') { # no defined lens - $where .= " AND id NOT IN ( SELECT image FROM exif_info WHERE (key='Lens' OR key='LensSpec') AND TRIM(value)<>'' )"; + $where .= " AND lens IS NULL"; } else { - $where .= " AND id IN ( SELECT image FROM exif_info WHERE (key='Lens' OR key='LensSpec') AND TRIM(value)=$lq )"; + $where .= " AND lens=$lq"; } } if (defined($author)) { @@ -153,14 +153,14 @@ sub handler { my ($date, $name); if ($event eq '+all' || defined($tag)) { - $ref = $dbh->selectrow_hashref("SELECT EXTRACT(EPOCH FROM MAX(last_update)) AS last_update FROM events WHERE vhost=?", + $ref = $dbh->selectrow_hashref("SELECT EXTRACT(EPOCH FROM MAX(last_update)) AS last_update FROM last_picture_cache WHERE vhost=?", undef, $r->get_server_name) or error($r, "Could not list events", 404, "File not found"); $date = undef; $name = Sesse::pr0n::Templates::fetch_template($r, 'all-event-title'); $r->set_last_modified($ref->{'last_update'}); } else { - $ref = $dbh->selectrow_hashref("SELECT name,date,EXTRACT(EPOCH FROM last_update) AS last_update FROM events WHERE vhost=? AND event=?", + $ref = $dbh->selectrow_hashref("SELECT name,date,EXTRACT(EPOCH FROM last_update) AS last_update FROM events NATURAL JOIN last_picture_cache WHERE vhost=? AND event=?", undef, $r->get_server_name, $event) or error($r, "Could not find event $event", 404, "File not found"); @@ -181,7 +181,7 @@ sub handler { # Find all images related to this event. my $limit = (defined($start) && defined($num) && !$settings{'fullscreen'}) ? (" LIMIT $num OFFSET " . ($start-1)) : ""; - my $q = $dbh->prepare("SELECT *, (date - INTERVAL '6 hours')::date AS day FROM images WHERE vhost=? $where ORDER BY COALESCE((date - INTERVAL '6 hours')::date, '1970-01-01') $datesort,takenby,date,filename $limit") + my $q = $dbh->prepare("SELECT *, (date - INTERVAL '6 hours')::date AS day FROM images WHERE vhost=? $where ORDER BY (date - INTERVAL '6 hours')::date $datesort,takenby,date,filename $limit") or dberror($r, "prepare()"); $q->execute($r->get_server_name) or dberror($r, "image enumeration"); @@ -199,13 +199,15 @@ sub handler { my @files = (); while (my $ref = $q->fetchrow_hashref()) { - push @files, [ $ref->{'event'}, $ref->{'filename'} ]; + my $width = defined($ref->{'width'}) ? $ref->{'width'} : -1; + my $height = defined($ref->{'height'}) ? $ref->{'height'} : -1; + push @files, [ $ref->{'event'}, $ref->{'filename'}, $width, $height ]; } for my $i (0..$#files) { - $r->print(" [ \"" . $files[$i]->[0] . "\", \"" . $files[$i]->[1] . "\" ]"); - $r->print(",") unless ($i == $#files); - $r->print("\n"); + my $line = sprintf " [ \"%s\", \"%s\", %d, %d ]", @{$files[$i]}; + $line .= "," unless ($i == $#files); + $r->print($line . "\n"); } my %settings_no_fullscreen = %settings; @@ -213,14 +215,14 @@ sub handler { my $returnurl = "http://" . $r->get_server_name . "/" . $event . "/" . Sesse::pr0n::Common::get_query_string(\%settings_no_fullscreen, \%defsettings); - + # *whistle* $returnurl =~ s/&/&/g; Sesse::pr0n::Templates::print_template($r, "fullscreen-footer", { vhost => $r->get_server_name, - start => $settings{'start'} - 1, returnurl => $returnurl, + start => $settings{'start'} - 1, sel => $settings{'sel'}, infobox => $infobox }); @@ -250,15 +252,12 @@ sub handler { if (1 || $event ne '+all') { # Find the equipment used my $eq = $dbh->prepare(" - SELECT - TRIM(model.value) AS model, - coalesce(TRIM(lens_spec.value), TRIM(lens.value)) AS lens, + SELECT + model, + lens, COUNT(*) AS num - FROM ( SELECT * FROM images WHERE vhost=? $where ) i - LEFT JOIN exif_info model ON i.id=model.image - LEFT JOIN ( SELECT * FROM exif_info WHERE key='Lens' ) lens ON i.id=lens.image - LEFT JOIN ( SELECT * FROM exif_info WHERE key='LensSpec') lens_spec ON i.id=lens_spec.image - WHERE model.key='Model' + FROM images + WHERE vhost=? $where GROUP BY 1,2 ORDER BY 1,2") or die "Couldn't prepare to find equipment: $!"; @@ -366,7 +365,7 @@ sub handler { } } - if ($ref->{'width'} != -1 && $ref->{'height'} != -1) { + if (defined($ref->{'width'}) && defined($ref->{'height'})) { my $width = $ref->{'width'}; my $height = $ref->{'height'}; @@ -376,7 +375,7 @@ sub handler { my $filename = $ref->{'filename'}; my $uri = $infobox . $filename; - if (defined($xres) && defined($yres) && $xres != -1) { + if (defined($xres) && defined($yres) && $xres != -1 && $xres != -2) { $uri = "${xres}x$yres/$infobox$filename"; } elsif (defined($xres) && $xres == -1) { $uri = "original/$infobox$filename"; @@ -480,10 +479,10 @@ sub print_thumbsize { } sub print_viewres { my ($r, $event, $settings, $defsettings) = @_; - my @alternatives = qw(320x256 512x384 640x480 800x600 1024x768 1280x960 1400x1050 1600x1200); + my @alternatives = qw(320x256 512x384 640x480 800x600 1024x768 1152x864 1280x960 1400x1050 1600x1200 1920x1440 2048x1536 2304x1728); chomp (my $unlimited = Sesse::pr0n::Templates::fetch_template($r, 'viewres-unlimited')); chomp (my $original = Sesse::pr0n::Templates::fetch_template($r, 'viewres-original')); - push @alternatives, [ $unlimited, undef, undef ]; + push @alternatives, [ $unlimited, -2, -2 ]; push @alternatives, [ $original, -1, -1 ]; print_changes($r, $event, 'viewres', $settings, $defsettings,