Description:
This is version 0.2.3 of the hotlist_flex box which in addition to the treditonal hotlist display, also allos the user to view a predefined hotlist of that user's own stories, as well as (most significantly) displaying a list of stories on which the user commented and to which comments there have been replies made. The display mode of the box is stored in the user's session hash.
Box Code:
### Start hotlist_flex Box ###
# Display Hotlist, Stories and unread replies to user comments
# Version 0.2.3 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/){
$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'){
$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>
$results->{$sid}
};
}
$content.="<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}'},
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';
}else{$content.="This error should never occur.";}
return {title => "$S->{NICK}'s $view", content => $content};
}
### End hotlist_flex Box ###
Announcement and Discussion
|