/**
  * Plugin main function.
  *
  * @param string $strContent The content given from Typo3
  * @param mixed  $arConf     The Typo3 configuration for this plugin
  *
  * @return string The content after this plugin.
  */
 public function main($strContent, $arConf)
 {
     $ip = $this->getIp();
     $geoip = Tx_Contexts_Geolocation_Adapter::getInstance($ip);
     $data = $geoip->getLocation();
     return $this->pi_wrapInBaseClass($strContent . $this->renderForm($ip) . $this->renderMap($ip, $data) . $this->renderData($ip, $data));
 }
 /**
  * Detects the user's IP position and checks if it is within
  * the given radius.
  *
  * @return boolean True if the user's position is within the given
  *                 radius around the configured position.
  */
 public function matchDistance()
 {
     try {
         $geoip = Tx_Contexts_Geolocation_Adapter::getInstance($_SERVER['REMOTE_ADDR']);
         $bUnknown = (bool) $this->getConfValue('field_unknown');
         $arPosition = $geoip->getLocation();
         if ($arPosition === false) {
             //unknown position
             return $bUnknown;
         }
         if ($arPosition['latitude'] == 0 && $arPosition['longitude'] == 0) {
             //broken position
             return $bUnknown;
         }
         $strPosition = trim($this->getConfValue('field_position'));
         $strMaxDistance = trim($this->getConfValue('field_distance'));
         if ($strPosition == '' || $strMaxDistance == '') {
             //nothing configured? no match.
             return false;
         }
         list($reqLat, $reqLong) = explode(',', $strPosition);
         $flDistance = $this->getDistance($reqLat, $reqLong, $arPosition['latitude'], $arPosition['longitude']);
         return $flDistance <= (double) $strMaxDistance;
     } catch (Tx_Contexts_Geolocation_Exception $exception) {
         return false;
     }
 }
 /**
  * Detects the current continent and matches it against the list
  * of allowed continents
  *
  * @return boolean True if the user's continent is in the list of
  *                 allowed continents, false if not
  */
 public function matchContinents()
 {
     try {
         $strContinents = trim($this->getConfValue('field_continents'));
         if ($strContinents == '') {
             //nothing configured? no match.
             return false;
         }
         $geoip = Tx_Contexts_Geolocation_Adapter::getInstance($_SERVER['REMOTE_ADDR']);
         $arContinents = explode(',', $strContinents);
         $strContinent = $geoip->getContinentCode();
         if ($strContinent === false && in_array('*unknown*', $arContinents)) {
             return true;
         }
         if ($strContinent !== false && in_array($strContinent, $arContinents)) {
             return true;
         }
     } catch (Tx_Contexts_Geolocation_Exception $exception) {
     }
     return false;
 }
 /**
  * Check if the extension has been setup properly.
  * Renders a flash message when geoip is not available.
  *
  * @return void
  */
 public function setupCheck()
 {
     try {
         Tx_Contexts_Geolocation_Adapter::getInstance();
     } catch (Tx_Contexts_Geolocation_Exception $exception) {
         t3lib_FlashMessageQueue::addMessage(t3lib_div::makeInstance('t3lib_FlashMessage', 'The "<tt>geoip</tt>" PHP extension is not available.' . ' Geolocation contexts will not work.', 'Geolocation configuration', t3lib_FlashMessage::ERROR));
     }
 }