8 $Gruta::VERSION
= '2.0-pre2';
10 sub sources
{ return @
{$_[0]->{sources
}}; }
11 sub template
{ return $_[0]->{template
}; }
12 sub cgi
{ return $_[0]->{cgi
}; }
18 print STDERR
$self->{id
}, ' ', scalar(localtime), ': ', $msg, "\n";
29 foreach my $s ($self->sources()) {
30 if (my $m = $s->can($method)) {
31 my @pr = $m->($s, @_);
41 return wantarray ?
@r : $r[0];
44 sub topic
{ my $self = shift; return $self->_call('topic', 1, @_); }
45 sub topics
{ my $self = shift; return $self->_call('topics', 0); }
47 sub user
{ my $self = shift; return $self->_call('user', 1, @_); }
48 sub users
{ my $self = shift; return $self->_call('users', 0); }
55 if (! $topic_id || ! $id) {
60 my $ck = $topic_id . '/' . $id;
62 if ($story = $self->{story_cache
}->{$ck}) {
66 if (not $story = $self->_call('story', 1, $topic_id, $id)) {
70 my $format = $story->get('format') || 'grutatxt';
72 if (my $rndr = $self->{renderers_h
}->{$format}) {
76 return $self->{story_cache
}->{$ck} = $story;
80 sub stories
{ my $self = shift; return $self->_call('stories', 0, @_); }
81 sub stories_by_date
{ my $self = shift; return $self->_call('stories_by_date', 1, @_); }
82 sub search_stories
{ my $self = shift; return $self->_call('search_stories', 1, @_); }
87 my @l = $self->_call('stories_top_ten', 0, @_);
89 return sort { $b->[0] cmp $a->[0] } @l;
92 sub search_stories_by_tag
{ my $self = shift; return $self->_call('search_stories_by_tag', 0, @_); }
97 my @l = $self->_call('tags', 0, @_);
99 return sort { $b->[1] <=> $a->[1] } @l;
102 sub insert_topic
{ my $self = shift; return $self->_call('insert_topic', 1, @_); }
103 sub insert_user
{ my $self = shift; return $self->_call('insert_user', 1, @_); }
104 sub insert_story
{ my $self = shift; return $self->_call('insert_story', 1, @_); }
110 if (@_) { $self->{auth
} = shift; } # Gruta::Data::User
112 return $self->{auth
};
123 $self->_call('purge_old_sessions', 0);
125 if (my $session = $self->_call('session', 1, $sid)) {
126 $u = $session->source->user( $session->get('user_id') );
127 $u->set('sid', $sid);
143 if (my $u = $self->user( $user_id )) {
145 # account expired? go!
146 if (my $xdate = $u->get('xdate')) {
147 if (Gruta
::Data
::today
() > $xdate) {
152 my $p = $u->get('password');
154 if (crypt($passwd, $p) eq $p) {
158 my $session = Gruta
::Data
::Session
->new(
164 $u->source->insert_session( $session );
166 $u->set('sid', $sid);
178 if (my $auth = $self->auth()) {
179 if( my $sid = $auth->get('sid')) {
180 if (my $session = $auth->source->session( $sid )) {
181 $session->delete() if $session->can('delete');
186 $self->auth( undef );
193 my $topic_id = shift;
197 if (my $t = $self->topic($topic_id)) {
198 $ret = "<a href='?t=TOPIC;topic=$topic_id'>" .
199 $t->get('name') . '</a>';
202 $ret = "Bad topic $topic_id";
211 my $topic_id = shift;
212 my $story_id = shift;
216 if (my $s = $self->story($topic_id, $story_id)) {
217 $ret = "<a href='?t=STORY;topic=$topic_id;id=$story_id'>" .
218 $s->get('title') . '</a>';
221 $ret = "Bad story '$topic_id/$story_id'";
232 $string =~ s!topic://([\w\d_]+)!$self->_link_to_topic($1)!ge;
233 $string =~ s!story://([\w\d_]+)/([\w\d_]+)!$self->_link_to_story($1,$2)!ge;
239 sub transfer_to_source
{
243 foreach my $id ($self->users()) {
244 my $u = $self->user($id);
245 $dst->insert_user($u);
248 foreach my $topic_id (sort $self->topics()) {
249 my $t = $self->topic($topic_id);
254 if ($nti =~ /-arch$/) {
255 # don't insert topic, just rename
259 $dst->insert_topic($t);
262 foreach my $id ($self->stories($topic_id)) {
264 # get story and its tags
265 my $s = $self->story($topic_id, $id);
266 my @tags = $s->tags();
269 $s->set('topic_id', $nti);
271 my $ns = $dst->insert_story($s);
283 sub flush_story_cache
{
286 $self->{story_cache
} = {};
293 my $g = bless( { @_ } , $class);
295 $g->{id
} ||= 'Gruta';
296 $g->{story_cache
} = {};
297 $g->{renderers_h
} = {};
299 if (ref($g->{sources
}) ne 'ARRAY') {
300 $g->{sources
} = [ $g->{sources
} ];
303 if ($g->{renderers
}) {
304 if (ref($g->{renderers
}) ne 'ARRAY') {
305 $g->{renderers
} = [ $g->{renderers
} ];
308 foreach my $r (@
{$g->{renderers
}}) {
309 $g->{renderers_h
}->{$r->{renderer_id
}} = $r;
313 $g->template->data($g) if $g->{template
};
314 $g->cgi->data($g) if $g->{cgi
};