X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=Memories.pm;h=c3f1127d1c41189a19daac1262415337d1d03bcc;hb=3b371b0c2e584c3b9164fef7df7faae8d58401d0;hp=7027b09e400e3f7c9cd7defd3d2984b5d0027760;hpb=79a133c5b5ef5e8a4879a8bfaaf43fc119be7631;p=memories.git diff --git a/Memories.pm b/Memories.pm index 7027b09..c3f1127 100644 --- a/Memories.pm +++ b/Memories.pm @@ -1,9 +1,10 @@ package Memories; use strict; our $VERSION = "1.2"; -use Maypole::Application qw(Upload Authentication::UserSessionCookie -Debug); +use Maypole::Application qw(Authentication::UserSessionCookie); use HTML::TagCloud; use URI; +use Tagtools; use Memories::Config; use Memories::DBI; use Memories::Photo; @@ -13,13 +14,14 @@ use Memories::SystemTag; 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"); Memories->setup([qw/ Memories::Photo Memories::User Memories::Tag Memories::Album Memories::SystemTag/]); +Memories->setup_tagging("photo"); +Memories->setup_tagging("photo", "system_tag"); sub message { my ($self, $message) = @_; @@ -80,7 +82,7 @@ sub additional_data { } $r->{template_args}{now} = Time::Piece->new; if ($r->session) { - (tied %{$r->session})->{lock_manager}->clean('/var/lib/memories/sessionlock', 3600) #remove files older than 1 hour + (tied %{$r->session})->{lock_manager}->clean(Memories->config->{auth}{session_args}{LockDirectory}, 3600) #remove files older than 1 hour } return $r->do_rss if ($r->params->{format} =~ /rss/) } @@ -90,88 +92,22 @@ sub authenticate { my ($self, $r) = @_; return DECLINED if $self->path =~/static|store/; # XXX $r->get_user; + if (!$r->user and $self->path =~ /upload/) { $r->template("login"); } + # Don't let 'em go until they've fixed it + if ($r->session and $r->session->{quarantined} and $self->path !~ /js$/) { + $r->table("photo"); $r->action("quarantine"); + $r->model_class("Memories::Photo"); + } return OK; } - -use Cache::SharedMemoryCache; -my %cache_options = ( 'namespace' => 'MemoriesStuff', - 'default_expires_in' => 600 ); -my $cache = - new Cache::SharedMemoryCache( \%cache_options ) or - croak( "Couldn't instantiate SharedMemoryCache" ); - -sub zap_cache { $cache->Clear } -use Storable qw(freeze); use MIME::Base64; -sub do_cached { - my ($self, $codeblock,$arg) = @_; - my $key = 0+$codeblock; if ($arg) { $key .=":".encode_base64(freeze(\$arg)); } - my $c = $cache->get(0+$codeblock); return @$c if $c; - my @stuff = $codeblock->($arg); - $cache->set(0+$codeblock, [ @stuff ]); - return @stuff; -} - -sub _recent_uploads { Memories::Photo->search_recent() } -sub _random { Memories::Photo->search_random() } - -sub recent_uploads { shift->do_cached(\&_recent_uploads) } -sub random { shift->do_cached(\&_random) } -sub tagcloud { shift->do_cached(\&_tagcloud) } - -sub _tagcloud { - my $cloud = HTML::TagCloud->new(); - my $base = Memories->config->uri_base."tag/view/"; - for my $tagging (Memories::Tagging->search_summary) { - my $name = $tagging->tag->name; - $cloud->add($name, - $base.uri_escape($name), - $tagging->{count} - ) - } - $cloud +for my $how (qw(random recent interesting popular)) { + no strict; + my $method = "search_$how"; + *{"_$how"} = sub { Memories::Photo->$method }; + *{$how} = sub { shift->do_cached(\&{"_$how"})}; } -sub calendar { - # shift->do_cached(\&_calendar, shift ) } -#sub _calendar { - my $self = shift; - my $arg = shift; - my ($y, $m) = split /-/, ($arg || Time::Piece->new->ymd); - my @m = Calendar::Simple::calendar($m, $y); - my @month; - foreach my $week (@m) { - my @weekdays; - foreach my $day (@$week) { - my $d = { day => $day }; - if ($day) { - my $tag = "date:$y-$m-".sprintf("%02d", $day); - my ($x) = Memories::SystemTag->search(name => $tag); - if ($x) { $d->{tag} = "/system_tag/view/$tag" } - } - push(@weekdays, $d); - } - push(@month, \@weekdays); - } - return \@month; -} - -# THIS IS A HACK - -use Time::Seconds; -sub Time::Piece::next_month { - my $tp = shift; - my $month = $tp + ONE_MONTH; - return if $month > Time::Piece->new; - return $month -} -sub Time::Piece::prev_month { - my $tp = shift; - my $month = $tp - ONE_MONTH; - return $month -} - - sub tag_select { my ($r, $tags) = @_; my %counter;