/** * Save the geolocation container to cookie */ protected function saveCookie() { $arrDuration = deserialize($GLOBALS['TL_CONFIG']['geo_cookieDuration']); if (!is_array($arrDuration) || count($arrDuration) != 3) { $arrDuration = array(5, 1, 1); } $this->objUserGeolocation->setIP(preg_replace("/\\.\\d?\\d?\\d?\$/", ".0", $this->objUserGeolocation->getIP())); // Make a string from container $strCookieValue = 'GeolocationContainerV2'; $strCookieValue .= '|'; $strCookieValue .= implode(",", $this->objUserGeolocation->getCountriesShort()); $strCookieValue .= '|'; $strCookieValue .= $this->objUserGeolocation->getIP(); $strCookieValue .= '|'; $strCookieValue .= $this->objUserGeolocation->getLat(); $strCookieValue .= '|'; $strCookieValue .= $this->objUserGeolocation->getLon(); $strCookieValue .= '|'; $strCookieValue .= $this->objUserGeolocation->getTrackRunning(); $strCookieValue .= '|'; $strCookieValue .= $this->objUserGeolocation->getTrackType(); $strCookieValue .= '|'; $strCookieValue .= $this->objUserGeolocation->isTracked(); $strCookieValue .= '|'; $strCookieValue .= $this->objUserGeolocation->isFailed(); $strCookieName = $GLOBALS['TL_CONFIG']['geo_cookieName'] ? $GLOBALS['TL_CONFIG']['geo_cookieName'] : 'geolocation'; try { // User another lifetime for cookies if the geolocation failed or is deactivated if ($this->objUserGeolocation->isFailed() == true || $this->objUserGeolocation->getTrackType() == GeolocationContainer::LOCATION_NONE) { $this->setCookie($strCookieName, $strCookieValue, time() + 60 * 60 * 24 * intval($arrDuration[2])); } elseif ($this->objUserGeolocation->getTrackType() == GeolocationContainer::LOCATION_BY_USER) { $this->setCookie($strCookieName, $strCookieValue, time() + 60 * 60 * 24 * intval($arrDuration[1])); } else { $this->setCookie($strCookieName, $strCookieValue, time() + 60 * 60 * 24 * intval($arrDuration[0])); } } catch (\Exception $exc) { // Nothing to do. } }