Changeset 407 for veekun/trunk

Show
Ignore:
Timestamp:
02/09/08 02:53:35 (10 months ago)
Author:
eevee
Message:

Added Bulbanews feed to the front page. (#178)

Location:
veekun/trunk
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • veekun/trunk/README.pod

    r256 r407  
    2828    Catalyst::Plugin::Session::State::Cookie 
    2929    Catalyst::Plugin::Session::Store::DBIC 
     30    Catalyst::Plugin::Unicode 
    3031    DBIx::Class 
    3132    DBIx::Class::QueryLog 
     
    3839    String::Approx 
    3940    Template 
     41    XML::Feed 
    4042    YAML 
    4143 
  • veekun/trunk/lib/Vee.pm

    r328 r407  
    1111    -Debug 
    1212    StackTrace 
    13     Static::Simple  
     13    Static::Simple 
    1414     
    1515    ConfigLoader 
     16    Unicode 
    1617     
    1718    Authentication 
     
    6768{ 
    6869    # WARNING: HERE BE DRAGONS, AND BY DRAGONS I MEAN HACKS 
    69     # TODO: WHAT THE FUCK CLEAN THIS GARBAGE UP WITH PLUGINS OR SOMETHING 
    70  
    71     no strict 'refs'; 
     70    no warnings 'redefine'; 
    7271 
    7372    # I find myself doing this a lot and it's a bit cumbersome 
    74     *{'DBIx::Class::ResultSet::is_empty'} = sub { 
     73    *DBIx::Class::ResultSet::is_empty = sub { 
    7574        my ($self) = @_; 
    7675        my $first = $self->first; 
     
    8281    # conditions with critical code like this. 
    8382    # CAVEAT EMPTOR: may break if you upgrade 
    84     *{'DBIx::Class::ResultSet::find_or_create'} = sub { 
     83    *DBIx::Class::ResultSet::find_or_create = sub { 
    8584        my $self     = shift; 
    8685        my $attrs    = (@_ > 1 && ref $_[$#_] eq 'HASH' ? pop(@_) : {}); 
  • veekun/trunk/lib/Vee/Controller/Index.pm

    r406 r407  
    7070        $s->{is_unread} = sub { $unread_hash{$_[0]->id} }; 
    7171    } 
    72          
    73     # check for latest subversion revision every 15 minutes or so 
    74     if (not $c->cache->{svn} or $c->cache->{svn}{last_checked} < time - 15 * 60) { 
    75         eval { 
    76             open my $svn_fh, '-|', 'svn', 'log', '--limit' => 1, '--incremental', $c->site_opts->{svn_url}; 
    77             my (undef, $details, undef, @log) = <$svn_fh>; 
    78             close $svn_fh; 
    79             my ($rev, $user, $time, undef) = split / \| /, $details; 
    80             $rev =~ s/^r//; 
    81             my ($yr, $mo, $day, $hr, $min, $sec, $tz) = split /[- :]/, $time, 7; 
    82  
    83             $c->cache->{svn} = { 
    84                 revision     => $rev, 
    85                 user         => $user, 
    86                 time         => new DateTime( 
    87                     year   => $yr, 
    88                     month  => $mo, 
    89                     day    => $day, 
    90                     hour   => $hr, 
    91                     minute => $min, 
    92                     second => $sec, 
    93                     time_zone => substr $tz, 0, 5, 
    94                 ), 
    95                 last_checked => time, 
    96                 log          => join '', @log, 
    97             } 
    98         }; 
    99     } 
    100  
    101     $s->{recent_revision} = $c->cache->{svn}; 
    10272 
    10373    $s->{recent_users} = $c->model('DBIC::Users')->search( 
    10474        { time_active => { '>', time - $c->site_opts->{user_activity_timeout} } }, 
    10575        { order_by => 'me.time_active DESC' } 
    106     );     
     76    ); 
    10777 
    10878    my $shoutbox_form = Vee::Form->new( 
  • veekun/trunk/lib/Vee/Controller/Root.pm

    r406 r407  
    55use base 'Catalyst::Controller'; 
    66 
    7 use Time::HiRes; 
    87use Data::Dumper; 
    98use DBIx::Class::QueryLog; 
    109use File::Path; 
     10use Time::HiRes; 
     11use URI; 
     12use XML::Feed; 
     13 
    1114use Vee::Authorization; 
    1215use Vee::Utils; 
     
    5457        $s->{$_} = $c->flash->{$_} for qw/error_msg info_msg success_msg/; 
    5558    } 
     59 
     60    $self->_do_periodic_tasks($c); 
    5661         
    5762    return 1; 
     
    233238} 
    234239 
     240=head2 _do_periodic_tasks 
     241 
     242Performs various actions if they haven't been done for some amount of time. 
     243 
     244Regular method!  Not an action. 
     245 
     246=cut 
     247 
     248sub _do_periodic_tasks 
     249{ 
     250    my ($self, $c) = @_; 
     251 
     252    if ($c->{cache}{_last_performed} and 
     253        $c->{cache}{_last_performed} > time - 15 * 60) 
     254    { 
     255        next; 
     256    } 
     257 
     258    # Last subversion commit 
     259eval { 
     260    open my $svn_fh, '-|', 'svn', 'log', '--limit' => 1, '--incremental', $c->site_opts->{svn_url}; 
     261    my (undef, $details, undef, @log) = <$svn_fh>; 
     262    close $svn_fh; 
     263    my ($rev, $user, $time, undef) = split / \| /, $details; 
     264    $rev =~ s/^r//; 
     265    my ($yr, $mo, $day, $hr, $min, $sec, $tz) = split /[- :]/, $time, 7; 
     266 
     267    $c->cache->{svn} = { 
     268        revision     => $rev, 
     269        user         => $user, 
     270        time         => new DateTime( 
     271            year   => $yr, 
     272            month  => $mo, 
     273            day    => $day, 
     274            hour   => $hr, 
     275            minute => $min, 
     276            second => $sec, 
     277            time_zone => substr $tz, 0, 5, 
     278        ), 
     279        log          => join '', @log, 
     280    }; 
     281}; 
     282 
     283    # Refresh Bulbapedia feeds 
     284eval { 
     285    Vee::Utils::timed_exec( 5 => sub { 
     286        my $uri = URI->new($c->site_opts->{rss_url}); 
     287        my @entries = XML::Feed->parse($uri)->entries; 
     288        @entries = grep { defined } 
     289            @entries[ 0 .. $c->site_opts->{page_sizes}{index}{rss} - 1 ]; 
     290        $c->cache->{rss_entries} = \@entries; 
     291    } ); 
     292}; 
     293 
     294    $c->cache->{_last_performed} = time; 
     295} 
     296 
    235297=head1 AUTHOR 
    236298 
  • veekun/trunk/lib/Vee/View/TT.pm

    r388 r407  
    44use base 'Catalyst::View::TT'; 
    55 
    6 use Vee::Utils; 
    7 use Time::HiRes; 
     6use DateTime; 
    87use File::Temp qw/tempdir/; 
    98use Template::Namespace::Constants; 
    109use Template::Stash; 
     10use Time::HiRes; 
     11 
     12use Vee::Utils; 
    1113 
    1214if (Vee->debug) { 
     
    4547        postbar_color => sub { Vee::Utils::hsv2rgb(shift, 84, 192) }, 
    4648 
     49        format_time => \&format_time, 
     50 
    4751            # forum stuff... 
    4852    #                allowed_postedit    => sub { return !$self->test_postedit(@_) }, 
     
    6165        bbcode      => \&Vee::BBCode::apply_bbcode, 
    6266        timespan    => \&_format_timespan, 
    63         date        => \&_format_date,  # later this may have to change to use user's date prefs 
     67        date        => \&format_time,  # later this may have to change to use user's date prefs 
    6468        email       => \&_obfuscate_email, 
    6569    #                wordcap         => \&Vee::wordcap, 
     
    9296} 
    9397 
    94 =head2 _format_date 
     98=head2 format_time 
    9599 
    96100Returns a pretty-printed version of the given UNIX-style timestamp. 
     
    99103 
    100104# TODO: add options for this 
    101 sub _format_date { 
    102     my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(shift); 
    103     return sprintf "%02d/%02d/%02d %02d:%02d", $mon+1, $mday, substr($year, -2), $hour, $min; 
     105sub format_time { 
     106    my ($time) = @_; 
     107    if (not ref $time) { 
     108        $time = DateTime->from_epoch( epoch => $time, time_zone => 'floating' ); 
     109    } 
     110 
     111    return $time->strftime('%D %R'); 
    104112} 
    105113 
  • veekun/trunk/site_options.yml

    r374 r407  
    7878        forum: 20 
    7979        users: 25 
     80        rss: 3 
    8081    posts: 20 
    8182    posts_preview: 3 
     
    103104# Note that at the moment this *requires* anon access! 
    104105svn_url: svn://veekun.com/veekun 
     106 
     107# URL for RSS feed on the front page and the site behind it 
     108rss_url: http://bulbanews.bulbagarden.net/feed/news.rss 
     109rss_site_url: http://bulbanews.bulbagarden.net/ 
    105110 
    106111# Number of posts => rank you get 
  • veekun/trunk/templates/index.tt

    r406 r407  
    2828<div id="leftcol"> 
    2929    <div class="front-box"> 
     30        <a href="[% c.site_opts.rss_site_url %]" class="heading"><img src="/images/icons/index/news.png" alt="" class="icon"/> Pok&eacute;mon News</a> 
     31[% FOR feed_entry IN c.cache.rss_entries %] 
     32        <div class="front-feedentry"> 
     33            <div class="title"> <a href="[% feed_entry.link %]">[% feed_entry.title %]</a> </div> 
     34            <div class="time"> [% format_time(feed_entry.issued) %] </div> 
     35            <p class="summary"> [% feed_entry.content.body | nohtml %] </p> 
     36        </div> 
     37[% END %] 
     38[% IF NOT c.cache.rss_entries %] 
     39        <p> No Pok&eacute;mon news. </p> 
     40[% END %] 
     41    </div> 
     42    <div class="front-box"> 
    3043        <a href="/forum/[% c.site_opts.special_forums.news %]" class="heading"><img src="/images/icons/index/news.png" alt="" class="icon"/> News</a> 
    3144[% WHILE (t = recent_news.next) %] 
    3245        <div class="front-newspost"> 
     46            <div class="time">[% format_time(t.first_post.time) %]</div> 
    3347            <a href="/users/[% t.first_post.user_id %]" class="icon">[% IF t.first_post.user.news_pic %]<img src="/images/news/[% t.first_post.user.news_pic %]" alt="[% t.first_post.user.name %]" title="[% t.first_post.user.name %]"/>[% ELSE; t.first_post.user.name; END %]</a> 
    34             <div class="date">[% format_date(t.first_post.time) %]</div> 
    3548            <div class="title">[% t.subject %]</div> 
    3649            <div class="body">[% t.first_post.content | bbcode %]</div> 
     
    113126[% END %] 
    114127    </div> 
    115     <div class="front-box"> 
    116         <a href="/forum/" class="heading"><img src="/images/icons/index/news.png" alt="" class="icon"/> Pok&eacute;mon News</a> 
    117         <p> hold yer horses </p> 
    118     </div> 
    119 [% IF recent_revision %] 
     128[% IF c.svn %] 
    120129    <div class="front-box"> 
    121130        <a href="http://trac.veekun.com/browser/veekun/trunk" class="heading"><img src="/images/icons/index/svn.png" alt="" class="icon"/>Subversion</a> 
    122         <p class="svncommit-revision"> <em>Last Subversion commit:</em> <a href="http://trac.veekun.com/changeset/[% recent_revision.revision.replace('r','') %]">[% recent_revision.revision %]</a> </p> 
    123         <p class="svncommit-log">[% recent_revision.log | nohtml %]</p> 
    124         <p class="svncommit-stamp">by [% recent_revision.user %] on [% recent_revision.time %]</p> 
     131        <p class="svncommit-revision"> <em>Last Subversion commit:</em> <a href="http://trac.veekun.com/changeset/[% c.svn.revision.replace('r','') %]">[% c.svn.revision %]</a> </p> 
     132        <p class="svncommit-log">[% c.svn.log | nohtml %]</p> 
     133        <p class="svncommit-stamp">by [% c.svn.user %] on [% format_time(c.svn.time) %]</p> 
    125134    </div> 
    126135[% END %] 
  • veekun/trunk/templates/style/index.tt

    r287 r407  
    1818  .front-forum a { display: block; } 
    1919 
     20.front-feedentry { padding: 3px; clear: right; } 
     21.front-feedentry + .front-feedentry { border-top: 1px dotted [% dark_separator %]; } 
     22  .front-feedentry .title { font-size: bigger; font-weight: bold; float: left; } 
     23  .front-feedentry .time { float: right; font-size: 85%; } 
     24  .front-feedentry .summary { margin: 0.5em; clear: both; } 
     25 
    2026.front-newspost { padding: 3px; clear: right; } 
    2127.front-newspost + .front-newspost { border-top: 1px dotted [% dark_separator %]; } 
    22   .front-newspost .icon { float: right; padding: 3px 3px 0 0; } 
    23   .front-newspost .date { float: right; font-size: 85%; } 
     28  .front-newspost .time { float: right; font-size: 85%; } 
     29  .front-newspost .icon { float: right; clear: right; padding: 3px 3px 0 0; } 
    2430  .front-newspost .title { color: [% header_text %]; font-size: bigger; font-weight: bold; } 
    2531  .front-newspost .body { margin: 0.5em; }