Пример #1
0
 protected function compile()
 {
     if (REQUEST_TOKEN == "REQUEST_TOKEN") {
         $strRequestToken = "";
     } else {
         $strRequestToken = REQUEST_TOKEN;
     }
     $strJS = "<script type=\"text/javascript\">";
     $strJS .= "window.addEvent('domready', function(){";
     $strJS .= "if (typeof(RunGeolocation) != 'undefined') RunGeolocation.addInfoElement('geoInfo_" . $this->id . "');";
     $strJS .= "GeoUpdater.setMessages({";
     $strJS .= "changing:'{$GLOBALS['TL_LANG']['MSC']['geo_msc_Changing']}',";
     $strJS .= "noConnection:'{$GLOBALS['TL_LANG']['ERR']['geo_err_NoConnection']}',";
     $strJS .= "});";
     $strJS .= "GeoUpdater.setRequestToken('" . $strRequestToken . "');";
     $strJS .= "GeoUpdater.setSession('" . session_id() . "');";
     $strJS .= "});";
     $strJS .= "</script>";
     // Add location object
     $this->Template->UserGeolocation = Geolocation::getInstance()->getUserGeolocation();
     // Add JS
     $this->Template->strJS = $strJS;
     $this->Template->strId = $this->id;
     $this->Template->lang = $GLOBALS['TL_LANGUAGE'];
     $this->Template->geoChosen = $this->geo_chosen;
 }
Пример #2
0
 public function beforeSave()
 {
     // Let's Geocode the postcode
     $geo = Geolocation::getInstance();
     $location = $geo->geoLocate($this->postcode);
     $this->lat = $location["lat"];
     $this->lng = $location["lng"];
 }
 /**
  * Check for redirects.
  * 
  * @return void
  */
 public function geolocationRedirect()
 {
     // Load current url.
     $strUrl = $this->getCurrentUrl();
     // Seach for an entry in the database.
     $strSQL = 'SELECT *
                 FROM tl_geolocation_redirect
                 WHERE published=?
                     AND ( (rgxp="" AND url=?) OR (rgxp="1" AND ? REGEXP url) )
                     AND ( host=? OR CONCAT("www.",host)=? OR host="" )
                 ORDER BY priority, url';
     $objTarget = Database::getInstance()->prepare($strSQL)->limit(1)->execute('1', $strUrl, $strUrl, $this->Environment->host, $this->Environment->host);
     // Check if we have some values.
     if ($objTarget->numRows == 0) {
         $this->log(vsprintf('Could not found a match for: %s', $strUrl), __CLASS__ . ' | ' . __FUNCTION__, TL_GENERAL);
         return;
     }
     // Chose a jump to method. Direct per page id or pattern url.
     if ($objTarget->jumpToType == 'jumpToUrl') {
         $targetURL = $objTarget->jumpToUrl;
         // replace regex-params
         if ($objTarget->rgxp == '1' && preg_match("~{$objTarget->url}~i", $strUrl)) {
             preg_match("~{$objTarget->url}~i", $strUrl, $arrErg);
             foreach ($arrErg as $i => $param) {
                 $targetURL = str_replace('$' . $i, $param, $targetURL);
             }
         }
         // TL knows only "303: see other", no "307: temporary"
         $type = $objTarget->type == '301' ? '301' : '303';
         // Get all countries.
         $arrCountries = deserialize($objTarget->countries, true);
         Geolocation::getInstance()->setUserGeolocationByShortCountries($arrCountries);
         // Redirect to page
         $this->redirect($targetURL, $type);
     } else {
         if ($objTarget->jumpToType == 'jumpTo') {
             // Search for the jumpTo page.
             $objJumpTo = Database::getInstance()->prepare("SELECT id, alias FROM tl_page WHERE id=?")->limit(1)->execute($objTarget->jumpTo);
             // Check if we have a jumpTo page.
             if ($objJumpTo->numRows == 0) {
                 $this->log(vsprintf('Could not found the jump to page for: "%s" with ID: %s ', $strUrl, $objTarget->jumpTo), __CLASS__ . ' | ' . __FUNCTION__, TL_ERROR);
                 return;
             }
             // TL knows only "303: see other", no "307: temporary".
             $type = $objTarget->type == '301' ? '301' : '303';
             // set objPage cause we need the rootLanguage there for generateFrontendUrl
             $GLOBALS['objPage'] = $this->getPageDetails($objJumpTo->id);
             // Get all countries.
             $arrCountries = deserialize($objTarget->countries, true);
             Geolocation::getInstance()->setUserGeolocationByShortCountries($arrCountries);
             // Redirect.
             $this->redirect($this->generateFrontendUrl($objJumpTo->row()), $type);
         }
     }
 }
Пример #4
0
 public function checkPermission($objElement, $strBuffer)
 {
     //check if geoprotection is enabled
     if ($objElement->gp_protected && TL_MODE != 'BE') {
         $objGeo = Geolocation::getInstance()->getUserGeolocation();
         $country = $objGeo->getCountryShort() != '' ? $objGeo->getCountryShort() : 'xx';
         //the geoContainser has a country and matches one of the group countries
         if (in_array($country, deserialize($objElement->gp_group_countries))) {
             if ($objElement->gp_mode == "gp_show") {
                 return in_array($country, deserialize($objElement->gp_countries)) ? $strBuffer : '';
             }
             return in_array($country, deserialize($objElement->gp_countries)) ? '' : $strBuffer;
         } else {
             //use Fallback
             return $objElement->gp_mode == "gp_show" && $objElement->gp_fallback || $objElement->gp_mode != "gp_show" && !$objElement->gp_fallback ? $strBuffer : '';
         }
     }
     return $strBuffer;
 }