/**
  *
  * @param string $street
  * @param string $zip
  * @param string $city
  * @param string $country
  * @param string $state
  * @throws Exception
  */
 public function lookupGeoCodeCached($street, $zip, $city, $country, $state = '')
 {
     if (!tx_rnbase_util_Extensions::isLoaded('wec_map')) {
         throw new Exception('wec_map not loaded');
     }
     return tx_wecmap_cache::lookup($street, $city, $state, $zip, $country);
 }
Exemplo n.º 2
0
 public function __construct()
 {
     parent::__construct();
     // Lets see if the user is logged in
     if ($this->rightsObj->isLoggedIn() && !$this->rightsObj->isCalAdmin() && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('wec_map') && $this->conf['view.']['calendar.']['nearbyDistance'] > 0) {
         require_once \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('wec_map') . 'class.tx_wecmap_cache.php';
         $user = $GLOBALS['TSFE']->fe_user->user;
         /* Geocode the address */
         $latlong = \tx_wecmap_cache::lookup($user['street'], $user['city'], $user['state'], $user['zip'], $user['country']);
         if (isset($latlong['long']) && isset($latlong['lat'])) {
             $this->internalAdditionTable = ',' . $this->conf['view.']['calendar.']['nearbyAdditionalTable'];
             $this->internalAdditionWhere = ' ' . str_replace(array('###LONGITUDE###', '###LATITUDE###', '###DISTANCE###'), array($latlong['long'], $latlong['lat'], $this->conf['view.']['calendar.']['nearbyDistance']), $this->conf['view.']['calendar.']['nearbyAdditionalWhere']);
         } else {
             $this->internalAdditionWhere = ' AND 1=2';
         }
     } else {
         // not logged in -> we can't localize
         $this->internalAdditionWhere = ' AND 1=2';
     }
 }
Exemplo n.º 3
0
 /**
  * Adds a marker by getting the address info from the TCA
  *
  * @param	string		The db table that contains the mappable records
  * @param	integer		The uid of the record to be mapped
  * @param	string		The title for the marker popup.
  * @param	string		The description to be displayed in the marker popup.
  * @param	integer		Minimum zoom level for marker to appear.
  * @param	integer		Maximum zoom level for marker to appear.
  * @return	marker object
  **/
 function addMarkerByTCA($table, $uid, $title = '', $description = '', $minzoom = 0, $maxzoom = 18, $iconID = '')
 {
     $uid = intval($uid);
     // first get the mappable info from the TCA
     $tca = $GLOBALS['TCA'][$table]['ctrl']['EXT']['wec_map'];
     if (!$tca) {
         return false;
     }
     if (!$tca['isMappable']) {
         return false;
     }
     // get address from db for this record
     $record = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', $table, 'uid=' . intval($uid));
     $record = $record[0];
     if ($tca['addressFields']) {
         $streetfield = tx_wecmap_shared::getAddressField($table, 'street');
         $cityfield = tx_wecmap_shared::getAddressField($table, 'city');
         $statefield = tx_wecmap_shared::getAddressField($table, 'state');
         $zipfield = tx_wecmap_shared::getAddressField($table, 'zip');
         $countryfield = tx_wecmap_shared::getAddressField($table, 'country');
         $street = $record[$streetfield];
         $city = $record[$cityfield];
         $state = $record[$statefield];
         $zip = $record[$zipfield];
         $country = $record[$countryfield];
         if (empty($country) && $countryfield == 'static_info_country') {
             $country = $record['country'];
         } else {
             if (empty($country) && $countryfield == 'country') {
                 $country = $record['static_info_country'];
             }
         }
         /* Geocode the address */
         $latlong = tx_wecmap_cache::lookup($street, $city, $state, $zip, $country, $this->key);
         /* Create a marker at the specified latitude and longitude */
         return $this->addMarkerByLatLong($latlong['lat'], $latlong['long'], $title, $description, $minzoom, $maxzoom, $iconID);
     } else {
         if ($tca['latlongFields']) {
             $latfield = tx_wecmap_shared::getLatLongField($table, 'lat');
             $longfield = tx_wecmap_shared::getLatLongField($table, 'long');
             $lat = $record[$latfield];
             $long = $record[$longfield];
             /* Create a marker at the specified latitude and longitude */
             return $this->addMarkerByLatLong($lat, $long, $title, $description, $minzoom, $maxzoom, $iconID);
         } else {
             return false;
         }
     }
 }
    /**
     * Checks the geocoding status of the address and displays an editing form.
     *
     * @param	string	Street portion of the address.
     * @param	string	City portion of the address.
     * @param	string	State portion of the address.
     * @param	string	ZIP code portion of the address.
     * @param	string	Country portion of the address.
     * @return	string	HTML output of current geocoding status and editing form.
     */
    static function drawGeocodeStatus($street, $city, $state, $zip, $country)
    {
        global $LANG;
        $LANG->includeLLFile('EXT:wec_map/locallang_db.xml');
        /* Normalize the address before we try to insert it or anything like that */
        tx_wecmap_cache::normalizeAddress($street, $city, $state, $zip, $country);
        // if there is no info about the user, return different status
        if (!$city) {
            return $LANG->getLL('geocodeNoAddress');
        }
        /* Grab the lat and long that were posted */
        $newlat = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('wec_map_lat');
        $newlong = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('wec_map_long');
        $origlat = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('wec_map_original_lat');
        $origlong = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('wec_map_original_long');
        /* If the new lat/long are empty, delete our cached entry */
        if (empty($newlat) && empty($newlong) && !empty($origlat) && !empty($origlong)) {
            tx_wecmap_cache::delete($street, $city, $state, $zip, $country);
        }
        /* If the lat/long changed, then insert a new entry into the cache or update it. */
        if (($newlat != $origlat or $newlong != $origlong) and !empty($newlat) && !empty($newlong) and is_numeric($newlat) && is_numeric($newlong)) {
            tx_wecmap_cache::insert($street, $city, $state, $zip, $country, $newlat, $newlong);
        }
        /* Get the lat/long and status from the geocoder */
        $latlong = tx_wecmap_cache::lookup($street, $city, $state, $zip, $country);
        $status = tx_wecmap_cache::status($street, $city, $state, $zip, $country);
        switch ($status) {
            case -1:
                $status = $LANG->getLL('geocodeFailed');
                break;
            case 0:
                $status = $LANG->getLL('geocodeNotPerformed');
                break;
            case 1:
                $status = $LANG->getLL('geocodeSuccessful');
                break;
        }
        $form = '<label for="wec_map_lat">' . $LANG->getLL('latitude') . '</label> <input id="wec_map_lat" name="wec_map_lat" value="' . htmlspecialchars($latlong['lat']) . '" />
				 <label for="wec_map_long">' . $LANG->getLL('longitude') . '</label>  <input id="wec_map_long" name="wec_map_long" value="' . htmlspecialchars($latlong['long']) . '" />
				 <input type="hidden" name="wec_map_original_lat" value="' . htmlspecialchars($latlong['lat']) . '" />
				 <input type="hidden" name="wec_map_original_long" value="' . htmlspecialchars($latlong['long']) . '" />';
        return '<p>' . $status . '</p><p>' . $form . '</p>';
    }
Exemplo n.º 5
0
 function ajaxSaveRecord($params, &$ajaxObj)
 {
     $hash = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('record');
     $latitude = floatval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('latitude'));
     $longitude = floatval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('longitude'));
     tx_wecmap_cache::updateByUID($hash, $latitude, $longitude);
     // $hash is escaped in updateByUID()
     $ajaxObj->addContent('content', '');
 }
 /**
  * Performs geocoding on an individual row.
  *
  * @param		array		The associative array of the record to be geocoded.
  * @param		array		The array mapping address elements to individual fields in the record.
  * @return		none
  */
 function geocodeRecord($row, $addressFields)
 {
     $street = $row[$addressFields['street']];
     $city = $row[$addressFields['city']];
     $state = $row[$addressFields['state']];
     $zip = $row[$addressFields['zip']];
     $country = $row[$addressFields['country']];
     // increment total count
     $this->processedAddresses++;
     tx_wecmap_cache::lookupWithCallback($street, $city, $state, $zip, $country, '', false, $this);
 }
 /**
  * Sets the map center to a given address' coordinates.
  *
  * @return void
  **/
 function setCenterByAddress($street, $city, $state, $zip, $country = null)
 {
     /* Geocode the address */
     $latlong = tx_wecmap_cache::lookup($street, $city, $state, $zip, $country, $this->key);
     $this->lat = $latlong['lat'];
     $this->long = $latlong['long'];
 }