4 use Maypole::Application qw(Upload Authentication::UserSessionCookie -Debug);
10 use Memories::Comment;
12 use Memories::SystemTag;
19 Memories->config->auth->{ user_field } = "name";
20 Memories->config->model("Maypole::Model::CDBI::Plain");
21 Memories->setup([qw/ Memories::Photo Memories::User Memories::Tag
22 Memories::Album Memories::SystemTag/]);
25 my ($self, $message) = @_;
26 push @{$self->{template_args}{messages}}, $message;
29 sub check_credentials {
31 my ($uid, $user) = $r->SUPER::check_credentials;
32 #if (!$uid) { return (-1, undef) }
38 $r->model_class->process($r);
39 my $photos = $r->get_photos;
40 my $rss = XML::RSS->new(version => "2.0");
42 title => ($r->config->{application_name}. " : ".ucfirst($r->action)." ".ucfirst($r->table)." ".($r->objects||[])->[0]) ,
43 link => $r->config->{uri_base}."/".$r->path
45 for my $item (@$photos) {
46 my $link = $r->config->{uri_base}."photo/view/".$item->id;
47 $rss->add_item( title => $item->title, link => $link,
50 <img src=\"". $item->thumb_url."\" alt=\"".$item->title."\"></a>",
51 dc => { subject => join " ", $item->tags },
52 pubDate => $item->uploaded->strftime("%a, %d %b %Y %H:%M:%S %z")
55 $r->output($rss->as_string);
56 $r->content_type("application/rss+xml");
62 my $maybe_photos = $r->{objects}||[];
63 return (@$maybe_photos && $maybe_photos->[0]->isa("Memories::Photo"))
65 ($r->{template_args}->{photos} || []);
70 my $photos = $r->get_photos;
71 $r->{session}{last_search} = join ",", map { $_->id } @$photos
77 if ($r->params->{view_cal}) {
78 $r->{template_args}{view_cal} = eval {
79 Time::Piece->strptime($r->{params}{view_cal}, "%Y-%m-%d") };
81 $r->{template_args}{now} = Time::Piece->new;
83 (tied %{$r->session})->{lock_manager}->clean('/var/lib/memories/sessionlock', 3600) #remove files older than 1 hour
85 return $r->do_rss if ($r->params->{format} =~ /rss/)
88 use Maypole::Constants;
91 return DECLINED if $self->path =~/static|store/; # XXX
97 use Cache::SharedMemoryCache;
98 my %cache_options = ( 'namespace' => 'MemoriesStuff',
99 'default_expires_in' => 600 );
101 new Cache::SharedMemoryCache( \%cache_options ) or
102 croak( "Couldn't instantiate SharedMemoryCache" );
104 sub zap_cache { $cache->Clear }
105 use Storable qw(freeze); use MIME::Base64;
107 my ($self, $codeblock,$arg) = @_;
108 my $key = 0+$codeblock; if ($arg) { $key .=":".encode_base64(freeze(\$arg)); }
109 my $c = $cache->get(0+$codeblock); return @$c if $c;
110 my @stuff = $codeblock->($arg);
111 $cache->set(0+$codeblock, [ @stuff ]);
115 sub _recent_uploads { Memories::Photo->search_recent() }
117 sub recent_uploads { shift->do_cached(\&_recent_uploads) }
118 sub tagcloud { shift->do_cached(\&_tagcloud) }
121 my $cloud = HTML::TagCloud->new();
122 my $base = Memories->config->uri_base."tag/view/";
123 for my $tagging (Memories::Tagging->search_summary) {
124 my $name = $tagging->tag->name;
126 $base.uri_escape($name),
134 # shift->do_cached(\&_calendar, shift ) }
138 my ($y, $m) = split /-/, ($arg || Time::Piece->new->ymd);
139 my @m = Calendar::Simple::calendar($m, $y);
141 foreach my $week (@m) {
143 foreach my $day (@$week) {
144 my $d = { day => $day };
146 my $tag = "date:$y-$m-".sprintf("%02d", $day);
147 my ($x) = Memories::SystemTag->search(name => $tag);
148 if ($x) { $d->{tag} = "/system_tag/view/$tag" }
152 push(@month, \@weekdays);
160 sub Time::Piece::next_month {
162 my $month = $tp + ONE_MONTH;
163 return if $month > Time::Piece->new;
166 sub Time::Piece::prev_month {
168 my $month = $tp - ONE_MONTH;
176 my @photos = Memories::Photo->sth_to_objects(Memories::Tag->multi_search(@$tags));
177 for (map {$_->tags} @photos) {
178 $counter{$_->name}++;
180 delete $counter{$_->name} for @$tags;
183 my $cloud = HTML::TagCloud->new();
184 my $base = $r->config->uri_base.$r->path."/";
186 for my $name (sort {$a cmp $b} keys %counter) {
187 if ($counter{$name} == @photos) {
190 $cloud->add($name, $base.uri_escape($name), $counter{$name});
195 if (@super) { $res{super} = \@super }
196 if ($tags) { $res{cloud} = $cloud }