X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fapigroupprofileupdate.php;h=379e01a428efd09c694b06b62b2c6405b9661317;hb=0cbb7411a69f63a4c2947d5c66e62f28e0714532;hp=0d3620c265382dda76dff68dfe224b6f95b85190;hpb=b407665b983297078f5361db24c60a7d46e0f4ba;p=quix0rs-gnu-social.git diff --git a/actions/apigroupprofileupdate.php b/actions/apigroupprofileupdate.php index 0d3620c265..379e01a428 100644 --- a/actions/apigroupprofileupdate.php +++ b/actions/apigroupprofileupdate.php @@ -33,8 +33,6 @@ if (!defined('STATUSNET')) { require_once INSTALLDIR . '/lib/apiauth.php'; -class ApiValidationException extends Exception { } - /** * API analog to the group edit page * @@ -44,10 +42,8 @@ class ApiValidationException extends Exception { } * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ - class ApiGroupProfileUpdateAction extends ApiAuthAction { - /** * Take arguments for running * @@ -56,12 +52,12 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction * @return boolean success flag * */ - function prepare($args) { parent::prepare($args); $this->nickname = common_canonical_nickname($this->trimmed('nickname')); + $this->fullname = $this->trimmed('fullname'); $this->homepage = $this->trimmed('homepage'); $this->description = $this->trimmed('description'); @@ -83,13 +79,13 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction * * @return void */ - function handle($args) { 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 ); @@ -98,6 +94,7 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction 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 @@ -106,16 +103,19 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction } 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; } 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; } 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; } @@ -169,15 +169,15 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction if (!$result) { common_log_db_error($this->group, 'UPDATE', __FILE__); + // TRANS: Server error displayed when group update fails. $this->serverError(_('Could not update group.')); } - $aliases = null; + $aliases = array(); try { - if (!empty($this->aliasstring)) { - $aliases = $this->parseAliases(); + $aliases = $this->validateAliases(); } } catch (ApiValidationException $ave) { @@ -192,10 +192,11 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction $result = $this->group->setAliases($aliases); if (!$result) { + // TRANS: Server error displayed when adding group aliases fails. $this->serverError(_('Could not create aliases.')); } - if (!empty($this->nickname) && $this->nickname != $orig->nickname) { + if (!empty($this->nickname) && ($this->nickname != $orig->nickname)) { common_log(LOG_INFO, "Saving local group info."); $local = Local_group::staticGet('group_id', $this->group->id); $local->setNickname($this->nickname); @@ -211,6 +212,7 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction $this->showSingleJsonGroup($this->group); break; default: + // TRANS: Client error displayed when coming across a non-supported API method. $this->clientError(_('API method not found.'), 404, $this->format); break; } @@ -246,20 +248,22 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction ) ) { throw new ApiValidationException( - _( - 'Nickname must have only lowercase letters ' . - 'and numbers and no spaces.' - ) + // TRANS: API validation exception thrown when nickname does not validate. + _('Nickname must have only lowercase letters and numbers and no spaces.') ); } else if ($this->nicknameExists($this->nickname)) { throw new ApiValidationException( + // TRANS: API validation exception thrown when nickname is already used. _('Nickname already in use. Try another one.') ); } else if (!User_group::allowedNickname($this->nickname)) { throw new ApiValidationException( + // TRANS: API validation exception thrown when nickname does not validate. _('Not a valid nickname.') ); } + + return true; } function validateHomepage() @@ -273,6 +277,7 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction ) ) { throw new ApiValidationException( + // TRANS: API validation exception thrown when homepage URL does not validate. _('Homepage is not a valid URL.') ); } @@ -282,7 +287,8 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction { if (!is_null($this->fullname) && mb_strlen($this->fullname) > 255) { throw new ApiValidationException( - _('Full name is too long (max 255 chars).') + // TRANS: API validation exception thrown when full name does not validate. + _('Full name is too long (maximum 255 characters).') ); } } @@ -290,12 +296,12 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction function validateDescription() { if (User_group::descriptionTooLong($this->description)) { - throw new ApiValidationException( - sprintf( - _('description is too long (max %d chars).'), - User_group::maxDescription() - ) - ); + // TRANS: API validation exception thrown when description does not validate. + // TRANS: %d is the maximum description length and used for plural. + throw new ApiValidationException(sprintf(_m('Description is too long (maximum %d character).', + 'Description is too long (maximum %d characters).', + User_group::maxDescription()), + User_group::maxDescription())); } } @@ -303,7 +309,8 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction { if (!is_null($this->location) && mb_strlen($this->location) > 255) { throw new ApiValidationException( - _('Location is too long (max 255 chars).') + // TRANS: API validation exception thrown when location does not validate. + _('Location is too long (maximum 255 characters).') ); } } @@ -319,17 +326,13 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction ) ); - if (empty($aliases)) { - $aliases = array(); - } - if (count($aliases) > common_config('group', 'maxaliases')) { - throw new ApiValidationException( - sprintf( - _('Too many aliases! Maximum %d.'), - common_config('group', 'maxaliases') - ) - ); + // TRANS: API validation exception thrown when aliases do not validate. + // TRANS: %d is the maximum number of aliases and used for plural. + throw new ApiValidationException(sprintf(_m('Too many aliases! Maximum %d allowed.', + 'Too many aliases! Maximum %d allowed.', + common_config('group', 'maxaliases')), + common_config('group', 'maxaliases'))); } foreach ($aliases as $alias) { @@ -342,7 +345,9 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction ) { throw new ApiValidationException( sprintf( - _('Invalid alias: "%s"'), + // TRANS: API validation exception thrown when aliases does not validate. + // TRANS: %s is the invalid alias. + _('Invalid alias: "%s".'), $alias ) ); @@ -351,20 +356,22 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction if ($this->nicknameExists($alias)) { throw new ApiValidationException( sprintf( + // TRANS: API validation exception thrown when aliases is already used. + // TRANS: %s is the already used alias. _('Alias "%s" already in use. Try another one.'), $alias) ); } // XXX assumes alphanum nicknames - if (strcmp($alias, $nickname) == 0) { + if (strcmp($alias, $this->nickname) == 0) { throw new ApiValidationException( - _('Alias can\'t be the same as nickname.') + // TRANS: API validation exception thrown when alias is the same as nickname. + _('Alias cannot be the same as nickname.') ); } } return $aliases; } - -} \ No newline at end of file +}