Description:
This displays the number of users that have viewed a particular story.
Box Code:
# story_hit_box
# NOTE: you might want to add an index to your
# viewed_stories table to make this run quite
# a bit faster, especially if your site is more
# than just a little busy
# mysql> create index sid_idx on viewed_stories (sid);
# ALSO, this doesn't cache yet, it will in the future.
# Shouldn't be a problem for small sites.
my $sid = $S->{CGI}->param('sid');
$sid = $S->{DBH}->quote($sid);
my ($rv,$sth) = $S->db_select({
FROM => 'viewed_stories',
WHAT => 'count(uid) as c',
WHERE => "sid = $sid"
});
my $count = 0;
if( $rv ) {
my $r = $sth->fetchrow_hashref;
$count = $r->{c};
}
$sth->finish();
my $content = qq[
%%norm_font%%<b>$count</b> Scoop users have viewed this story.%%norm_font_end%%
];
return { content => $content };
|