From b90a2bd4a7a31ea891d9c9692c5d96cb52b2e3b3 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Fri, 16 Feb 2007 22:31:28 +0000 Subject: [PATCH] Mess around with things to make it easier to support multiple file uploads, quarantining and multiple file types. References #8, #10, #14. git-svn-id: http://svn.simon-cozens.org/memories/trunk@33 041978f6-d955-411f-a9d7-1d8545c9c3c7 --- Memories/Photo.pm | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/Memories/Photo.pm b/Memories/Photo.pm index d14619e..8286480 100644 --- a/Memories/Photo.pm +++ b/Memories/Photo.pm @@ -1,4 +1,7 @@ package Memories::Photo; +use File::Basename; +use File::Copy; +use Archive::Any; use strict; use Carp qw(cluck confess); use base qw(Memories::DBI Maypole::Model::CDBI::Plain); @@ -43,52 +46,48 @@ __PACKAGE__->has_a(uploaded => "Time::Piece", sub do_upload :Exported { my ($self, $r) = @_; - my %upload = $r->upload("photo"); + my $upload = $r->{ar}->upload("photo"); + # Check $self->type + my @photos = $self->upload_jpeg($upload->tempname, ($r->params->{title}||basename($upload->filename)), $r->params->{tags}, $r); + my @quarantined = grep { !$_->tags } @photos; + # Set it up to go again + $r->objects(\@photos); + $r->template("view"); + $r->message("Thanks for the upload!"); + # Deal with the quarantined +} +sub upload_jpeg { + my ($self, $filename, $title, $tags, $r) = @_; + my $quarantine; my $photo = $self->create({ uploader => $r->user, uploaded => Time::Piece->new(), - title => $r->params->{title}, + title => $title, hit_count => 0, rating => 0, - rated => 0, # Oh, the potential for divide by zero errors... + rated => 0, }); - - # Dump content - if (!open OUT, ">". $photo->path("file")) { - die "Can't write ".$photo->path("file")." because $!"; - } - # XXX Check it's a JPEG, etc. - # XXX Unzip ZIP file - print OUT $upload{content}; - close OUT; + copy($filename, $photo->path("file")); my ($x, $y) = dim(image_info($photo->path)); $photo->x($x); $photo->y($y); # Rotate? $photo->unrotate(); if (!$photo->title){ - $photo->title($photo->title_exif || $upload{filename}); + $photo->title($photo->title_exif || basename($filename)); } $photo->make_thumb; - $r->{params}{tags} ||= join " ", map { qq{"$_"} } $photo->tags_exif; - $photo->add_tags($r->{params}{tags}); + $tags ||= join " ", map { qq{"$_"} } $photo->tags_exif; + $photo->add_tags($tags); $photo->add_to_imageseek_library; 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}) }); - - # Set it up to go again - $r->objects([$photo]); - $r->template("view"); - $r->message("Thanks for the upload! ". - ($r->{params}{tags} ? "" - : "Don't forget to config->uri_base."photo/view/".$photo->id."?active=tagedit\">tag your photo" - ) - ); + return $photo; } sub approx_rating { -- 2.39.2