X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fapi.php;h=987f2cc1bfe99c35292d1cd50e51f6a0477089ff;hb=779204b194447397d0770d96e291d9491fd731b9;hp=539aac4af252adfafa14fa9b325d441c866f0caf;hpb=234e6a10b1b95b271bacd11687e1dcb168712147;p=quix0rs-gnu-social.git diff --git a/lib/api.php b/lib/api.php index 539aac4af2..987f2cc1bf 100644 --- a/lib/api.php +++ b/lib/api.php @@ -53,13 +53,19 @@ 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; + const READ_ONLY = 1; + const READ_WRITE = 2; + + 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; + + var $access = self::READ_ONLY; // read (default) or read-write /** * Initialization. @@ -134,12 +140,13 @@ 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 don't have an associated user + $defaultDesign = Design::siteDesign(); + if (!empty($user)) { $design = $user->getDesign(); } @@ -166,7 +173,7 @@ class ApiAction extends Action $timezone = 'UTC'; - if ($user->timezone) { + if (!empty($user) && $user->timezone) { $timezone = $user->timezone; } @@ -191,13 +198,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); @@ -216,6 +224,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(); @@ -265,17 +288,18 @@ class ApiAction extends Action $twitter_status['attachments'] = array(); foreach ($attachments as $attachment) { - if ($attachment->isEnclosure()) { + $enclosure_o=$attachment->getEnclosure(); + if ($enclosure_o) { $enclosure = array(); - $enclosure['url'] = $attachment->url; - $enclosure['mimetype'] = $attachment->mimetype; - $enclosure['size'] = $attachment->size; + $enclosure['url'] = $enclosure_o->url; + $enclosure['mimetype'] = $enclosure_o->mimetype; + $enclosure['size'] = $enclosure_o->size; $twitter_status['attachments'][] = $enclosure; } } } - if ($include_user) { + if ($include_user && $profile) { # Don't get notice (recursive!) $twitter_user = $this->twitterUserArray($profile, false); $twitter_status['user'] = $twitter_user; @@ -449,9 +473,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': @@ -466,11 +490,14 @@ class ApiAction extends Action 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) @@ -589,7 +616,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'); @@ -603,6 +630,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'); @@ -622,7 +658,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'); @@ -631,6 +667,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', @@ -755,7 +795,7 @@ class ApiAction extends Action $from = $message->getFrom(); - $entry['title'] = sprintf('Message from %s to %s', + $entry['title'] = sprintf('Message from %1$s to %2$s', $from->nickname, $message->getTo()->nickname); $entry['content'] = common_xml_safe_str($message->rendered); @@ -1142,10 +1182,15 @@ class ApiAction extends Action function getTargetUser($id) { - if (!preg_match('/^[a-zA-Z0-9]+$/', $id)) { + if (empty($id)) { // Twitter supports these other ways of passing the user ID - if ($this->arg('user_id')) { + if (is_numeric($this->arg('id'))) { + return User::staticGet($this->arg('id')); + } else if ($this->arg('id')) { + $nickname = common_canonical_nickname($this->arg('id')); + 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 doesn't get used if (is_numeric($this->arg('user_id'))) { @@ -1154,12 +1199,6 @@ class ApiAction extends Action } else if ($this->arg('screen_name')) { $nickname = common_canonical_nickname($this->arg('screen_name')); return User::staticGet('nickname', $nickname); - - } else if (is_numeric($this->arg('id'))) { - return User::staticGet($this->arg('id')); - } else if ($this->arg('id')) { - $nickname = common_canonical_nickname($this->arg('id')); - return User::staticGet('nickname', $nickname); } else { // Fall back to trying the currently authenticated user return $this->auth_user;