diff --git a/plugins/OStatus/lib/feedmunger.php b/plugins/OStatus/lib/feedmunger.php index 9480177025..cbaec67750 100644 --- a/plugins/OStatus/lib/feedmunger.php +++ b/plugins/OStatus/lib/feedmunger.php @@ -225,10 +225,45 @@ class FeedMunger $notice->created = common_sql_date($entry->updated); // @fixme $notice->is_local = Notice::GATEWAY; $notice->source = 'feed'; - + + $location = $this->getLocation($entry); + if ($location) { + if ($location->location_id) { + $notice->location_ns = $location->location_ns; + $notice->location_id = $location->location_id; + } + $notice->lat = $location->lat; + $notice->lon = $location->lon; + } + return $notice; } + /** + * @param feed item $entry + * @return mixed Location or false + */ + function getLocation($entry) + { + $dom = $entry->model; + $points = $dom->getElementsByTagNameNS('http://www.georss.org/georss', 'point'); + + for ($i = 0; $i < $points->length; $i++) { + $point = trim($points->item(0)->textContent); + $coords = explode(' ', $point); + if (count($coords) == 2) { + list($lat, $lon) = $coords; + if (is_numeric($lat) && is_numeric($lon)) { + common_log(LOG_INFO, "Looking up location for $lat $lon from georss"); + return Location::fromLatLon($lat, $lon); + } + } + common_log(LOG_ERR, "Ignoring bogus georss:point value $point"); + } + + return false; + } + /** * @param XML_Feed_Type $entry * @return string notice text, within post size limit