X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=Memories%2FPhoto.pm;h=e2175c5ca80737387fae96525b7f4e559369a8b5;hb=f9656aa2ad257959dd4ed469714ca75791b70040;hp=5a9b91e56aa133ea4cda60c948a12a6d7e7a9bba;hpb=006c40622b5547fcbb693fb37e2216e1d0e7bb6e;p=memories.git diff --git a/Memories/Photo.pm b/Memories/Photo.pm index 5a9b91e..e2175c5 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); @@ -14,7 +17,9 @@ BEGIN { my %order_by = ( recent => "uploaded", popular => "hit_count", - interesting => INTERESTINGNESS_ALGORITHM + loved => "rating/(1+rated)", + interesting => INTERESTINGNESS_ALGORITHM, + random => "rand()" ); while (my($label, $how) = each %order_by) { @@ -41,53 +46,50 @@ __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 +} - # XXX Stop anonymous uploads! +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 $!"; + if (!copy($filename, $photo->path("file"))) { + $photo->delete(); die "Couldn't copy photo: $!"; } - # XXX Check it's a JPEG, etc. - # XXX Unzip ZIP file - print OUT $upload{content}; - close OUT; 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 { @@ -131,6 +133,7 @@ sub exif :Exported {} sub comment :Exported {} sub tagedit :Exported {} sub similar :Exported {} +sub sized :Exported {} use Class::DBI::Plugin::Pager; use Class::DBI::Plugin::AbstractCount;