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
Who's Online Box Boxes
By panner , Section Code []
Posted on Thu Jul 05, 2001 at 12:00:00 PM PST

For anyone that wants such a thing (and you know you do!), here's a box that displays who's currently online. Note that it's not 100% accurate or anything, it just makes the assumption that anyone thats done something in the last 30 minutes it online.

Update [2001-7-5 17:50:30 by panner]: The box has been updated. See here.

Update [2001-7-6 0:59:58 by panner]: Updated, once again. Some errors started popping up, and those led to bugs that lead back into Scoop, but I think they're all ironed out. If you've gotten this box before now, you should probably get it again.

Update [2001-7-9 23:53:31 by rusty]: The story that never ends! I've edited the box again, to respect a "cloak me" preference, and to do some totaling.

## begin whos_online

return if $S->{UID} == -1;

require Storable;

my ($rv,$sth) = $S->db_select({
   FROM => 'sessions',
   WHAT => 'a_session',
   WHERE => 'last_accessed > DATE_SUB(NOW(), INTERVAL 10 MINUTE)'
});

my %uids;
my $total;
while (my ($s) = $sth->fetchrow_array) {
   my $d = Storable::thaw($s);

   next if $d->{UID} eq '';
   $uids{ $d->{UID} } = 0 unless $uids{ $d->{UID} };
   $total++;
   $uids{ $d->{UID} }++;
}

$sth->finish;
my @sorted = sort { return 1 if $a == -1; return -1 if $b == -1;
return 0; } keys %uids;
return unless @sorted;

$S->user_data(\@sorted); # pre-cache user data

my $out;
my $hidden;
foreach (@sorted) {
   $_ = -1 if $_ eq 'anon';
   if ($S->user_data($_)->{prefs}->{online_cloak}) {
      $hidden++;
      next;
   }
   my $nick = $S->user_data($_)->{nickname};
   $out .= qq~|dot|~;
   $out .= qq~ <A HREF="/?op=user;tool=info;uid=$_">~ unless $_ == -1;
   $out .= ' ' if $_ == -1;
   $out .= $nick;
   $out .= "</A>" unless $_ == -1;
   $out .= " ($uids{$_})" if $uids{$_} > 1;
   $out .= "<BR>\n";
}
if ($hidden) {
   $out .= qq~|dot| Cloaked Users ($hidden)<p>~;
} else {
   $out .= '<p>';
}
$out .= qq~<small>Note: You may cloak yourself from appearing here in your <A HREF="http://www.kuro5hin.org/?op=interface&tool=prefs">Display Preferences</A></small>.~;
return {content => $out, title => "Who's Online? ($total)"};

This should work right away for you, though you may want to do some customizing. First of all, by default, anonymous users won't see this box. If you want them to, comment out the first line ("return if $S->{UID} == -1;") by placing a hash ("#") in front of it.

Second, if you want to tweak the time frame in which a user is online, change the INTERVAL part of the select statment to something like "15 MINUTE" or "1 HOUR".

Finally, the box won't show a bunch of the same user if they're logged in more than once (this includes several anonymous users at once). The previous code made the name of the anonymous user plural if there was more than one logged in, but that doesn't apply any more, so I've changed this paragraph :)

< All right, who broke the hotlist? | More on section perms... >

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

Login
Make a new account
Username:
Password:

Related Links
· Scoop
· Kuro5hin
· here
· More on Boxes
· Also by panner

Story Views
  62 Scoop users have viewed this story.

Display: Sort:
Who's Online Box | 8 comments (8 topical, 1 hidden)
Updated (none / 0) (#1)
by panner on Thu Jul 05, 2001 at 05:45:42 PM PST

For anyone that got this between when it was posted (about 3:20 EDT) and now (about 7:30 EDT), I've updated it. The code is much cleaner, and it works better. Before, it would just display all the names. Now it checks, and if a user has more than one session, it displays a count after their name. Anonymous users use the same code now, so no worries about making them plural.

Also, if you're trying to use it, and get an error about "Missing right curly brace at EOF" (except much longer :), then add a newline to the end of the box, and/or remove the comment at the end. This is a bug in Scoop, which I just put a fix in for, but for now you can work around it.



--
Keith Smiley



still having that problem panner (none / 0) (#2)
by elby on Fri Jul 06, 2001 at 12:03:06 PM PST

somehow I've got some sort of weird data in sessions. I was able to fix the 500 errors by adding this to the code in the while loop that thaws the session data, just after the code is unthawed:
if ($d->{UID} eq '') {
  warn "bad UID returned to whos_online from sessions.\n";
  next;
}
Perhaps this change might be better to add to user data, since it's the one that's actually causing the problem by being passed bad data. Any idea why I'd be getting null uids?

-lb



I added another thing to the box too. (none / 0) (#5)
by Captain_Tenille on Wed Jul 11, 2001 at 05:39:44 PM PST

Sometimes, the first time you go to a page, and nobody's been there during the interval defined, the box won't load. However, if you add these lines:

my $noneonline = "No one currently online (except you just now, of course).
";
{content => $noneonline, title => "Who's Online?"}; return {content => $noneonline, title => "Who's Online?"} unless @sorted;

to the box where it says "return unless @sorted;", it will put a message of your choosing up saying basically that nobody's been there recently.

Hope this is handy to somebody.

---------------
/* You are not expected to understand this. */



cash advance carson (none / 0) (#7)
by Pervez on Sat Apr 21, 2018 at 04:13:34 AM PST

Great submitting! My partner and I in fact really like someone's program listed here. Definitely right now there is an effective subject matter. Thank you quite a bit to have offering added to your thoughts. Currently follow-up cash advance carson Great job!



Best Construction Company (none / 0) (#8)
by Pervez on Sun Apr 07, 2019 at 08:05:46 AM PST

My organization is basically definitely gratified soon after perusing this blog post. That I very seriously enjoy an individual's patience you would probably pay out to specific this valuable approximately! Right now, push the Best Construction Company I really undertake like to look through even more shifts by someone.



Who's Online Box | 8 comments (8 topical, 1 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