Description:
This box updates its cache every 30 min of whose been viewing the site. It shows whose online, with a link to their user info. Anonymous users are listed in bulk ( i.e. Anonymous(50) ). Users can cloak themselves from this box via their display preferences page from their user_box
Box Code:
## begin whos_online
return if $S->{UID} == -1;
if (($S->cache->{CACHE}->{WHOBOX}->{TIME}) &&
($S->cache->{CACHE}->{WHOBOX}->{TIME} < (time + 120))) {
return {
content => $S->cache->{CACHE}->{WHOBOX}->{CONTENT},
title => $S->cache->{CACHE}->{WHOBOX}->{TITLE}
};
}
require Storable;
my $interval = 5;
my ($rv,$sth) = $S->db_select({
FROM => 'sessions',
WHAT => 'a_session',
WHERE => "last_accessed > DATE_SUB(NOW(), INTERVAL $interval MINUTE)",
ORDER_BY => 'last_accessed DESC',
DEBUG => 0
});
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;
my $list;
my $max_show = 75;
foreach (@sorted) {
$_ = -1 if $_ eq 'anon';
if ($S->user_data($_)->{prefs}->{online_cloak}) {
$hidden++;
next;
}
next unless (($list < $max_show) || $_ == -1);
$list++ unless $_ == -1;
my $nick = $S->user_data($_)->{nickname};
my $linknick = $S->urlify($nick);
$out .= qq~%%dot%%~;
$out .= qq~ <A HREF="%%rootdir%%/user/$linknick">~ unless $_ == -1;
$out .= ' ' if $_ == -1;
$out .= $nick;
$out .= "</A>" unless $_ == -1;
$out .= " ($uids{$_})" if $uids{$_} > 1;
$out .= "<BR>\n";
}
if ($total > ($list + $hidden + $uids{-1})) {
my $more = ($total - $list - $hidden - $uids{-1});
$out .= qq~%%dot%% ...and $more more. :-)<br>~;
}
if ($hidden) {
$out .= qq~%%dot%% Cloaked Users ($hidden)<p>~;
} else {
$out .= '<p>';
}
$out .= qq~<small>
$interval minute interval.<br>You may cloak yourself from appearing here in your <A HREF="%%rootdir%%/interface/prefs">Display Preferences</A></small>.~;
my $title = "Who's Online? ($total)";
$S->cache->{CACHE}->{WHOBOX}->{CONTENT} = $out;
$S->cache->{CACHE}->{WHOBOX}->{TITLE} = $title;
$S->cache->{CACHE}->{WHOBOX}->{TIME} = time;
return {content => $out, title => $title};
|