user = $user; $pdo = sfDatabaseSessionStorage::$pdo; $blog = blogStore::$blogId; $time = time(); if ($user->isAuthenticated()) { $id = $pdo->quote($user->getUserId()); $fullname = $pdo->quote($user->getUserFullname()); $pdo->exec("insert into online_user values($blog, $id, $fullname, $time) on duplicate key update ou_time=$time"); } else { $crc = crc32(myUtility::getRealIpAddr()); $pdo->exec("insert into online_guest values($blog, $crc, $time) on duplicate key update og_time=$time"); } } public function removeCurrentUser() { if ($this->user) { if ($this->user->isAuthenticated()) { sfDatabaseSessionStorage::$pdo->exec('delete from online_user where ou_userid = '.$this->user->getUserId()); } else { $crc = crc32(myUtility::getRealIpAddr()); sfDatabaseSessionStorage::$pdo->exec('delete from online_guest where og_crc = '.$crc); } } } public function getOnlineUsers($baseLink, &$numGuest, &$numUser, $maxNum=100) { $ret = ''; $bl_id = blogStore::$blogId; $pdo = sfDatabaseSessionStorage::$pdo; $numGuest = $pdo->query("select count(*) from online_guest where og_blog=$bl_id")->fetchColumn(); $numUser = $pdo->query("select count(*) from online_user where ou_blog=$bl_id")->fetchColumn(); $stmt = $pdo->query("select ou_userid, ou_user_fullname from online_user where ou_blog=$bl_id limit $maxNum"); while ($row = $stmt->fetch(PDO::FETCH_NUM)) { $ret .= '
  • '.link_to($row[1], $baseLink.$row[0]).'
  • '; } return $ret; } public function getAllOnlineUsers($baseLink, &$numGuest, &$numUser, $maxNum=100) { $ret = ''; $bl_id = blogStore::$blogId; $pdo = sfDatabaseSessionStorage::$pdo; $numGuest = $pdo->query("select count(*) from sessions where ss_userid=0")->fetchColumn(); $numUser = $pdo->query("select count(*) from sessions where ss_userid>0")->fetchColumn(); $stmt = $pdo->query("select ss_userid, ss_user_fullname from sessions where ss_userid>0 limit $maxNum"); $order = 0; while ($row = $stmt->fetch(PDO::FETCH_NUM)) { if (++$order == 10) $ret .=" << >> "; } return $ret; } }