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);
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 <a href=\"?".$r->config->uri_base."photo/view/".$photo->id."?active=tagedit\">tag your photo</a>"
- )
- );
+ return $photo;
}
sub approx_rating {