*/
class ApiAccountUpdateDeliveryDeviceAction extends ApiAuthAction
{
+ protected $needPost = true;
+
/**
* Take arguments for running
*
{
parent::handle($args);
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- $this->clientError(
- // TRANS: Client error message. POST is a HTTP command. It should not be translated.
- _('This method requires a POST.'),
- 400, $this->format
- );
- return;
- }
-
if (!in_array($this->format, array('xml', 'json'))) {
$this->clientError(
// TRANS: Client error displayed when coming across a non-supported API method.
if (empty($this->user)) {
// TRANS: Client error displayed when no existing user is provided for a user's delivery device setting.
- $this->clientError(_('No such user.'), 404, $this->format);
- return;
+ $this->clientError(_('No such user.'), 404);
}
$original = clone($this->user);
*/
class ApiAccountUpdateProfileAction extends ApiAuthAction
{
+ protected $needPost = true;
+
/**
* Take arguments for running
*
*
* @return boolean success flag
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
*
* See which request params have been set, and update the profile
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
-
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- $this->clientError(
- // TRANS: Client error. POST is a HTTP command. It should not be translated.
- _('This method requires a POST.'),
- 400, $this->format
- );
- return;
- }
+ parent::handle();
if (!in_array($this->format, array('xml', 'json'))) {
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 404,
- $this->format
- );
- return;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'), 404);
}
if (empty($this->user)) {
// TRANS: Client error displayed if a user could not be found.
- $this->clientError(_('No such user.'), 404, $this->format);
- return;
+ $this->clientError(_('No such user.'), 404);
}
$profile = $this->user->getProfile();
*/
class ApiAccountUpdateProfileImageAction extends ApiAuthAction
{
- /**
- * Take arguments for running
- *
- * @param array $args $_REQUEST args
- *
- * @return boolean success flag
- */
- function prepare($args)
- {
- parent::prepare($args);
-
- $this->user = $this->auth_user;
-
- return true;
- }
+ protected $needPost = true;
/**
* Handle the request
*
* Check whether the credentials are valid and output the result
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
-
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- $this->clientError(
- // TRANS: Client error. POST is a HTTP command. It should not be translated.
- _('This method requires a POST.'),
- 400, $this->format
- );
- return;
- }
+ parent::handle();
// Workaround for PHP returning empty $_POST and $_FILES when POST
// length > post_max_size in php.ini
'The server was unable to handle that much POST data (%s bytes) due to its current configuration.',
intval($_SERVER['CONTENT_LENGTH']));
$this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
- return;
}
if (empty($this->user)) {
// TRANS: Client error displayed updating profile image without having a user object.
- $this->clientError(_('No such user.'), 404, $this->format);
- return;
+ $this->clientError(_('No such user.'), 404);
}
try {
$imagefile = ImageFile::fromUpload('image');
} catch (Exception $e) {
- $this->clientError($e->getMessage(), 400, $this->format);
- return;
+ $this->clientError($e->getMessage());
}
$type = $imagefile->preferredType();
$imagefile->copyTo($filepath);
$profile = $this->user->getProfile();
-
- if (empty($profile)) {
- // TRANS: Error message displayed when referring to a user without a profile.
- $this->clientError(_('User has no profile.'));
- return;
- }
-
$profile->setOriginal($filename);
common_broadcast_profile($profile);
if (empty($this->user)) {
// TRANS: Client error displayed when making an Atom API request for an unknown user.
- $this->clientError(_('No such user.'), 404, $this->format);
- return;
+ $this->clientError(_('No such user.'), 404);
}
return true;
*/
class ApiBlockCreateAction extends ApiAuthAction
{
+ protected $needPost = true;
+
var $other = null;
/**
* @return boolean success flag
*
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
- $this->user = $this->auth_user;
$this->other = $this->getTargetProfile($this->arg('id'));
return true;
*
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
-
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- $this->clientError(
- // TRANS: Client error. POST is a HTTP command. It should not be translated.
- _('This method requires a POST.'),
- 400,
- $this->format
- );
- return;
- }
+ parent::handle();
if (empty($this->user) || empty($this->other)) {
// TRANS: Client error displayed when trying to block a non-existing user or a user from another site.
- $this->clientError(_('No such user.'), 404, $this->format);
- return;
+ $this->clientError(_('No such user.'), 404);
}
// Don't allow blocking yourself!
if ($this->user->id == $this->other->id) {
- $this->clientError(
- // TRANS: Client error displayed when users try to block themselves.
- _("You cannot block yourself!"),
- 403,
- $this->format
- );
- return;
+ // TRANS: Client error displayed when users try to block themselves.
+ $this->clientError(_("You cannot block yourself!"), 403);
}
if (!$this->user->hasBlocked($this->other)) {
$this->endDocument($this->format);
} else {
// TRANS: Server error displayed when blocking a user has failed.
- $this->serverError(_('Block user failed.'), 500, $this->format);
+ $this->serverError(_('Block user failed.'), 500);
}
}
}
*/
class ApiBlockDestroyAction extends ApiAuthAction
{
+ protected $needPost = true;
+
var $other = null;
/**
*
* @return boolean success flag
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
- $this->user = $this->auth_user;
$this->other = $this->getTargetProfile($this->arg('id'));
return true;
*
* Save the new message
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
-
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- $this->clientError(
- // TRANS: Client error. POST is a HTTP command. It should not be translated.
- _('This method requires a POST.'),
- 400,
- $this->format
- );
- return;
- }
+ parent::handle();
if (empty($this->user) || empty($this->other)) {
// TRANS: Client error when user not found for an API action to remove a block for a user.
- $this->clientError(_('No such user.'), 404, $this->format);
- return;
+ $this->clientError(_('No such user.'), 404);
}
if ($this->user->hasBlocked($this->other)) {
if (empty($this->user)) {
// TRANS: Client error given when a user was not found (404).
- $this->clientError(_('No such user.'), 404, $this->format);
- return;
+ $this->clientError(_('No such user.'), 404);
}
$server = common_root_url();
*/
class ApiDirectMessageNewAction extends ApiAuthAction
{
+ protected $needPost = true;
+
var $other = null;
var $content = null;
*
* @return boolean success flag
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
- $this->user = $this->auth_user;
-
if (empty($this->user)) {
// TRANS: Client error when user not found for an API direct message action.
- $this->clientError(_('No such user.'), 404, $this->format);
- return;
+ $this->clientError(_('No such user.'), 404);
}
$this->content = $this->trimmed('text');
- $this->user = $this->auth_user;
-
$user_param = $this->trimmed('user');
$user_id = $this->arg('user_id');
$screen_name = $this->trimmed('screen_name');
*
* Save the new message
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
-
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- $this->clientError(
- // TRANS: Client error. POST is a HTTP command. It should not be translated.
- _('This method requires a POST.'),
- 400,
- $this->format
- );
- return;
- }
+ parent::handle();
if (empty($this->content)) {
- $this->clientError(
- // TRANS: Client error displayed when no message text was submitted (406).
- _('No message text!'),
- 406,
- $this->format
- );
+ // TRANS: Client error displayed when no message text was submitted (406).
+ $this->clientError(_('No message text!'), 406);
} else {
$content_shortened = $this->auth_user->shortenLinks($this->content);
if (Message::contentTooLong($content_shortened)) {
+ // TRANS: Client error displayed when message content is too long.
+ // TRANS: %d is the maximum number of characters for a message.
$this->clientError(
- // TRANS: Client error displayed when message content is too long.
- // TRANS: %d is the maximum number of characters for a message.
- sprintf(_m('That\'s too long. Maximum message size is %d character.', 'That\'s too long. Maximum message size is %d characters.', Message::maxContent()),
- Message::maxContent()
- ),
- 406,
- $this->format
- );
- return;
+ sprintf(_m('That\'s too long. Maximum message size is %d character.', 'That\'s too long. Maximum message size is %d characters.', Message::maxContent()), Message::maxContent()),
+ 406);
}
}
if (empty($this->other)) {
// TRANS: Client error displayed if a recipient user could not be found (403).
- $this->clientError(_('Recipient user not found.'), 403, $this->format);
- return;
+ $this->clientError(_('Recipient user not found.'), 403);
} else if (!$this->user->mutuallySubscribed($this->other)) {
- $this->clientError(
- // TRANS: Client error displayed trying to direct message another user who's not a friend (403).
- _('Cannot send direct messages to users who aren\'t your friend.'),
- 403,
- $this->format
- );
- return;
+ // TRANS: Client error displayed trying to direct message another user who's not a friend (403).
+ $this->clientError(_('Cannot send direct messages to users who aren\'t your friend.'), 403);
} else if ($this->user->id == $this->other->id) {
// Note: sending msgs to yourself is allowed by Twitter
// TRANS: Client error displayed trying to direct message self (403).
- $this->clientError(_('Do not send a message to yourself; ' .
- 'just say it to yourself quietly instead.'), 403, $this->format);
- return;
+ $this->clientError(_('Do not send a message to yourself; just say it to yourself quietly instead.'), 403);
}
$message = Message::saveNew(
*/
class ApiFriendshipsCreateAction extends ApiAuthAction
{
+ protected $needPost = true;
+
var $other = null;
/**
* @return boolean success flag
*
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
- $this->user = $this->auth_user;
$this->other = $this->getTargetProfile($this->arg('id'));
return true;
*
* Check the format and show the user info
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
-
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- $this->clientError(
- // TRANS: Client error. POST is a HTTP command. It should not be translated.
- _('This method requires a POST.'),
- 400,
- $this->format
- );
- return;
- }
+ parent::handle();
if (!in_array($this->format, array('xml', 'json'))) {
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 404,
- $this->format
- );
- return;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'), 404);
}
if (empty($this->other)) {
- $this->clientError(
- // TRANS: Client error displayed when trying follow who's profile could not be found.
- _('Could not follow user: profile not found.'),
- 403,
- $this->format
- );
- return;
+ // TRANS: Client error displayed when trying follow who's profile could not be found.
+ $this->clientError(_('Could not follow user: profile not found.'), 403);
}
if ($this->user->isSubscribed($this->other)) {
_('Could not follow user: %s is already on your list.'),
$this->other->nickname
);
- $this->clientError($errmsg, 403, $this->format);
- return;
+ $this->clientError($errmsg, 403);
}
try {
Subscription::start($this->user->getProfile(), $this->other);
} catch (Exception $e) {
- $this->clientError($e->getMessage(), 403, $this->format);
+ $this->clientError($e->getMessage(), 403);
}
$this->initDocument($this->format);
$this->endDocument('json');
break;
default:
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 404,
- $this->format
- );
- break;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'), 404);
}
}
$this->endDocument('json');
break;
default:
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 404,
- $this->format
- );
- break;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'), 404);
}
}
*/
class ApiGroupCreateAction extends ApiAuthAction
{
+ protected $needPost = true;
+
var $group = null;
var $nickname = null;
var $fullname = null;
*
* @return boolean success flag
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
- $this->user = $this->auth_user;
-
$this->nickname = Nickname::normalize($this->arg('nickname'));
$this->fullname = $this->arg('full_name');
$this->homepage = $this->arg('homepage');
*
* Save the new group
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
-
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- $this->clientError(
- // TRANS: Client error. POST is a HTTP command. It should not be translated.
- _('This method requires a POST.'),
- 400,
- $this->format
- );
- return;
- }
+ parent::handle();
if (empty($this->user)) {
// TRANS: Client error given when a user was not found (404).
- $this->clientError(_('No such user.'), 404, $this->format);
- return;
+ $this->clientError(_('No such user.'), 404);
}
if ($this->validateParams() == false) {
$this->showSingleJsonGroup($group);
break;
default:
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 404,
- $this->format
- );
- break;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'), 404);
}
}
function validateParams()
{
if ($this->groupNicknameExists($this->nickname)) {
- $this->clientError(
- // TRANS: Client error trying to create a group with a nickname this is already in use.
- _('Nickname already in use. Try another one.'),
- 403,
- $this->format
- );
- return false;
- } else if (!User_group::allowedNickname($this->nickname)) {
- $this->clientError(
- // TRANS: Client error in form for group creation.
- _('Not a valid nickname.'),
- 403,
- $this->format
- );
- return false;
+ // TRANS: Client error trying to create a group with a nickname this is already in use.
+ $this->clientError(_('Nickname already in use. Try another one.'), 403);
+
+ } elseif (!User_group::allowedNickname($this->nickname)) {
+ // TRANS: Client error in form for group creation.
+ $this->clientError(_('Not a valid nickname.'), 403);
} elseif (!is_null($this->homepage)
&& strlen($this->homepage) > 0
&& !common_valid_http_url($this->homepage)) {
- $this->clientError(
- // TRANS: Client error in form for group creation.
- _('Homepage is not a valid URL.'),
- 403,
- $this->format
- );
- return false;
+ // TRANS: Client error in form for group creation.
+ $this->clientError(_('Homepage is not a valid URL.'), 403);
+
} elseif (
- !is_null($this->fullname)
- && mb_strlen($this->fullname) > 255) {
- $this->clientError(
- // TRANS: Client error in form for group creation.
- _('Full name is too long (maximum 255 characters).'),
- 403,
- $this->format
- );
- return false;
+ !is_null($this->fullname)
+ && mb_strlen($this->fullname) > 255) {
+ // TRANS: Client error in form for group creation.
+ $this->clientError(_('Full name is too long (maximum 255 characters).'), 403);
+
} elseif (User_group::descriptionTooLong($this->description)) {
- $this->clientError(
- sprintf(
- // TRANS: Client error shown when providing too long a description during group creation.
- // TRANS: %d is the maximum number of allowed characters.
- _m('Description is too long (maximum %d character).',
- 'Description is too long (maximum %d characters).',
- User_group::maxDescription()),
- User_group::maxDescription()
- ),
- 403,
- $this->format
- );
- return false;
- } elseif (
- !is_null($this->location)
- && mb_strlen($this->location) > 255) {
- $this->clientError(
- // TRANS: Client error shown when providing too long a location during group creation.
- _('Location is too long (maximum 255 characters).'),
- 403,
- $this->format
- );
- return false;
+ // TRANS: Client error shown when providing too long a description during group creation.
+ // TRANS: %d is the maximum number of allowed characters.
+ $this->clientError(sprintf(_m('Description is too long (maximum %d character).',
+ 'Description is too long (maximum %d characters).',
+ User_group::maxDescription()), User_group::maxDescription()), 403);
+
+ } elseif (!is_null($this->location)
+ && mb_strlen($this->location) > 255) {
+ // TRANS: Client error shown when providing too long a location during group creation.
+ $this->clientError(_('Location is too long (maximum 255 characters).'), 403);
}
if (!empty($this->aliasstring)) {
}
if (count($this->aliases) > common_config('group', 'maxaliases')) {
- $this->clientError(
- sprintf(
+ $this->clientError(sprintf(
// TRANS: Client error shown when providing too many aliases during group creation.
// TRANS: %d is the maximum number of allowed aliases.
_m('Too many aliases! Maximum %d allowed.',
'Too many aliases! Maximum %d allowed.',
common_config('group', 'maxaliases')),
- common_config('group', 'maxaliases')
- ),
- 403,
- $this->format
- );
- return false;
+ common_config('group', 'maxaliases')),
+ 403);
}
foreach ($this->aliases as $alias) {
if (!Nickname::isValid($alias)) {
- $this->clientError(
- // TRANS: Client error shown when providing an invalid alias during group creation.
- // TRANS: %s is the invalid alias.
- sprintf(_('Invalid alias: "%s".'), $alias),
- 403,
- $this->format
- );
- return false;
+ // TRANS: Client error shown when providing an invalid alias during group creation.
+ // TRANS: %s is the invalid alias.
+ $this->clientError(sprintf(_('Invalid alias: "%s".'), $alias), 403);
}
if ($this->groupNicknameExists($alias)) {
- $this->clientError(
- sprintf(
- // TRANS: Client error displayed when trying to use an alias during group creation that is already in use.
- // TRANS: %s is the alias that is already in use.
- _('Alias "%s" already in use. Try another one.'),
- $alias
- ),
- 403,
- $this->format
- );
- return false;
+ // TRANS: Client error displayed when trying to use an alias during group creation that is already in use.
+ // TRANS: %s is the alias that is already in use.
+ $this->clientError(sprintf(_('Alias "%s" already in use. Try another one.'), $alias), 403);
}
// XXX assumes alphanum nicknames
if (strcmp($alias, $this->nickname) == 0) {
- $this->clientError(
- // TRANS: Client error displayed when trying to use an alias during group creation that is the same as the group's nickname.
- _('Alias can\'t be the same as nickname.'),
- 403,
- $this->format
- );
- return false;
+ // TRANS: Client error displayed when trying to use an alias during group creation that is the same as the group's nickname.
+ $this->clientError(_('Alias can\'t be the same as nickname.'), 403);
}
}
* @return boolean success flag
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
- $this->user = $this->getTargetUser(null);
+ $this->target = $this->getTargetProfile(null);
$this->group = $this->getTargetGroup(null);
return true;
*
* Save the new message
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
+ parent::handle();
- if (empty($this->user)) {
+ if (empty($this->target)) {
// TRANS: Client error displayed when checking group membership for a non-existing user.
- $this->clientError(_('No such user.'), 404, $this->format);
- return;
+ $this->clientError(_('No such user.'), 404);
}
if (empty($this->group)) {
// TRANS: Client error displayed when checking group membership for a non-existing group.
- $this->clientError(_('Group not found.'), 404, $this->format);
- return false;
+ $this->clientError(_('Group not found.'), 404);
}
- $is_member = $this->user->isMember($this->group);
+ $is_member = $this->target->isMember($this->group);
switch($this->format) {
case 'xml':
$this->endDocument('json');
break;
default:
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 400,
- $this->format
- );
- break;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'));
}
}
*/
class ApiGroupJoinAction extends ApiAuthAction
{
+ protected $needPost = true;
+
var $group = null;
/**
*
* @return boolean success flag
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
- $this->user = $this->auth_user;
$this->group = $this->getTargetGroup($this->arg('id'));
return true;
*
* Save the new message
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
-
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- $this->clientError(
- // TRANS: Client error. POST is a HTTP command. It should not be translated.
- _('This method requires a POST.'),
- 400,
- $this->format
- );
- return;
- }
+ parent::handle();
if (empty($this->user)) {
// TRANS: Client error displayed when trying to have a non-existing user join a group.
- $this->clientError(_('No such user.'), 404, $this->format);
- return;
+ $this->clientError(_('No such user.'), 404);
}
if (empty($this->group)) {
// TRANS: Client error displayed when trying to join a group that does not exist.
- $this->clientError(_('Group not found.'), 404, $this->format);
- return false;
+ $this->clientError(_('Group not found.'), 404);
}
if ($this->user->isMember($this->group)) {
- $this->clientError(
- // TRANS: Server error displayed when trying to join a group the user is already a member of.
- _('You are already a member of that group.'),
- 403,
- $this->format
- );
- return;
+ // TRANS: Server error displayed when trying to join a group the user is already a member of.
+ $this->clientError(_('You are already a member of that group.'), 403);
}
if (Group_block::isBlocked($this->group, $this->user->getProfile())) {
- $this->clientError(
- // TRANS: Server error displayed when trying to join a group the user is blocked from joining.
- _('You have been blocked from that group by the admin.'),
- 403,
- $this->format
- );
- return;
+ // TRANS: Server error displayed when trying to join a group the user is blocked from joining.
+ $this->clientError(_('You have been blocked from that group by the admin.'), 403);
}
try {
// TRANS: %1$s is the joining user's nickname, $2$s is the group nickname for which the join failed.
$this->serverError(sprintf(_('Could not join user %1$s to group %2$s.'),
$cur->nickname, $this->group->nickname));
- return;
}
switch($this->format) {
$this->showSingleJsonGroup($this->group);
break;
default:
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 404,
- $this->format
- );
- break;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'), 404);
}
}
}
*/
class ApiGroupLeaveAction extends ApiAuthAction
{
+ protected $needPost = true;
+
var $group = null;
/**
*
* @return boolean success flag
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
- $this->user = $this->auth_user;
$this->group = $this->getTargetGroup($this->arg('id'));
return true;
*
* Save the new message
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
-
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- $this->clientError(
- // TRANS: Client error. POST is a HTTP command. It should not be translated.
- _('This method requires a POST.'),
- 400,
- $this->format
- );
- return;
- }
+ parent::handle();
if (empty($this->user)) {
// TRANS: Client error displayed when trying to have a non-existing user leave a group.
- $this->clientError(_('No such user.'), 404, $this->format);
- return;
+ $this->clientError(_('No such user.'), 404);
}
if (empty($this->group)) {
// TRANS: Client error displayed when trying to leave a group that does not exist.
- $this->clientError(_('Group not found.'), 404, $this->format);
- return false;
+ $this->clientError(_('Group not found.'), 404);
}
$member = new Group_member();
if (!$member->find(true)) {
// TRANS: Server error displayed when trying to leave a group the user is not a member of.
$this->serverError(_('You are not a member of this group.'));
- return;
}
try {
// TRANS: %1$s is the leaving user's nickname, $2$s is the group nickname for which the leave failed.
$this->serverError(sprintf(_('Could not remove user %1$s from group %2$s.'),
$cur->nickname, $this->group->nickname));
- return;
}
switch($this->format) {
case 'xml':
$this->showSingleJsonGroup($this->group);
break;
default:
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 404,
- $this->format
- );
- break;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'), 404);
}
}
}
*
* @return boolean success flag
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
$this->group = $this->getTargetGroup($this->arg('id'));
if (empty($this->group)) {
// TRANS: Client error displayed trying to show group membership on a non-existing group.
- $this->clientError(_('Group not found.'), 404, $this->format);
- return false;
+ $this->clientError(_('Group not found.'), 404);
}
$this->profiles = $this->getProfiles();
*
* Show the members of the group
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
+ parent::handle();
// XXX: RSS and Atom
$this->showJsonUsers($this->profiles);
break;
default:
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 404,
- $this->format
- );
- break;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'), 404);
}
}
*/
class ApiGroupProfileUpdateAction extends ApiAuthAction
{
+ protected $needPost = true;
/**
* Take arguments for running
*
* @return boolean success flag
*
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
*
* See which request params have been set, and update the profile
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
-
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- $this->clientError(
- // TRANS: Client error message. POST is a HTTP command. It should not be translated.
- _('This method requires a POST.'),
- 400, $this->format
- );
- return;
- }
+ parent::handle();
if (!in_array($this->format, array('xml', 'json'))) {
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 404,
- $this->format
- );
- return;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'), 404);
}
if (empty($this->user)) {
// TRANS: Client error displayed when not providing a user or an invalid user.
- $this->clientError(_('No such user.'), 404, $this->format);
- return;
+ $this->clientError(_('No such user.'), 404);
}
if (empty($this->group)) {
// TRANS: Client error displayed when not providing a group or an invalid group.
- $this->clientError(_('Group not found.'), 404, $this->format);
- return false;
+ $this->clientError(_('Group not found.'), 404);
}
if (!$this->user->isAdmin($this->group)) {
// TRANS: Client error displayed when trying to edit a group without being an admin.
$this->clientError(_('You must be an admin to edit the group.'), 403);
- return false;
}
$this->group->query('BEGIN');
}
} catch (ApiValidationException $ave) {
- $this->clientError(
- $ave->getMessage(),
- 403,
- $this->format
- );
- return;
+ $this->clientError($ave->getMessage(), 403);
}
$result = $this->group->update($orig);
}
} catch (ApiValidationException $ave) {
- $this->clientError(
- $ave->getMessage(),
- 403,
- $this->format
- );
- return;
+ $this->clientError($ave->getMessage(), 403);
}
$result = $this->group->setAliases($aliases);
break;
default:
// TRANS: Client error displayed when coming across a non-supported API method.
- $this->clientError(_('API method not found.'), 404, $this->format);
- break;
+ $this->clientError(_('API method not found.'), 404);
}
}
*
* @return boolean success flag
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
$args = array('id' => $alias->group_id, 'format' => $this->format);
common_redirect(common_local_url('ApiGroupShow', $args), 301);
} else {
- $this->clientError(
- // TRANS: Client error displayed when trying to show a group that could not be found.
- _('Group not found.'),
- 404,
- $this->format
- );
+ // TRANS: Client error displayed when trying to show a group that could not be found.
+ $this->clientError(_('Group not found.'), 404);
}
return;
}
*
* Check the format and show the user info
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
+ parent::handle();
switch($this->format) {
case 'xml':
break;
default:
// TRANS: Client error displayed when coming across a non-supported API method.
- $this->clientError(_('API method not found.'), 404, $this->format);
- break;
+ $this->clientError(_('API method not found.'), 404);
}
}
*
* @return boolean success flag
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
if (empty($this->list)) {
// TRANS: Client error displayed when referring to a non-existing list.
- $this->clientError(_('List not found.'), 404, $this->format);
- return false;
+ $this->clientError(_('List not found.'), 404);
}
return true;
*
* @return boolean success flag
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
+ parent::handle();
if($this->delete) {
$this->handleDelete();
$this->showSingleJsonList($this->list);
break;
default:
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 404,
- $this->format
- );
- break;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'), 404);
}
}
function handlePut()
{
if($this->auth_user->id != $this->list->tagger) {
- $this->clientError(
- // TRANS: Client error displayed when trying to update another user's list.
- _('You cannot update lists that do not belong to you.'),
- 401,
- $this->format
- );
+ // TRANS: Client error displayed when trying to update another user's list.
+ $this->clientError(_('You cannot update lists that do not belong to you.'), 401);
}
$new_list = clone($this->list);
$result = $new_list->update($this->list);
if(!$result) {
- $this->clientError(
- // TRANS: Client error displayed when an unknown error occurs updating a list.
- _('An error occured.'),
- 503,
- $this->format
- );
+ // TRANS: Client error displayed when an unknown error occurs updating a list.
+ $this->clientError(_('An error occured.'), 503);
}
switch($this->format) {
$this->showSingleJsonList($new_list);
break;
default:
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 404,
- $this->format
- );
- break;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'), 404);
}
}
function handleDelete()
{
if($this->auth_user->id != $this->list->tagger) {
- $this->clientError(
- // TRANS: Client error displayed when trying to delete another user's list.
- _('You cannot delete lists that do not belong to you.'),
- 401,
- $this->format
- );
+ // TRANS: Client error displayed when trying to delete another user's list.
+ $this->clientError(_('You cannot delete lists that do not belong to you.'), 401);
}
$record = clone($this->list);
$this->showSingleJsonList($record);
break;
default:
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 404,
- $this->format
- );
- break;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'), 404);
}
}
*
* @return boolean success flag
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
- $this->user = $this->getTargetUser($this->arg('id'));
+ $this->target = $this->getTargetProfile($this->arg('id'));
$this->list = $this->getTargetList($this->arg('user'), $this->arg('list_id'));
if (empty($this->list)) {
// TRANS: Client error displayed when referring to a non-existing list.
- $this->clientError(_('List not found.'), 404, $this->format);
- return false;
+ $this->clientError(_('List not found.'), 404);
}
- if (empty($this->user)) {
+ if (!($this->target instanceof Profile)) {
// TRANS: Client error displayed when referring to a non-existing user.
- $this->clientError(_('No such user.'), 404, $this->format);
- return false;
+ $this->clientError(_('No such user.'), 404);
}
return true;
}
*
* @return boolean success flag
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
+ parent::handle();
$arr = array('tagger' => $this->list->tagger,
'tag' => $this->list->tag,
- 'tagged' => $this->user->id);
+ 'tagged' => $this->target->id);
$ptag = Profile_tag::pkeyGet($arr);
if(empty($ptag)) {
- $this->clientError(
- // TRANS: Client error displayed when referring to a non-list member.
- _('The specified user is not a member of this list.'),
- 400,
- $this->format
- );
+ // TRANS: Client error displayed when referring to a non-list member.
+ $this->clientError(_('The specified user is not a member of this list.'));
}
- $user = $this->twitterUserArray($this->user->getProfile(), true);
+ $user = $this->twitterUserArray($this->target, true);
switch($this->format) {
case 'xml':
$this->showSingleJsonUser($user);
break;
default:
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 404,
- $this->format
- );
- break;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'), 404);
}
return true;
}
function handlePost()
{
if($this->auth_user->id != $this->list->tagger) {
- $this->clientError(
- // TRANS: Client error displayed when trying to add members to a list without having the right to do so.
- _('You are not allowed to add members to this list.'),
- 401,
- $this->format
- );
- return false;
+ // TRANS: Client error displayed when trying to add members to a list without having the right to do so.
+ $this->clientError(_('You are not allowed to add members to this list.'), 401);
}
- if($this->user === false) {
- $this->clientError(
- // TRANS: Client error displayed when trying to modify list members without specifying them.
- _('You must specify a member.'),
- 400,
- $this->format
- );
- return false;
+ if (!($this->target instanceof Profile)) {
+ // TRANS: Client error displayed when trying to modify list members without specifying them.
+ $this->clientError(_('You must specify a member.'));
}
$result = Profile_tag::setTag($this->auth_user->id,
- $this->user->id, $this->list->tag);
+ $this->target->id, $this->list->tag);
if(empty($result)) {
- $this->clientError(
- // TRANS: Client error displayed when an unknown error occurs viewing list members.
- _('An error occured.'),
- 500,
- $this->format
- );
- return false;
+ // TRANS: Client error displayed when an unknown error occurs viewing list members.
+ $this->clientError(_('An error occured.'), 500);
}
switch($this->format) {
$this->showSingleJsonList($this->list);
break;
default:
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 404,
- $this->format
- );
- return false;
- break;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'), 404);
}
}
function handleDelete()
{
if($this->auth_user->id != $this->list->tagger) {
- $this->clientError(
- // TRANS: Client error displayed when trying to remove members from a list without having the right to do so.
- _('You are not allowed to remove members from this list.'),
- 401,
- $this->format
- );
- return false;
+ // TRANS: Client error displayed when trying to remove members from a list without having the right to do so.
+ $this->clientError(_('You are not allowed to remove members from this list.'), 401);
}
- if($this->user === false) {
- $this->clientError(
- // TRANS: Client error displayed when trying to modify list members without specifying them.
- _('You must specify a member.'),
- 400,
- $this->format
- );
- return false;
+ if (!($this->target instanceof Profile)) {
+ // TRANS: Client error displayed when trying to modify list members without specifying them.
+ $this->clientError(_('You must specify a member.'));
}
$args = array('tagger' => $this->auth_user->id,
- 'tagged' => $this->user->id,
+ 'tagged' => $this->target->id,
'tag' => $this->list->tag);
$ptag = Profile_tag::pkeyGet($args);
- if(empty($ptag)) {
- $this->clientError(
- // TRANS: Client error displayed when trying to remove a list member that is not part of a list.
- _('The user you are trying to remove from the list is not a member.'),
- 400,
- $this->format
- );
- return false;
+ if (empty($ptag)) {
+ // TRANS: Client error displayed when trying to remove a list member that is not part of a list.
+ $this->clientError(_('The user you are trying to remove from the list is not a member.'));
}
- $result = $ptag->delete();
-
- if(empty($result)) {
- $this->clientError(
- // TRANS: Client error displayed when an unknown error occurs viewing list members.
- _('An error occured.'),
- 500,
- $this->format
- );
- return false;
+ if (!$ptag->delete()) {
+ // TRANS: Client error displayed when an unknown error occurs viewing list members.
+ $this->clientError(_('An error occured.'), 500);
}
switch($this->format) {
$this->showSingleJsonList($this->list);
break;
default:
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 404,
- $this->format
- );
- return false;
- break;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'), 404);
}
+
return true;
}
* @return boolean success flag
*
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
$this->cursor = (int) $this->arg('cursor', -1);
- $this->user = $this->getTargetUser($this->arg('user'));
+ $user = $this->getTargetUser($this->arg('user'));
- if (empty($this->user)) {
+ if (!($user instanceof User)) {
// TRANS: Client error displayed trying to perform an action related to a non-existing user.
- $this->clientError(_('No such user.'), 404, $this->format);
- return;
+ $this->clientError(_('No such user.'), 404);
}
+ $this->target = $user->getProfile();
$this->getLists();
*
* Show the lists
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
+ parent::handle();
switch($this->format) {
case 'xml':
$this->showJsonLists($this->lists, $this->next_cursor, $this->prev_cursor);
break;
default:
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 400,
- $this->format
- );
- break;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'));
}
}
function getLists()
{
- $profile = $this->user->getProfile();
+ $profile = $this->target;
$fn = array($profile, 'getOtherTags');
# 20 lists
*
* @return boolean success flag
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
$this->user = $this->getTargetUser($this->arg('user'));
- if (empty($this->user)) {
+ if (!($user instanceof User)) {
// TRANS: Client error displayed trying to perform an action related to a non-existing user.
- $this->clientError(_('No such user.'), 404, $this->format);
- return false;
+ $this->clientError(_('No such user.'), 404);
}
+ $this->target = $user->getProfile();
$this->getLists();
}
* Show the lists the user has created if the request method is GET
* Create a new list by diferring to handlePost() if it is POST.
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
+ parent::handle();
if($this->create) {
return $this->handlePost();
$this->showSingleJsonList($list);
break;
default:
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 404,
- $this->format
- );
- break;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'), 404);
}
return true;
}
// twitter fixes count at 20
// there is no argument named count
$count = 20;
- $profile = $this->user->getProfile();
- $fn = array($profile, 'getLists');
+ $fn = array($this->target, 'getLists');
list($this->lists,
$this->next_cursor,
':',
array($this->arg('action'),
common_language(),
- $this->user->id,
+ $this->target->id,
strtotime($this->lists[0]->created),
strtotime($this->lists[$last]->created))
)
{
parent::prepare($args);
- $this->user = $this->getTargetUser($this->arg('id'));
+ $this->target = $this->getTargetProfile($this->arg('id'));
$this->list = $this->getTargetList($this->arg('user'), $this->arg('list_id'));
if (empty($this->list)) {
// TRANS: Client error displayed trying to perform an action related to a non-existing list.
- $this->clientError(_('List not found.'), 404, $this->format);
- return false;
+ $this->clientError(_('List not found.'), 404);
}
- if (empty($this->user)) {
+ if (!($this->target instanceof Profile)) {
// TRANS: Client error displayed trying to perform an action related to a non-existing user.
- $this->clientError(_('No such user.'), 404, $this->format);
- return false;
+ $this->clientError(_('No such user.'), 404);
}
return true;
}
parent::handle($args);
$arr = array('profile_tag_id' => $this->list->id,
- 'profile_id' => $this->user->id);
+ 'profile_id' => $this->target->id);
$sub = Profile_tag_subscription::pkeyGet($arr);
if(empty($sub)) {
- $this->clientError(
- // TRANS: Client error displayed when a membership check for a user is nagative.
- _('The specified user is not a subscriber of this list.'),
- 400,
- $this->format
- );
+ // TRANS: Client error displayed when a membership check for a user is nagative.
+ $this->clientError(_('The specified user is not a subscriber of this list.'));
}
- $user = $this->twitterUserArray($this->user->getProfile(), true);
+ $user = $this->twitterUserArray($this->target, true);
switch($this->format) {
case 'xml':
$this->auth_user);
if(empty($result)) {
- $this->clientError(
- // TRANS: Client error displayed when an unknown error occurs in the list subscribers action.
- _('An error occured.'),
- 500,
- $this->format
- );
- return false;
+ // TRANS: Client error displayed when an unknown error occurs in the list subscribers action.
+ $this->clientError(_('An error occured.'), 500);
}
switch($this->format) {
$this->showSingleJsonList($this->list);
break;
default:
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 404,
- $this->format
- );
- return false;
- break;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'), 404);
}
}
$ptag = Profile_tag_subscription::pkeyGet($args);
if(empty($ptag)) {
- $this->clientError(
- // TRANS: Client error displayed when trying to unsubscribe from a non-subscribed list.
- _('You are not subscribed to this list.'),
- 400,
- $this->format
- );
- return false;
+ // TRANS: Client error displayed when trying to unsubscribe from a non-subscribed list.
+ $this->clientError(_('You are not subscribed to this list.'));
}
- Profile_tag_subscription::remove($this->list, $this->auth_user);
+ $result = Profile_tag_subscription::remove($this->list, $this->auth_user);
- if(empty($result)) {
- $this->clientError(
- // TRANS: Client error displayed when an unknown error occurs unsubscribing from a list.
- _('An error occured.'),
- 500,
- $this->format
- );
- return false;
+ if (empty($result)) {
+ // TRANS: Client error displayed when an unknown error occurs unsubscribing from a list.
+ $this->clientError(_('An error occured.'), 500);
}
switch($this->format) {
$this->showSingleJsonList($this->list);
break;
default:
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 404,
- $this->format
- );
- return false;
- break;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'), 404);
}
return true;
}
* @return boolean success flag
*
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
$this->cursor = (int) $this->arg('cursor', -1);
- $this->user = $this->getTargetUser($this->arg('user'));
+ $user = $this->getTargetUser($this->arg('user'));
+ if (!($user instanceof User)) {
+ // TRANS: Client error displayed trying to perform an action related to a non-existing user.
+ $this->clientError(_('No such user.'), 404);
+ }
+ $this->target = $user->getProfile();
$this->getLists();
return true;
*
* Show the lists
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
-
- if (empty($this->user)) {
- // TRANS: Client error displayed trying to perform an action related to a non-existing user.
- $this->clientError(_('No such user.'), 404, $this->format);
- return;
- }
+ parent::handle();
switch($this->format) {
case 'xml':
$this->showJsonLists($this->lists, $this->next_cursor, $this->prev_cursor);
break;
default:
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 400,
- $this->format
- );
- break;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'));
}
}
function getLists()
{
- if(empty($this->user)) {
- return;
- }
-
- $profile = $this->user->getProfile();
- $fn = array($profile, 'getTagSubscriptions');
+ $fn = array($this->target, 'getTagSubscriptions');
# 20 lists
list($this->lists, $this->next_cursor, $this->prev_cursor) =
Profile_list::getAtCursor($fn, array(), $this->cursor, 20);
*/
class ApiStatusesUpdateAction extends ApiAuthAction
{
+ protected $needPost = true;
+
var $status = null;
var $in_reply_to_status_id = null;
var $lat = null;
*
* Make a new notice for the update, save it, and show it
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
protected function handle()
{
parent::handle();
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- $this->clientError(
- // TRANS: Client error. POST is a HTTP command. It should not be translated.
- _('This method requires a POST.'),
- 400,
- $this->format
- );
- return;
- }
-
// Workaround for PHP returning empty $_POST and $_FILES when POST
// length > post_max_size in php.ini
intval($_SERVER['CONTENT_LENGTH']));
$this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH']));
- return;
}
if (empty($this->status)) {
- $this->clientError(
- // TRANS: Client error displayed when the parameter "status" is missing.
- _('Client must provide a \'status\' parameter with a value.'),
- 400,
- $this->format
- );
- return;
+ // TRANS: Client error displayed when the parameter "status" is missing.
+ $this->clientError(_('Client must provide a \'status\' parameter with a value.'));
}
if (is_null($this->scoped)) {
// TRANS: Client error displayed when updating a status for a non-existing user.
- $this->clientError(_('No such user.'), 404, $this->format);
- return;
+ $this->clientError(_('No such user.'), 404);
}
/* Do not call shortenlinks until the whole notice has been build */
if ($reply) {
$reply_to = $this->in_reply_to_status_id;
} else {
- $this->clientError(
- // TRANS: Client error displayed when replying to a non-existing notice.
- _('Parent notice not found.'),
- $code = 404,
- $this->format
- );
- return;
+ // TRANS: Client error displayed when replying to a non-existing notice.
+ $this->clientError(_('Parent notice not found.'), 404);
}
}
try {
$upload = MediaFile::fromUpload('media', $this->scoped);
} catch (Exception $e) {
- $this->clientError($e->getMessage(), $e->getCode(), $this->format);
- return;
+ $this->clientError($e->getMessage(), $e->getCode());
}
if (isset($upload)) {
/* Use HTTP 413 error code (Request Entity Too Large)
* instead of basic 400 for better understanding
*/
- $this->clientError(sprintf($msg, Notice::maxContent()),
- 413,
- $this->format);
+ $this->clientError(sprintf($msg, Notice::maxContent()), 413);
}
$options
);
} catch (Exception $e) {
- $this->clientError($e->getMessage(), $e->getCode(), $this->format);
- return;
+ $this->clientError($e->getMessage(), $e->getCode());
}
if (isset($upload)) {
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
-class ApiSubscriptionsAction extends ApiBareAuthAction
+abstract class ApiSubscriptionsAction extends ApiBareAuthAction
{
var $profiles = null;
var $tag = null;
*
* @return boolean success flag
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
$this->count = isset($this->ids_only) ?
5000 : (int)$this->arg('count', 100);
- $this->user = $this->getTargetUser($this->arg('id'));
+ $this->target = $this->getTargetProfile($this->arg('id'));
- if (empty($this->user)) {
+ if (!($this->target instanceof Profile)) {
// TRANS: Client error displayed when requesting a list of followers for a non-existing user.
- $this->clientError(_('No such user.'), 404, $this->format);
- return false;
+ $this->clientError(_('No such user.'), 404);
}
$this->profiles = $this->getProfiles();
*
* Show the profiles
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
+ parent::handle();
if (!in_array($this->format, array('xml', 'json'))) {
// TRANS: Client error displayed when coming across a non-supported API method.
- $this->clientError(_('API method not found.'), $code = 404);
- return;
+ $this->clientError(_('API method not found.'), 404);
}
$this->initDocument($this->format);
}
/**
- * Get profiles - should get overrrided
+ * Get profiles related to the type of subscriber/subscription action
*
* @return array Profiles
*/
- function getProfiles()
- {
- }
+ abstract protected function getProfiles();
/**
* Is this action read only?
array($this->arg('action'),
common_user_cache_hash($this->auth_user),
common_language(),
- $this->user->id,
+ $this->target->id,
// Caching tags.
isset($this->ids_only) ? 'IDs' : 'Profiles',
strtotime($this->profiles[0]->created),
*
* @return boolean success flag
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
- $this->user = $this->getTargetUser($this->arg('id'));
+ $this->target = $this->getTargetProfile($this->arg('id'));
- if (empty($this->user)) {
+ if (!($this->target instanceof Profile)) {
// TRANS: Client error displayed when requesting most recent favourite notices by a user for a non-existing user.
- $this->clientError(_('No such user.'), 404, $this->format);
- return;
+ $this->clientError(_('No such user.'), 404);
}
$this->notices = $this->getNotices();
*
* Just show the notices
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
+ parent::handle();
$this->showTimeline();
}
*/
function showTimeline()
{
- $profile = $this->user->getProfile();
-
$sitename = common_config('site', 'name');
$title = sprintf(
// TRANS: Title for timeline of most recent favourite notices by a user.
// TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname.
_('%1$s / Favorites from %2$s'),
$sitename,
- $this->user->nickname
+ $this->target->nickname
);
$taguribase = TagURI::base();
- $id = "tag:$taguribase:Favorites:" . $this->user->id;
+ $id = "tag:$taguribase:Favorites:" . $this->target->id;
$subtitle = sprintf(
// TRANS: Subtitle for timeline of most recent favourite notices by a user.
// TRANS: %3$s is a user nickname.
_('%1$s updates favorited by %2$s / %3$s.'),
$sitename,
- $profile->getBestName(),
- $this->user->nickname
+ $this->target->getBestName(),
+ $this->target->nickname
);
- $logo = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
+ $logo = $this->target->avatarUrl(AVATAR_PROFILE_SIZE);
$link = common_local_url('showfavorites',
- array('nickname' => $this->user->nickname));
+ array('nickname' => $this->target->nickname));
$self = $this->getSelfUri();
switch($this->format) {
break;
default:
// TRANS: Client error displayed when coming across a non-supported API method.
- $this->clientError(_('API method not found.'), $code = 404);
- break;
+ $this->clientError(_('API method not found.'), 404);
}
}
common_debug("since id = " . $this->since_id . " max id = " . $this->max_id);
- if (!empty($this->auth_user) && $this->auth_user->id == $this->user->id) {
- $notice = $this->user->favoriteNotices(
+ if (!empty($this->auth_user) && $this->auth_user->id == $this->target->id) {
+ $notice = $this->target->favoriteNotices(
true,
($this->page-1) * $this->count,
$this->count,
$this->max_id
);
} else {
- $notice = $this->user->favoriteNotices(
+ $notice = $this->target->favoriteNotices(
false,
($this->page-1) * $this->count,
$this->count,
array($this->arg('action'),
common_user_cache_hash($this->auth_user),
common_language(),
- $this->user->id,
+ $this->target->id,
strtotime($this->notices[0]->created),
strtotime($this->notices[$last]->created))
)
* @return boolean success flag
*
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
- $this->user = $this->getTargetUser($this->arg('id'));
+ $this->target = $this->getTargetProfile($this->arg('id'));
- if (empty($this->user)) {
+ if (!($this->target instanceof Profile)) {
// TRANS: Client error displayed when requesting dents of a user and friends for a user that does not exist.
- $this->clientError(_('No such user.'), 404, $this->format);
- return;
+ $this->clientError(_('No such user.'), 404);
}
$this->notices = $this->getNotices();
*
* Just show the notices
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
+ parent::handle();
$this->showTimeline();
}
*/
function showTimeline()
{
- $profile = $this->user->getProfile();
$sitename = common_config('site', 'name');
// TRANS: Title of API timeline for a user and friends.
// TRANS: %s is a username.
- $title = sprintf(_("%s and friends"), $this->user->nickname);
+ $title = sprintf(_("%s and friends"), $this->target->nickname);
$taguribase = TagURI::base();
- $id = "tag:$taguribase:FriendsTimeline:" . $this->user->id;
+ $id = "tag:$taguribase:FriendsTimeline:" . $this->target->id;
$subtitle = sprintf(
// TRANS: Message is used as a subtitle. %1$s is a user nickname, %2$s is a site name.
_('Updates from %1$s and friends on %2$s!'),
- $this->user->nickname,
+ $this->target->nickname,
$sitename
);
- $logo = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
+ $logo = $this->target->avatarUrl(AVATAR_PROFILE_SIZE);
$link = common_local_url('all',
- array('nickname' => $this->user->nickname));
+ array('nickname' => $this->target->nickname));
$self = $this->getSelfUri();
switch($this->format) {
default:
// TRANS: Client error displayed when coming across a non-supported API method.
$this->clientError(_('API method not found.'), 404);
- break;
}
}
{
$notices = array();
- $profile = null;
-
- if (isset($this->auth_user)) {
- $profile = $this->auth_user->getProfile();
- }
-
- $stream = new InboxNoticeStream($this->user, $profile);
+ $stream = new InboxNoticeStream($this->target->getUser(), $this->scoped);
$notice = $stream->getNotices(($this->page-1) * $this->count,
$this->count,
array($this->arg('action'),
common_user_cache_hash($this->auth_user),
common_language(),
- $this->user->id,
+ $this->target->id,
strtotime($this->notices[0]->created),
strtotime($this->notices[$last]->created))
)
* @return boolean success flag
*
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
*
* Just show the notices
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
+ parent::handle();
if (empty($this->group)) {
// TRANS: Client error displayed requesting most recent notices to a group for a non-existing group.
- $this->clientError(_('Group not found.'), 404, $this->format);
- return false;
+ $this->clientError(_('Group not found.'), 404);
}
$this->notices = $this->getNotices();
$this->raw($doc->asString());
break;
default:
- $this->clientError(
- // TRANS: Client error displayed when trying to handle an unknown API method.
- _('API method not found.'),
- 404,
- $this->format
- );
- break;
+ // TRANS: Client error displayed when trying to handle an unknown API method.
+ $this->clientError(_('API method not found.'), 404);
}
}
*
* @return boolean success flag
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
- $this->user = $this->getTargetUser($this->arg('id'));
+ $this->target = $this->getTargetProfile($this->arg('id'));
- if (empty($this->user)) {
+ if (!($this->target instanceof Profile)) {
// TRANS: Client error displayed when requesting most recent dents by user and friends for a non-existing user.
- $this->clientError(_('No such user.'), 404, $this->format);
- return;
+ $this->clientError(_('No such user.'), 404);
}
$this->notices = $this->getNotices();
*
* Just show the notices
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
+ parent::handle();
$this->showTimeline();
}
*/
function showTimeline()
{
- $profile = $this->user->getProfile();
$sitename = common_config('site', 'name');
// TRANS: Timeline title for user and friends. %s is a user nickname.
- $title = sprintf(_("%s and friends"), $this->user->nickname);
+ $title = sprintf(_("%s and friends"), $this->target->nickname);
$taguribase = TagURI::base();
- $id = "tag:$taguribase:HomeTimeline:" . $this->user->id;
+ $id = "tag:$taguribase:HomeTimeline:" . $this->target->id;
$subtitle = sprintf(
// TRANS: Message is used as a subtitle. %1$s is a user nickname, %2$s is a site name.
_('Updates from %1$s and friends on %2$s!'),
- $this->user->nickname, $sitename
+ $this->target->nickname, $sitename
);
- $logo = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
+ $logo = $this->target->avatarUrl(AVATAR_PROFILE_SIZE);
$link = common_local_url('all',
- array('nickname' => $this->user->nickname));
+ array('nickname' => $this->target->nickname));
$self = $this->getSelfUri();
switch($this->format) {
break;
default:
// TRANS: Client error displayed when coming across a non-supported API method.
- $this->clientError(_('API method not found.'), $code = 404);
- break;
+ $this->clientError(_('API method not found.'), 404);
}
}
{
$notices = array();
- $profile = null;
-
- if (isset($this->auth_user)) {
- $profile = $this->auth_user->getProfile();
- }
-
- $stream = new InboxNoticeStream($this->user, $profile);
+ $stream = new InboxNoticeStream($this->target->getUser(), $this->scoped);
$notice = $stream->getNotices(($this->page-1) * $this->count,
$this->count,
array($this->arg('action'),
common_user_cache_hash($this->auth_user),
common_language(),
- $this->user->id,
+ $this->target->id,
strtotime($this->notices[0]->created),
strtotime($this->notices[$last]->created))
)
* @return boolean success flag
*
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
*
* Just show the notices
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
+ parent::handle();
if (empty($this->list)) {
// TRANS: Client error displayed trying to perform an action related to a non-existing list.
- $this->clientError(_('List not found.'), 404, $this->format);
- return false;
+ $this->clientError(_('List not found.'), 404);
}
$this->getNotices();
} catch (Atom10FeedException $e) {
// TRANS: Server error displayed whe trying to get a timeline fails.
// TRANS: %s is the error message.
- $this->serverError( sprintf(_('Could not generate feed for list - %s'),$e->getMessage()));
- return;
+ $this->serverError(sprintf(_('Could not generate feed for list - %s'), $e->getMessage()));
}
break;
$this->initDocument('json');
break;
default:
- $this->clientError(
- // TRANS: Client error displayed when coming across a non-supported API method.
- _('API method not found.'),
- 404,
- $this->format
- );
- break;
+ // TRANS: Client error displayed when coming across a non-supported API method.
+ $this->clientError(_('API method not found.'), 404);
}
}
*
* @return boolean success flag
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
- $this->user = $this->getTargetUser($this->arg('id'));
+ $this->target = $this->getTargetProfile($this->arg('id'));
- if (empty($this->user)) {
+ if (!($this->target instanceof Profile)) {
// TRANS: Client error displayed when requesting most recent mentions for a non-existing user.
- $this->clientError(_('No such user.'), 404, $this->format);
- return;
+ $this->clientError(_('No such user.'), 404);
}
$this->notices = $this->getNotices();
*
* Just show the notices
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
+ parent::handle();
$this->showTimeline();
}
*/
function showTimeline()
{
- $profile = $this->user->getProfile();
-
$sitename = common_config('site', 'name');
$title = sprintf(
// TRANS: Title for timeline of most recent mentions of a user.
// TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname.
_('%1$s / Updates mentioning %2$s'),
- $sitename, $this->user->nickname
+ $sitename, $this->target->nickname
);
$taguribase = TagURI::base();
- $id = "tag:$taguribase:Mentions:" . $this->user->id;
+ $id = "tag:$taguribase:Mentions:" . $this->target->id;
- $logo = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
+ $logo = $this->target->avatarUrl(AVATAR_PROFILE_SIZE);
$link = common_local_url('replies',
- array('nickname' => $this->user->nickname));
+ array('nickname' => $this->target->nickname));
$self = $this->getSelfUri();
$subtitle = sprintf(
// TRANS: %1$s is the StatusNet sitename, %2$s is a user nickname,
// TRANS: %3$s is a user's full name.
_('%1$s updates that reply to updates from %2$s / %3$s.'),
- $sitename, $this->user->nickname, $profile->getBestName()
+ $sitename, $this->target->getBestName(), $this->target->nickname
);
switch($this->format) {
{
$notices = array();
- if (empty($this->auth_user)) {
- $profile = null;
- } else {
- $profile = $this->auth_user->getProfile();
- }
-
- $stream = new ReplyNoticeStream($this->user->id, $profile);
+ $stream = new ReplyNoticeStream($this->target->id, $this->scoped);
$notice = $stream->getNotices(($this->page - 1) * $this->count,
$this->count,
array($this->arg('action'),
common_user_cache_hash($this->auth_user),
common_language(),
- $this->user->id,
+ $this->target->id,
strtotime($this->notices[0]->created),
strtotime($this->notices[$last]->created))
)
*
* @return boolean success flag
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
- $this->user = $this->getTargetUser($this->arg('id'));
+ $this->target = $this->getTargetProfile($this->arg('id'));
- if (empty($this->user)) {
+ if (!($this->target instanceof Profile)) {
// TRANS: Client error displayed requesting most recent notices for a non-existing user.
- $this->clientError(_('No such user.'), 404, $this->format);
- return;
+ $this->clientError(_('No such user.'), 404);
}
$this->notices = $this->getNotices();
*
* Just show the notices
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
+ parent::handle();
if ($this->isPost()) {
$this->handlePost();
*/
function showTimeline()
{
- $profile = $this->user->getProfile();
-
// We'll use the shared params from the Atom stub
// for other feed types.
- $atom = new AtomUserNoticeFeed($this->user, $this->auth_user);
+ $atom = new AtomUserNoticeFeed($this->target->getUser(), $this->auth_user);
$link = common_local_url(
'showstream',
- array('nickname' => $this->user->nickname)
+ array('nickname' => $this->target->nickname)
);
$self = $this->getSelfUri();
// FriendFeed's SUP protocol
// Also added RSS and Atom feeds
- $suplink = common_local_url('sup', null, null, $this->user->id);
+ $suplink = common_local_url('sup', null, null, $this->target->id);
header('X-SUP-ID: ' . $suplink);
switch($this->format) {
if (!empty($this->next_id)) {
$nextUrl = common_local_url('ApiTimelineUser',
array('format' => 'atom',
- 'id' => $this->user->id),
+ 'id' => $this->target->id),
array('max_id' => $this->next_id));
$atom->addLink($nextUrl,
$prevUrl = common_local_url('ApiTimelineUser',
array('format' => 'atom',
- 'id' => $this->user->id),
+ 'id' => $this->target->id),
array('since_id' => $lastId));
$atom->addLink($prevUrl,
$firstUrl = common_local_url('ApiTimelineUser',
array('format' => 'atom',
- 'id' => $this->user->id));
+ 'id' => $this->target->id));
$atom->addLink($firstUrl,
array('rel' => 'first',
default:
// TRANS: Client error displayed when coming across a non-supported API method.
$this->clientError(_('API method not found.'), $code = 404);
- break;
}
}
{
$notices = array();
- $notice = $this->user->getNotices(($this->page-1) * $this->count,
+ $notice = $this->target->getNotices(($this->page-1) * $this->count,
$this->count + 1,
$this->since_id,
$this->max_id,
array($this->arg('action'),
common_user_cache_hash($this->auth_user),
common_language(),
- $this->user->id,
+ $this->target->id,
strtotime($this->notices[0]->created),
strtotime($this->notices[$last]->created))
)
function handlePost()
{
if (empty($this->auth_user) ||
- $this->auth_user->id != $this->user->id) {
+ $this->auth_user->id != $this->target->id) {
// TRANS: Client error displayed trying to add a notice to another user's timeline.
$this->clientError(_('Only the user can add to their own timeline.'));
- return;
}
// Only handle posts for Atom
if ($this->format != 'atom') {
// TRANS: Client error displayed when using another format than AtomPub.
$this->clientError(_('Only accept AtomPub for Atom feeds.'));
- return;
}
$xml = trim(file_get_contents('php://input'));
$dom->documentElement->localName != 'entry') {
// TRANS: Client error displayed when not using an Atom entry.
$this->clientError(_('Atom post must be an Atom entry.'));
- return;
}
$activity = new Activity($dom->documentElement);
$saved = null;
- if (Event::handle('StartAtomPubNewActivity', array(&$activity, $this->user, &$saved))) {
+ if (Event::handle('StartAtomPubNewActivity', array(&$activity, $this->target->getUser(), &$saved))) {
if ($activity->verb != ActivityVerb::POST) {
// TRANS: Client error displayed when not using the POST verb. Do not translate POST.
$this->clientError(_('Can only handle POST activities.'));
- return;
}
$note = $activity->objects[0];
// TRANS: %s is the unsupported activity object type.
$this->clientError(sprintf(_('Cannot handle activity object type "%s".'),
$note->type));
- return;
}
$saved = $this->postNote($activity);
- Event::handle('EndAtomPubNewActivity', array($activity, $this->user, $saved));
+ Event::handle('EndAtomPubNewActivity', array($activity, $this->target->getUser(), $saved));
}
if (!empty($saved)) {
// @fixme fetch from $sourceUrl?
// TRANS: Client error displayed when posting a notice without content through the API.
// TRANS: %d is the notice ID (number).
- $this->clientError(sprintf(_('No content for notice %d.'),
- $note->id));
- return;
+ $this->clientError(sprintf(_('No content for notice %d.'), $note->id));
}
// Get (safe!) HTML and text versions of the content
if (!empty($notice)) {
// TRANS: Client error displayed when using another format than AtomPub.
// TRANS: %s is the notice URI.
- $this->clientError(sprintf(_('Notice with URI "%s" already exists.'),
- $note->id));
- return;
+ $this->clientError(sprintf(_('Notice with URI "%s" already exists.'), $note->id));
}
common_log(LOG_NOTICE, "Saving client-supplied notice URI '$note->id'");
$options['uri'] = $note->id;
$options['urls'][] = $href;
}
- $saved = Notice::saveNew($this->user->id,
+ $saved = Notice::saveNew($this->target->id,
$content,
'atompub', // TODO: deal with this
$options);
* @link http://status.net/
*/
-if (!defined('STATUSNET')) {
- exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Ouputs the authenticating user's followers (subscribers), each with
*
* @return array Profiles
*/
- function getProfiles()
+ protected function getProfiles()
{
$offset = ($this->page - 1) * $this->count;
$limit = $this->count + 1;
$subs = null;
if (isset($this->tag)) {
- $subs = $this->user->getTaggedSubscribers(
+ $subs = $this->target->getTaggedSubscribers(
$this->tag, $offset, $limit
);
} else {
- $subs = $this->user->getSubscribers(
+ $subs = $this->target->getSubscribers(
$offset,
$limit
);
$profiles = array();
- if (!empty($subs)) {
- while ($subs->fetch()) {
- $profiles[] = clone($subs);
- }
+ while ($subs->fetch()) {
+ $profiles[] = clone($subs);
}
return $profiles;
* @link http://status.net/
*/
-if (!defined('STATUSNET')) {
- exit(1);
-}
+if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Ouputs the authenticating user's friends (subscriptions), each with
*
* @return array Profiles
*/
- function getProfiles()
+ protected function getProfiles()
{
$offset = ($this->page - 1) * $this->count;
$limit = $this->count + 1;
$subs = null;
if (isset($this->tag)) {
- $subs = $this->user->getTaggedSubscriptions(
+ $subs = $this->target->getTaggedSubscriptions(
$this->tag, $offset, $limit
);
} else {
- $subs = $this->user->getSubscribed(
+ $subs = $this->target->getSubscribed(
$offset,
$limit
);
$profiles = array();
- if (!empty($subs)) {
- while ($subs->fetch()) {
- $profiles[] = clone($subs);
- }
+ while ($subs->fetch()) {
+ $profiles[] = clone($subs);
}
return $profiles;
* @return boolean success flag
*
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
- $this->user = User::getKV('nickname', $this->arg('screen_name'));
+ $user = User::getKV('nickname', $this->arg('screen_name'));
+ if (!($user instanceof User)) {
+ // TRANS: Client error displayed when requesting user information for a non-existing user.
+ $this->clientError(_('User not found.'), 404);
+ }
+ $this->target = $user->getProfile();
$this->size = $this->arg('size');
return true;
*
* Check the format and show the user info
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
-
- if (empty($this->user)) {
- // TRANS: Client error displayed when requesting user information for a non-existing user.
- $this->clientError(_('User not found.'), 404, $this->format);
- return;
- }
-
- $profile = $this->user->getProfile();
-
- if (empty($profile)) {
- // TRANS: Error message displayed when referring to a user without a profile.
- $this->clientError(_('User has no profile.'));
- return;
- }
+ parent::handle();
$size = $this->avatarSize();
- $url = $profile->avatarUrl($size);
+ $url = $this->target->avatarUrl($size);
// We don't actually output JSON or XML data -- redirect!
common_redirect($url, 302);
* @return boolean success flag
*
*/
- function prepare($args)
+ protected function prepare($args)
{
parent::prepare($args);
// XXX: email field deprecated in Twitter's API
if (!empty($email)) {
- $this->user = User::getKV('email', $email);
+ $user = User::getKV('email', $email);
} else {
- $this->user = $this->getTargetUser($this->arg('id'));
+ $user = $this->getTargetUser($this->arg('id'));
}
+ if (!($user instanceof User)) {
+ // TRANS: Client error displayed when requesting user information for a non-existing user.
+ $this->clientError(_('User not found.'), 404);
+ }
+ $this->target = $user->getProfile();
+
return true;
}
*
* Check the format and show the user info
*
- * @param array $args $_REQUEST data (unused)
- *
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
-
- if (empty($this->user)) {
- // TRANS: Client error displayed when requesting user information for a non-existing user.
- $this->clientError(_('User not found.'), 404, $this->format);
- return;
- }
+ parent::handle();
if (!in_array($this->format, array('xml', 'json'))) {
// TRANS: Client error displayed when coming across a non-supported API method.
- $this->clientError(_('API method not found.'), $code = 404);
- return;
- }
-
- $profile = $this->user->getProfile();
-
- if (empty($profile)) {
- // TRANS: Error message displayed when referring to a user without a profile.
- $this->clientError(_('User has no profile.'));
- return;
+ $this->clientError(_('API method not found.'), 404);
}
- $twitter_user = $this->twitterUserArray($this->user->getProfile(), true);
+ $twitter_user = $this->twitterUserArray($this->target, true);
if ($this->format == 'xml') {
$this->initDocument('xml');
protected function prepare(array $args=array())
{
if ($this->needPost && !$this->isPost()) {
+ // TRANS: Client error. POST is a HTTP command. It should not be translated.
$this->clientError(_('This method requires a POST.'), 405);
}
$nickname = common_canonical_nickname($this->arg('screen_name'));
$user = User::getKV('nickname', $nickname);
return $user ? $user->getProfile() : null;
+ } else {
+ // Fall back to trying the currently authenticated user
+ return $this->scoped;
}
} else if (self::is_decimal($id)) {
return Profile::getKV($id);
$this->scoped = null;
}
+ // legacy user transferral
+ // TODO: remove when sure no extended classes need it
+ $this->user = $this->auth_user;
+
// Reject API calls with the wrong access level
if ($this->isReadOnly($args) == false) {
var $prev_cursor = 0;
var $users = null;
- function prepare($args)
+ protected function prepare($args)
{
// delete list member if method is DELETE or if method is POST and an argument
// _method is set to DELETE
$this->create = (!$this->delete &&
$_SERVER['REQUEST_METHOD'] == 'POST');
- if($this->arg('id')) {
- $this->user = $this->getTargetUser($this->arg('id'));
+ if ($this->arg('id')) {
+ $this->target = $this->getTargetProfile($this->arg('id'));
}
parent::prepare($args);
$this->create || $this->delete;
}
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
+ parent::handle();
if($this->delete) {
return $this->handleDelete();