X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Ftwitapifavorites.php;h=3eaff327a1c202d684106ad70876ce9fefb9e192;hb=c3f2d195f934c4deff91d30640ec703cb576e55d;hp=d7d77907dd0efe4248386b147d1340fe9af00b49;hpb=dec2f29c6a77dd97383ebdbabdc0bff8e524bfa4;p=quix0rs-gnu-social.git diff --git a/actions/twitapifavorites.php b/actions/twitapifavorites.php index d7d77907dd..3eaff327a1 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,46 +83,44 @@ class TwitapifavoritesAction extends TwitterapiAction { common_user_error(_('API method not found!'), $code = 404); } - exit(); } function create($args, $apidata) { parent::handle($args); - if (!in_array($apidata['content-type'], array('xml', 'json'))) { - common_user_error(_('API method not found!'), $code = 404); - exit; - } - // Check for RESTfulness 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; } - $user = $apidata['user']; + if (!in_array($apidata['content-type'], array('xml', 'json'))) { + common_user_error(_('API method not found!'), $code = 404); + return; + } + + $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']); - $fave = Fave::addNew($user, $notice); if (!$fave) { common_server_error(_('Could not create favorite.')); - exit(); + return; } $this->notify($fave, $notice, $user); @@ -162,13 +132,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?