Skip to content

Commit

Permalink
If cdt is set, use it as current timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
mattab committed Oct 9, 2014
1 parent 740a7f1 commit 6532bfd
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions core/Tracker/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public function __construct($params, $tokenAuth = false)
$this->params = $params;
$this->tokenAuth = $tokenAuth;
$this->timestamp = time();
$this->enforcedIp = false;

// When the 'url' and referrer url parameter are not given, we might be in the 'Simple Image Tracker' mode.
// The URL can default to the Referrer, which will be in this case
Expand Down Expand Up @@ -319,11 +318,16 @@ public function getParams()

public function getCurrentTimestamp()
{
$cdt = $this->getCustomTimestamp();
if(!empty($cdt)) {
return $cdt;
}
return $this->timestamp;
}

public function getCustomTimestamp()
protected function getCustomTimestamp()
{
// TODO window
$cdt = $this->getParam('cdt');
if (!is_numeric($cdt)) {
$cdt = strtotime($cdt);
Expand Down Expand Up @@ -530,16 +534,7 @@ public function getVisitorId()

public function getIp()
{
$cip = $this->getParam('cip');
if(!empty($cip)) {
if (!$this->isAuthenticated()) {
throw new Exception("You must specify token_auth parameter to use the 'cip' parameter.");
}
$ipString = $cip;
} else {
$ipString = IP::getIpFromHeader();
}

$ipString = $this->getIpString();
$ip = IP::P2N($ipString);
return $ip;
}
Expand Down Expand Up @@ -607,4 +602,21 @@ public function getUserIdHashed($userId)
{
return substr( sha1( $userId ), 0, 16);
}

/**
* @return mixed|string
* @throws Exception
*/
private function getIpString()
{
$cip = $this->getParam('cip');
if (empty($cip)) {
return IP::getIpFromHeader();
}

if (!$this->isAuthenticated()) {
throw new Exception("You must specify token_auth parameter to use the 'cip' parameter.");
}
return $cip;
}
}

0 comments on commit 6532bfd

Please sign in to comment.