Esempio n. 1
0
 /**
  * @see ItemParameterManipulation::doManipulation
  * 
  * @since 0.7.5
  */
 public function doManipulation(&$value, Parameter $parameter, array &$parameters)
 {
     global $egMapsDefaultGeoService;
     static $validatedDefault = false;
     if (!MapsGeocoders::canGeocode()) {
         throw new MWException('There are no geocoders registered, so no geocoding can happen.');
     }
     // Get rid of any aliases.
     $value = $this->getMainIndentifier($value);
     // Override the defaulting.
     if ($parameter->wasSetToDefault() && is_string($this->mappingServiceParam) && array_key_exists($this->mappingServiceParam, $parameters)) {
         $value = self::resolveOverrides($value, $parameters[$this->mappingServiceParam]->getValue());
     }
     if ($value === '' || !array_key_exists($value, MapsGeocoders::$registeredGeocoders)) {
         if (!$validatedDefault) {
             if (!array_key_exists($egMapsDefaultGeoService, MapsGeocoders::$registeredGeocoders)) {
                 $geoServices = array_keys(MapsGeocoders::$registeredGeocoders);
                 $egMapsDefaultGeoService = array_shift($geoServices);
                 if (is_null($egMapsDefaultGeoService)) {
                     throw new MWException('Tried to geocode while there are no geocoders available at ' . __METHOD__);
                 }
             }
         }
         if (array_key_exists($egMapsDefaultGeoService, MapsGeocoders::$registeredGeocoders)) {
             $value = $egMapsDefaultGeoService;
         } else {
             throw new MWException('Attempt to use the default geocoder while it does not exist.');
         }
     }
 }
Esempio n. 2
0
 /**
  * Returns true if the parameter value contains atleast 1 comma
  * meaning that there are atleast two enpoints on which to draw a line.
  *
  * @param string $value
  * @param Parameter $parameter
  * @param array $parameters
  *
  * @since 0.4
  *
  * @return boolean
  */
 protected function doValidation($value, Parameter $parameter, array $parameters)
 {
     //fetch locations
     $value = explode($this->metaDataSeparator, $value);
     $value = $value[0];
     //need atleast two points to create a line
     $valid = strpos($value, ':') != false;
     if (!$valid) {
         return $valid;
     }
     //setup geocode deps
     $canGeoCode = MapsGeocoders::canGeocode();
     if ($canGeoCode) {
         $geoService = $parameter->hasDependency('geoservice') ? $parameters['geoservice']->getValue() : '';
         $mappingService = $parameter->hasDependency('mappingservice') ? $parameters['mappingservice']->getValue() : false;
     }
     //strip away line parameters and check for valid locations
     $parts = explode(':', $value);
     foreach ($parts as $part) {
         $toIndex = strpos($part, $this->metaDataSeparator);
         if ($toIndex != false) {
             $part = substr($part, 0, $toIndex);
         }
         if ($canGeoCode) {
             $valid = MapsGeocoders::isLocation($part, $geoService, $mappingService);
         } else {
             $valid = MapsCoordinateParser::areCoordinates($part);
         }
         if (!$valid) {
             break;
         }
     }
     return $valid;
 }
 /**
  * @see ItemParameterCriterion::validate
  */
 protected function doValidation($value, Parameter $parameter, array $parameters)
 {
     if ($this->metaDataSeparator !== false) {
         $parts = explode($this->metaDataSeparator, $value);
         $value = $parts[0];
     }
     if (MapsGeocoders::canGeocode()) {
         $geoService = $parameter->hasDependency('geoservice') ? $parameters['geoservice']->getValue() : '';
         $mappingService = $parameter->hasDependency('mappingservice') ? $parameters['mappingservice']->getValue() : false;
         return MapsGeocoders::isLocation($value, $geoService, $mappingService);
     } else {
         return MapsCoordinateParser::areCoordinates($value);
     }
 }
 /**
  * Initiate the geocoding functionality.
  * 
  * @since 1.0.3
  * 
  * @return boolean Indicates if init happened
  */
 public static function init()
 {
     static $initiated = false;
     if ($initiated) {
         return false;
     }
     $initiated = true;
     // Register the geocoders.
     wfRunHooks('GeocoderFirstCallInit');
     // Determine if there are any geocoders.
     self::$canGeocode = count(self::$registeredGeocoders) > 0;
     return true;
 }
Esempio n. 5
0
 /**
  * Renders and returns the output.
  * @see ParserHook::render
  * 
  * @since 0.7
  * 
  * @param array $parameters
  * 
  * @return string
  */
 public function render(array $parameters)
 {
     if (MapsGeocoders::canGeocode()) {
         $geovalues = MapsGeocoders::attemptToGeocodeToString($parameters['location'], $parameters['geoservice'], $parameters['mappingservice'], $parameters['allowcoordinates'], $parameters['format'], $parameters['directional']);
         $output = $geovalues ? $geovalues : '';
     } else {
         $output = htmlspecialchars(wfMsg('maps-geocoder-not-available'));
     }
     return $output;
 }
Esempio n. 6
0
 /**
  * Renders and returns the output.
  * @see ParserHook::render
  * 
  * @since 0.7
  * 
  * @param array $parameters
  * 
  * @return string
  */
 public function render(array $parameters)
 {
     $canGeocode = MapsGeocoders::canGeocode();
     if ($canGeocode) {
         $location = MapsGeocoders::attemptToGeocode($parameters['location'], $parameters['geoservice'], $parameters['mappingservice']);
     } else {
         $location = MapsCoordinateParser::parseCoordinates($parameters['location']);
     }
     // TODO
     if ($location) {
         $destination = MapsGeoFunctions::findDestination($location, $parameters['bearing'], MapsDistanceParser::parseDistance($parameters['distance']));
         $output = MapsCoordinateParser::formatCoordinates($destination, $parameters['format'], $parameters['directional']);
     } else {
         // The location should be valid when this method gets called.
         throw new MWException('Attempt to find a destination from an invalid location');
     }
     return $output;
 }
Esempio n. 7
0
 /**
  * Renders and returns the output.
  * @see ParserHook::render
  * 
  * @since 0.7
  * 
  * @param array $parameters
  * 
  * @return string
  */
 public function render(array $parameters)
 {
     if (MapsGeocoders::canGeocode()) {
         $start = MapsGeocoders::attemptToGeocode($parameters['location1'], $parameters['geoservice'], $parameters['mappingservice']);
         $end = MapsGeocoders::attemptToGeocode($parameters['location2'], $parameters['geoservice'], $parameters['mappingservice']);
     } else {
         $start = MapsCoordinateParser::parseCoordinates($parameters['location1']);
         $end = MapsCoordinateParser::parseCoordinates($parameters['location2']);
     }
     if ($start && $end) {
         $output = MapsDistanceParser::formatDistance(MapsGeoFunctions::calculateDistance($start, $end), $parameters['unit'], $parameters['decimals']);
     } else {
         // The locations should be valid when this method gets called.
         throw new Exception('Attempt to find the distance between locations of at least one is invalid');
     }
     return $output;
 }