Description:
This is a new version of the hotlist_flex box which adds the ability to view a list of diaried to which the logged-in user has subscribed. In order ot use this feature, it is nessecery to deploy the diarysub_box for management of those subscriptions.
Box Code:
# Display Hotlist, Stories and unread replies to user comments
# Version 0.3.1 by hillct
my($view,$content,$item);
my $uri=$S->{APACHE}->uri;
my $arg = $S->apache->args();
$arg =~ s/set-view=\w+//g;
$arg =~ s/;$//;
$uri .= ($arg) ? "?$arg;" : '?';
if($S->{GID} ne 'Anonymous') { # Only if we're logged in
if($S->{CGI}->param('set-view')=~/Hotlist\|Replies\|Stories\|Diaries/){
$view=$S->{CGI}->param('set-view');
$S->session('hotlist-view',$view);
} else {$view = $S->session('hotlist-view') \|\| 'Hotlist';}
$content="<center><b>\|</b> ";
for ('Hotlist','Replies','Stories','Diaries'){
$content.=(($_ eq $view)?"<b>$_ \|</b> ":"<a
href=\"$uri"."set-view=$_\">$_</a> <b>\|</b> ");
} $content.="</center><br>";
if($view eq 'Hotlist'){
if ($S->{HOTLIST} && $#{$S->{HOTLIST}} >= 0) {
foreach my $sid (@{$S->{HOTLIST}}) {
my $stories = $S->getstories(
{-type => 'fullstory',
-sid => $sid});
my $story = $stories->[0];
my $show = $S->{UI}->{VARS}->{show_new_comments};
my $num_new = $S->new_comments_since_last_seen($sid) if
($show eq "hotlist" \|\| $show eq "all");
my $end_s = ($story->{commentcount} == 1) ? '' : 's';
$content .= qq{|dot| <A CLASS="light"
href="|rootdir|/story/$sid">$story->{title}</a> ($story->{commentcount}
comment$end_s};
$content .= qq{, $num_new new} if defined($num_new);
$content .= qq{)<br />};
}
} else{ $content.="<font size=1>No Hotlisted Stories</font>"; }
}elsif($view eq 'Replies'){
my($results,$comment,$sid);
my ($rv, $sth) = $S->db_select({
WHAT => 'c1.sid,c2.cid,c2.subject',
FROM => 'comments AS c1 LEFT JOIN comments as c2 on c2.sid=c1.sid
AND c2.pid=c1.cid LEFT JOIN viewed_stories ON viewed_stories.sid=c1.sid
AND viewed_stories.uid=c1.uid',
WHERE => qq{c1.uid=$S->{UID} AND c2.sid IS NOT NULL AND c2.cid > viewed_stories.highest_idx}
});
while ($comment = $sth->fetchrow_hashref()) {
$results->{$comment->{'sid'}}.=qq{
|dot|
<a href="|rootdir|/comments/$comment->{'sid'}/$comment->{'cid'}#$comment->{'cid'}"><font size="1">$comment->{'subject'}</font></a><br /> };
}
for $sid (keys %$results){
my $story = $S->getstories({
-type => 'titlesonly',
-sid => $sid
});
$content.=qq{
<a href="|rootdir|/story/$sid"><font
size="2">$story->[0]->{title}</font></a><br />
};
}
$content.=qq{<font size="1">No New Replies to your Comments</font>} if $rv eq '0E0';
}elsif($view eq 'Stories'){
my ($results,$story);
my ($rv, $sth) = $S->db_select({
WHAT => 'stories.title,stories.sid,COUNT(comments.cid) AS commentcount',
FROM => 'stories LEFT JOIN comments ON comments.sid=stories.sid',
WHERE => qq{aid='$S->{NICK}' AND section != 'Diary'},
GROUP_BY => 'stories.sid',
ORDER_BY => 'time DESC'
});
while ($story = $sth->fetchrow_hashref()) {
my $sid=$story->{sid};
my $show = $S->{UI}->{VARS}->{show_new_comments};
my $num_new = $S->new_comments_since_last_seen($sid) if
($show eq "hotlist" \|\| $show eq "all");
my $end_s = ($story->{commentcount} == 1) ? '' : 's';
$content .= qq{|dot| <a class="light"
href="|rootdir|/story/$sid">$story->{title}</a> ($story->{commentcount}
comment$end_s};
$content .= qq{, $num_new new} if defined($num_new);
$content .= qq{)<br />};
}
$content.="<font size=1>You have written no stories</font>" if $rv eq '0E0';
}elsif($view eq 'Diaries'){
my @subscriptions=split(/,/,$S->pref('diary_sub'));
my $author_sql=join("' OR aid='", @subscriptions);
$author_sql="aid='$author_sql'"; # faster than doing a map
my ($rv, $sth) = $S->db_select({
DEBUG=> 0,
WHAT => 'stories.aid,COUNT(stories.sid) AS diarycount',
FROM => 'stories LEFT JOIN viewed_stories ON stories.sid=viewed_stories.sid',
WHERE => qq{($author_sql) AND section='Diary' AND tid LIKE 'diary\%' AND viewed_stories.sid is NULL},
GROUP_BY => 'stories.aid',
ORDER_BY => 'stories.aid'
});
my $authors;
map {$authors->{$_->{aid}}=$_->{diarycount};} @{$sth->fetchall_arrayref({})};
for(@subscriptions){
$content.=qq{[<a href="|rootdir|/diary/$_">x</a>] };
$content.=qq{<a href="|rootdir|/user/$_/diary">$_</a>};
if($authors->{$_}){$content.=qq{ ($authors->{$_} new)};}
$content.=qq{<br />\n};
}
$content.="<font size=1>You have no diary subscriptions</font>" if $#subscriptions==-1;
}else{$content.="This error should never occur.";}
return {title => "$S->{NICK}'s $view", content => $content};
}
Announcement and Discussion
|