]> git.decadent.org.uk Git - memories.git/blobdiff - Memories/Photo.pm
At least one of these changes is showstopper!
[memories.git] / Memories / Photo.pm
index 4945dd8fc719510f045da426022b9692882dc649..76375a576dd9bf26774836e36f37f8315da42404 100644 (file)
@@ -1,5 +1,5 @@
 package Memories::Photo;
-use Apache2::Upload;
+#use Apache2::Upload;
 use File::Basename;
 use File::Copy;
 use Archive::Any;
@@ -7,6 +7,7 @@ use File::Temp qw(tempdir tmpnam);
 use File::Path qw(rmtree);
 use File::Find;
 use File::MMagic;
+use Image::Size qw(imgsize);
 use strict;
 use Carp qw(cluck confess);
 use base qw(Memories::DBI Maypole::Model::CDBI::Plain);
@@ -64,7 +65,7 @@ sub do_upload :Exported {
     }
     $r->objects(\@photos);
     if (@photos == 0) { $r->template("upload"); return  }
-    if (@photos > 1) { $r->template("list") } 
+    if (@photos > 1) { $r->template_args->{title} = "This upload"; $r->template("paged") } 
     else { $r->template("view"); }
     $r->message("Thanks for the upload!"); 
 }
@@ -83,7 +84,7 @@ sub quarantine :Exported {
     }
     $r->{session}{quarantined} = join ",", sort keys %q;
     if (!$r->{session}{quarantined}) {
-        $r->template("list");
+        $r->template_args->{title} = "This upload"; $r->template("paged");
         $r->objects([ map { $self->retrieve($_) } @quarantined ]);
     } else {
         $r->objects([ map { $self->retrieve($_) } sort keys %q ]);
@@ -124,11 +125,11 @@ sub upload_raw {
     my ($self, $r, $filename, $offered_name) = @_;
     my $jpg = tmpnam().".jpg";
     system("dcraw -c $filename | convert - $jpg");
-    my $photo = $self->upload_jpeg($r, $jpg, $offered_name);
     $filename =~ /\.(.*)$/;
     my $format = $1;
-    $photo->format($format);
     # Put the file in place
+    my $photo = $self->upload_jpeg($r, $jpg, $offered_name);
+    $photo->format($format);
     copy($filename, 
          Memories->config->{data_store}."/".$photo->id.".".$format);
     return $photo;
@@ -148,7 +149,7 @@ sub upload_jpeg {
        warn "Couldn't copy photo to ".$photo->path("file").": $!";
         $photo->delete(); die;
     }
-    my ($x, $y) = dim(image_info($photo->path));
+    my ($x, $y, undef) = imgsize($photo->path);
     $photo->x($x); $photo->y($y);
 
     # Rotate?
@@ -164,7 +165,7 @@ sub upload_jpeg {
     Memories->zap_cache();
     # Add system tags here
     my $tag = "date:".$photo->shot->ymd;
-    $photo->add_to_system_tags({tag => Memories::SystemTag->find_or_create({name =>$tag}) });
+    $photo->add_to_system_tags({system_tag => Memories::SystemTag->find_or_create({name =>$tag}) });
     return $photo;
 }
 
@@ -178,7 +179,7 @@ sub add_rating :Exported {
     my ($self, $r) = @_;
     my $photo = $r->{objects}[0];
     my $delta = $r->{params}{rating};
-    if ($delta < 0 or $delta > 5) { return; } # Scammer
+    if ($delta <= 0 or $delta > 5) { return; } # Scammer
     # XXX Race
     $photo->rating($photo->rating() + $delta);
     $photo->rated($photo->rated() + 1);
@@ -210,6 +211,16 @@ sub comment :Exported {}
 sub tagedit :Exported {}
 sub similar :Exported {}
 sub sized :Exported {}
+sub delete :Exported {
+    my ($self, $r, $photo) = @_;
+    if ($r) { 
+    if ($photo and $photo->uploader == $r->user) {
+        $photo->delete;
+        $r->message("Photo deleted!");
+    }
+    $r->template("frontpage");
+    } else { $self->SUPER::delete() } 
+}
 
 use Class::DBI::Plugin::Pager;
 use Class::DBI::Plugin::AbstractCount;
@@ -232,14 +243,15 @@ sub view_paged_ordered {
 sub add_comment :Exported {
     my ($self, $r, $photo) = @_;
     $r->template("view");
+    if ($r->params->{content} =~ /\S/) {
     $r->objects->[0]->add_to_comments({
         name => $r->params->{name},
         content => $r->params->{content}
     });
+    }
 }
 
 use Cache::MemoryCache;
-use Image::Info qw(dim image_info);
 use Image::ExifTool;
 my $cache = new Cache::MemoryCache( { 'namespace' => 'MemoriesInfo' });
 
@@ -452,7 +464,7 @@ sub tags_exif {
         map { split /\s*,\s*/, $md{$_}}
         grep {$md{$_} and $md{$_} =~/[^ 0:]/}
         (qw(Keywords Subject City State Location Country Province-State), 
-        'Transmission Reference', 'Intellectual Genre', 
+        'Intellectual Genre', 
         'Country-Primary Location Name'
         );
     return keys %tags;