diff --git a/actions/apiblockcreate.php b/actions/apiblockcreate.php index c26485f591..b355cd1c7e 100644 --- a/actions/apiblockcreate.php +++ b/actions/apiblockcreate.php @@ -23,7 +23,7 @@ * @package StatusNet * @author Evan Prodromou * @author Zach Copley - * @copyright 2009 StatusNet, Inc. + * @copyright 2009-2010 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ @@ -65,7 +65,7 @@ class ApiBlockCreateAction extends ApiAuthAction parent::prepare($args); $this->user = $this->auth_user; - $this->other = $this->getTargetUser($this->arg('id')); + $this->other = $this->getTargetProfile($this->arg('id')); return true; } diff --git a/actions/apiblockdestroy.php b/actions/apiblockdestroy.php index 666f308f4c..7ea201677e 100644 --- a/actions/apiblockdestroy.php +++ b/actions/apiblockdestroy.php @@ -23,7 +23,7 @@ * @package StatusNet * @author Evan Prodromou * @author Zach Copley - * @copyright 2009 StatusNet, Inc. + * @copyright 2009-2010 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ @@ -64,7 +64,7 @@ class ApiBlockDestroyAction extends ApiAuthAction parent::prepare($args); $this->user = $this->auth_user; - $this->other = $this->getTargetUser($this->arg('id')); + $this->other = $this->getTargetProfile($this->arg('id')); return true; } diff --git a/actions/apifriendshipscreate.php b/actions/apifriendshipscreate.php index 1de2cc32e0..a7ec5b28a4 100644 --- a/actions/apifriendshipscreate.php +++ b/actions/apifriendshipscreate.php @@ -24,7 +24,7 @@ * @author Dan Moore * @author Evan Prodromou * @author Zach Copley - * @copyright 2009 StatusNet, Inc. + * @copyright 2009-2010 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ @@ -67,7 +67,7 @@ class ApiFriendshipsCreateAction extends ApiAuthAction parent::prepare($args); $this->user = $this->auth_user; - $this->other = $this->getTargetUser($id); + $this->other = $this->getTargetProfile($this->arg('id')); return true; } @@ -106,7 +106,7 @@ class ApiFriendshipsCreateAction extends ApiAuthAction if (empty($this->other)) { $this->clientError( - _('Could not follow user: User not found.'), + _('Could not follow user: profile not found.'), 403, $this->format ); diff --git a/actions/apifriendshipsdestroy.php b/actions/apifriendshipsdestroy.php index d48a577562..551d016823 100644 --- a/actions/apifriendshipsdestroy.php +++ b/actions/apifriendshipsdestroy.php @@ -24,7 +24,7 @@ * @author Dan Moore * @author Evan Prodromou * @author Zach Copley - * @copyright 2009 StatusNet, Inc. + * @copyright 2009-2010 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ @@ -67,7 +67,7 @@ class ApiFriendshipsDestroyAction extends ApiAuthAction parent::prepare($args); $this->user = $this->auth_user; - $this->other = $this->getTargetUser($id); + $this->other = $this->getTargetProfile($this->arg('id')); return true; } @@ -125,8 +125,7 @@ class ApiFriendshipsDestroyAction extends ApiAuthAction } // throws an exception on error - Subscription::cancel($this->user->getProfile(), - $this->other->getProfile()); + Subscription::cancel($this->user->getProfile(), $this->other); $this->initDocument($this->format); $this->showProfile($this->other, $this->format); diff --git a/actions/apifriendshipsexists.php b/actions/apifriendshipsexists.php index ca62b5f514..725178fd42 100644 --- a/actions/apifriendshipsexists.php +++ b/actions/apifriendshipsexists.php @@ -24,7 +24,7 @@ * @author Dan Moore * @author Evan Prodromou * @author Zach Copley - * @copyright 2009 StatusNet, Inc. + * @copyright 2009-2010 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ @@ -50,8 +50,8 @@ require_once INSTALLDIR . '/lib/apiprivateauth.php'; class ApiFriendshipsExistsAction extends ApiPrivateAuthAction { - var $user_a = null; - var $user_b = null; + var $profile_a = null; + var $profile_b = null; /** * Take arguments for running @@ -66,11 +66,8 @@ class ApiFriendshipsExistsAction extends ApiPrivateAuthAction { parent::prepare($args); - $user_a_id = $this->trimmed('user_a'); - $user_b_id = $this->trimmed('user_b'); - - $this->user_a = $this->getTargetUser($user_a_id); - $this->user_b = $this->getTargetUser($user_b_id); + $this->profile_a = $this->getTargetProfile($this->trimmed('user_a')); + $this->profile_b = $this->getTargetProfile($this->trimmed('user_b')); return true; } @@ -89,16 +86,16 @@ class ApiFriendshipsExistsAction extends ApiPrivateAuthAction { parent::handle($args); - if (empty($this->user_a) || empty($this->user_b)) { + if (empty($this->profile_a) || empty($this->profile_b)) { $this->clientError( - _('Two user ids or screen_names must be supplied.'), + _('Two valid IDs or screen_names must be supplied.'), 400, $this->format ); return; } - $result = $this->user_a->isSubscribed($this->user_b); + $result = Subscription::exists($this->profile_a, $this->profile_b); switch ($this->format) { case 'xml': diff --git a/lib/apiaction.php b/lib/apiaction.php index 89a4871029..8de13a62da 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -1374,6 +1374,34 @@ class ApiAction extends Action } } + function getTargetProfile($id) + { + if (empty($id)) { + + // Twitter supports these other ways of passing the user ID + if (is_numeric($this->arg('id'))) { + return Profile::staticGet($this->arg('id')); + } else if ($this->arg('id')) { + $nickname = common_canonical_nickname($this->arg('id')); + return Profile::staticGet('nickname', $nickname); + } else if ($this->arg('user_id')) { + // This is to ensure that a non-numeric user_id still + // overrides screen_name even if it doesn't get used + if (is_numeric($this->arg('user_id'))) { + return Profile::staticGet('id', $this->arg('user_id')); + } + } else if ($this->arg('screen_name')) { + $nickname = common_canonical_nickname($this->arg('screen_name')); + return Profile::staticGet('nickname', $nickname); + } + } else if (is_numeric($id)) { + return Profile::staticGet($id); + } else { + $nickname = common_canonical_nickname($id); + return Profile::staticGet('nickname', $nickname); + } + } + function getTargetGroup($id) { if (empty($id)) {