Exemplo n.º 1
0
function newGroup($i, $j)
{
    global $groupprefix;
    global $userprefix;
    // Pick a random user to be the admin
    $n = rand(0, max($j - 1, 0));
    $user = User::staticGet('nickname', sprintf('%s%d', $userprefix, $n));
    $group = User_group::register(array('nickname' => sprintf('%s%d', $groupprefix, $i), 'local' => true, 'userid' => $user->id, 'fullname' => sprintf('Test Group %d', $i)));
}
 function __construct()
 {
     parent::__construct();
     $authorNick1 = 'activitygenerationtestsuser' . common_good_rand(4);
     $authorNick2 = 'activitygenerationtestsuser' . common_good_rand(4);
     $targetNick1 = 'activitygenerationteststarget' . common_good_rand(4);
     $targetNick2 = 'activitygenerationteststarget' . common_good_rand(4);
     $groupNick1 = 'activitygenerationtestsgroup' . common_good_rand(4);
     $groupNick2 = 'activitygenerationtestsgroup' . common_good_rand(4);
     $this->author1 = User::register(array('nickname' => $authorNick1, 'email' => $authorNick1 . '@example.net', 'email_confirmed' => true));
     $this->author2 = User::register(array('nickname' => $authorNick2, 'email' => $authorNick2 . '@example.net', 'email_confirmed' => true));
     $this->targetUser1 = User::register(array('nickname' => $targetNick1, 'email' => $targetNick1 . '@example.net', 'email_confirmed' => true));
     $this->targetUser2 = User::register(array('nickname' => $targetNick2, 'email' => $targetNick2 . '@example.net', 'email_confirmed' => true));
     $this->targetGroup1 = User_group::register(array('nickname' => $groupNick1, 'userid' => $this->author1->id, 'aliases' => array(), 'local' => true, 'location' => null, 'description' => null, 'fullname' => null, 'homepage' => null, 'mainpage' => null));
     $this->targetGroup2 = User_group::register(array('nickname' => $groupNick2, 'userid' => $this->author1->id, 'aliases' => array(), 'local' => true, 'location' => null, 'description' => null, 'fullname' => null, 'homepage' => null, 'mainpage' => null));
 }
Exemplo n.º 3
0
 /**
  * Handle the request
  *
  * Save the new group
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         $this->clientError(_('This method requires a POST.'), 400, $this->format);
         return;
     }
     if (empty($this->user)) {
         // TRANS: Client error given when a user was not found (404).
         $this->clientError(_('No such user.'), 404, $this->format);
         return;
     }
     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, $this->format);
             break;
     }
 }
Exemplo n.º 4
0
 /**
  * Load or create an imported group from Yammer data.
  *
  * @param object $item loaded JSON data for Yammer importer
  * @return User_group
  */
 function importGroup($item)
 {
     $data = $this->prepGroup($item);
     $nickname = $data['options']['nickname'];
     $groupId = $this->findImportedGroup($data['orig_id']);
     if ($groupId) {
         return User_group::staticGet('id', $groupId);
     } else {
         $local = Local_group::staticGet('nickname', $nickname);
         if ($local) {
             common_log(LOG_WARN, "Copying Yammer group info onto existing group {$nickname}");
             $group = User_group::staticGet('id', $local->group_id);
             $this->savePropertiesOn($group, $data['options'], array('fullname', 'description'));
         } else {
             $group = User_group::register($data['options']);
         }
         if ($data['avatar']) {
             try {
                 $this->saveAvatar($data['avatar'], $group);
             } catch (Exception $e) {
                 common_log(LOG_ERR, "Error importing Yammer avatar: " . $e->getMessage());
             }
         }
         $this->recordImportedGroup($data['orig_id'], $group->id);
         return $group;
     }
 }
Exemplo n.º 5
0
 function trySave()
 {
     $nickname = $this->trimmed('nickname');
     $fullname = $this->trimmed('fullname');
     $homepage = $this->trimmed('homepage');
     $description = $this->trimmed('description');
     $location = $this->trimmed('location');
     $aliasstring = $this->trimmed('aliases');
     if (!Validate::string($nickname, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT))) {
         $this->showForm(_('Nickname must have only lowercase letters ' . 'and numbers and no spaces.'));
         return;
     } else {
         if ($this->nicknameExists($nickname)) {
             $this->showForm(_('Nickname already in use. Try another one.'));
             return;
         } else {
             if (!User_group::allowedNickname($nickname)) {
                 $this->showForm(_('Not a valid nickname.'));
                 return;
             } else {
                 if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
                     $this->showForm(_('Homepage is not a valid URL.'));
                     return;
                 } else {
                     if (!is_null($fullname) && mb_strlen($fullname) > 255) {
                         $this->showForm(_('Full name is too long (max 255 chars).'));
                         return;
                     } else {
                         if (User_group::descriptionTooLong($description)) {
                             $this->showForm(sprintf(_('description is too long (max %d chars).'), User_group::maxDescription()));
                             return;
                         } else {
                             if (!is_null($location) && mb_strlen($location) > 255) {
                                 $this->showForm(_('Location is too long (max 255 chars).'));
                                 return;
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!empty($aliasstring)) {
         $aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\\s,]+/', $aliasstring)));
     } else {
         $aliases = array();
     }
     if (count($aliases) > common_config('group', 'maxaliases')) {
         $this->showForm(sprintf(_('Too many aliases! Maximum %d.'), common_config('group', 'maxaliases')));
         return;
     }
     foreach ($aliases as $alias) {
         if (!Validate::string($alias, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT))) {
             $this->showForm(sprintf(_('Invalid alias: "%s"'), $alias));
             return;
         }
         if ($this->nicknameExists($alias)) {
             $this->showForm(sprintf(_('Alias "%s" already in use. Try another one.'), $alias));
             return;
         }
         // XXX assumes alphanum nicknames
         if (strcmp($alias, $nickname) == 0) {
             $this->showForm(_('Alias can\'t be the same as nickname.'));
             return;
         }
     }
     $mainpage = common_local_url('showgroup', array('nickname' => $nickname));
     $cur = common_current_user();
     // Checked in prepare() above
     assert(!is_null($cur));
     $group = User_group::register(array('nickname' => $nickname, 'fullname' => $fullname, 'homepage' => $homepage, 'description' => $description, 'location' => $location, 'aliases' => $aliases, 'userid' => $cur->id, 'mainpage' => $mainpage, 'local' => true));
     common_redirect($group->homeUrl(), 303);
 }
Exemplo n.º 6
0
 function trySave()
 {
     if (Event::handle('StartGroupSaveForm', array($this))) {
         try {
             $nickname = Nickname::normalize($this->trimmed('nickname'));
         } catch (NicknameException $e) {
             $this->showForm($e->getMessage());
         }
         $fullname = $this->trimmed('fullname');
         $homepage = $this->trimmed('homepage');
         $description = $this->trimmed('description');
         $location = $this->trimmed('location');
         $aliasstring = $this->trimmed('aliases');
         if ($this->nicknameExists($nickname)) {
             // TRANS: Group create form validation error.
             $this->showForm(_('Nickname already in use. Try another one.'));
             return;
         } else {
             if (!User_group::allowedNickname($nickname)) {
                 // TRANS: Group create form validation error.
                 $this->showForm(_('Not a valid nickname.'));
                 return;
             } else {
                 if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
                     // TRANS: Group create form validation error.
                     $this->showForm(_('Homepage is not a valid URL.'));
                     return;
                 } else {
                     if (!is_null($fullname) && mb_strlen($fullname) > 255) {
                         // TRANS: Group create form validation error.
                         $this->showForm(_('Full name is too long (maximum 255 characters).'));
                         return;
                     } else {
                         if (User_group::descriptionTooLong($description)) {
                             // TRANS: Group create form validation error.
                             // TRANS: %d is the maximum number of allowed characters.
                             $this->showForm(sprintf(_m('Description is too long (maximum %d character).', 'Description is too long (maximum %d characters).', User_group::maxDescription()), User_group::maxDescription()));
                             return;
                         } else {
                             if (!is_null($location) && mb_strlen($location) > 255) {
                                 // TRANS: Group create form validation error.
                                 $this->showForm(_('Location is too long (maximum 255 characters).'));
                                 return;
                             }
                         }
                     }
                 }
             }
         }
         if (!empty($aliasstring)) {
             $aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\\s,]+/', $aliasstring)));
         } else {
             $aliases = array();
         }
         if (count($aliases) > common_config('group', 'maxaliases')) {
             // TRANS: Group create form validation error.
             // TRANS: %d is the maximum number of allowed aliases.
             $this->showForm(sprintf(_m('Too many aliases! Maximum %d allowed.', 'Too many aliases! Maximum %d allowed.', common_config('group', 'maxaliases')), common_config('group', 'maxaliases')));
             return;
         }
         foreach ($aliases as $alias) {
             if (!Nickname::isValid($alias)) {
                 // TRANS: Group create form validation error.
                 // TRANS: %s is the invalid alias.
                 $this->showForm(sprintf(_('Invalid alias: "%s"'), $alias));
                 return;
             }
             if ($this->nicknameExists($alias)) {
                 // TRANS: Group create form validation error. %s is the already used alias.
                 $this->showForm(sprintf(_('Alias "%s" already in use. Try another one.'), $alias));
                 return;
             }
             // XXX assumes alphanum nicknames
             if (strcmp($alias, $nickname) == 0) {
                 // TRANS: Group create form validation error.
                 $this->showForm(_('Alias cannot be the same as nickname.'));
                 return;
             }
         }
         $cur = common_current_user();
         // Checked in prepare() above
         assert(!is_null($cur));
         $group = User_group::register(array('nickname' => $nickname, 'fullname' => $fullname, 'homepage' => $homepage, 'description' => $description, 'location' => $location, 'aliases' => $aliases, 'userid' => $cur->id, 'local' => true));
         $this->group = $group;
         Event::handle('EndGroupSaveForm', array($this));
         common_redirect($group->homeUrl(), 303);
     }
 }
Exemplo n.º 7
0
// Cogemos nick de grupo de parámetro
if (have_option('g', 'group')) {
    $gnick = get_option_value('g', 'group');
} else {
    print "You must provide the nickname of the group.\n";
    exit(1);
}
// Comprobamos que el nick del grupo sea válido
try {
    $nickname = Nickname::normalize($gnick);
    if (!User_group::allowedNickname($nickname)) {
        print "Nick de grupo no válido.\n";
        exit(1);
    }
} catch (NicknameException $e) {
    print "Nick de grupo no válido.\n";
    exit(1);
}
// Comprobamos si ese nick de grupo existe.
$local = Local_group::staticGet('nickname', $nickname);
$alias = Group_alias::staticGet('alias', $nickname);
if (!empty($alias) || !empty($local)) {
    print "Nick de grupo en uso, elige otro nombre de grupo.\n";
    exit(1);
}
// Si hemos llegado aquí es que el usuario y el nick del grupo son válidos.
$force_scope = 1;
$join_policy = User_group::JOIN_POLICY_MODERATE;
User_group::register(array('nickname' => $nickname, 'userid' => $profile->id, 'join_policy' => $join_policy, 'force_scope' => $force_scope, 'local' => true));
print "Registrado grupo '{$nickname}'.\n";
print "Vinculado usuario '{$profile->nickname}' con grupo '{$nickname}'.\n";
Exemplo n.º 8
0
 /**
  * Handle the request
  *
  * Save the new group
  *
  * @return void
  */
 protected function handle()
 {
     parent::handle();
     if (empty($this->user)) {
         // TRANS: Client error given when a user was not found (404).
         $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:
             // TRANS: Client error displayed when coming across a non-supported API method.
             $this->clientError(_('API method not found.'), 404);
     }
 }
Exemplo n.º 9
0
 protected function doPost()
 {
     if (Event::handle('StartGroupSaveForm', array($this))) {
         $nickname = Nickname::normalize($this->trimmed('newnickname'), true);
         $fullname = $this->trimmed('fullname');
         $homepage = $this->trimmed('homepage');
         $description = $this->trimmed('description');
         $location = $this->trimmed('location');
         $private = $this->boolean('private');
         $aliasstring = $this->trimmed('aliases');
         if (!is_null($homepage) && strlen($homepage) > 0 && !common_valid_http_url($homepage)) {
             // TRANS: Group create form validation error.
             throw new ClientException(_('Homepage is not a valid URL.'));
         } else {
             if (!is_null($fullname) && mb_strlen($fullname) > 255) {
                 // TRANS: Group create form validation error.
                 throw new ClientException(_('Full name is too long (maximum 255 characters).'));
             } else {
                 if (User_group::descriptionTooLong($description)) {
                     // TRANS: Group create form validation error.
                     // TRANS: %d is the maximum number of allowed characters.
                     throw new ClientException(sprintf(_m('Description is too long (maximum %d character).', 'Description is too long (maximum %d characters).', User_group::maxDescription()), User_group::maxDescription()));
                 } else {
                     if (!is_null($location) && mb_strlen($location) > 255) {
                         // TRANS: Group create form validation error.
                         throw new ClientException(_('Location is too long (maximum 255 characters).'));
                     }
                 }
             }
         }
         if (!empty($aliasstring)) {
             $aliases = array_map(array('Nickname', 'normalize'), array_unique(preg_split('/[\\s,]+/', $aliasstring)));
         } else {
             $aliases = array();
         }
         if (count($aliases) > common_config('group', 'maxaliases')) {
             // TRANS: Group create form validation error.
             // TRANS: %d is the maximum number of allowed aliases.
             throw new ClientException(sprintf(_m('Too many aliases! Maximum %d allowed.', 'Too many aliases! Maximum %d allowed.', common_config('group', 'maxaliases')), common_config('group', 'maxaliases')));
         }
         if ($private) {
             $force_scope = 1;
             $join_policy = User_group::JOIN_POLICY_MODERATE;
         } else {
             $force_scope = 0;
             $join_policy = User_group::JOIN_POLICY_OPEN;
         }
         // This is set up in parent->prepare and checked in self->prepare
         assert(!is_null($this->scoped));
         $group = User_group::register(array('nickname' => $nickname, 'fullname' => $fullname, 'homepage' => $homepage, 'description' => $description, 'location' => $location, 'aliases' => $aliases, 'userid' => $this->scoped->id, 'join_policy' => $join_policy, 'force_scope' => $force_scope, 'local' => true));
         $this->group = $group;
         Event::handle('EndGroupSaveForm', array($this));
         common_redirect($group->homeUrl(), 303);
     }
 }