*/
public function getVisitTime($objectType)
{
+ if (!WCF::getUser()->userID) {
+ return \TIME_NOW;
+ }
+
$objectTypeID = $this->getObjectTypeID($objectType);
if ($this->userVisits === null) {
- if (WCF::getUser()->userID) {
- $data = UserStorageHandler::getInstance()->getField('trackedUserVisits');
+ $data = UserStorageHandler::getInstance()->getField('trackedUserVisits');
- // cache does not exist or is outdated
- if ($data === null) {
- $sql = "SELECT objectTypeID, visitTime
+ // cache does not exist or is outdated
+ if ($data === null) {
+ $sql = "SELECT objectTypeID, visitTime
FROM wcf1_tracked_visit_type
WHERE userID = ?";
- $statement = WCF::getDB()->prepare($sql);
- $statement->execute([WCF::getUser()->userID]);
- $this->userVisits = $statement->fetchMap('objectTypeID', 'visitTime');
-
- // update storage data
- UserStorageHandler::getInstance()->update(
- WCF::getUser()->userID,
- 'trackedUserVisits',
- \serialize($this->userVisits)
- );
- } else {
- $this->userVisits = @\unserialize($data);
- }
+ $statement = WCF::getDB()->prepare($sql);
+ $statement->execute([WCF::getUser()->userID]);
+ $this->userVisits = $statement->fetchMap('objectTypeID', 'visitTime');
+
+ // update storage data
+ UserStorageHandler::getInstance()->update(
+ WCF::getUser()->userID,
+ 'trackedUserVisits',
+ \serialize($this->userVisits)
+ );
} else {
- $this->userVisits = WCF::getSession()->getVar('trackedUserVisits');
+ $this->userVisits = @\unserialize($data);
}
if (!$this->userVisits) {
$minimum = TIME_NOW - self::LIFETIME;
- if (WCF::getUser()->userID) {
- // Mark everything before the registration date as read.
- $minimum = \max($minimum, WCF::getUser()->registrationDate);
- }
+ // Mark everything before the registration date as read.
+ $minimum = \max($minimum, WCF::getUser()->registrationDate);
return \max($this->userVisits[$objectTypeID] ?? 0, $minimum);
}
*/
public function getObjectVisitTime($objectType, $objectID)
{
- if (WCF::getUser()->userID) {
- $sql = "SELECT visitTime
- FROM wcf1_tracked_visit
- WHERE objectTypeID = ?
- AND objectID = ?
- AND userID = ?";
- $statement = WCF::getDB()->prepare($sql);
- $statement->execute([$this->getObjectTypeID($objectType), $objectID, WCF::getUser()->userID]);
- $row = $statement->fetchArray();
- if ($row) {
- return $row['visitTime'];
- }
- } else {
- if ($visitTime = WCF::getSession()->getVar('trackedUserVisit_' . $this->getObjectTypeID($objectType) . '_' . $objectID)) {
- return $visitTime;
- }
+ if (!WCF::getUser()->userID) {
+ return \TIME_NOW;
+ }
+
+ $sql = "SELECT visitTime
+ FROM wcf1_tracked_visit
+ WHERE objectTypeID = ?
+ AND objectID = ?
+ AND userID = ?";
+ $statement = WCF::getDB()->prepare($sql);
+ $statement->execute([$this->getObjectTypeID($objectType), $objectID, WCF::getUser()->userID]);
+ $row = $statement->fetchArray();
+ if ($row) {
+ return $row['visitTime'];
}
return $this->getVisitTime($objectType);
*/
public function trackObjectVisit($objectType, $objectID, $time = TIME_NOW)
{
- if (WCF::getUser()->userID) {
- // save visit
- $sql = "REPLACE INTO wcf1_tracked_visit
- (objectTypeID, objectID, userID, visitTime)
- VALUES (?, ?, ?, ?)";
- $statement = WCF::getDB()->prepare($sql);
- $statement->execute([$this->getObjectTypeID($objectType), $objectID, WCF::getUser()->userID, $time]);
- } elseif (WCF::getSession()->spiderIdentifier === null) {
- WCF::getSession()->register(
- 'trackedUserVisit_' . $this->getObjectTypeID($objectType) . '_' . $objectID,
- $time
- );
+ if (!WCF::getUser()->userID) {
+ return;
}
+
+ $sql = "REPLACE INTO wcf1_tracked_visit
+ (objectTypeID, objectID, userID, visitTime)
+ VALUES (?, ?, ?, ?)";
+ $statement = WCF::getDB()->prepare($sql);
+ $statement->execute([$this->getObjectTypeID($objectType), $objectID, WCF::getUser()->userID, $time]);
}
/**
*/
public function trackTypeVisit($objectType, $time = TIME_NOW)
{
- if (WCF::getUser()->userID) {
- // save visit
- $sql = "REPLACE INTO wcf1_tracked_visit_type
- (objectTypeID, userID, visitTime)
- VALUES (?, ?, ?)";
- $statement = WCF::getDB()->prepare($sql);
- $statement->execute([$this->getObjectTypeID($objectType), WCF::getUser()->userID, $time]);
-
- // delete obsolete object visits
- $sql = "DELETE FROM wcf1_tracked_visit
- WHERE objectTypeID = ?
- AND userID = ?
- AND visitTime <= ?";
- $statement = WCF::getDB()->prepare($sql);
- $statement->execute([$this->getObjectTypeID($objectType), WCF::getUser()->userID, $time]);
-
- // reset storage
- UserStorageHandler::getInstance()->reset([WCF::getUser()->userID], 'trackedUserVisits');
- } elseif (WCF::getSession()->spiderIdentifier === null) {
- $this->getVisitTime($objectType);
- $this->userVisits[$this->getObjectTypeID($objectType)] = $time;
- WCF::getSession()->register('trackedUserVisits', $this->userVisits);
+ if (!WCF::getUser()->userID) {
+ return;
}
+
+ // save visit
+ $sql = "REPLACE INTO wcf1_tracked_visit_type
+ (objectTypeID, userID, visitTime)
+ VALUES (?, ?, ?)";
+ $statement = WCF::getDB()->prepare($sql);
+ $statement->execute([$this->getObjectTypeID($objectType), WCF::getUser()->userID, $time]);
+
+ // delete obsolete object visits
+ $sql = "DELETE FROM wcf1_tracked_visit
+ WHERE objectTypeID = ?
+ AND userID = ?
+ AND visitTime <= ?";
+ $statement = WCF::getDB()->prepare($sql);
+ $statement->execute([$this->getObjectTypeID($objectType), WCF::getUser()->userID, $time]);
+
+ // reset storage
+ UserStorageHandler::getInstance()->reset([WCF::getUser()->userID], 'trackedUserVisits');
}
/**