]> git.sesse.net Git - pr0n/blobdiff - perl/Sesse/pr0n/Common.pm
Fix up infobox separators.
[pr0n] / perl / Sesse / pr0n / Common.pm
index d175979b1cf0b888fd3bf187659d255704af2dd8..28a1989b1f5d8f8ef2dc04103b984249210c83af 100644 (file)
@@ -32,7 +32,7 @@ BEGIN {
                require Sesse::pr0n::Config_local;
        };
 
-       $VERSION     = "v3.02";
+       $VERSION     = "v3.10";
        @ISA         = qw(Exporter);
        @EXPORT      = qw(&error &dberror);
        %EXPORT_TAGS = qw();
@@ -212,17 +212,20 @@ sub get_disk_location {
 }
 
 sub get_cache_location {
-       my ($r, $id, $width, $height, $infobox, $dpr) = @_;
+       my ($id, $width, $height) = @_;
         my $dir = POSIX::floor($id / 256);
 
-       if ($infobox) {
-               if ($dpr == 1) {
-                       return $Sesse::pr0n::Config::image_base . "cache/$dir/$id-$width-$height-box.png";
-               } else {
-                       return $Sesse::pr0n::Config::image_base . "cache/$dir/$id-$width-$height-box\@$dpr.png";
-               }
+       return $Sesse::pr0n::Config::image_base . "cache/$dir/$id-$width-$height-nobox.jpg";
+}
+
+sub get_infobox_cache_location {
+       my ($id, $width, $height, $dpr) = @_;
+        my $dir = POSIX::floor($id / 256);
+
+       if ($dpr == 1) {
+               return $Sesse::pr0n::Config::image_base . "cache/$dir/$id-$width-$height-box.png";
        } else {
-               return $Sesse::pr0n::Config::image_base . "cache/$dir/$id-$width-$height-nobox.jpg";
+               return $Sesse::pr0n::Config::image_base . "cache/$dir/$id-$width-$height-box\@$dpr.png";
        }
 }
 
@@ -569,7 +572,7 @@ sub read_original_image {
 }
 
 sub ensure_cached {
-       my ($r, $filename, $id, $dbwidth, $dbheight, $dpr, $xres, $yres, @otherres) = @_;
+       my ($r, $filename, $id, $dbwidth, $dbheight, $xres, $yres, @otherres) = @_;
 
        my ($new_dbwidth, $new_dbheight);
 
@@ -578,7 +581,7 @@ sub ensure_cached {
                return ($fname, undef);
        }
 
-       my $cachename = get_cache_location($r, $id, $xres, $yres, $infobox, $dpr);
+       my $cachename = get_cache_location($id, $xres, $yres);
        my $err;
        if (! -r $cachename or (-M $cachename > -M $fname)) {
                # If we are in overload mode (aka Slashdot mode), refuse to generate
@@ -593,7 +596,7 @@ sub ensure_cached {
 
                while (defined($xres) && defined($yres)) {
                        my ($nxres, $nyres) = (shift @otherres, shift @otherres);
-                       my $cachename = get_cache_location($r, $id, $xres, $yres, $infobox, $dpr);
+                       my $cachename = get_cache_location($id, $xres, $yres);
                        
                        my $cimg;
                        if (defined($nxres) && defined($nyres)) {
@@ -662,12 +665,12 @@ sub ensure_cached {
 }
 
 sub ensure_infobox_cached {
-       my ($r, $filename, $id, $dbwidth, $dbheight, $infobox, $dpr, $xres, $yres) = @_;
+       my ($r, $filename, $id, $dbwidth, $dbheight, $dpr, $xres, $yres) = @_;
 
        my ($new_dbwidth, $new_dbheight);
 
        my $fname = get_disk_location($r, $id);
-       my $cachename = get_cache_location($r, $id, $xres, $yres, 1, $dpr);
+       my $cachename = get_infobox_cache_location($id, $xres, $yres, $dpr);
        my $err;
        if (! -r $cachename or (-M $cachename > -M $fname)) {
                # If we are in overload mode (aka Slashdot mode), refuse to generate
@@ -719,11 +722,10 @@ sub ensure_infobox_cached {
 
                $err = $img->write(filename => $cachename, quality => 90, depth => 8);
                log_info($r, "New infobox cache: $width x $height for $id.jpg");
-
-               return ($cachename, 'image/png');
        }
-}
 
+       return ($cachename, 'image/png');
+}
 
 sub get_mimetype_from_filename {
        my $filename = shift;
@@ -745,7 +747,7 @@ sub make_infobox {
                $info->{'ExposureProgram'} =~ /shutter\b.*\bpriority/i);
        my $manual_aperture = (defined($info->{'ExposureProgram'}) &&
                $info->{'ExposureProgram'} =~ /aperture\b.*\bpriority/i);
-       if ($info->{'ExposureProgram'} =~ /manual/i) {
+       if (defined($info->{'ExposureProgram'}) && $info->{'ExposureProgram'} =~ /manual/i) {
                $manual_shutter = 1;
                $manual_aperture = 1;
        }
@@ -815,13 +817,13 @@ sub make_infobox {
                $model =~ s/^\s+//;
                $model =~ s/\s+$//;
 
-               push @parts, [ ' - ', 0 ] if (scalar @parts > 0);
+               push @parts, [ "\x{00A0}\x{2013}\x{00A0}", 0 ] if (scalar @parts > 0);
                push @parts, [ $model, 0 ];
        }
        
        # classic fields
        if (scalar @classic_fields > 0) {
-               push @parts, [ ' - ', 0 ] if (scalar @parts > 0);
+               push @parts, [ "\x{00A0}\x{2013}\x{00A0}", 0 ] if (scalar @parts > 0);
 
                my $first_elem = 1;
                for my $field (@classic_fields) {
@@ -836,14 +838,14 @@ sub make_infobox {
                    $info->{'Flash'} =~ /no flash/i ||
                    $info->{'Flash'} =~ /not fired/i ||
                    $info->{'Flash'} =~ /Off/)  {
-                       push @parts, [ ' - ', 0 ] if (scalar @parts > 0);
+                       push @parts, [ "\x{00A0}\x{2013}\x{00A0}", 0 ] if (scalar @parts > 0);
                        push @parts, [ "No flash", 0 ];
                } elsif ($info->{'Flash'} =~ /fired/i ||
                         $info->{'Flash'} =~ /On/) {
-                       push @parts, [ ' - ', 0 ] if (scalar @parts > 0);
+                       push @parts, [ "\x{00A0}\x{2013}\x{00A0}", 0 ] if (scalar @parts > 0);
                        push @parts, [ "Flash", 0 ];
                } else {
-                       push @parts, [ ' - ', 0 ] if (scalar @parts > 0);
+                       push @parts, [ "\x{00A0}\x{2013}\x{00A0}", 0 ] if (scalar @parts > 0);
                        push @parts, [ $info->{'Flash'}, 0 ];
                }
        }