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;
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");
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 =>
+ "<a href=\"$link\">
+ <img src=\"". $item->thumb_url."\" alt=\"".$item->title."\"></a>",
+ 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;
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;
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});