X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Ftwitapifavorites.php;h=7783707a4029922c0d6b3ed768c4f935a0636fd9;hb=4f3d1e93e97365deac2366bfe422e8301d773a25;hp=932ee79337fb9eead3aed1ea38f026d62be88a39;hpb=37b3bd54893b0221fba32461c2720fc252e11743;p=quix0rs-gnu-social.git diff --git a/actions/twitapifavorites.php b/actions/twitapifavorites.php index 932ee79337..7783707a40 100644 --- a/actions/twitapifavorites.php +++ b/actions/twitapifavorites.php @@ -23,50 +23,22 @@ require_once(INSTALLDIR.'/lib/twitterapi.php'); class TwitapifavoritesAction extends TwitterapiAction { - function is_readonly() { - - static $write_methods = array('favorites'); - - $cmdtext = explode('.', $this->arg('method')); - - if (in_array($cmdtext[0], $write_methods)) { - return false; - } - - return true; - } - 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 +55,7 @@ class TwitapifavoritesAction extends TwitterapiAction { if (!$notice) { common_server_error(_('Could not retrieve favorite notices.')); - exit(); + return; } $sitename = common_config('site', 'name'); @@ -99,7 +71,7 @@ class TwitapifavoritesAction extends TwitterapiAction { $this->show_xml_timeline($notice); break; case 'rss': - $this->show_rss_timeline($notice, $title, $id, $link, $subtitle); + $this->show_rss_timeline($notice, $title, $link, $subtitle); break; case 'atom': $this->show_atom_timeline($notice, $title, $id, $link, $subtitle); @@ -111,7 +83,6 @@ class TwitapifavoritesAction extends TwitterapiAction { common_user_error(_('API method not found!'), $code = 404); } - exit(); } function create($args, $apidata) { @@ -121,22 +92,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 +122,7 @@ class TwitapifavoritesAction extends TwitterapiAction { if (!$fave) { common_server_error(_('Could not create favorite.')); - exit(); + return; } $this->notify($fave, $notice, $user); @@ -157,13 +134,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?