Scoop -- the swiss army chainsaw of content management
Front Page · Everything · News · Code · Help! · Wishlist · Project · Scoop Sites · Dev Notes · Latest CVS changes · Development Activities
Updated hotlist_flex box Bugs
By hulver , Section Code []
Posted on Mon Dec 08, 2003 at 12:00:00 PM PST
I've done some changes to the hotlist_flex box from the SBE.

1. To make it actually work with the changes to the story table.
2. Steal k5's "Clear all" and "Clear user" functions.
3. Sort it in name order
4. Speed the diary hotlist up a bit. This was doing at least one query for every user on the hotlist. I've changed it to do only one query.

Update [2003-12-11 23:8:16 by Mostly Harmless]: applied a patch from hulver so if the box is now broken, it's probably my fault :-)

## 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 ##

< Scoop: The need for usablity | Getting parameters in 'story_summary' >

Menu
· create account
· faq
· search
· report bugs
· Scoop Administrators Guide
· Scoop Box Exchange

Login
Make a new account
Username:
Password:

Related Links
· patch from hulver
· More on Bugs
· Also by hulver

Story Views
  52 Scoop users have viewed this story.

Display: Sort:
Updated hotlist_flex box | 9 comments (9 topical, 0 hidden)
the diaries DB query (none / 0) (#1)
by janra on Mon Dec 08, 2003 at 07:00:41 AM PST

instead of WHERE users.nickname = nick1 OR users.nickname = nick2 OR ...

try WHERE users.nickname IN nick1, nick2, nick3, ...

Not entirely sure, but I think it's faster. It's definitely cleaner though :-)

--
Discuss the art and craft of writing




Hmmm... (none / 0) (#3)
by Vladinator on Tue Dec 16, 2003 at 02:39:03 PM PST

I updated both of my existing sites hotflex boxes with this new version, and the box disapeared. :-) Is it correct as patched?

"Even Marylin Monroe was a man, but this tends to get overlooked by our motherfixated overweight sexist media." -- Robyn Hitchcock and the Egyptians


ack (5.00 / 1) (#8)
by slinberg on Mon Dec 22, 2003 at 03:22:00 PM PST

$content="<center>";

IT BURNS USSSSSSSSSSSS

Seriously, everybody, it would be great if we could start coding better HTML in all this.  The bad HTML in Scoop is a tremendous and difficult problem, and the more of it there is, the more there will be to fix later.  XHTML 1.1 and basic stylesheets can coexist within a 4-transitional framework.

At some point, we're going to have to come up with some HTML standards and stick to them, if we want to fix this problem.




Updated hotlist_flex box | 9 comments (9 topical, 0 hidden)
Display: Sort:

Hosted by ScoopHost.com Powered by Scoop
All trademarks and copyrights on this page are owned by their respective companies. Comments are owned by the Poster. The Rest © 1999 The Management

create account | faq | search