Changeset 38
- Timestamp:
- 02/24/07 20:08:09 (2 years ago)
- Files:
-
- trunk/Memories/Photo.pm (modified) (8 diffs)
- trunk/templates/custom/list (modified) (1 diff)
- trunk/templates/photo/upload (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Memories/Photo.pm
r37 r38 2 2 use File::Basename; 3 3 use File::Copy; 4 use Archive::Any; 5 use File::Temp qw(tempdir); 6 use File::Path qw(rmtree); 7 use File::Find; 8 use File::MMagic; 4 9 use strict; 5 10 use Carp qw(cluck confess); … … 48 53 my $upload = $r->{ar}->upload("photo"); 49 54 # Check $self->type 50 my @photos = ($self->upload_ jpeg($upload->tempname, ($r->params->{title}||basename($upload->filename)), $r->params->{tags}, $r));55 my @photos = ($self->upload_file($r, $upload->tempname, $upload->filename)); 51 56 my @quarantined = grep { !$_->tags } @photos; 52 warn "Quarantined these photos: ".join(",", map {$_->id} @quarantined);53 57 # Set it up to go again 54 58 if (@quarantined) { 55 59 $r->{session}{quarantined} = join ",", sort map { $_->id} @quarantined; 56 warn "Setting quarantineined to: ".( join ",", sort map { $_->id} @quarantined);57 60 $r->objects(\@quarantined); 58 61 $r->template("quarantine"); … … 60 63 } 61 64 $r->objects(\@photos); 65 if (@photos == 0) { $r->template("upload"); return } 62 66 if (@photos > 1) { $r->template("list") } 63 67 else { $r->template("view"); } … … 69 73 my @quarantined = split /,/, $r->{session}{quarantined}; 70 74 my %q = map { $_ => 1 } @quarantined; 71 warn "Before we had these quarantined: @{[ keys %q ]}";72 75 for (map /(\d+)/,grep /tags\d+/, keys %{$r->{params}}) { 73 76 my $tags = $r->{params}{"tags$_"}; 74 warn "Got tags for $_: <$tags>";75 77 next unless $tags; 76 78 if (my $photo = $self->retrieve($_)) { … … 80 82 } 81 83 $r->{session}{quarantined} = join ",", sort keys %q; 82 warn "After, we have these quarantined: @{[ keys %q ]}";83 warn "And we set session to $r->{session}{quarantined}";84 84 if (!$r->{session}{quarantined}) { 85 85 $r->template("list"); … … 90 90 } 91 91 92 sub upload_file { 93 my ($self, $r, $filename, $offered_name) = @_; 94 my $mm = File::MMagic->new; 95 my $res = $mm->checktype_filename($filename); 96 warn "$filename is a $res\n"; 97 if ($res =~ m{/x-zip} or $offered_name =~ /t(ar\.)?gz/) { 98 return $self->upload_archive($r, $filename); 99 } elsif ($res =~ m{image/jpeg}) { 100 return $self->upload_jpeg($r, $filename, $offered_name); 101 } else { 102 $r->message(basename($offered_name).": I can't handle $res files yet"); 103 return (); 104 } 105 } 106 107 sub upload_archive { 108 my ($self, $r, $filename, $tags) = @_; 109 $r->{params}{title} = ""; # Kill that dead. 110 my $archive = Archive::Any->new($filename); 111 my $dir = tempdir(); 112 $archive->extract($dir); 113 my @results; 114 find({ wanted => sub { return unless -f $_; 115 push @results, $self->upload_file($r, $_, $_) }, 116 no_chdir => 1}, $dir); 117 rmtree($dir); 118 return @results; 119 } 120 92 121 sub upload_jpeg { 93 my ($self, $ filename, $title, $tags, $r) = @_;122 my ($self, $r, $filename, $offered_name) = @_; 94 123 my $photo = $self->create({ 95 124 uploader => $r->user, 96 125 uploaded => Time::Piece->new(), 97 title => $title,126 title => ($r->{params}{title} || basename($offered_name)), 98 127 hit_count => 0, 99 128 rating => 0, … … 113 142 114 143 $photo->make_thumb; 115 $tags ||=join " ", map { qq{"$_"} } $photo->tags_exif;144 my $tags = $r->{params}{tags}.join " ", map { qq{"$_"} } $photo->tags_exif; 116 145 $photo->add_tags($tags); 117 146 $photo->add_to_imageseek_library; … … 293 322 if (!$resized) { cluck "Asked for crazy size $size"; return; } 294 323 if ($resized eq "full") { return $self->path("url") } 324 warn "Looking for path ".$self->path(file => $resized); 295 325 $self->scale($resized) 296 326 unless -e $self->path( file => $resized ); trunk/templates/custom/list
r2 r38 8 8 [% FOR object = minilist %] 9 9 <td> 10 <a href="[%base%]/ object/view/[%object.id%]">[% object %]<br/>10 <a href="[%base%]/[%object.moniker%]/view/[%object.id%]">[% object %]<br/> 11 11 <img src="[% object.photos.last.thumb_url |uri%]"></a><br/> 12 12 <span class="info"> trunk/templates/photo/upload
r35 r38 2 2 <h1> Upload a photo </h1> 3 3 <p> 4 This is where you can upload your photographs. At the moment, you must5 upload them one at a time; in the near future, you will be able to 6 upload a Zip file containing several photos.4 This is where you can upload your photographs. You can upload 5 photographs individually or a Zip file (or Unix tar/tar.gz) full of 6 pictures. 7 7 </p> 8 8 <p>
