## START hotlist_flex+diaries K5 style ##
## START hotlist_flex+diary ##
# Display Hotlist, Stories and unread replies to user comments
# Version 0.3.1 by hillct
# Version 0.4.0 by hulver
return unless ($S->have_perm('hotlist_flex'));
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';}
my $clear = $S->{CGI}->param('clear');
$content="<center>";
for ('Hotlist','Replies','Stories','Diaries'){
$content.=(($_ eq $view)?"<b>$_</b> \| ":"<a
href=\"$uri"."set-view=$_\" CLASS=\"light\">$_</a> \| ");
}
$content =~ s/\\|\s$//;
$content.="</center>";
if($view eq 'Hotlist'){
$content .= '<p>';
if ($S->{HOTLIST} && $#{$S->{HOTLIST}} >= 0) {
$content .= qq{
<TABLE WIDTH="100%" BORDER=0 CELLPADDING=1 CELLSPACING=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{
<TR>
<TD VALIGN="top"><A HREF="|rootdir|/hotlist/remove/$sid/displaystory" CLASS="light">|hotlist_remove_link|</a></td><TD>|norm_font|<A HREF="|rootdir|/story/$sid" CLASS="light">$story->{title}</a><BR>($story->{commentcount} comment$end_s};
$content .= ", <B>$num_new</b> new" if defined($num_new);
$content .= qq{)|norm_font_end|</td>
</tr>};
}
$content .= qq{
</table>};
} else{ $content.="<font size=1>No Hotlisted Stories</font>"; }
}elsif($view eq 'Replies'){
$content .= '<p>';
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.date > DATE_SUB(NOW(), INTERVAL 14 DAY) AND (c2.cid > viewed_stories.highest_idx or viewed_stories.highest_idx is null)}
});
while ($comment = $sth->fetchrow_hashref()) {
$results->{$comment->{'sid'}}.=qq{
<br>|dot|
<a CLASS="light" href="|rootdir|/comments/$comment->{'sid'}/$comment->{'cid'}#$comment->{'cid'}"><font size="1">$comment->{'subject'}</font></a> };
}
my $reply_txt;
for $sid (keys %$results){
next if ($S->_check_story_mode($sid) == -1);
next unless($S->_does_poll_exist($sid) \|\| $S->have_section_perm('norm_read_comments',$S->_get_story_section( $sid )) );
my $title;
my $path;
if( $S->_does_poll_exist($sid) ) {
$title = $S->get_poll_hash($sid)->{question};
$path = "/poll/";
} else {
$title = $S->_get_story_title($sid);
$path = "/story/";
}
$reply_txt .= qq{
<p>
<a CLASS="light" href="|rootdir|$path$sid"><font
size="2">$title</font></a>
$results->{$sid}
</p>
};
}
$content .= $reply_txt \|\| qq{<font size="1">No New Replies to your Comments</font>};
}elsif($view eq 'Stories'){
$content.='<p>';
my ($results,$story);
my $uid = $S->get_uid_from_nick($S->{NICK});
my ($rv, $sth) = $S->db_select({
WHAT => 'stories.title,stories.sid,stories.section,COUNT(comments.cid) AS commentcount',
FROM => 'stories LEFT JOIN comments ON comments.sid=stories.sid',
#WHERE => qq{aid='$S->{NICK}' AND time >= DATE_SUB(NOW(), INTERVAL 30 DAY) AND displaystatus != '-1'},
WHERE => qq{aid='$uid' AND time >= DATE_SUB(NOW(), INTERVAL 30 DAY) AND displaystatus != '-1'},
GROUP_BY => 'stories.sid',
ORDER_BY => 'time DESC'
});
my $linknick = $S->urlify($S->{NICK});
my $stories_text;
my ($story_count, $diary_count);
while ($story = $sth->fetchrow_hashref()) {
my $sid=$story->{sid};
if ($story->{section} eq 'Diary') {
$diary_count++;
} elsif ($story->{section} ne 'advertisements') {
$story_count++;
}
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';
$stories_text .= qq{
<TR>
<TD VALIGN="top">|dot|</td>
<td valign="top">|norm_font|<a class="light" href="|rootdir|/story/$sid">$story->{title}</a><br>($story->{commentcount}
comment$end_s};
$stories_text .= qq{, <b>$num_new</b> new} if defined($num_new);
$stories_text .= qq{)|norm_font_end|</td></tr>};
}
if ($stories_text) {
$content .= qq{
<TABLE WIDTH="100%" BORDER=0 CELLPADDING=1 CELLSPACING=0>
$stories_text
</table>
<p>
Older: <a CLASS="light" href="|rootdir|/?op=search&offset=$story_count&old_count=0&type=author&topic=§ion=&string=$linknick&count=30&next=Next+Page+%3E%3E">Stories</a>,
<a CLASS="light" href="|rootdir|/?op=search&offset=$diary_count&old_count=0&type=diary_by&topic=§ion=&string=$linknick&count=30&next=Next+Page+%3E%3E">Diaries</a>};
} else {
$content.="<font size=1>You have written no stories in the last 30 days.</font>";
}
#"
}elsif($view eq 'Diaries'){
$content.='<p>';
my $clear_link = $uri . "clear=_all_";
$content.=qq{<center><b><a href="$clear_link" class="light">Clear All</a></b></center><p>};
my @subscriptions=split(/,/,$S->pref('diary_sub'));
@subscriptions=sort { lc($a) cmp lc($b) } @subscriptions;
my $authors;
my @sids;
my $titles;
my $uid;
my $where;
foreach my $auth (@subscriptions) {
$where .= ", " if ($where);
$where .= $S->{DBH}->quote($auth);
}
$where = "users.nickname in (" . $where . ")";
my ($rv, $sth) = $S->db_select({
DEBUG=> 0,
WHAT => 'users.nickname, sid, title',
FROM => 'stories inner join users on aid=uid',
WHERE => qq{$where AND time >= DATE_SUB(NOW(), INTERVAL 30 DAY) AND section='Diary'},
ORDER_BY => 'time desc'
});
while (my ($auth, $sid, $title) = $sth->fetchrow()) {
next if (defined $S->story_last_seen($sid));
if (($clear eq $auth) \|\| ($clear eq '_all_')) {
$S->update_seen_if_needed($sid);
next;
}
push @sids, $sid;
push @{$authors->{$auth}}, $sid;
if (length($title) > 25) {
$title =~ s/^(.{22}).*$/$1.../;
}
$titles->{$sid} = $title;
}
$sth->finish();
foreach my $author (@subscriptions) {
my $l_author = $S->urlify($author);
my $new = 0;
#warn "Author is $author, new is $new\n";
$content.=qq{<b><a CLASS="light" href="|rootdir|/diary/$l_author">|hotlist_remove_link|</a> };
$content.=qq{<a CLASS="light" href="|rootdir|/user/$l_author/diary">$author</a></b>};
my $title_links;
foreach my $posted_sid (@{$authors->{$author}}) {
#warn "SID is $posted_sid, New is $new\n";
$new++;
$title_links .= qq{<br>|dot| <a CLASS="light" href="|rootdir|/story/$posted_sid">$titles->{$posted_sid}</a>};
}
if ($new) {
$clear_link = $uri . "clear=$l_author";
$content .= qq{ (<b>$new</b> new) (<a href="$clear_link" class="light">clear</a>) |smallfont|$title_links|smallfont_end|<br>};
} else {
$content .= qq{ (0 new)<br>};
}
}
$content.="<font size=1>You have no diaries on your watch list</font>" if $#subscriptions==-1;
}else{$content.="This error should never occur.";}
return {title => "$S->{NICK}'s $view", content => $content};
}
## END hotlist_flex+diary ##
## END hotlist_flex+diaries K5 style ##