Piwik\Tracker\Request::getCustomTimestamp PHP Method

getCustomTimestamp() protected method

protected getCustomTimestamp ( )
    protected function getCustomTimestamp()
    {
        if (!$this->hasParam('cdt')) {
            return false;
        }
        $cdt = $this->getParam('cdt');
        if (empty($cdt)) {
            return false;
        }
        if (!is_numeric($cdt)) {
            $cdt = strtotime($cdt);
        }
        if (!$this->isTimestampValid($cdt, $this->timestamp)) {
            Common::printDebug(sprintf("Datetime %s is not valid", date("Y-m-d H:i:m", $cdt)));
            return false;
        }
        // If timestamp in the past, token_auth is required
        $timeFromNow = $this->timestamp - $cdt;
        $isTimestampRecent = $timeFromNow < $this->customTimestampDoesNotRequireTokenauthWhenNewerThan;
        if (!$isTimestampRecent) {
            if (!$this->isAuthenticated()) {
                $message = sprintf("Custom timestamp is %s seconds old, requires &token_auth...", $timeFromNow);
                Common::printDebug($message);
                Common::printDebug("WARN: Tracker API 'cdt' was used with invalid token_auth");
                throw new InvalidRequestParameterException($message);
            }
        }
        return $cdt;
    }