App-news
view release on metacpan or search on metacpan
script/news view on Meta::CPAN
my ($tag) = $subject =~ /\[(.*?)\]/;
my $from = no_email(decode("MIME-Header", $headers->header("from")));
my $date = $headers->header("date");
app->log->debug("$from/$subject/$date") unless $date;
my $dt = $parser->parse_datetime($date);
$date = [$dt->ymd, sprintf("%02d:%02d", $dt->hour, $dt->minute)];
my $newsgroups = [split(/\s*,\s*/, decode("MIME-Header", $headers->header("newsgroups")) || "")];
my $group = "@$newsgroups";
my $url = $c->url_for('article', group => $group, id => $id); # $num is not available
push(@$articles, {
id => $id,
tag => $tag,
url => $url,
group => $group,
from => $from,
subject => $subject,
date => $date,
newsgroups => $newsgroups, });
};
$nntp->quit;
return $articles });
return $c->render(template => 'noserver') if $list eq 'error';
$c->render(template => 'latest', list => $list);
} => 'latest';
app->start;
__DATA__
@@ index.html.ep
% layout "default";
% title 'News';
<h1>News</h1>
<p>
This is a forum. The groups and posts it shows are from a <a
href="https://en.wikipedia.org/wiki/News_server">news server</a>. If you have a
web browser that knows how to handle news URLs, like <tt>lynx</tt>, you can
visit the news server <a href="news://<%= $address %>/">directly</a>.
<p>
% if ($id) {
<%= link_to url_for('article_id', id => $id) => begin %>Start here<% end %>.
% }
<%= link_to url_for('latest') => begin %>Latest posts<% end %>.
<table>
<tr><th class="status">Post</th><th>Group</th></tr>
% my @seen;
% for my $group (sort keys %$list) {
% my ($last, $first, $flag) = @{$list->{$group}};
% my $status = "";
% my $edit = 0;
% if ($flag eq "y") { $status = "OK"; $edit = 1 }
% elsif ($flag eq "m") { $status = "Moderated"; $edit = 1 }
% elsif ($flag eq "n") { $status = "Remote" }
% elsif ($flag eq "j") { $status = "Junked" }
% elsif ($flag eq "x") { $status = "Archived" }
% else { $status = "Renamed" }
% push(@seen, $flag) unless grep { $_ eq $flag } @seen;
% if ($edit) {
<tr><td class="status"><%= $status %></td><td><%= link_to url_for('group', group => $group)->fragment($last) => begin %><%= $group %><% end %><br></td></tr>
% } else {
<tr><td class="status"><%= $status %></td><td><%= link_to url_for('group', group => $group)->query(edit => 'no')->fragment($last) => begin %><%= $group %><% end %><br></td></tr>
% }
% }
</table>
<p>
% for my $flag (@seen) {
% if ($flag eq "y") {
OK: Posting is possible and probably requires an account.
% } elsif ($flag eq "m") {
Moderated: Posts aren't published unless approved by a moderator.
% } elsif ($flag eq "n") {
Remote: Posts from a peer are shown but you cannot post.
% } elsif ($flag eq "j") {
Junked: All posts are immediately moved to the junk group.
% } elsif ($flag eq "x") {
Archived: No new posts.
% } else {
Renamed: Posts will get moved to a different group.
% }
% }
@@ group.html.ep
% layout "default";
% title "$group";
<h1><%= $group %></h1>
% if ($description) {
<p><%= $description %>
% }
<p>
<%= link_to url_for('index') => begin %>List all groups<% end %>
% if ($pagination->{page} > 1) {
<%= link_to url_for('group', group => $group)->query(page => 1) => begin %>First<% end %>
% }
% if ($pagination->{page} > 2) {
<%= link_to url_for('group', group => $group)->query(page => $pagination->{page} - 1) => begin %>Older<% end %>
% }
% if ($pagination->{page} < $pagination->{last_page} - 1) {
<%= link_to url_for('group', group => $group)->query(page => $pagination->{page} + 1) => begin %>Newer<% end %>
% }
% if ($pagination->{page} < $pagination->{last_page}) {
<%= link_to url_for('group', group => $group) => begin %>Last<% end %>
% }
% unless ($ENV{NEWS_MODE} and $ENV{NEWS_MODE} eq "NOPOST" or $edit and $edit eq "no") {
<%= link_to url_for('new', group => $group) => begin %>Add post<% end %> (requires account)
% }
% if (@$list) {
<table>
<tr><th class="date">Date</th><th class="from">From</th><th class="subject">Subject</th></tr>
% my $date = "";
% for my $article (@$list) {
% if ($article->{date}->[0] ne $date) {
% $date = $article->{date}->[0];
<tr><td class="day"><%= $date %></td><td></td><td></td></tr>
% }
% if ($article->{tag}) {
% my $re = quotemeta($article->{tag});
% my @part = split(/$re/, $article->{subject}, 2);
<tr><td class="time"><a href="<%= $article->{url} %>"><%= $article->{date}->[1] %></a></td><td class="from"><%= $article->{from} %></td><td class="subject"><%= $part[0] %><%= link_to url_for('tag', group => $group, tag => $article->{tag})->query(incl...
% } else {
<tr><td class="time"><a href="<%= $article->{url} %>"><%= $article->{date}->[1] %></a></td><td class="from"><%= $article->{from} %></td><td class="subject"><%= $article->{subject} %></td></tr>
% }
( run in 1.778 second using v1.01-cache-2.11-cpan-b16cb0d3907 )