* @since Version 2.0 */ class cUsersOnline { public $module; private $sUser; // Session class object public $suoTimeout = 300; // 5 mins in ms const CRON_ID = 7; /** * Class constructor * * @author Mareks Keišs * @category sysUsersOnline Controller * @param bool $bSetMeOnline - set current user online * @param bool $bIsCmsSide - cms side passed */ public function __construct($bSetMeOnline = true, $bIsCmsSide = false){ $this->sUser = new cSession(($bIsCmsSide ? sysUsersController::USER_SESSION_KEY : pubUsersController::USER_SESSION_KEY)); $this->module = new cUsersOnlineModule($bIsCmsSide); // Set current user online if set to true if($bSetMeOnline) $this->setMeOnline(); } /** * Function to check if log needed or not - and log online user * * @author Mareks Keišs * @category sysUsersOnline Controller * @return array of data */ public function setMeOnline(){ if(!($this->sUser->suser || $this->sUser->noSuOnline)){ if( 0 || !$this->sUser->suo_time || $this->sUser->suo_time < time() - $this->suoTimeout || $this->sUser->id <> $this->sUser->suo_ser_d ){ $this->sUser->suo_ser_d = $this->sUser->id; $this->sUser->suo_time = $t = time(); $md5Key = md5($this->sUser->id . '_' . session_id()); return $this->module->addOnlineMe($this->sUser->id, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'], $md5Key, $t); } } return false; } /** * Function to get online user count * * @author Mareks Keišs * @category sysUsersOnline Controller * @return array of data */ public function getOnlineCount(){ $this->setMeOnline(); if($onlineCount = $this->module->getOnlineCount($this->suoTimeout, array($this->sUser->id => $_SERVER['REMOTE_ADDR'], self::CRON_ID => null))){ // Exclude myself return $onlineCount; } return 0; } /** * Function to get online user data * * @author Mareks Keišs * @category sysUsersOnline Controller * @return array of data */ public function getOnlineUsers(){ $this->setMeOnline(); if(!!($data = $this->module->getOnlineUserData($this->suoTimeout, array($this->sUser->id => $_SERVER['REMOTE_ADDR'], self::CRON_ID => null)))){ // Exclude myself return $data; } return false; } }