Example #1
0
 /**
  * Take arguments for running
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     $this->group = $this->getTargetGroup($this->arg('id'));
     if (empty($this->group)) {
         $alias = Group_alias::staticGet('alias', common_canonical_nickname($this->arg('id')));
         if (!empty($alias)) {
             $args = array('id' => $alias->group_id, 'format' => $this->format);
             common_redirect(common_local_url('ApiGroupShow', $args), 301);
         } else {
             $this->clientError(_('Group not found.'), 404, $this->format);
         }
         return;
     }
     return true;
 }
Example #2
0
 /**
  * Take arguments for running
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 protected function prepare(array $args = array())
 {
     parent::prepare($args);
     $this->group = $this->getTargetGroup($this->arg('id'));
     if (empty($this->group)) {
         $alias = Group_alias::getKV('alias', common_canonical_nickname($this->arg('id')));
         if (!empty($alias)) {
             $args = array('id' => $alias->group_id, 'format' => $this->format);
             common_redirect(common_local_url('ApiGroupShow', $args), 301);
         } else {
             // TRANS: Client error displayed when trying to show a group that could not be found.
             $this->clientError(_('Group not found.'), 404);
         }
         return;
     }
     return true;
 }
Example #3
0
 function prepare($args)
 {
     parent::prepare($args);
     $nickname_arg = $this->arg('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         if ($this->page != 1) {
             $args['page'] = $this->page;
         }
         common_redirect(common_local_url('showgroup', $args), 301);
         return false;
     }
     if (!$nickname) {
         // TRANS: Client error displayed if no nickname argument was given requesting a group page.
         $this->clientError(_('No nickname.'), 404);
         return false;
     }
     $local = Local_group::staticGet('nickname', $nickname);
     if (!$local) {
         $alias = Group_alias::staticGet('alias', $nickname);
         if ($alias) {
             $args = array('id' => $alias->group_id);
             if ($this->page != 1) {
                 $args['page'] = $this->page;
             }
             common_redirect(common_local_url('groupbyid', $args), 301);
             return false;
         } else {
             common_log(LOG_NOTICE, "Couldn't find local group for nickname '{$nickname}'");
             // TRANS: Client error displayed if no remote group with a given name was found requesting group page.
             $this->clientError(_('No such group.'), 404);
             return false;
         }
     }
     $this->group = User_group::staticGet('id', $local->group_id);
     if (!$this->group) {
         // TRANS: Client error displayed if no local group with a given name was found requesting group page.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
 }
Example #4
0
 static function getForNickname($nickname, $profile = null)
 {
     $nickname = common_canonical_nickname($nickname);
     // Are there any matching remote groups this profile's in?
     if ($profile) {
         $group = $profile->getGroups();
         while ($group->fetch()) {
             if ($group->nickname == $nickname) {
                 // @fixme is this the best way?
                 return clone $group;
             }
         }
     }
     // If not, check local groups.
     $group = Local_group::staticGet('nickname', $nickname);
     if (!empty($group)) {
         return User_group::staticGet('id', $group->group_id);
     }
     $alias = Group_alias::staticGet('alias', $nickname);
     if (!empty($alias)) {
         return User_group::staticGet('id', $alias->group_id);
     }
     return null;
 }
Example #5
0
 function nicknameExists($nickname)
 {
     $group = Local_group::staticGet('nickname', $nickname);
     if (!empty($group) && $group->group_id != $this->group->id) {
         return true;
     }
     $alias = Group_alias::staticGet('alias', $nickname);
     if (!empty($alias) && $alias->group_id != $this->group->id) {
         return true;
     }
     return false;
 }
Example #6
0
 /**
  * Check to see whether a nickname is already in use by a group
  *
  * @param String $nickname The nickname in question
  *
  * @return boolean true or false
  */
 function groupNicknameExists($nickname)
 {
     $local = Local_group::staticGet('nickname', $nickname);
     if (!empty($local)) {
         return true;
     }
     $alias = Group_alias::staticGet('alias', $nickname);
     if (!empty($alias)) {
         return true;
     }
     return false;
 }
Example #7
0
 /**
  * Is the nickname already in use locally? Checks the User table.
  *
  * @param   string $str
  * @return  Profile|null   Returns Profile if nickname found, otherwise null
  */
 public static function isTaken($str)
 {
     $found = User::getKV('nickname', $str);
     if ($found instanceof User) {
         return $found->getProfile();
     }
     $found = Local_group::getKV('nickname', $str);
     if ($found instanceof Local_group) {
         return $found->getProfile();
     }
     $found = Group_alias::getKV('alias', $str);
     if ($found instanceof Group_alias) {
         return $found->getProfile();
     }
     return null;
 }
Example #8
0
 /**
  * Prepare the action
  *
  * Reads and validates arguments and instantiates the attributes.
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     $nickname_arg = $this->arg('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         if ($this->page != 1) {
             $args['page'] = $this->page;
         }
         common_redirect(common_local_url('showgroup', $args), 301);
         return false;
     }
     if (!$nickname) {
         $this->clientError(_('No nickname.'), 404);
         return false;
     }
     $local = Local_group::staticGet('nickname', $nickname);
     if (!$local) {
         $alias = Group_alias::staticGet('alias', $nickname);
         if ($alias) {
             $args = array('id' => $alias->group_id);
             if ($this->page != 1) {
                 $args['page'] = $this->page;
             }
             common_redirect(common_local_url('groupbyid', $args), 301);
             return false;
         } else {
             common_log(LOG_NOTICE, "Couldn't find local group for nickname '{$nickname}'");
             $this->clientError(_('No such group.'), 404);
             return false;
         }
     }
     $this->group = User_group::staticGet('id', $local->group_id);
     if (!$this->group) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     common_set_returnto($this->selfUrl());
     return true;
 }
Example #9
0
 static function getForNickname($nickname, Profile $profile = null)
 {
     $nickname = Nickname::normalize($nickname);
     // Are there any matching remote groups this profile's in?
     if ($profile instanceof Profile) {
         $group = $profile->getGroups(0, null);
         while ($group instanceof User_group && $group->fetch()) {
             if ($group->nickname == $nickname) {
                 // @fixme is this the best way?
                 return clone $group;
             }
         }
     }
     // If not, check local groups.
     $group = Local_group::getKV('nickname', $nickname);
     if ($group instanceof Local_group) {
         return User_group::getKV('id', $group->group_id);
     }
     $alias = Group_alias::getKV('alias', $nickname);
     if ($alias instanceof Group_alias) {
         return User_group::getKV('id', $alias->group_id);
     }
     return null;
 }
Example #10
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";
Example #11
0
 /**
  * Prepare the action
  *
  * Reads and validates arguments and instantiates the attributes.
  *
  * @param array $args $_REQUEST args
  *
  * @return boolean success flag
  */
 function prepare($args)
 {
     parent::prepare($args);
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     $nickname_arg = $this->arg('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         if ($this->page != 1) {
             $args['page'] = $this->page;
         }
         common_redirect(common_local_url('showgroup', $args), 301);
         return false;
     }
     if (!$nickname) {
         // TRANS: Client error displayed if no nickname argument was given requesting a group page.
         $this->clientError(_('No nickname.'), 404);
         return false;
     }
     $local = Local_group::staticGet('nickname', $nickname);
     if (!$local) {
         $alias = Group_alias::staticGet('alias', $nickname);
         if ($alias) {
             $args = array('id' => $alias->group_id);
             if ($this->page != 1) {
                 $args['page'] = $this->page;
             }
             common_redirect(common_local_url('groupbyid', $args), 301);
             return false;
         } else {
             common_log(LOG_NOTICE, "Couldn't find local group for nickname '{$nickname}'");
             // TRANS: Client error displayed if no remote group with a given name was found requesting group page.
             $this->clientError(_('No such group.'), 404);
             return false;
         }
     }
     $this->group = User_group::staticGet('id', $local->group_id);
     if (!$this->group) {
         // TRANS: Client error displayed if no local group with a given name was found requesting group page.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $this->userProfile = Profile::current();
     $stream = new ThreadingGroupNoticeStream($this->group, $this->userProfile);
     $this->notice = $stream->getNotices(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
     common_set_returnto($this->selfUrl());
     return true;
 }