X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fapiaction.php;h=0eea08bed63f147a4c05b1edaec6fbfc68793cd2;hb=b53e1439969bfa2c0b551d8cc2fc8fe15652c62a;hp=36ccc82135f734299a586b9ef6cce226cdabe7a2;hpb=fcdd061b4f89d04889025c516f98c9eead53ad1a;p=quix0rs-gnu-social.git diff --git a/lib/apiaction.php b/lib/apiaction.php index 36ccc82135..0eea08bed6 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -54,7 +54,7 @@ @subsection usermethods_sec User Methods - @subsection directmessagemethods_sec Direct Message Methods + @subsection directmessagemethods_sec Direct Message Methods (now a plugin) @subsection friendshipmethods_sec Friendship Methods @@ -123,10 +123,13 @@ class ApiAction extends Action var $auth_user = null; var $page = null; var $count = null; + var $offset = null; + var $limit = null; var $max_id = null; var $since_id = null; var $source = null; var $callback = null; + var $format = null; var $access = self::READ_ONLY; // read (default) or read-write @@ -141,7 +144,7 @@ class ApiAction extends Action */ protected function prepare(array $args=array()) { - StatusNet::setApi(true); // reduce exception reports to aid in debugging + GNUsocial::setApi(true); // reduce exception reports to aid in debugging parent::prepare($args); $this->format = $this->arg('format'); @@ -151,8 +154,12 @@ class ApiAction extends Action $this->max_id = (int)$this->arg('max_id', 0); $this->since_id = (int)$this->arg('since_id', 0); + // These two are not used everywhere, mainly just AtompubAction extensions + $this->offset = ($this->page-1) * $this->count; + $this->limit = $this->count + 1; + if ($this->arg('since')) { - header('X-StatusNet-Warning: since parameter is disabled; use since_id'); + header('X-GNUsocial-Warning: since parameter is disabled; use since_id'); } $this->source = $this->trimmed('source'); @@ -243,8 +250,6 @@ class ApiAction extends Action $twitter_user['created_at'] = $this->dateTwitter($profile->created); - $twitter_user['favourites_count'] = $profile->faveCount(); // British spelling! - $timezone = 'UTC'; if (!empty($user) && $user->timezone) { @@ -259,22 +264,20 @@ class ApiAction extends Action $twitter_user['statuses_count'] = $profile->noticeCount(); // Is the requesting user following this user? + // These values might actually also mean "unknown". Ambiguity issues? $twitter_user['following'] = false; $twitter_user['statusnet_blocking'] = false; $twitter_user['notifications'] = false; - if (isset($this->auth_user)) { - - $twitter_user['following'] = $this->auth_user->isSubscribed($profile); - $twitter_user['statusnet_blocking'] = $this->auth_user->hasBlocked($profile); - - // Notifications on? - $sub = Subscription::pkeyGet(array('subscriber' => - $this->auth_user->id, - 'subscribed' => $profile->id)); - - if ($sub) { + if ($this->scoped instanceof Profile) { + try { + $sub = Subscription::getSubscription($this->scoped, $profile); + // Notifications on? + $twitter_user['following'] = true; + $twitter_user['statusnet_blocking'] = $this->scoped->hasBlocked($profile); $twitter_user['notifications'] = ($sub->jabber || $sub->sms); + } catch (NoResultException $e) { + // well, the values are already false... } } @@ -290,22 +293,21 @@ class ApiAction extends Action $twitter_user['statusnet_profile_url'] = $profile->profileurl; + // The event call to handle NoticeSimpleStatusArray lets plugins add data to the output array + Event::handle('TwitterUserArray', array($profile, &$twitter_user, $this->scoped, array())); + return $twitter_user; } function twitterStatusArray($notice, $include_user=true) { - // The event call to handle NoticeSimpleStatusArray lets plugins add data to the output array $base = $this->twitterSimpleStatusArray($notice, $include_user); - Event::handle('NoticeSimpleStatusArray', array($notice, &$base, $this->scoped, - array('include_user'=>$include_user))); + // FIXME: MOVE TO SHARE PLUGIN if (!empty($notice->repeat_of)) { $original = Notice::getKV('id', $notice->repeat_of); if ($original instanceof Notice) { $orig_array = $this->twitterSimpleStatusArray($original, $include_user); - Event::handle('NoticeSimpleStatusArray', array($original, &$orig_array, $this->scoped, - array('include_user'=>$include_user))); $base['retweeted_status'] = $orig_array; } } @@ -334,7 +336,7 @@ class ApiAction extends Action $source = null; $ns = $notice->getSource(); - if ($ns) { + if ($ns instanceof Notice_source) { if (!empty($ns->name) && !empty($ns->url)) { $source = 'getBestName(); - $entry['author-uri'] = $from->homepage; - - $entry['avatar'] = $from->avatarUrl(AVATAR_STREAM_SIZE); - try { - $avatar = $from->getAvatar(AVATAR_STREAM_SIZE); - $entry['avatar-type'] = $avatar->mediatype; - } catch (Exception $e) { - $entry['avatar-type'] = 'image/png'; - } - - // RSS item specific - - $entry['description'] = $entry['content']; - $entry['pubDate'] = common_date_rfc2822($message->created); - $entry['guid'] = $entry['link']; - - return $entry; - } - - function showSingleXmlDirectMessage($message) - { - $this->initDocument('xml'); - $dmsg = $this->directMessageArray($message); - $this->showXmlDirectMessage($dmsg, true); - $this->endDocument('xml'); - } - - function showSingleJsonDirectMessage($message) - { - $this->initDocument('json'); - $dmsg = $this->directMessageArray($message); - $this->showJsonObjects($dmsg); - $this->endDocument('json'); - } - function showAtomGroups($group, $title, $id, $link, $subtitle=null, $selfuri=null) { $this->initDocument('atom'); @@ -1440,7 +1339,7 @@ class ApiAction extends Action return User::getKV('nickname', $nickname); } else { // Fall back to trying the currently authenticated user - return $this->auth_user; + return $this->scoped->getUser(); } } else if (self::is_decimal($id)) { @@ -1536,7 +1435,7 @@ class ApiAction extends Action } if (!empty($list) && $list->private) { - if ($this->auth_user->id == $list->tagger) { + if ($this->scoped->id == $list->tagger) { return $list; } } else { @@ -1604,6 +1503,11 @@ class ApiAction extends Action $aargs['id'] = $id; } + $user = $this->arg('user'); + if (!empty($user)) { + $aargs['user'] = $user; + } + $tag = $this->arg('tag'); if (!empty($tag)) { $aargs['tag'] = $tag;