XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
online.php
Go to the documentation of this file.
1 <?php
19 defined('XOOPS_ROOT_PATH') or die('Restricted access');
20 
30 {
37  var $db;
38 
44  function XoopsOnlineHandler(&$db)
45  {
46  $this->db =& $db;
47  }
48 
60  function write($uid, $uname, $time, $module, $ip)
61  {
62  $uid = intval($uid);
63  if ($uid > 0) {
64  $sql = "SELECT COUNT(*) FROM " . $this->db->prefix('online') . " WHERE online_uid=" . $uid;
65  } else {
66  $sql = "SELECT COUNT(*) FROM " . $this->db->prefix('online') . " WHERE online_uid=" . $uid . " AND online_ip='" . $ip . "'";
67  }
68  list ($count) = $this->db->fetchRow($this->db->queryF($sql));
69  if ($count > 0) {
70  $sql = "UPDATE " . $this->db->prefix('online') . " SET online_updated=" . $time . ", online_module = " . $module . " WHERE online_uid = " . $uid;
71  if ($uid == 0) {
72  $sql .= " AND online_ip='" . $ip . "'";
73  }
74  } else {
75  $sql = sprintf("INSERT INTO %s (online_uid, online_uname, online_updated, online_ip, online_module) VALUES (%u, %s, %u, %s, %u)", $this->db->prefix('online'), $uid, $this->db->quoteString($uname), $time, $this->db->quoteString($ip), $module);
76  }
77  if (!$this->db->queryF($sql)) {
78  return false;
79  }
80  return true;
81  }
82 
90  function destroy($uid)
91  {
92  $sql = sprintf("DELETE FROM %s WHERE online_uid = %u", $this->db->prefix('online'), $uid);
93  if (!$result = $this->db->queryF($sql)) {
94  return false;
95  }
96  return true;
97  }
98 
106  function gc($expire)
107  {
108  $sql = sprintf("DELETE FROM %s WHERE online_updated < %u", $this->db->prefix('online'), time() - intval($expire));
109  $this->db->queryF($sql);
110  }
111 
118  function getAll($criteria = null)
119  {
120  $ret = array();
121  $limit = $start = 0;
122  $sql = 'SELECT * FROM ' . $this->db->prefix('online');
123  if (is_object($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
124  $sql .= ' ' . $criteria->renderWhere();
125  $limit = $criteria->getLimit();
126  $start = $criteria->getStart();
127  }
128  $result = $this->db->query($sql, $limit, $start);
129  if (!$result) {
130  return false;
131  }
132  while ($myrow = $this->db->fetchArray($result)) {
133  $ret[] = $myrow;
134  unset($myrow);
135  }
136  return $ret;
137  }
138 
144  function getCount($criteria = null)
145  {
146  $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('online');
147  if (is_object($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
148  $sql .= ' ' . $criteria->renderWhere();
149  }
150  if (!$result = $this->db->query($sql)) {
151  return false;
152  }
153  list ($ret) = $this->db->fetchRow($result);
154  return $ret;
155  }
156 }
157 ?>