X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Ftwitapifavorites.php;h=2c6c2e1d9e7cf57b2825f0ad1a81a392a1f496c2;hb=f2e3021b59f3661b3c900b06600a580b8970df2f;hp=932ee79337fb9eead3aed1ea38f026d62be88a39;hpb=37b3bd54893b0221fba32461c2720fc252e11743;p=quix0rs-gnu-social.git diff --git a/actions/twitapifavorites.php b/actions/twitapifavorites.php index 932ee79337..2c6c2e1d9e 100644 --- a/actions/twitapifavorites.php +++ b/actions/twitapifavorites.php @@ -39,34 +39,19 @@ class TwitapifavoritesAction extends TwitterapiAction { function favorites($args, $apidata) { parent::handle($args); - $user = null; - - // function was called with an argument /favorites/api_arg.format - if (isset($apidata['api_arg'])) { - - if (is_numeric($apidata['api_arg'])) { - $user = User::staticGet($apidata['api_arg']); - } else { - $nickname = common_canonical_nickname($apidata['api_arg']); - $user = User::staticGet('nickname', $nickname); - } - } else { - - // if no user was specified, then we'll use the authenticated user - $user = $apidata['user']; - } + $this->auth_user = $apidata['user']; + $user = $this->get_user($apidata['api_arg'], $apidata); if (!$user) { - // Set the user to be the auth user if asked-for can't be found - // honestly! This is what Twitter does, I swear --Zach - $user = $apidata['user']; + $this->client_error('Not Found', 404, $apidata['content-type']); + return; } $profile = $user->getProfile(); if (!$profile) { common_server_error(_('User has no profile.')); - exit(); + return; } $page = $this->arg('page'); @@ -83,7 +68,7 @@ class TwitapifavoritesAction extends TwitterapiAction { if (!$notice) { common_server_error(_('Could not retrieve favorite notices.')); - exit(); + return; } $sitename = common_config('site', 'name'); @@ -111,7 +96,6 @@ class TwitapifavoritesAction extends TwitterapiAction { common_user_error(_('API method not found!'), $code = 404); } - exit(); } function create($args, $apidata) { @@ -121,22 +105,28 @@ class TwitapifavoritesAction extends TwitterapiAction { if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) { // XXX: Twitter just prints the err msg, no XML / JSON. $this->client_error(_('This method requires a POST or DELETE.'), 400, $apidata['content-type']); - exit(); + return; + } + + if (!in_array($apidata['content-type'], array('xml', 'json'))) { + common_user_error(_('API method not found!'), $code = 404); + return; } - $user = $apidata['user']; + $this->auth_user = $apidata['user']; + $user = $this->auth_user; $notice_id = $apidata['api_arg']; $notice = Notice::staticGet($notice_id); if (!$notice) { $this->client_error(_('No status found with that ID.'), 404, $apidata['content-type']); - exit(); + return; } // XXX: Twitter lets you fave things repeatedly via api. if ($user->hasFave($notice)) { $this->client_error(_('This notice is already a favorite!'), 403, $apidata['content-type']); - exit(); + return; } common_debug("notice: " . $apidata['api_arg']); @@ -145,7 +135,7 @@ class TwitapifavoritesAction extends TwitterapiAction { if (!$fave) { common_server_error(_('Could not create favorite.')); - exit(); + return; } $this->notify($fave, $notice, $user); @@ -157,13 +147,11 @@ class TwitapifavoritesAction extends TwitterapiAction { $this->show_single_json_status($notice); } - exit(); } function destroy($args, $apidata) { parent::handle($args); common_server_error(_('API method under construction.'), $code=501); - exit(); } // XXX: these two funcs swiped from faves. Maybe put in util.php, or some common base class?