X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Ftwitapistatuses.php;h=87043b1821cb47672af710706b63c901014cd9bc;hb=affe00276a008038e8a8b37b3812215e382fe98e;hp=2bc404063846d58f15fdc63b845837aba97b5a1e;hpb=29bebdb50bf008a02e6c3e9530b3dff3bdd2b821;p=quix0rs-gnu-social.git diff --git a/actions/twitapistatuses.php b/actions/twitapistatuses.php index 2bc4040638..87043b1821 100644 --- a/actions/twitapistatuses.php +++ b/actions/twitapistatuses.php @@ -1,7 +1,7 @@ . */ -if (!defined('LACONICA')) { +if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } @@ -75,8 +75,8 @@ class TwitapistatusesAction extends TwitterapiAction { parent::handle($args); + $this->auth_user = $apidata['user']; $user = $this->get_user($apidata['api_arg'], $apidata); - $this->auth_user = $user; if (empty($user)) { $this->clientError(_('No such user!'), 404, @@ -100,8 +100,13 @@ class TwitapistatusesAction extends TwitterapiAction $since_id = (int)$this->arg('since_id', 0); $since = $this->arg('since'); - $notice = $user->noticesWithFriends(($page-1)*$count, - $count, $since_id, $max_id,$since); + if (!empty($this->auth_user) && $this->auth_user->id == $user->id) { + $notice = $user->noticeInbox(($page-1)*$count, + $count, $since_id, $max_id, $since); + } else { + $notice = $user->noticesWithFriends(($page-1)*$count, + $count, $since_id, $max_id, $since); + } switch($apidata['content-type']) { case 'xml': @@ -131,6 +136,11 @@ class TwitapistatusesAction extends TwitterapiAction } + function home_timeline($args, $apidata) + { + call_user_func(array($this, 'friends_timeline'), $args, $apidata); + } + function user_timeline($args, $apidata) { parent::handle($args); @@ -237,14 +247,15 @@ class TwitapistatusesAction extends TwitterapiAction $status_shortened = common_shorten_links($status); - if (mb_strlen($status_shortened) > 140) { + if (Notice::contentTooLong($status_shortened)) { // XXX: Twitter truncates anything over 140, flags the status // as "truncated." Sending this error may screw up some clients // that assume Twitter will truncate for them. Should we just // truncate too? -- Zach - $this->clientError(_('That\'s too long. Max notice size is 140 chars.'), - $code = 406, $apidata['content-type']); + $this->clientError(sprintf(_('That\'s too long. Max notice size is %d chars.'), + Notice::maxContent()), + $code = 406, $apidata['content-type']); return; } } @@ -286,11 +297,6 @@ class TwitapistatusesAction extends TwitterapiAction html_entity_decode($status, ENT_NOQUOTES, 'UTF-8'), $source, 1, $reply_to); - if (is_string($notice)) { - $this->serverError($notice); - return; - } - common_broadcast_notice($notice); $apidata['api_arg'] = $notice->id; } @@ -368,9 +374,19 @@ class TwitapistatusesAction extends TwitterapiAction return; } + // 'id' is an undocumented parameter in Twitter's API. Several + // clients make use of it, so we support it too. + + // show.json?id=12345 takes precedence over /show/12345.json + $this->auth_user = $apidata['user']; - $notice_id = $apidata['api_arg']; - $notice = Notice::staticGet($notice_id); + $notice_id = $this->trimmed('id'); + + if (empty($notice_id)) { + $notice_id = $apidata['api_arg']; + } + + $notice = Notice::staticGet((int)$notice_id); if ($notice) { if ($apidata['content-type'] == 'xml') { @@ -381,10 +397,15 @@ class TwitapistatusesAction extends TwitterapiAction } else { // XXX: Twitter just sets a 404 header and doens't bother // to return an err msg - $this->clientError(_('No status with that ID found.'), - 404, $apidata['content-type']); + $deleted = Deleted_notice::staticGet($notice_id); + if (!empty($deleted)) { + $this->clientError(_('Status deleted.'), + 410, $apidata['content-type']); + } else { + $this->clientError(_('No status with that ID found.'), + 404, $apidata['content-type']); + } } - } function destroy($args, $apidata) @@ -435,7 +456,8 @@ class TwitapistatusesAction extends TwitterapiAction function friends($args, $apidata) { parent::handle($args); - return $this->subscriptions($apidata, 'subscribed', 'subscriber'); + $includeStatuses=! (boolean) $args['lite']; + return $this->subscriptions($apidata, 'subscribed', 'subscriber', false, $includeStatuses); } function friendsIDs($args, $apidata) @@ -447,7 +469,8 @@ class TwitapistatusesAction extends TwitterapiAction function followers($args, $apidata) { parent::handle($args); - return $this->subscriptions($apidata, 'subscriber', 'subscribed'); + $includeStatuses=! (boolean) $args['lite']; + return $this->subscriptions($apidata, 'subscriber', 'subscribed', false, $includeStatuses); } function followersIDs($args, $apidata) @@ -456,7 +479,7 @@ class TwitapistatusesAction extends TwitterapiAction return $this->subscriptions($apidata, 'subscriber', 'subscribed', true); } - function subscriptions($apidata, $other_attr, $user_attr, $onlyIDs=false) + function subscriptions($apidata, $other_attr, $user_attr, $onlyIDs=false, $includeStatuses=true) { $this->auth_user = $apidata['user']; $user = $this->get_user($apidata['api_arg'], $apidata); @@ -512,26 +535,26 @@ class TwitapistatusesAction extends TwitterapiAction if ($onlyIDs) { $this->showIDs($others, $type); } else { - $this->show_profiles($others, $type); + $this->show_profiles($others, $type, $includeStatuses); } $this->end_document($type); } - function show_profiles($profiles, $type) + function show_profiles($profiles, $type, $includeStatuses) { switch ($type) { case 'xml': $this->elementStart('users', array('type' => 'array')); foreach ($profiles as $profile) { - $this->show_profile($profile); + $this->show_profile($profile,$type,null,$includeStatuses); } $this->elementEnd('users'); break; case 'json': $arrays = array(); foreach ($profiles as $profile) { - $arrays[] = $this->twitter_user_array($profile, true); + $arrays[] = $this->twitter_user_array($profile, $includeStatuses); } print json_encode($arrays); break;