Description:
Shows the recent diaries with post date, truncated subject and comment count. Swiped directly from k5 a while ago, so all authoring propz to Rusty or whoever did the first one. I just tweaked it a little.
Box Code:
my $content;
my $num_diaries = 10;
my $trim_length = 45;
####
# New diary list
####
# Get the last $num_diaries Diary entries
my ($rv, $sth) = $S->db_select({
WHAT => 'sid, aid, tid, title, time',
FROM => 'stories',
WHERE => qq{section = "Diary" AND displaystatus = 1},
ORDER_BY => 'time DESC',
LIMIT => $num_diaries});
my $table = $sth->fetchall_arrayref;
for (@$table) {
my ($sid, $aid, $tid, $title, $time) = @$_;
if (length $title > $trim_length) {
$title = substr($title, 0, $trim_length);
$title =~ s/\s+\S+$//;
$title .= '...';
}
($rv, $sth) = $S->db_select({
WHAT => 'count(cid)',
FROM => 'comments',
WHERE => qq{sid='$sid'},
});
my $comments = ($sth->fetchrow_array)[0];
$comments = $comments ? qq{ ($comments)} : '';
my $month = (qw/Null January February March April May June July August September October November December/)[substr($time, 5, 2)];
my $day = substr($time, 8, 2);
$content .= qq{<table border="1" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td bgcolor="#CCCCCC"><font face="arial, helvetica, sans-serif" size="-1"><a href="/?op=section;section=Diary;user=$tid"><b>$aid</b></a> - $month $day</font></td></tr>
<tr><td><font face="arial, helvetica, sans-serif" size="-1"><A HREF="|rootdir|/?op=displaystory;sid=$sid">$title</a>$comments</td>
</tr></table><br>};
}
# Add the "More..." link for diaries
$content .= qq{
<BR><A HREf="|rootdir|/?op=search;type=diary;offset=25">More Diaries...</a>
|smallfont_end|
<P>};
# And return the content, like normal.
return {content => $content};
|