4 use Maypole::Application qw(Authentication::UserSessionCookie);
10 use Memories::Comment;
12 use Memories::SystemTag;
20 Memories->config->auth->{ user_field } = "name";
21 Memories->config->model("Maypole::Model::CDBI::Plain");
22 Memories->setup([qw/ Memories::Photo Memories::User Memories::Tag
23 Memories::Album Memories::SystemTag/]);
26 my ($self, $message) = @_;
27 push @{$self->{template_args}{messages}}, $message;
30 sub check_credentials {
32 my ($uid, $user) = $r->SUPER::check_credentials;
33 #if (!$uid) { return (-1, undef) }
39 $r->model_class->process($r);
40 my $photos = $r->get_photos;
41 my $rss = XML::RSS->new(version => "2.0");
43 title => ($r->config->{application_name}. " : ".ucfirst($r->action)." ".ucfirst($r->table)." ".($r->objects||[])->[0]) ,
44 link => $r->config->{uri_base}."/".$r->path
46 for my $item (@$photos) {
47 my $link = $r->config->{uri_base}."photo/view/".$item->id;
48 $rss->add_item( title => $item->title, link => $link,
51 <img src=\"". $item->thumb_url."\" alt=\"".$item->title."\"></a>",
52 dc => { subject => join " ", $item->tags },
53 pubDate => $item->uploaded->strftime("%a, %d %b %Y %H:%M:%S %z")
56 $r->output($rss->as_string);
57 $r->content_type("application/rss+xml");
63 my $maybe_photos = $r->{objects}||[];
64 return (@$maybe_photos && $maybe_photos->[0]->isa("Memories::Photo"))
66 ($r->{template_args}->{photos} || []);
71 my $photos = $r->get_photos;
72 $r->{session}{last_search} = join ",", map { $_->id } @$photos
78 if ($r->params->{view_cal}) {
79 $r->{template_args}{view_cal} = eval {
80 Time::Piece->strptime($r->{params}{view_cal}, "%Y-%m-%d") };
82 $r->{template_args}{now} = Time::Piece->new;
84 (tied %{$r->session})->{lock_manager}->clean('/var/lib/memories/sessionlock', 3600) #remove files older than 1 hour
86 return $r->do_rss if ($r->params->{format} =~ /rss/)
89 use Maypole::Constants;
92 return DECLINED if $self->path =~/static|store/; # XXX
94 if (!$r->user and $self->path =~ /upload/) { $r->template("login"); }
95 # Don't let 'em go until they've fixed it
96 if ($r->session and $r->session->{quarantined} and $self->path !~ /js$/) {
97 $r->table("photo"); $r->action("quarantine");
98 $r->model_class("Memories::Photo");
103 for my $how (qw(random recent interesting popular)) {
105 my $method = "search_$how";
106 *{"_$how"} = sub { Memories::Photo->$method };
107 *{$how} = sub { shift->do_cached(\&{"_$how"})};
113 my @photos = Memories::Photo->sth_to_objects(Memories::Tag->multi_search(@$tags));
114 for (map {$_->tags} @photos) {
115 $counter{$_->name}++;
117 delete $counter{$_->name} for @$tags;
120 my $cloud = HTML::TagCloud->new();
121 my $base = $r->config->uri_base.$r->path."/";
123 for my $name (sort {$a cmp $b} keys %counter) {
124 if ($counter{$name} == @photos) {
127 $cloud->add($name, $base.uri_escape($name), $counter{$name});
132 if (@super) { $res{super} = \@super }
133 if ($tags) { $res{cloud} = $cloud }