summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2010-11-13 10:27:32 +0100
committerYorhel <git@yorhel.nl>2010-11-13 10:27:32 +0100
commita985f2316e50a7170229538efc907c232889bfcc (patch)
treef4113dfea3fe1e2a331ce24c0df83ef620a94bc6 /lib
parent935ad7c2c3b7f442664c84e2ccf44957dd642381 (diff)
Added <link> elements for the related atom feeds to some pages
Diffstat (limited to 'lib')
-rw-r--r--lib/Multi/Feed.pm51
-rw-r--r--lib/VNDB/Handler/Discussions.pm4
-rw-r--r--lib/VNDB/Handler/Misc.pm4
-rw-r--r--lib/VNDB/Util/LayoutHTML.pm4
4 files changed, 25 insertions, 38 deletions
diff --git a/lib/Multi/Feed.pm b/lib/Multi/Feed.pm
index 4c157b2d..c97d87d8 100644
--- a/lib/Multi/Feed.pm
+++ b/lib/Multi/Feed.pm
@@ -23,9 +23,6 @@ sub spawn {
heap => {
regenerate_interval => 900, # 15 min.
stats_interval => 86400, # daily
- num_announcements => 10,
- num_changes => 25,
- num_posts => 25,
debug => 0,
@_,
stats => {}, # key = feed, value = [ count, total, max ]
@@ -62,12 +59,8 @@ sub generate {
JOIN users u ON u.id = tp.uid
WHERE NOT t.hidden
ORDER BY t.id DESC
- LIMIT ?}, [ $_[HEAP]{num_announcements} ], 'write_atom',
- {
- feed => 'announcements',
- title => 'VNDB.org Site Announcements',
- id => '/t/an',
- });
+ LIMIT ?}, [ $VNDB::S{atom_feeds}{announcements}[0] ], 'write_atom', 'announcements'
+ );
# changes
$_[KERNEL]->post(pg => query => q{
@@ -81,12 +74,8 @@ sub generate {
JOIN users u ON u.id = c.requester
WHERE c.requester <> 1
ORDER BY c.id DESC
- LIMIT ?}, [ $_[HEAP]{num_changes} ], 'write_atom',
- {
- feed => 'changes',
- title => 'VNDB.org Recent Changes',
- id => '/hist',
- });
+ LIMIT ?}, [ $VNDB::S{atom_feeds}{changes}[0] ], 'write_atom', 'changes'
+ );
# posts (this query isn't all that fast)
$_[KERNEL]->post(pg => query => q{
@@ -97,18 +86,14 @@ sub generate {
JOIN users u ON u.id = tp.uid
WHERE NOT tp.hidden AND NOT t.hidden
ORDER BY tp.date DESC
- LIMIT ?}, [ $_[HEAP]{num_posts} ], 'write_atom',
- {
- feed => 'posts',
- title => 'VNDB.org Recent Posts',
- id => '/t',
- });
+ LIMIT ?}, [ $VNDB::S{atom_feeds}{posts}[0] ], 'write_atom', 'posts'
+ );
}
-sub write_atom { # num, res, nfo, time
+sub write_atom { # num, res, feed, time
my $r = $_[ARG1];
- my $nfo = $_[ARG2];
+ my $feed = $_[ARG2];
my $start = time;
@@ -122,11 +107,11 @@ sub write_atom { # num, res, nfo, time
my $x = XML::Writer->new(OUTPUT => \$data, DATA_MODE => 1, DATA_INDENT => 2);
$x->xmlDecl('UTF-8');
$x->startTag(feed => xmlns => 'http://www.w3.org/2005/Atom', 'xml:lang' => 'en', 'xml:base' => $VNDB::S{url}.'/');
- $x->dataElement(title => $nfo->{title});
+ $x->dataElement(title => $VNDB::S{atom_feeds}{$feed}[1]);
$x->dataElement(updated => datetime($updated));
- $x->dataElement(id => $VNDB::S{url}.$nfo->{id});
- $x->emptyTag(link => rel => 'self', type => 'application/atom+xml', href => "$VNDB::S{url}/feeds/$nfo->{feed}.atom");
- $x->emptyTag(link => rel => 'alternate', type => 'text/html', href => $nfo->{id});
+ $x->dataElement(id => $VNDB::S{url}.$VNDB::S{atom_feeds}{$feed}[2]);
+ $x->emptyTag(link => rel => 'self', type => 'application/atom+xml', href => "$VNDB::S{url}/feeds/$feed.atom");
+ $x->emptyTag(link => rel => 'alternate', type => 'text/html', href => $VNDB::S{atom_feeds}{$feed}[2]);
for(@$r) {
$x->startTag('entry');
@@ -147,18 +132,18 @@ sub write_atom { # num, res, nfo, time
$x->endTag('feed');
- open my $f, '>:utf8', "$VNDB::ROOT/www/feeds/$nfo->{feed}.atom" || die $!;
+ open my $f, '>:utf8', "$VNDB::ROOT/www/feeds/$feed.atom" || die $!;
print $f $data;
close $f;
$_[HEAP]{debug} && $_[KERNEL]->call(core => log => 'Wrote %s.atom (%d entries, sql:%4dms, perl:%4dms)',
- $nfo->{feed}, scalar(@$r), $_[ARG3]*1000, (time-$start)*1000);
+ $feed, scalar(@$r), $_[ARG3]*1000, (time-$start)*1000);
- $_[HEAP]{stats}{$nfo->{feed}} = [ 0, 0, 0 ] if !$_[HEAP]{stats}{$nfo->{feed}};
+ $_[HEAP]{stats}{$feed} = [ 0, 0, 0 ] if !$_[HEAP]{stats}{$feed};
my $time = ((time-$start)+$_[ARG3])*1000;
- $_[HEAP]{stats}{$nfo->{feed}}[0]++;
- $_[HEAP]{stats}{$nfo->{feed}}[1] += $time;
- $_[HEAP]{stats}{$nfo->{feed}}[2] = $time if $_[HEAP]{stats}{$nfo->{feed}}[2] < $time;
+ $_[HEAP]{stats}{$feed}[0]++;
+ $_[HEAP]{stats}{$feed}[1] += $time;
+ $_[HEAP]{stats}{$feed}[2] = $time if $_[HEAP]{stats}{$feed}[2] < $time;
}
diff --git a/lib/VNDB/Handler/Discussions.pm b/lib/VNDB/Handler/Discussions.pm
index ed18fcaf..ee6e460d 100644
--- a/lib/VNDB/Handler/Discussions.pm
+++ b/lib/VNDB/Handler/Discussions.pm
@@ -294,7 +294,7 @@ sub board {
sort => $type eq 'an' ? 'id' : 'lastpost', reverse => 1,
);
- $self->htmlHeader(title => $title, noindex => !@$list || $type eq 'u');
+ $self->htmlHeader(title => $title, noindex => !@$list || $type eq 'u', feeds => [ $type eq 'an' ? 'announcements' : 'posts' ]);
$self->htmlMainTabs($type, $obj, 'disc') if $iid;
div class => 'mainbox';
@@ -330,7 +330,7 @@ sub board {
sub index {
my $self = shift;
- $self->htmlHeader(title => mt '_disindex_title');
+ $self->htmlHeader(title => mt('_disindex_title'), feeds => [ 'posts', 'announcements' ]);
div class => 'mainbox';
h1 mt '_disindex_title';
p class => 'browseopts';
diff --git a/lib/VNDB/Handler/Misc.pm b/lib/VNDB/Handler/Misc.pm
index 87839730..901e25e0 100644
--- a/lib/VNDB/Handler/Misc.pm
+++ b/lib/VNDB/Handler/Misc.pm
@@ -37,7 +37,7 @@ YAWF::register(
sub homepage {
my $self = shift;
- $self->htmlHeader(title => mt '_site_title');
+ $self->htmlHeader(title => mt('_site_title'), feeds => [ keys %{$self->{atom_feeds}} ]);
div class => 'mainbox';
h1 mt '_site_title';
@@ -216,7 +216,7 @@ sub history {
releases => $f->{r},
);
- $self->htmlHeader(title => $title, noindex => 1);
+ $self->htmlHeader(title => $title, noindex => 1, feeds => [ 'changes' ]);
$self->htmlMainTabs($type, $obj, 'hist') if $type;
# url generator
diff --git a/lib/VNDB/Util/LayoutHTML.pm b/lib/VNDB/Util/LayoutHTML.pm
index 93a35e0e..8b2f9ef1 100644
--- a/lib/VNDB/Util/LayoutHTML.pm
+++ b/lib/VNDB/Util/LayoutHTML.pm
@@ -10,7 +10,7 @@ use VNDB::Func;
our @EXPORT = qw|htmlHeader htmlFooter|;
-sub htmlHeader { # %options->{ title, noindex, search }
+sub htmlHeader { # %options->{ title, noindex, search, feeds }
my($self, %o) = @_;
my $skin = $self->reqParam('skin') || $self->authInfo->{skin} || $self->{skin_default};
$skin = $self->{skin_default} if !$self->{skins}{$skin} || !-d "$VNDB::ROOT/static/s/$skin";
@@ -26,6 +26,8 @@ sub htmlHeader { # %options->{ title, noindex, search }
(my $css = $self->authInfo->{customcss}) =~ s/\n/ /g;
style type => 'text/css', $css;
}
+ Link rel => 'alternate', type => 'application/atom+xml', href => "/feeds/$_.atom", title => $self->{atom_feeds}{$_}[1]
+ for ($o{feeds} ? @{$o{feeds}} : ());
meta name => 'robots', content => 'noindex, follow', undef if $o{noindex};
end;
body;