XOOPS  2.6.0
online.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
13 
25 {
27  $online_handler = $xoops->getHandlerOnline();
28  mt_srand((double)microtime() * 1000000);
29  // set gc probabillity to 10% for now..
30  if (mt_rand(1, 100) < 11) {
31  $online_handler->gc(300);
32  }
33  if ($xoops->isUser()) {
34  $uid = $xoops->user->getVar('uid');
35  $uname = $xoops->user->getVar('uname');
36  } else {
37  $uid = 0;
38  $uname = '';
39  }
40  if ($xoops->isModule()) {
41  $online_handler->write($uid, $uname, time(), $xoops->module->getVar('mid'), $_SERVER['REMOTE_ADDR']);
42  } else {
43  $online_handler->write($uid, $uname, time(), 0, $_SERVER['REMOTE_ADDR']);
44  }
45  $onlines = $online_handler->getAll(null, null, false, false);
46  if (false != $onlines) {
47  $total = count($onlines);
48  $block = array();
49  $guests = 0;
50  $members = '';
51  for ($i = 0; $i < $total; ++$i) {
52  if ($onlines[$i]['online_uid'] > 0) {
53  $members .= ' <a href="' . \XoopsBaseConfig::get('url') . '/userinfo.php?uid=' . $onlines[$i]['online_uid'] . '" title="' . $onlines[$i]['online_uname'] . '">' . $onlines[$i]['online_uname'] . '</a>,';
54  } else {
55  ++$guests;
56  }
57  }
58  $block['online_total'] = sprintf(XoopsLocale::F_USERS_ONLINE, $total);
59  if ($xoops->isModule()) {
60  $mytotal = $online_handler->getCount(new Criteria('online_module', $xoops->module->getVar('mid')));
61  $block['online_total'] .= ' (' . sprintf(XoopsLocale::F_USERS_BROWSING, $mytotal, $xoops->module->getVar('name')) . ')';
62  }
63  $block['lang_members'] = XoopsLocale::MEMBERS;
64  $block['lang_guests'] = XoopsLocale::GUESTS;
65  $block['online_names'] = $members;
66  $block['online_members'] = $total - $guests;
67  $block['online_guests'] = $guests;
68  $block['lang_more'] = XoopsLocale::MORE;
69  return $block;
70  } else {
71  return false;
72  }
73 }
$i
Definition: dialog.php:68
const GUESTS
Definition: en_US.php:457
static getInstance()
Definition: Xoops.php:160
const MEMBERS
Definition: en_US.php:833
$_SERVER['REQUEST_URI']
const F_USERS_BROWSING
Definition: en_US.php:443
b_system_online_show()
Definition: online.php:24
$xoops
Definition: admin.php:25
static get($name)
if(!$xoops->isUser()) $uid
Definition: index.php:31
const F_USERS_ONLINE
Definition: en_US.php:445
$uname
Definition: checklogin.php:37