X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fapi.php;h=4ed49e45293197f790d167f9a8da24e882ce4b98;hb=ca3b2d614a0f7340ee5e83687be1951020c5aafa;hp=5da9d4982507a9e2fad590590a9e9a420b21762c;hpb=cae06a49ea60cacb926f27b18b88a8a7f801f011;p=quix0rs-gnu-social.git diff --git a/lib/api.php b/lib/api.php index 5da9d49825..4ed49e4529 100644 --- a/lib/api.php +++ b/lib/api.php @@ -53,33 +53,34 @@ if (!defined('STATUSNET')) { class ApiAction extends Action { - var $format = null; - var $user = null; - var $page = null; - var $count = null; - var $max_id = null; - var $since_id = null; - var $since = null; - + var $format = null; + var $user = null; + var $auth_user = null; + var $page = null; + var $count = null; + var $max_id = null; + var $since_id = null; + var $since = null; + /** * Initialization. * * @param array $args Web and URL arguments * - * @return boolean false if user does not exist + * @return boolean false if user doesn't exist */ 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,18 +135,17 @@ class ApiAction extends Action $twitter_user['protected'] = false; # not supported by StatusNet yet $twitter_user['followers_count'] = $profile->subscriberCount(); - $defaultDesign = Design::siteDesign(); $design = null; $user = $profile->getUser(); - // Note: some profiles do not have an associated user + // Note: some profiles don't have an associated user if (!empty($user)) { $design = $user->getDesign(); } if (empty($design)) { - $design = $defaultDesign; + $design = Design::siteDesign(); } $color = Design::toWebColor(empty($design->backgroundcolor) ? $defaultDesign->backgroundcolor : $design->backgroundcolor); @@ -164,7 +164,6 @@ class ApiAction extends Action $twitter_user['favourites_count'] = $profile->faveCount(); // British spelling! - $timezone = 'UTC'; if ($user->timezone) { @@ -192,13 +191,14 @@ class ApiAction extends Action $twitter_user['following'] = false; $twitter_user['notifications'] = false; - if (isset($apidata['user'])) { + if (isset($this->auth_user)) { - $twitter_user['following'] = $apidata['user']->isSubscribed($profile); + $twitter_user['following'] = $this->auth_user->isSubscribed($profile); // Notifications on? $sub = Subscription::pkeyGet(array('subscriber' => - $apidata['user']->id, 'subscribed' => $profile->id)); + $this->auth_user->id, + 'subscribed' => $profile->id)); if ($sub) { $twitter_user['notifications'] = ($sub->jabber || $sub->sms); @@ -208,7 +208,7 @@ class ApiAction extends Action if ($get_notice) { $notice = $profile->getCurrentNotice(); if ($notice) { - # do not get user! + # don't get user! $twitter_user['status'] = $this->twitterStatusArray($notice, false); } } @@ -217,6 +217,21 @@ class ApiAction extends Action } function twitterStatusArray($notice, $include_user=true) + { + $base = $this->twitterSimpleStatusArray($notice, $include_user); + + if (!empty($notice->repeat_of)) { + $original = Notice::staticGet('id', $notice->repeat_of); + if (!empty($original)) { + $original_array = $this->twitterSimpleStatusArray($original, $include_user); + $base['retweeted_status'] = $original_array; + } + } + + return $base; + } + + function twitterSimpleStatusArray($notice, $include_user=true) { $profile = $notice->getProfile(); @@ -243,6 +258,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 { @@ -268,7 +292,7 @@ class ApiAction extends Action } if ($include_user) { - # Do not get notice (recursive!) + # Don't get notice (recursive!) $twitter_user = $this->twitterUserArray($profile, false); $twitter_status['user'] = $twitter_user; } @@ -367,10 +391,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,9 +465,9 @@ class ApiAction extends Action } } - function showTwitterXmlStatus($twitter_status) + function showTwitterXmlStatus($twitter_status, $tag='status') { - $this->elementStart('status'); + $this->elementStart($tag); foreach($twitter_status as $element => $value) { switch ($element) { case 'user': @@ -446,11 +479,17 @@ class ApiAction extends Action case 'attachments': $this->showXmlAttachments($twitter_status['attachments']); break; + case 'geo': + $this->showGeoRSS($value); + break; + case 'retweeted_status': + $this->showTwitterXmlStatus($value, 'retweeted_status'); + break; default: $this->element($element, null, $value); } } - $this->elementEnd('status'); + $this->elementEnd($tag); } function showTwitterXmlGroup($twitter_group) @@ -489,6 +528,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'); @@ -510,6 +561,7 @@ class ApiAction extends Action } } + $this->showGeoRSS($entry['geo']); $this->elementEnd('item'); } @@ -534,7 +586,6 @@ class ApiAction extends Action $this->endDocument('json'); } - function showXmlTimeline($notice) { @@ -557,7 +608,7 @@ class ApiAction extends Action $this->endDocument('xml'); } - function showRssTimeline($notice, $title, $link, $subtitle, $suplink=null) + function showRssTimeline($notice, $title, $link, $subtitle, $suplink=null, $logo=null) { $this->initDocument('rss'); @@ -571,6 +622,15 @@ class ApiAction extends Action 'href' => $suplink, 'type' => 'application/json')); } + + if (!is_null($logo)) { + $this->elementStart('image'); + $this->element('link', null, $link); + $this->element('title', null, $title); + $this->element('url', null, $logo); + $this->elementEnd('image'); + } + $this->element('description', null, $subtitle); $this->element('language', null, 'en-us'); $this->element('ttl', null, '40'); @@ -590,7 +650,7 @@ class ApiAction extends Action $this->endTwitterRss(); } - function showAtomTimeline($notice, $title, $id, $link, $subtitle=null, $suplink=null, $selfuri=null) + function showAtomTimeline($notice, $title, $id, $link, $subtitle=null, $suplink=null, $selfuri=null, $logo=null) { $this->initDocument('atom'); @@ -599,6 +659,10 @@ class ApiAction extends Action $this->element('id', null, $id); $this->element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), null); + if (!is_null($logo)) { + $this->element('logo',null,$logo); + } + if (!is_null($suplink)) { # For FriendFeed's SUP protocol $this->element('link', array('rel' => 'http://api.friendfeed.com/2008/03#sup', @@ -654,7 +718,6 @@ class ApiAction extends Action $this->endTwitterRss(); } - function showTwitterAtomEntry($entry) { $this->elementStart('entry'); @@ -1079,7 +1142,7 @@ class ApiAction extends Action function initTwitterAtom() { $this->startXML(); - // FIXME: do not hardcode the language here! + // FIXME: don't hardcode the language here! $this->elementStart('feed', array('xmlns' => 'http://www.w3.org/2005/Atom', 'xml:lang' => 'en-US', 'xmlns:thr' => 'http://purl.org/syndication/thread/1.0')); @@ -1121,7 +1184,7 @@ class ApiAction extends Action return User::staticGet('nickname', $nickname); } else if ($this->arg('user_id')) { // This is to ensure that a non-numeric user_id still - // overrides screen_name even if it does not get used + // overrides screen_name even if it doesn't get used if (is_numeric($this->arg('user_id'))) { return User::staticGet('id', $this->arg('user_id')); } @@ -1151,7 +1214,7 @@ class ApiAction extends Action return User_group::staticGet('nickname', $nickname); } else if ($this->arg('group_id')) { // This is to ensure that a non-numeric user_id still - // overrides screen_name even if it does not get used + // overrides screen_name even if it doesn't get used if (is_numeric($this->arg('group_id'))) { return User_group::staticGet('id', $this->arg('group_id')); }