X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=Memories%2FPhoto.pm;h=98444a7bbe0c8a001835c076c610c4a4175cf3a7;hb=b637f6e61ec3f236de28a3d502f70ce7aacba84e;hp=960810d59ab8fcf6414489c4fa35b430492d2496;hpb=af01b9b60fb8342adaca76f30bc9f9209d6bc326;p=memories.git diff --git a/Memories/Photo.pm b/Memories/Photo.pm index 960810d..98444a7 100644 --- a/Memories/Photo.pm +++ b/Memories/Photo.pm @@ -5,7 +5,7 @@ use base qw(Memories::DBI Maypole::Model::CDBI::Plain); use Time::Piece; use Image::Seek; use constant PAGER_SYNTAX => "LimitXY"; -__PACKAGE__->columns(Essential => qw(id title uploader uploaded x y)); +__PACKAGE__->columns(Essential => qw(id title uploader uploaded x y rating rated hit_count)); __PACKAGE__->untaint_columns(printable => [qw/title/]); __PACKAGE__->columns(TEMP => qw/exif_object/); __PACKAGE__->set_sql(recent => q{ @@ -30,7 +30,10 @@ sub do_upload :Exported { my $photo = $self->create({ uploader => $r->user, uploaded => Time::Piece->new(), - title => $r->params->{title} + title => $r->params->{title}, + hit_count => 0, + rating => 0, + rated => 0, # Oh, the potential for divide by zero errors... }); # Dump content @@ -51,6 +54,7 @@ sub do_upload :Exported { } $photo->make_thumb; + $r->{params}{tags} ||= join " ", map { qq{"$_"} } $photo->tags_exif; $photo->add_tags($r->{params}{tags}); $photo->add_to_imageseek_library; Memories->zap_cache(); @@ -71,8 +75,9 @@ sub do_upload :Exported { sub view :Exported { my ($self, $r) = @_; + my $photo = $r->{objects}[0]; + $photo->hit_count($photo->hit_count()+1); if ($r->{session}{last_search}) { - my $photo = $r->{objects}[0]; # This is slightly inefficient my @search = split/,/, $r->{session}{last_search}; my $found = -1; @@ -314,4 +319,19 @@ sub description { sub title_exif { shift->_grovel_metadata( 'Headline', 'Title'); } sub license { shift->_grovel_metadata( 'Rights Usage Terms', 'Usage Terms' ) } sub copyright { shift->_grovel_metadata( 'Rights', 'Copyright', 'Copyright Notice') } + +# This one's slightly different since we want everything we can get... +sub tags_exif { + my $self = shift; + my %md = map {%$_} values %{$self->exif_info}; + my %tags = + map { s/\s+/-/g; lc $_ => 1 } + map { split /\s*,\s*/, $md{$_}} + grep {$md{$_} and $md{$_} =~/[^ 0:]/} + (qw(Keywords Subject City State Location Country Province-State), + 'Transmission Reference', 'Intellectual Genre', + 'Country-Primary Location Name' + ); + return keys %tags; +} 1;