X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=Memories.pm;h=eaf5fe39a2a026b7120f7530c99c5df1d6948fdc;hb=98c885f77094b64006ddc020529f3ce0125c8a1a;hp=33fbf408b67973853efcff26596b4356463bebfc;hpb=3741acaec618fde1e4c230ee2a503987746235e4;p=memories.git diff --git a/Memories.pm b/Memories.pm index 33fbf40..eaf5fe3 100644 --- a/Memories.pm +++ b/Memories.pm @@ -1,9 +1,9 @@ package Memories; use strict; +our $VERSION = "1.2"; +use Maypole::Application qw(Upload Authentication::UserSessionCookie); use HTML::TagCloud; use URI; -use Maypole::Application qw(Upload Authentication::UserSessionCookie --Debug); use Memories::Config; use Memories::DBI; use Memories::Photo; @@ -14,6 +14,7 @@ use Memories::User; use Memories::Album; use URI::Escape; use Calendar::Simple; +use XML::RSS; Memories->config->auth->{ user_field } = "name"; Memories->config->model("Maypole::Model::CDBI::Plain"); @@ -25,13 +26,42 @@ sub message { push @{$self->{template_args}{messages}}, $message; } +sub do_rss { + my $r = shift; + $r->model_class->process($r); + my $rss = XML::RSS->new(version => "2.0"); + $rss->channel( + title => ($r->config->{application_name}. " : ".ucfirst($r->action)." ".ucfirst($r->table)." ".($r->objects||[])->[0]) , + link => $r->config->{uri_base}."/".$r->path + ); + my $maybe_photos = $r->{objects}||[]; + my $photos = + (@$maybe_photos && $maybe_photos->[0]->isa("Memories::Photo")) + ? $maybe_photos : + ($r->{template_args}->{photos} || []); + for my $item (@$photos) { + my $link = $r->config->{uri_base}."photo/view/".$item->id; + $rss->add_item( title => $item->title, link => $link, + description => + " + thumb_url."\" alt=\"".$item->title."\">", + dc => { subject => join " ", $item->tags }, + pubDate => $item->uploaded->strftime("%a, %d %b %Y %H:%M:%S %z") + ) + } + $r->output($rss->as_string); + $r->content_type("application/rss+xml"); + return +} + sub additional_data { my $r = shift; if ($r->params->{view_cal}) { - $r->{template_args}{view_cal} = eval { + $r->{template_args}{view_cal} = eval { Time::Piece->strptime($r->{params}{view_cal}, "%Y-%m-%d") }; } $r->{template_args}{now} = Time::Piece->new; + return $r->do_rss if ($r->params->{format} =~ /rss/) } use Maypole::Constants; @@ -120,10 +150,10 @@ sub Time::Piece::prev_month { sub tag_select { - my ($r, $tags, $photos) = @_; - # XXX only affects current page + my ($r, $tags) = @_; my %counter; - for (map {$_->tags} @$photos) { + my @photos = Memories::Photo->sth_to_objects(Memories::Tag->multi_search(@$tags)); + for (map {$_->tags} @photos) { $counter{$_->name}++; } delete $counter{$_->name} for @$tags; @@ -133,7 +163,7 @@ sub tag_select { my $base = $r->config->uri_base.$r->path."/"; my $tags; for my $name (sort {$a cmp $b} keys %counter) { - if ($counter{$name} == @$photos) { + if ($counter{$name} == @photos) { push @super, $name; } else { $cloud->add($name, $base.uri_escape($name), $counter{$name});