Changeset 33

Show
Ignore:
Timestamp:
02/16/07 22:31:28 (2 years ago)
Author:
simon
Message:

Mess around with things to make it easier to support multiple file
uploads, quarantining and multiple file types. References #8, #10, #14.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Memories/Photo.pm

    r32 r33  
    11package Memories::Photo; 
     2use File::Basename; 
     3use File::Copy; 
     4use Archive::Any; 
    25use strict; 
    36use Carp qw(cluck confess); 
     
    4447sub do_upload :Exported { 
    4548    my ($self, $r) = @_; 
    46     my %upload = $r->upload("photo"); 
    47  
     49    my $upload = $r->{ar}->upload("photo"); 
     50    # Check $self->type 
     51    my @photos = $self->upload_jpeg($upload->tempname, ($r->params->{title}||basename($upload->filename)), $r->params->{tags}, $r); 
     52    my @quarantined = grep { !$_->tags } @photos; 
     53    # Set it up to go again 
     54    $r->objects(\@photos); 
     55    $r->template("view"); 
     56    $r->message("Thanks for the upload!");  
     57    # Deal with the quarantined 
     58
     59 
     60sub upload_jpeg { 
     61    my ($self, $filename, $title, $tags, $r) = @_; 
     62    my $quarantine; 
    4863    my $photo = $self->create({ 
    4964        uploader => $r->user, 
    5065        uploaded => Time::Piece->new(), 
    51         title => $r->params->{title}
     66        title => $title
    5267        hit_count => 0, 
    5368        rating => 0, 
    54         rated => 0, # Oh, the potential for divide by zero errors... 
     69        rated => 0, 
    5570    }); 
    56  
    57     # Dump content 
    58     if (!open OUT, ">". $photo->path("file")) { 
    59         die "Can't write ".$photo->path("file")." because $!"; 
    60     } 
    61     # XXX Check it's a JPEG, etc. 
    62     # XXX Unzip ZIP file 
    63     print OUT $upload{content}; 
    64     close OUT; 
     71    copy($filename, $photo->path("file")); 
    6572    my ($x, $y) = dim(image_info($photo->path)); 
    6673    $photo->x($x); $photo->y($y); 
     
    6976    $photo->unrotate();  
    7077    if (!$photo->title){  
    71         $photo->title($photo->title_exif || $upload{filename}); 
     78        $photo->title($photo->title_exif || basename($filename)); 
    7279    } 
    7380 
    7481    $photo->make_thumb; 
    75     $r->{params}{tags} ||= join " ", map { qq{"$_"} } $photo->tags_exif; 
    76     $photo->add_tags($r->{params}{tags}); 
     82    $tags ||= join " ", map { qq{"$_"} } $photo->tags_exif; 
     83    $photo->add_tags($tags); 
    7784    $photo->add_to_imageseek_library; 
    7885    Memories->zap_cache(); 
     
    8188    my $tag = "date:".$photo->shot->ymd; 
    8289    $photo->add_to_system_tags({tag => Memories::SystemTag->find_or_create({name =>$tag}) }); 
    83  
    84     # Set it up to go again 
    85     $r->objects([$photo]); 
    86     $r->template("view"); 
    87     $r->message("Thanks for the upload! ". 
    88         ($r->{params}{tags} ? ""  
    89         : "Don't forget to <a href=\"?".$r->config->uri_base."photo/view/".$photo->id."?active=tagedit\">tag your photo</a>" 
    90         ) 
    91     );  
     90    return $photo; 
    9291} 
    9392