123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class ApiGroupCreateAction extends ApiAuthAction
- {
- protected $needPost = true;
- var $group = null;
- var $nickname = null;
- var $fullname = null;
- var $homepage = null;
- var $description = null;
- var $location = null;
- var $aliasstring = null;
- var $aliases = null;
-
- protected function prepare(array $args=array())
- {
- parent::prepare($args);
- $this->nickname = Nickname::normalize($this->arg('nickname'), true);
- $this->fullname = $this->arg('full_name');
- $this->homepage = $this->arg('homepage');
- $this->description = $this->arg('description');
- $this->location = $this->arg('location');
- $this->aliasstring = $this->arg('aliases');
- return true;
- }
-
- protected function handle()
- {
- parent::handle();
- if (empty($this->user)) {
-
- $this->clientError(_('No such user.'), 404);
- }
- if ($this->validateParams() == false) {
- return;
- }
- $group = User_group::register(array('nickname' => $this->nickname,
- 'fullname' => $this->fullname,
- 'homepage' => $this->homepage,
- 'description' => $this->description,
- 'location' => $this->location,
- 'aliases' => $this->aliases,
- 'userid' => $this->user->id,
- 'local' => true));
- switch($this->format) {
- case 'xml':
- $this->showSingleXmlGroup($group);
- break;
- case 'json':
- $this->showSingleJsonGroup($group);
- break;
- default:
-
- $this->clientError(_('API method not found.'), 404);
- }
- }
-
- function validateParams()
- {
- if (!is_null($this->homepage)
- && strlen($this->homepage) > 0
- && !common_valid_http_url($this->homepage)) {
-
- $this->clientError(_('Homepage is not a valid URL.'), 403);
- } elseif (!is_null($this->fullname)
- && mb_strlen($this->fullname) > 255) {
-
- $this->clientError(_('Full name is too long (maximum 255 characters).'), 403);
- } elseif (User_group::descriptionTooLong($this->description)) {
-
-
- $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) {
-
- $this->clientError(_('Location is too long (maximum 255 characters).'), 403);
- }
- if (!empty($this->aliasstring)) {
- $this->aliases = array_map(
- array('Nickname', 'normalize'),
- array_unique(preg_split('/[\s,]+/', $this->aliasstring))
- );
- } else {
- $this->aliases = array();
- }
- if (count($this->aliases) > common_config('group', 'maxaliases')) {
- $this->clientError(sprintf(
-
-
- _m('Too many aliases! Maximum %d allowed.',
- 'Too many aliases! Maximum %d allowed.',
- common_config('group', 'maxaliases')),
- common_config('group', 'maxaliases')),
- 403);
- }
-
- return true;
- }
- }
|