X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=perl%2FSesse%2Fpr0n%2FIndex.pm;h=260aa64a755b2557b87097806af9138be1777a8c;hb=ef088e4bb570c5f2d27b3c7ab356e63615dbbaa8;hp=88e0e49339311096ae02bc6ae7af355aa4957cea;hpb=c8fb633d012a9078990d0abc28cdd527d1362e4a;p=pr0n diff --git a/perl/Sesse/pr0n/Index.pm b/perl/Sesse/pr0n/Index.pm index 88e0e49..260aa64 100644 --- a/perl/Sesse/pr0n/Index.pm +++ b/perl/Sesse/pr0n/Index.pm @@ -11,10 +11,22 @@ sub handler { my $apr = Apache2::Request->new($r); my $dbh = Sesse::pr0n::Common::get_dbh(); - # Find the event - $r->uri =~ m#^/([a-zA-Z0-9-]+)/?$# - or error($r, "Could not extract event"); - my $event = $1; + my ($event, $abspath, $datesort); + if ($r->uri =~ /^\/\+all\/?/) { + $event = '+all'; + $abspath = 1; + + # augh, this needs 8.3, so we'll have to fiddle around a bit instead + # $datesort = 'DESC NULLS LAST'; + $datesort = 'DESC'; + } else { + # Find the event + $r->uri =~ /^\/([a-zA-Z0-9-]+)\/?$/ + or error($r, "Could not extract event"); + $event = $1; + $abspath = 0; + $datesort = 'ASC'; + } # Fix common error: pr0n.sesse.net/event -> pr0n.sesse.net/event/ if ($r->uri !~ m#/$#) { @@ -37,17 +49,26 @@ sub handler { xres => -1, yres => -1, start => 1, - num => -1, + num => 100, all => 1, infobox => 1, rot => 0, sel => 0, fullscreen => 0, + model => undef, + lens => undef ); + my $where; + if ($event eq '+all') { + $where = ''; + } else { + $where = ' AND event=' . $dbh->quote($event); + } + # Any NEF files => default to processing - my $ref = $dbh->selectrow_hashref('SELECT * FROM images WHERE event=? AND vhost=? AND LOWER(filename) LIKE \'%.nef\' LIMIT 1', - undef, $event, $r->get_server_name) + my $ref = $dbh->selectrow_hashref("SELECT * FROM images WHERE vhost=? $where AND LOWER(filename) LIKE '%.nef' LIMIT 1", + undef, $r->get_server_name) and $defsettings{'xres'} = $defsettings{'yres'} = undef; # Reduce the front page load when in overload mode. @@ -57,7 +78,7 @@ sub handler { my %settings = %defsettings; - for my $s qw(thumbxres thumbyres xres yres start num all infobox rot sel fullscreen) { + for my $s qw(thumbxres thumbyres xres yres start num all infobox rot sel fullscreen model lens) { my $val = $apr->param($s); if (defined($val) && $val =~ /^(\d+)$/) { $settings{$s} = $val; @@ -65,6 +86,10 @@ sub handler { if (($s eq "num" || $s eq "xres" || $s eq "yres") && defined($val) && $val == -1) { $settings{$s} = $val; } + if ($s eq "model" || $s eq "lens") { + $val =~ s/_/ /g; + $settings{$s} = $val; + } } my $thumbxres = $settings{'thumbxres'}; @@ -77,18 +102,55 @@ sub handler { my $infobox = $settings{'infobox'} ? '' : 'nobox/'; my $rot = $settings{'rot'}; my $sel = $settings{'sel'}; + my $model = $settings{'model'}; + my $lens = $settings{'lens'}; + + # Construct SQL for this filter + if ($all == 0) { + $where .= ' AND selected=\'t\''; + } + if (defined($model) && defined($lens)) { + my $mq = $dbh->quote($model); + my $lq = $dbh->quote($lens); + + if ($model eq '') { + # no defined model + $where .= " AND id NOT IN ( SELECT image FROM exif_info WHERE tag='Model' AND TRIM(value)<>'' )"; + } else { + $where .= " AND id IN ( SELECT image FROM exif_info WHERE tag='Model' AND TRIM(value)=$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 (tag='Lens' OR tag='LensSpec') AND TRIM(value)<>'' )"; + } else { + $where .= " AND id IN ( SELECT image FROM exif_info WHERE (tag='Lens' OR tag='LensSpec') AND TRIM(value)=$lq )"; + } + } if (defined($num) && $num == -1) { $num = undef; } - $ref = $dbh->selectrow_hashref('SELECT name,date,EXTRACT(EPOCH FROM last_update) AS last_update FROM events WHERE event=? AND vhost=?', - undef, $event, $r->get_server_name) - or error($r, "Could not find event $event", 404, "File not found"); + my ($date, $name); + + if ($event eq '+all') { + $ref = $dbh->selectrow_hashref("SELECT EXTRACT(EPOCH FROM MAX(last_update)) AS last_update FROM events 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=?", + undef, $r->get_server_name, $event) + or error($r, "Could not find event $event", 404, "File not found"); - my $date = HTML::Entities::encode_entities(Encode::decode_utf8($ref->{'date'})); - my $name = HTML::Entities::encode_entities(Encode::decode_utf8($ref->{'name'})); - $r->set_last_modified($ref->{'last_update'}); + $date = HTML::Entities::encode_entities(Encode::decode_utf8($ref->{'date'})); + $name = HTML::Entities::encode_entities(Encode::decode_utf8($ref->{'name'})); + $r->set_last_modified($ref->{'last_update'}); + } # If the client can use cache, do so if ((my $rc = $r->meets_conditions) != Apache2::Const::OK) { @@ -96,16 +158,15 @@ sub handler { } # Count the number of selected images. - $ref = $dbh->selectrow_hashref("SELECT COUNT(*) AS num_selected FROM images WHERE event=? AND vhost=? AND selected=\'t\'", undef, $event, $r->get_server_name); + $ref = $dbh->selectrow_hashref("SELECT COUNT(*) AS num_selected FROM images WHERE vhost=? $where AND selected=\'t\'", undef, $r->get_server_name); my $num_selected = $ref->{'num_selected'}; # Find all images related to this event. - my $where = ($all == 0) ? ' AND selected=\'t\'' : ''; 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 event=? AND vhost=? $where ORDER BY (date - INTERVAL '6 hours')::date,takenby,date,filename $limit") + 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") or dberror($r, "prepare()"); - $q->execute($event, $r->get_server_name) + $q->execute($r->get_server_name) or dberror($r, "image enumeration"); # Print the page itself @@ -113,7 +174,7 @@ sub handler { $r->content_type("text/html; charset=utf-8"); Sesse::pr0n::Templates::print_template($r, "fullscreen-header", { title => "$name [$event]" }); while (my $ref = $q->fetchrow_hashref()) { - $r->print(" \"" . $infobox . $ref->{'filename'} . "\",\n"); + $r->print(" [ \"" . $ref->{'event'} . "\", \"" . $ref->{'filename'} . "\" ],\n"); } my %settings_no_fullscreen = %settings; @@ -127,14 +188,16 @@ sub handler { Sesse::pr0n::Templates::print_template($r, "fullscreen-footer", { vhost => $r->get_server_name, - event => $event, start => $settings{'start'} - 1, returnurl => $returnurl, sel => $settings{'sel'}, + infobox => $infobox }); } else { Sesse::pr0n::Common::header($r, "$name [$event]"); - Sesse::pr0n::Templates::print_template($r, "date", { date => $date }); + if (defined($date)) { + Sesse::pr0n::Templates::print_template($r, "date", { date => $date }); + } if (Sesse::pr0n::Overload::is_in_overload($r)) { Sesse::pr0n::Templates::print_template($r, "overloadmode"); @@ -146,59 +209,76 @@ sub handler { print_infobox($r, $event, \%settings, \%defsettings); print_selected($r, $event, \%settings, \%defsettings) if ($num_selected > 0); print_fullscreen($r, $event, \%settings, \%defsettings); - print_nextprev($r, $event, \%settings, \%defsettings); - - # Find the equipment used - my $eq = $dbh->prepare(" - SELECT - TRIM(model.value) AS model, - coalesce(TRIM(lens_spec.value), TRIM(lens.value)) AS lens, - COUNT(*) AS num - FROM ( SELECT * FROM images WHERE event=? AND vhost=? $where ORDER BY (date - INTERVAL '6 hours')::date,takenby,date,filename $limit ) i - LEFT JOIN exif_info model ON i.id=model.image - LEFT JOIN ( SELECT * FROM exif_info WHERE tag='Lens' ) lens ON i.id=lens.image - LEFT JOIN ( SELECT * FROM exif_info WHERE tag='LensSpec') lens_spec ON i.id=lens_spec.image - WHERE model.tag='Model' - GROUP BY 1,2 - ORDER BY 1,2") - or die "Couldn't prepare to find equipment: $!"; - $eq->execute($event, $r->get_server_name) - or die "Couldn't find equipment: $!"; - - my @equipment = (); - my %cameras_seen = (); - while (my $ref = $eq->fetchrow_hashref) { - if (!defined($ref->{'lens'}) && exists($cameras_seen{$ref->{'model'}})) { - # - # Some compact cameras seem to add lens info sometimes and not at other - # times; if we have seen a camera with at least one specific lens earlier, - # just combine entries without a lens with the previous one. - # - $equipment[$#equipment]->{'num'} += $ref->{'num'}; - next; + print_nextprev($r, $event, $where, \%settings, \%defsettings); + + 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, + 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 tag='Lens' ) lens ON i.id=lens.image + LEFT JOIN ( SELECT * FROM exif_info WHERE tag='LensSpec') lens_spec ON i.id=lens_spec.image + WHERE model.tag='Model' + GROUP BY 1,2 + ORDER BY 1,2") + or die "Couldn't prepare to find equipment: $!"; + $eq->execute($r->get_server_name) + or die "Couldn't find equipment: $!"; + + my @equipment = (); + my %cameras_seen = (); + while (my $ref = $eq->fetchrow_hashref) { + if (!defined($ref->{'lens'}) && exists($cameras_seen{$ref->{'model'}})) { + # + # Some compact cameras seem to add lens info sometimes and not at other + # times; if we have seen a camera with at least one specific lens earlier, + # just combine entries without a lens with the previous one. + # + $equipment[$#equipment]->{'num'} += $ref->{'num'}; + next; + } + push @equipment, $ref; + $cameras_seen{$ref->{'model'}} = 1; } - push @equipment, $ref; - $cameras_seen{$ref->{'model'}} = 1; - } - $eq->finish; - - if (scalar @equipment > 0) { - Sesse::pr0n::Templates::print_template($r, "equipment-start"); - for my $e (@equipment) { - my $eqspec = $e->{'model'}; - $eqspec .= ', ' . $e->{'lens'} if (defined($e->{'lens'})); - - # This isn't correct for all languages. Fix if we ever need to care. :-) - if ($e->{'num'} == 1) { - Sesse::pr0n::Templates::print_template($r, "equipment-item-singular", { eqspec => $eqspec }); - } else { - Sesse::pr0n::Templates::print_template($r, "equipment-item", { eqspec => $eqspec, num => $e->{'num'} }); + $eq->finish; + + if (scalar @equipment > 0) { + Sesse::pr0n::Templates::print_template($r, "equipment-start"); + for my $e (@equipment) { + my $eqspec = $e->{'model'}; + $eqspec .= ', ' . $e->{'lens'} if (defined($e->{'lens'})); + $eqspec = HTML::Entities::encode_entities($eqspec); + + my %newsettings = %settings; + + my $action; + if (defined($model) && defined($lens)) { + chomp ($action = Sesse::pr0n::Templates::fetch_template($r, "unfilter")); + $newsettings{'model'} = undef; + $newsettings{'lens'} = undef; + } else { + chomp ($action = Sesse::pr0n::Templates::fetch_template($r, "filter")); + $newsettings{'model'} = $e->{'model'}; + $newsettings{'lens'} = defined($e->{'lens'}) ? $e->{'lens'} : ''; + } + + my $url = "/$event/" . Sesse::pr0n::Common::get_query_string(\%newsettings, \%defsettings); + + # This isn't correct for all languages. Fix if we ever need to care. :-) + if ($e->{'num'} == 1) { + Sesse::pr0n::Templates::print_template($r, "equipment-item-singular", { eqspec => $eqspec, filterurl => $url, action => $action }); + } else { + Sesse::pr0n::Templates::print_template($r, "equipment-item", { eqspec => $eqspec, num => $e->{'num'}, filterurl => $url, action => $action }); + } } + Sesse::pr0n::Templates::print_template($r, "equipment-end"); } - Sesse::pr0n::Templates::print_template($r, "equipment-end"); } - my $toclose = 0; my $lastupl = ""; my $img_num = (defined($start) && defined($num)) ? $start : 1; @@ -238,7 +318,12 @@ sub handler { $uri = "original/$infobox$filename"; } - $r->print("
\n");
+ my $prefix = "";
+ if ($abspath) {
+ $prefix = "/" . $ref->{'event'} . "/";
+ }
+
+ $r->print("
\n");
$r->print(" 90 {'id'} . "-90\" />\n");
$r->print(" 180 print("
\n");
+ my $prefix = "";
+ if ($abspath) {
+ $prefix = "/" . $ref->{'event'} . "/";
+ }
+
+ $r->print("
\n");
++$img_num;
}
$r->print("