public function updateSession() { static $updated = false; if (!$updated) { $global = Ibos::app()->setting->toArray(); if (!Ibos::app()->user->isGuest) { if (isset($global["cookie"]["ulastactivity"])) { $userLastActivity = StringUtil::authCode($global["cookie"]["ulastactivity"], "DECODE"); } else { $userLastActivity = UserUtil::getUserProfile("lastactivity"); MainUtil::setCookie("ulastactivity", StringUtil::authCode($userLastActivity, "ENCODE"), 31536000); } } $onlineTimeSpan = 10; $lastOnlineUpdate = $this->var["lastolupdate"]; $onlineTimeOffset = $lastOnlineUpdate ? $lastOnlineUpdate : $userLastActivity; $allowUpdateOnlineTime = $onlineTimeSpan * 60 < TIMESTAMP - $onlineTimeOffset; if (!Ibos::app()->user->isGuest && $allowUpdateOnlineTime) { $updateStatus = OnlineTime::model()->updateOnlineTime(Ibos::app()->user->uid, $onlineTimeSpan, $onlineTimeSpan, TIMESTAMP); if ($updateStatus === false) { $onlineTime = new OnlineTime(); $onlineTime->uid = Ibos::app()->user->uid; $onlineTime->thismonth = $onlineTimeSpan; $onlineTime->total = $onlineTimeSpan; $onlineTime->lastupdate = $global["timestamp"]; $onlineTime->save(); } $this->setKey("lastolupdate", TIMESTAMP); } $this->var["invisible"] = UserUtil::getUserProfile("invisible"); foreach ($this->var as $key => $value) { if (Ibos::app()->user->hasState($key) && $key != "lastactivity") { $this->setKey($key, Ibos::app()->user->{$key}); } } Ibos::app()->session->update(); if (!Ibos::app()->user->isGuest) { $updateStatusField = array("lastip" => $global["clientip"], "lastactivity" => TIMESTAMP, "lastvisit" => TIMESTAMP, "invisible" => 1); if (21600 < TIMESTAMP - $userLastActivity) { if ($onlineTimeSpan && 43200 < TIMESTAMP - $userLastActivity) { $onlineTime = OnlineTime::model()->fetchByPk(Ibos::app()->user->uid); UserCount::model()->updateByPk(Ibos::app()->user->uid, array("oltime" => round(intval($onlineTime["total"]) / 60))); } MainUtil::setCookie("ulastactivity", StringUtil::authCode(TIMESTAMP, "ENCODE"), 31536000); UserStatus::model()->updateByPk(Ibos::app()->user->uid, $updateStatusField); } } $updated = true; } return $updated; }
<?php OnlineTime::model()->updateThisMonth();