add geo output to statuses in json, xml, atom, rss in API
This commit is contained in:
parent
27e6a3f36f
commit
cb64cfb44c
@ -1254,6 +1254,12 @@ class Notice extends Memcached_DataObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($this->lat) && !empty($this->lon)) {
|
||||||
|
$xs->elementStart('geo', array('xmlns:georss' => 'http://www.georss.org/georss'));
|
||||||
|
$xs->element('georss:point', null, $this->lat . ' ' . $this->lon);
|
||||||
|
$xs->elementEnd('geo');
|
||||||
|
}
|
||||||
|
|
||||||
$xs->elementEnd('entry');
|
$xs->elementEnd('entry');
|
||||||
|
|
||||||
return $xs->getString();
|
return $xs->getString();
|
||||||
|
39
lib/api.php
39
lib/api.php
@ -164,7 +164,6 @@ class ApiAction extends Action
|
|||||||
|
|
||||||
$twitter_user['favourites_count'] = $profile->faveCount(); // British spelling!
|
$twitter_user['favourites_count'] = $profile->faveCount(); // British spelling!
|
||||||
|
|
||||||
|
|
||||||
$timezone = 'UTC';
|
$timezone = 'UTC';
|
||||||
|
|
||||||
if ($user->timezone) {
|
if ($user->timezone) {
|
||||||
@ -238,6 +237,15 @@ class ApiAction extends Action
|
|||||||
$twitter_status['in_reply_to_screen_name'] =
|
$twitter_status['in_reply_to_screen_name'] =
|
||||||
($replier_profile) ? $replier_profile->nickname : null;
|
($replier_profile) ? $replier_profile->nickname : null;
|
||||||
|
|
||||||
|
if (isset($notice->lat) && isset($notice->lon)) {
|
||||||
|
// This is the format that GeoJSON expects stuff to be in
|
||||||
|
$twitter_status['geo'] = array('type' => 'Point',
|
||||||
|
'coordinates' => array((float) $notice->lat,
|
||||||
|
(float) $notice->lon));
|
||||||
|
} else {
|
||||||
|
$twitter_status['geo'] = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($this->auth_user)) {
|
if (isset($this->auth_user)) {
|
||||||
$twitter_status['favorited'] = $this->auth_user->hasFave($notice);
|
$twitter_status['favorited'] = $this->auth_user->hasFave($notice);
|
||||||
} else {
|
} else {
|
||||||
@ -362,10 +370,19 @@ class ApiAction extends Action
|
|||||||
$entry['pubDate'] = common_date_rfc2822($notice->created);
|
$entry['pubDate'] = common_date_rfc2822($notice->created);
|
||||||
$entry['guid'] = $entry['link'];
|
$entry['guid'] = $entry['link'];
|
||||||
|
|
||||||
|
if (isset($notice->lat) && isset($notice->lon)) {
|
||||||
|
// This is the format that GeoJSON expects stuff to be in.
|
||||||
|
// showGeoRSS() below uses it for XML output, so we reuse it
|
||||||
|
$entry['geo'] = array('type' => 'Point',
|
||||||
|
'coordinates' => array((float) $notice->lat,
|
||||||
|
(float) $notice->lon));
|
||||||
|
} else {
|
||||||
|
$entry['geo'] = null;
|
||||||
|
}
|
||||||
|
|
||||||
return $entry;
|
return $entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function twitterRelationshipArray($source, $target)
|
function twitterRelationshipArray($source, $target)
|
||||||
{
|
{
|
||||||
$relationship = array();
|
$relationship = array();
|
||||||
@ -441,6 +458,9 @@ class ApiAction extends Action
|
|||||||
case 'attachments':
|
case 'attachments':
|
||||||
$this->showXmlAttachments($twitter_status['attachments']);
|
$this->showXmlAttachments($twitter_status['attachments']);
|
||||||
break;
|
break;
|
||||||
|
case 'geo':
|
||||||
|
$this->showGeoRSS($value);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
$this->element($element, null, $value);
|
$this->element($element, null, $value);
|
||||||
}
|
}
|
||||||
@ -484,6 +504,18 @@ class ApiAction extends Action
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showGeoRSS($geo)
|
||||||
|
{
|
||||||
|
if (empty($geo)) {
|
||||||
|
// empty geo element
|
||||||
|
$this->element('geo');
|
||||||
|
} else {
|
||||||
|
$this->elementStart('geo', array('xmlns:georss' => 'http://www.georss.org/georss'));
|
||||||
|
$this->element('georss:point', null, $geo['coordinates'][0] . ' ' . $geo['coordinates'][1]);
|
||||||
|
$this->elementEnd('geo');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function showTwitterRssItem($entry)
|
function showTwitterRssItem($entry)
|
||||||
{
|
{
|
||||||
$this->elementStart('item');
|
$this->elementStart('item');
|
||||||
@ -505,6 +537,7 @@ class ApiAction extends Action
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->showGeoRSS($entry['geo']);
|
||||||
$this->elementEnd('item');
|
$this->elementEnd('item');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -529,7 +562,6 @@ class ApiAction extends Action
|
|||||||
$this->endDocument('json');
|
$this->endDocument('json');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function showXmlTimeline($notice)
|
function showXmlTimeline($notice)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -649,7 +681,6 @@ class ApiAction extends Action
|
|||||||
$this->endTwitterRss();
|
$this->endTwitterRss();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function showTwitterAtomEntry($entry)
|
function showTwitterAtomEntry($entry)
|
||||||
{
|
{
|
||||||
$this->elementStart('entry');
|
$this->elementStart('entry');
|
||||||
|
Loading…
Reference in New Issue
Block a user