summaryrefslogtreecommitdiff
path: root/lib/api.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api.php')
-rw-r--r--lib/api.php73
1 files changed, 59 insertions, 14 deletions
diff --git a/lib/api.php b/lib/api.php
index 9bd2083de..e2ea87b43 100644
--- a/lib/api.php
+++ b/lib/api.php
@@ -60,7 +60,7 @@ class ApiAction extends Action
var $max_id = null;
var $since_id = null;
var $since = null;
-
+
/**
* Initialization.
*
@@ -72,14 +72,14 @@ class ApiAction extends Action
function prepare($args)
{
parent::prepare($args);
-
+
$this->format = $this->arg('format');
$this->page = (int)$this->arg('page', 1);
$this->count = (int)$this->arg('count', 20);
$this->max_id = (int)$this->arg('max_id', 0);
$this->since_id = (int)$this->arg('since_id', 0);
$this->since = $this->arg('since');
-
+
return true;
}
@@ -134,11 +134,20 @@ class ApiAction extends Action
$twitter_user['protected'] = false; # not supported by StatusNet yet
$twitter_user['followers_count'] = $profile->subscriberCount();
- // Need to pull up the user for some of this
- $user = $profile->getUser();
- $design = $user->getDesign();
$defaultDesign = Design::siteDesign();
- if (!$design) $design = $defaultDesign;
+ $design = null;
+ $user = $profile->getUser();
+
+ // Note: some profiles don't have an associated user
+
+ if (!empty($user)) {
+ $design = $user->getDesign();
+ }
+
+ if (empty($design)) {
+ $design = $defaultDesign;
+ }
+
$color = Design::toWebColor(empty($design->backgroundcolor) ? $defaultDesign->backgroundcolor : $design->backgroundcolor);
$twitter_user['profile_background_color'] = ($color == null) ? '' : '#'.$color->hexValue();
$color = Design::toWebColor(empty($design->textcolor) ? $defaultDesign->textcolor : $design->textcolor);
@@ -155,7 +164,6 @@ class ApiAction extends Action
$twitter_user['favourites_count'] = $profile->faveCount(); // British spelling!
-
$timezone = 'UTC';
if ($user->timezone) {
@@ -168,9 +176,14 @@ class ApiAction extends Action
$twitter_user['utc_offset'] = $t->format('Z');
$twitter_user['time_zone'] = $timezone;
- // To be supported some day, perhaps
- $twitter_user['profile_background_image_url'] = '';
- $twitter_user['profile_background_tile'] = false;
+ $twitter_user['profile_background_image_url']
+ = empty($design->backgroundimage)
+ ? '' : ($design->disposition & BACKGROUND_ON)
+ ? Design::url($design->backgroundimage) : '';
+
+ $twitter_user['profile_background_tile']
+ = empty($design->disposition)
+ ? '' : ($design->disposition & BACKGROUND_TILE) ? 'true' : 'false';
$twitter_user['statuses_count'] = $profile->noticeCount();
@@ -229,6 +242,15 @@ class ApiAction extends Action
$twitter_status['in_reply_to_screen_name'] =
($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)) {
$twitter_status['favorited'] = $this->auth_user->hasFave($notice);
} else {
@@ -353,10 +375,19 @@ class ApiAction extends Action
$entry['pubDate'] = common_date_rfc2822($notice->created);
$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;
}
-
function twitterRelationshipArray($source, $target)
{
$relationship = array();
@@ -432,6 +463,9 @@ class ApiAction extends Action
case 'attachments':
$this->showXmlAttachments($twitter_status['attachments']);
break;
+ case 'geo':
+ $this->showGeoRSS($value);
+ break;
default:
$this->element($element, null, $value);
}
@@ -475,6 +509,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)
{
$this->elementStart('item');
@@ -496,6 +542,7 @@ class ApiAction extends Action
}
}
+ $this->showGeoRSS($entry['geo']);
$this->elementEnd('item');
}
@@ -520,7 +567,6 @@ class ApiAction extends Action
$this->endDocument('json');
}
-
function showXmlTimeline($notice)
{
@@ -640,7 +686,6 @@ class ApiAction extends Action
$this->endTwitterRss();
}
-
function showTwitterAtomEntry($entry)
{
$this->elementStart('entry');