# ================================================================== # Gossamer Forum - Advanced web community # # Website : http://gossamer-threads.com/ # Support : http://gossamer-threads.com/scripts/support/ # CVS Info : # Revision : $Id: Online.pm,v 1.17.2.1 2003/02/09 03:56:10 jagerman Exp $ # # Copyright (c) 2003 Gossamer Threads Inc. All Rights Reserved. # Redistribution in part or in whole strictly prohibited. Please # see LICENSE file for full details. # ================================================================== # package Plugins::GForum::Online; use strict; use GForum qw/:user $DB $USER $IN $CFG/; use GT::Date; sub whos_online { $DB->table('Online')->delete(GT::SQL::Condition->new(online_time => '<' => (time - $CFG->{online_timeout} * 60))); my $cond = new GT::SQL::Condition; $cond->add(user_id_fk => '!=' => '0'); $cond->add(user_invisible => '=' => 0) unless $USER and $USER->{user_status} == ADMINISTRATOR; my $ou = $DB->table('Online' => 'User'); $ou->select_options("ORDER BY online_time DESC"); my $sth = $ou->select($cond); my $users = []; while (my $rec = $sth->fetchrow_hashref) { push @$users, $rec; } my $o = $DB->table('Online'); $o->select_options("ORDER BY online_time DESC"); $sth = $o->select({ user_id_fk => 0 }); my $guests = []; while (my $rec = $sth->fetchrow_hashref) { push @$guests, $rec; } normalize([@$users, @$guests]); my $current_users = scalar(@$users); my $current_guests = scalar(@$guests); my $need_save; if ($current_users > $CFG->{highest_current_users_ever}) { $CFG->{highest_current_users_ever} = $current_users; $CFG->{highest_current_users_ever_time} = time; $need_save++; } if ($current_guests > $CFG->{highest_current_guests_ever}) { $CFG->{highest_current_guests_ever} = $current_guests; $CFG->{highest_current_guests_ever_time} = time; $need_save++; } $CFG->save if $need_save; return; } sub normalize { my $arg = shift; GT::Plugins->dispatch($CFG->{admin_root_path} . '/Plugins/GForum', "online_normalize", sub { return _plg_normalize(@_) }, $arg); } sub _plg_normalize { my $rec = ref $_[0] eq 'ARRAY' ? shift : [shift]; require GForum::User; GForum::User::normalize([grep $_->{user_id_fk}, @$rec]); for (@$rec) { $_->{online_date} = GForum::date($_->{online_time}); my $action = $_->{online_action}; my ($lang, $nomatch) = GForum::language("DO_$action"); if ($nomatch) { $lang = $CFG->{functions}->{$action}->{description} || $action; } # Normally, user_localtime and user_localdate are the _current_ date and timestamp - change that just for the online page to the online time if ($_->{user_id_fk} and ($_->{user_time_offset} || 0) != ($USER->{user_time_offset} || 0)) { $_->{user_localtime} = $_->{online_time} + 60 * 60 * ($_->{user_time_offset} || 0); $_->{user_localtime} -= 60 * 60 * $USER->{user_time_offset} if $USER->{user_time_offset}; $_->{user_localdate} = GForum::date($_->{user_localtime}); } $_->{online_action} = $lang; } $rec; } 1;