[mb-commits] r9835 - in mb_server/branches/TemplateToolkit/catalyst: lib/musicbrainz/Controller root/main
root at musicbrainz.org
root at musicbrainz.org
Tue May 13 10:14:59 UTC 2008
Author: acid2
Date: 2008-05-13 10:14:58 +0000 (Tue, 13 May 2008)
New Revision: 9835
Modified:
mb_server/branches/TemplateToolkit/catalyst/lib/musicbrainz/Controller/Root.pm
mb_server/branches/TemplateToolkit/catalyst/root/main/index.tt
Log:
Added support for the blog on the landing page, and moved away from using the Main.pm controller (didn't understand the purpores of the Root controller when I started)
Modified: mb_server/branches/TemplateToolkit/catalyst/lib/musicbrainz/Controller/Root.pm
===================================================================
--- mb_server/branches/TemplateToolkit/catalyst/lib/musicbrainz/Controller/Root.pm 2008-05-12 23:41:43 UTC (rev 9834)
+++ mb_server/branches/TemplateToolkit/catalyst/lib/musicbrainz/Controller/Root.pm 2008-05-13 10:14:58 UTC (rev 9835)
@@ -7,6 +7,7 @@
# We need this to specify the MusicBrainz perl codebase
use lib "/home/musicbrainz/blah/TemplateToolkit/cgi-bin";
+# Import MusicBrainz libraries
use DBDefs;
#
@@ -16,59 +17,85 @@
__PACKAGE__->config->{namespace} = '';
=head1 NAME
-
musicbrainz::Controller::Root - Root Controller for musicbrainz
=head1 DESCRIPTION
+This controller handles application wide logic for the MusicBrainz website.
-[enter your description here]
-
=head1 METHODS
+=cut
+=head2 index
+Render the standard MusicBrainz welcome page, which is mainly static, other than the blog feed.
=cut
-=head2 default
+sub index : Path Args(0)
+{
+ use MusicBrainz::Server::Replication ':replication_type';
+ require MusicBrainz::Server::NewsFeed;
-=cut
+ my ($self, $c) = @_;
-sub index : Path Args(0) {
- my ( $self, $c ) = @_;
+ $c->stash->{server_details} = {
+ is_slave_db => &DBDefs::REPLICATION_TYPE == RT_SLAVE,
+ staging_server => &DBDefs::DB_STAGING_SERVER,
+ };
- # Hello World
- $c->response->body( $c->welcome_message );
+ # Load the blog for the sidebar
+ #
+ my $feed = MusicBrainz::Server::NewsFeed->new(
+ url => 'http://blog.musicbrainz.org/index-excerpt.xml',
+ update_interval => 5 * 60,
+ max_items => 3);
+
+ $feed->Load() if defined $feed;
+
+ # Process the items to a template friendly data structure
+ #
+ my $item = undef;
+ $c->stash->{blog} = [];
+
+ foreach $item ($feed->GetItems()) {
+ push @{ $c->stash->{blog} }, {
+ title => $item->GetTitle(),
+ description => $item->GetDescription(),
+ date_time => $item->GetDateTimeString(),
+ link => $item->GetLink(),
+ };
+ }
+
+ $c->stash->{template} = 'main/index.tt';
}
-sub default : Path {
- my ( $self, $c ) = @_;
+=head2 default
+Handle any pages not matched by a specific controller path. In our case, this means serving a 404 error page.
+=cut
+
+sub default : Path
+{
+ my ($self, $c) = @_;
+
$c->response->body( 'Page not found' );
- $c->response->status(404);
-
+ $c->response->status(404);
}
=head2 end
-
Attempt to render a view, if needed. This will also set up some global variables in the
context containing important information about the server used on the majority of templates.
-
=cut
sub end : ActionClass('RenderView') {
my ($self, $c) = @_;
- $c->stash->{server_details} = {
- version => &DBDefs::VERSION,
- };
+ $c->stash->{server_details}->{version} = &DBDefs::VERSION;
}
=head1 AUTHOR
+Oliver Charles <oliver.g.charles at googlemail.com>
-Catalyst developer
-
=head1 LICENSE
-
This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
-
1;
Modified: mb_server/branches/TemplateToolkit/catalyst/root/main/index.tt
===================================================================
--- mb_server/branches/TemplateToolkit/catalyst/root/main/index.tt 2008-05-12 23:41:43 UTC (rev 9834)
+++ mb_server/branches/TemplateToolkit/catalyst/root/main/index.tt 2008-05-13 10:14:58 UTC (rev 9835)
@@ -2,7 +2,30 @@
<h1>Welcome to MusicBrainz!</h1>
-[% WRAPPER components/box.tt header="What is MusicBrainz?" %]
+[% IF server_details.staging_server %]
+ [% WRAPPER "components/box.tt"
+ header = "You are using a MusicBrainz $server_details.staging_server server!"
+ colour = "purple" %]
+ <p>
+ Unless you want to be testing the latest and greatest MusicBrainz features
+ you probably want to go to the <a href="http://musicbrainz.org/">
+ <img src="/images/icon/extlink.gif" alt="External Website" /> musicbrainz.org main
+ server</a>.
+ </p>
+ [% END %]
+[% END %]
+
+[% IF server_details.is_slave_db %]
+ [% WRAPPER "components/box.tt" header="You are using a MusicBrainz mirror" colour="purple" %]
+ <p>
+ If you want to edit the MusicBrainz data, you will need to go to the
+ <a href="http://musicbrainz.org/">
+ <img src="/images/icon/extlink.gif" alt="" width="12" /> musicbrainz.org main server</a>.
+ </p>
+ [% END %]
+[% END %]
+
+[% WRAPPER "components/box.tt" header="What is MusicBrainz?" %]
<p>MusicBrainz is a community music metadatabase that attempts to create a comprehensive music information
site. You can use the MusicBrainz data either by browsing this web site, or you can access the data from
a client program - for example, a CD player program can use MusicBrainz to identify CDs and provide
@@ -12,7 +35,7 @@
</p>
[% END %]
-[% WRAPPER components/box.tt header="Use MusicBrainz" %]
+[% WRAPPER "components/box.tt" header="Use MusicBrainz" %]
<p>
You can use Musicbrainz right now to automatically identify and label your music files - all you have to do is
download and run a MusicBrainz enabled tagger.
@@ -38,7 +61,7 @@
</p>
[% END %]
-[% WRAPPER components/box.tt header="Be a Part of MusicBrainz" %]
+[% WRAPPER "components/box.tt" header="Be a Part of MusicBrainz" %]
<p>Many people are needed to make MusicBrainz work. Come and take part!</p>
<ul>
<li>Please download and use Picard. By doing so, you will be using and adding to the MusicBrainz database.</li>
@@ -54,4 +77,15 @@
</ul>
[% END %]
-[% END %]
\ No newline at end of file
+[% WRAPPER "components/box.tt" color="purple" header="MusicBrainz Blog" %]
+ <ul id="blog">
+ [% FOREACH post IN blog %]
+ <li>
+ <h3>[% post.title %]</h3>
+ <p>[% post.description %]</p>
+ <p>Posted: [% post.date_time %]</p>
+ [% END %]
+ </ul>
+[% END %]
+
+[% END %]
More information about the MusicBrainz-commits
mailing list