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
Top Hotlisted Box Boxes
By panner , Section Code []
Posted on Tue Jul 31, 2001 at 12:00:00 PM PST

Recently, on k5 there was a discussion about disabling the Anonymous Hero. That story brought up several threads about the advantages and disadvantags of doing so. This, however, has nothing to do with that.

Instead, it relates to a specifc thread, in which ramses0 brought up his idea for a top hotlisted box. Not wanting to let an opportunity for a perfectly good box slip by, I managed to write one in about 15 minutes. The entire thing in (from what I can tell) working form is below. Just goes to show the power of boxes in Scoop :)

my ($rv,$sth) = $S->db_select({
   FROM     => 'stories, viewed_stories',
   WHAT     => 'stories.sid, title, COUNT(viewed_stories.sid) AS total',
   WHERE    => 'viewed_stories.sid = stories.sid AND hotlisted = 1',
   GROUP_BY => 'viewed_stories.sid',
   ORDER_BY => 'total DESC',
   LIMIT    => '10'
});

my @data;
my $where;
while (my @s = $sth->fetchrow_array) {
   push(@data, \@s);
   $where .= ' OR ' if $where;
   $where .= 'sid = ' . $S->{DBH}->quote($s[0]);
}
$sth->finish;

($rv,$sth) = $S->db_select({
   FROM     => 'comments',
   WHAT     => 'sid, COUNT(sid)',
   WHERE    => $where,
   GROUP_BY => 'sid'
});

my %counts;
while (my $s = $sth->fetchrow_arrayref) {
   $counts{ $s->[0] } = $s->[1];
   my $c = $counts{ $s->[0] };
}
$sth->finish;

my $out;
foreach my $d (@data) {
   my $up = ($d->[2] == 1) ? '' : 's';
   my $c = $counts{$d->[0]} || 0;
   my $cp = ($c == 1) ? '' : 's';
   $out .= qq~%%dot%% <a href="%%rootdir%%/story/$d->[0]">$d->[1]</a> ($c comment$cp) by $d->[2] user$up<br>~;
}

return $out;

I've only tested it locally, but it works for me (famous last words :). It could use some caching, which wouldn't be too difficult, but besides that should be fine. The second select could be removed if comment counts were stored with stories (as they will be soon), but for now that works.

Any problems/suggestions/comments, post below. If any changes are necessary, I'll update this (though hopefully it won't become another never ending story).

< install scoop without root | Scoop 0.8 Released >

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

Login
Make a new account
Username:
Password:

Related Links
· Scoop
· k5
· ramses0
· never ending story
· More on Boxes
· Also by panner

Story Views
  32 Scoop users have viewed this story.

Display: Sort:
Top Hotlisted Box | 3 comments (3 topical, 0 hidden)
Famous last words indeed... (none / 0) (#1)
by janra on Thu Aug 02, 2001 at 12:34:09 AM PST

Well, the box seems to work, but it insists on interpolating the variables instead of leaving them for later.

Every time I save the box, it evaluates the variables - %%dot%% or |dot| changes to what I have in the |dot| block, same with %%rootdir%% or |rootdir|, and the || operator vanishes. If I escape it to \|\| then it becomes || after saving.

Other boxes don't do that; they keep their variables as variables. Does anybody know what's going on?


--
Discuss the art and craft of writing




Check Cashing Oceanside (none / 0) (#2)
by Pervez on Mon Apr 16, 2018 at 01:20:58 AM PST

Attributable to superb web-site. People have been handy using a qualified. Soon we will be happy I actually essentially uncovered a majority of this web-site. With thanks a bunch devised for preaching about. A credit card I highly recommend you presses listed here Check Cashing Oceanside Absolutely everyone along readily obtain first of all brand-new together with the reveal.



construction company NYC (none / 0) (#3)
by Pervez on Sun Apr 07, 2019 at 08:04:59 AM PST

For that fine together with browsing available for associating a lot of computer files about it all extremely basically thrice. Someone established individuals quite a lot alongside dissecting this valuable offer It was observed countless brand-new alongside necessary computer files about that put. Right now, push the construction company NYC Much take cares.



Top Hotlisted Box | 3 comments (3 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