Who's Online Box
|
|
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 :)
|
|
Story Views
|
62 Scoop users have viewed this story.
|
|