コード例 #1
0
ファイル: grouprss.php プロジェクト: stevertiqo/StatusNet
 /**
  * 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);
     $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);
         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) {
         $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;
     }
     $this->notices = $this->getNotices($this->limit);
     return true;
 }
コード例 #2
0
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $this->user = common_current_user();
     if (empty($this->user)) {
         throw new ClientException(_('Must be logged in.'), 403);
     }
     if (!$this->user->hasRight(Right::NEWMESSAGE)) {
         throw new Exception(sprintf(_('User %s not allowed to send private messages.'), $this->user->nickname));
     }
     $nicknameArg = $this->trimmed('nickname');
     $nickname = common_canonical_nickname($nicknameArg);
     if ($nickname != $nicknameArg) {
         $url = common_local_url('newgroupmessage', array('nickname' => $nickname));
         common_redirect($url, 301);
         return false;
     }
     $localGroup = Local_group::staticGet('nickname', $nickname);
     if (empty($localGroup)) {
         throw new ClientException(_('No such group'), 404);
     }
     $this->group = User_group::staticGet('id', $localGroup->group_id);
     if (empty($this->group)) {
         throw new ClientException(_('No such group'), 404);
     }
     // This throws an exception on error
     Group_privacy_settings::ensurePost($this->user, $this->group);
     // If we're posted to, check session token and get text
     if ($this->isPost()) {
         $this->checkSessionToken();
         $this->text = $this->trimmed('content');
     }
     return true;
 }
コード例 #3
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;
     }
 }
コード例 #4
0
ファイル: grouprss.php プロジェクト: microcosmx/experiments
 /**
  * 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);
     $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);
         common_redirect(common_local_url('showgroup', $args), 301);
         return false;
     }
     if (!$nickname) {
         // TRANS: Client error displayed when requesting a group RSS feed without providing a group nickname.
         $this->clientError(_('No nickname.'), 404);
         return false;
     }
     $local = Local_group::staticGet('nickname', $nickname);
     if (!$local) {
         // TRANS: Client error displayed when requesting a group RSS feed for group that does not exist.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $this->group = User_group::staticGet('id', $local->group_id);
     if (!$this->group) {
         // TRANS: Client error displayed when requesting a group RSS feed for an object that is not a group.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $this->notices = $this->getNotices($this->limit);
     return true;
 }
コード例 #5
0
ファイル: groupmembers.php プロジェクト: stevertiqo/StatusNet
 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('groupmembers', $args), 301);
         return false;
     }
     if (!$nickname) {
         $this->clientError(_('No nickname.'), 404);
         return false;
     }
     $local = Local_group::staticGet('nickname', $nickname);
     if (!$local) {
         $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;
     }
     return true;
 }
コード例 #6
0
ファイル: foafgroup.php プロジェクト: microcosmx/experiments
 function prepare($args)
 {
     parent::prepare($args);
     $nickname_arg = $this->arg('nickname');
     if (empty($nickname_arg)) {
         // TRANS: Client error displayed when requesting Friends of a Friend feed without providing a group nickname.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $this->nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $this->nickname) {
         common_redirect(common_local_url('foafgroup', array('nickname' => $this->nickname)), 301);
         return false;
     }
     $local = Local_group::staticGet('nickname', $this->nickname);
     if (!$local) {
         // TRANS: Client error displayed when requesting Friends of a Friend feed for a non-local group.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $this->group = User_group::staticGet('id', $local->group_id);
     if (!$this->group) {
         // TRANS: Client error displayed when requesting Friends of a Friend feed for a nickname that is not a group.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     common_set_returnto($this->selfUrl());
     return true;
 }
コード例 #7
0
 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('groupmembers', $args), 301);
         return false;
     }
     if (!$nickname) {
         // TRANS: Client error displayed when trying to view group members without providing a group nickname.
         $this->clientError(_('No nickname.'), 404);
         return false;
     }
     $local = Local_group::staticGet('nickname', $nickname);
     if (!$local) {
         // TRANS: Client error displayed when trying to view group members for a non-existing group.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $this->group = User_group::staticGet('id', $local->group_id);
     if (!$this->group) {
         // TRANS: Client error displayed when trying to view group members for an object that is not a group.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     return true;
 }
コード例 #8
0
ファイル: groupinbox.php プロジェクト: microcosmx/experiments
 /**
  * For initializing members of the class.
  *
  * @param array $argarray misc. arguments
  *
  * @return boolean true
  */
 function prepare($argarray)
 {
     parent::prepare($argarray);
     $cur = common_current_user();
     if (empty($cur)) {
         throw new ClientException(_('Only for logged-in users'), 403);
     }
     $nicknameArg = $this->trimmed('nickname');
     $nickname = common_canonical_nickname($nicknameArg);
     if ($nickname != $nicknameArg) {
         $url = common_local_url('groupinbox', array('nickname' => $nickname));
         common_redirect($url);
         return false;
     }
     $localGroup = Local_group::staticGet('nickname', $nickname);
     if (empty($localGroup)) {
         throw new ClientException(_('No such group'), 404);
     }
     $this->group = User_group::staticGet('id', $localGroup->group_id);
     if (empty($this->group)) {
         throw new ClientException(_('No such group'), 404);
     }
     if (!$cur->isMember($this->group)) {
         throw new ClientException(_('Only for members'), 403);
     }
     $this->page = $this->trimmed('page');
     if (!$this->page) {
         $this->page = 1;
     }
     $this->gm = Group_message::forGroup($this->group, ($this->page - 1) * MESSAGES_PER_PAGE, MESSAGES_PER_PAGE + 1);
     return true;
 }
コード例 #9
0
ファイル: foafgroup.php プロジェクト: himmelex/NTW
 function prepare($args)
 {
     parent::prepare($args);
     $nickname_arg = $this->arg('nickname');
     if (empty($nickname_arg)) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $this->nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $this->nickname) {
         common_redirect(common_local_url('foafgroup', array('nickname' => $this->nickname)), 301);
         return false;
     }
     $local = Local_group::staticGet('nickname', $this->nickname);
     if (!$local) {
         $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;
 }
コード例 #10
0
ファイル: joingroup.php プロジェクト: microcosmx/experiments
 /**
  * Prepare to run
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         // TRANS: Client error displayed when trying to join a group while not logged in.
         $this->clientError(_('You must be logged in to join a group.'));
         return false;
     }
     $nickname_arg = $this->trimmed('nickname');
     $id = intval($this->arg('id'));
     if ($id) {
         $this->group = User_group::staticGet('id', $id);
     } else {
         if ($nickname_arg) {
             $nickname = common_canonical_nickname($nickname_arg);
             // Permanent redirect on non-canonical nickname
             if ($nickname_arg != $nickname) {
                 $args = array('nickname' => $nickname);
                 common_redirect(common_local_url('leavegroup', $args), 301);
                 return false;
             }
             $local = Local_group::staticGet('nickname', $nickname);
             if (!$local) {
                 // TRANS: Client error displayed when trying to join a non-local group.
                 $this->clientError(_('No such group.'), 404);
                 return false;
             }
             $this->group = User_group::staticGet('id', $local->group_id);
         } else {
             // TRANS: Client error displayed when trying to join a group without providing a group name or group ID.
             $this->clientError(_('No nickname or ID.'), 404);
             return false;
         }
     }
     if (!$this->group) {
         // TRANS: Client error displayed when trying to join a non-existing group.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $cur = common_current_user();
     if ($cur->isMember($this->group)) {
         // TRANS: Client error displayed when trying to join a group while already a member.
         $this->clientError(_('You are already a member of that group.'), 403);
         return false;
     }
     if (Group_block::isBlocked($this->group, $cur->getProfile())) {
         // TRANS: Client error displayed when trying to join a group while being blocked form joining it.
         $this->clientError(_('You have been blocked from that group by the admin.'), 403);
         return false;
     }
     return true;
 }
コード例 #11
0
ファイル: deletegroup.php プロジェクト: stevertiqo/StatusNet
 /**
  * Prepare to run
  *
  * @fixme merge common setup code with other group actions
  * @fixme allow group admins to delete their own groups
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         // TRANS: Client error when trying to delete group while not logged in.
         $this->clientError(_('You must be logged in to delete a group.'));
         return false;
     }
     $nickname_arg = $this->trimmed('nickname');
     $id = intval($this->arg('id'));
     if ($id) {
         $this->group = User_group::staticGet('id', $id);
     } else {
         if ($nickname_arg) {
             $nickname = common_canonical_nickname($nickname_arg);
             // Permanent redirect on non-canonical nickname
             if ($nickname_arg != $nickname) {
                 $args = array('nickname' => $nickname);
                 common_redirect(common_local_url('leavegroup', $args), 301);
                 return false;
             }
             $local = Local_group::staticGet('nickname', $nickname);
             if (!$local) {
                 // TRANS: Client error when trying to delete a non-local group.
                 $this->clientError(_('No such group.'), 404);
                 return false;
             }
             $this->group = User_group::staticGet('id', $local->group_id);
         } else {
             // TRANS: Client error when trying to delete a group without providing a nickname or ID for the group.
             $this->clientError(_('No nickname or ID.'), 404);
             return false;
         }
     }
     if (!$this->group) {
         // TRANS: Client error when trying to delete a non-existing group.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $cur = common_current_user();
     if (!$cur->hasRight(Right::DELETEGROUP)) {
         // TRANS: Client error when trying to delete a group without having the rights to delete it.
         $this->clientError(_('You are not allowed to delete this group.'), 403);
         return false;
     }
     return true;
 }
コード例 #12
0
 /**
  * Sets the right action for the form, and passes request args into
  * the base action
  *
  * @param array $args misc. arguments
  *
  * @return boolean true
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         // TRANS: Client error displayed trying to change group design settings while not logged in.
         $this->clientError(_('You must be logged in to edit a group.'));
         return false;
     }
     $nickname_arg = $this->trimmed('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         common_redirect(common_local_url('groupdesignsettings', $args), 301);
         return false;
     }
     if (!$nickname) {
         // TRANS: Client error displayed trying to change group design settings without providing a group nickname.
         $this->clientError(_('No nickname.'), 404);
         return false;
     }
     $groupid = $this->trimmed('groupid');
     if ($groupid) {
         $this->group = User_group::staticGet('id', $groupid);
     } else {
         $local = Local_group::staticGet('nickname', $nickname);
         if ($local) {
             $this->group = User_group::staticGet('id', $local->group_id);
         }
     }
     if (!$this->group) {
         // TRANS: Client error displayed trying to change group design settings while providing a nickname for a non-existing group.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $cur = common_current_user();
     if (!$cur->isAdmin($this->group)) {
         // TRANS: Client error displayed trying to change group design settings without being a (group) admin.
         $this->clientError(_('You must be an admin to edit the group.'), 403);
         return false;
     }
     $this->submitaction = common_local_url('groupdesignsettings', array('nickname' => $this->group->nickname));
     return true;
 }
コード例 #13
0
ファイル: groupaction.php プロジェクト: Grasia/bolotweet
 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;
     }
 }
コード例 #14
0
ファイル: leavegroup.php プロジェクト: stevertiqo/StatusNet
 /**
  * Prepare to run
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         $this->clientError(_('You must be logged in to leave a group.'));
         return false;
     }
     $nickname_arg = $this->trimmed('nickname');
     $id = intval($this->arg('id'));
     if ($id) {
         $this->group = User_group::staticGet('id', $id);
     } else {
         if ($nickname_arg) {
             $nickname = common_canonical_nickname($nickname_arg);
             // Permanent redirect on non-canonical nickname
             if ($nickname_arg != $nickname) {
                 $args = array('nickname' => $nickname);
                 common_redirect(common_local_url('leavegroup', $args), 301);
                 return false;
             }
             $local = Local_group::staticGet('nickname', $nickname);
             if (!$local) {
                 $this->clientError(_('No such group.'), 404);
                 return false;
             }
             $this->group = User_group::staticGet('id', $local->group_id);
         } else {
             $this->clientError(_('No nickname or ID.'), 404);
             return false;
         }
     }
     if (!$this->group) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $cur = common_current_user();
     if (!$cur->isMember($this->group)) {
         $this->clientError(_('You are not a member of that group.'), 403);
         return false;
     }
     return true;
 }
コード例 #15
0
ファイル: grouplogo.php プロジェクト: stevertiqo/StatusNet
 /**
  * Prepare to run
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         $this->clientError(_('You must be logged in to create a group.'));
         return false;
     }
     $nickname_arg = $this->trimmed('nickname');
     $nickname = common_canonical_nickname($nickname_arg);
     // Permanent redirect on non-canonical nickname
     if ($nickname_arg != $nickname) {
         $args = array('nickname' => $nickname);
         common_redirect(common_local_url('grouplogo', $args), 301);
         return false;
     }
     if (!$nickname) {
         $this->clientError(_('No nickname.'), 404);
         return false;
     }
     $groupid = $this->trimmed('groupid');
     if ($groupid) {
         $this->group = User_group::staticGet('id', $groupid);
     } else {
         $local = Local_group::staticGet('nickname', $nickname);
         if ($local) {
             $this->group = User_group::staticGet('id', $local->group_id);
         }
     }
     if (!$this->group) {
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $cur = common_current_user();
     if (!$cur->isAdmin($this->group)) {
         $this->clientError(_('You must be an admin to edit the group.'), 403);
         return false;
     }
     return true;
 }
コード例 #16
0
 /**
  * Build the canonical profile URI+URL of the requested user or group
  */
 function targetProfile()
 {
     if ($this->nickname) {
         $user = User::staticGet('nickname', $this->nickname);
         if ($user) {
             return common_local_url('userbyid', array('id' => $user->id));
         } else {
             $this->clientError("No such user.");
         }
     } else {
         if ($this->group) {
             $group = Local_group::staticGet('nickname', $this->group);
             if ($group) {
                 return common_local_url('groupbyid', array('id' => $group->group_id));
             } else {
                 $this->clientError("No such group.");
             }
         } else {
             $this->clientError("No local user or group nickname provided.");
         }
     }
 }
コード例 #17
0
ファイル: editgroup.php プロジェクト: himmelex/NTW
 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;
 }
コード例 #18
0
ファイル: cancelgroup.php プロジェクト: Grasia/bolotweet
 /**
  * Prepare to run
  */
 function prepare($args)
 {
     parent::prepare($args);
     if (!common_logged_in()) {
         // TRANS: Client error displayed when trying to leave a group while not logged in.
         $this->clientError(_('You must be logged in to leave a group.'));
         return false;
     }
     $nickname_arg = $this->trimmed('nickname');
     $id = intval($this->arg('id'));
     if ($id) {
         $this->group = User_group::staticGet('id', $id);
     } else {
         if ($nickname_arg) {
             $nickname = common_canonical_nickname($nickname_arg);
             // Permanent redirect on non-canonical nickname
             if ($nickname_arg != $nickname) {
                 $args = array('nickname' => $nickname);
                 common_redirect(common_local_url('leavegroup', $args), 301);
                 return false;
             }
             $local = Local_group::staticGet('nickname', $nickname);
             if (!$local) {
                 // TRANS: Client error displayed when trying to leave a non-local group.
                 $this->clientError(_('No such group.'), 404);
                 return false;
             }
             $this->group = User_group::staticGet('id', $local->group_id);
         } else {
             // TRANS: Client error displayed when trying to leave a group without providing a group name or group ID.
             $this->clientError(_('No nickname or ID.'), 404);
             return false;
         }
     }
     if (!$this->group) {
         // TRANS: Client error displayed when trying to leave a non-existing group.
         $this->clientError(_('No such group.'), 404);
         return false;
     }
     $cur = common_current_user();
     if (empty($cur)) {
         // TRANS: Client error displayed when trying to leave a group while not logged in.
         $this->clientError(_('Must be logged in.'), 403);
         return false;
     }
     if ($this->arg('profile_id')) {
         if ($cur->isAdmin($this->group)) {
             $this->profile = Profile::staticGet('id', $this->arg('profile_id'));
         } else {
             // TRANS: Client error displayed when trying to approve or cancel a group join request without
             // TRANS: being a group administrator.
             $this->clientError(_('Only group admin can approve or cancel join requests.'), 403);
             return false;
         }
     } else {
         $this->profile = $cur->getProfile();
     }
     $this->request = Group_join_queue::pkeyGet(array('profile_id' => $this->profile->id, 'group_id' => $this->group->id));
     if (empty($this->request)) {
         // TRANS: Client error displayed when trying to approve a non-existing group join request.
         // TRANS: %s is a user nickname.
         $this->clientError(sprintf(_('%s is not in the moderation queue for this group.'), $this->profile->nickname), 403);
     }
     return true;
 }
コード例 #19
0
ファイル: showgroup.php プロジェクト: stevertiqo/StatusNet
 /**
  * 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;
 }
コード例 #20
0
 function getTargetGroup($id)
 {
     if (empty($id)) {
         if (is_numeric($this->arg('id'))) {
             return User_group::staticGet($this->arg('id'));
         } else {
             if ($this->arg('id')) {
                 $nickname = common_canonical_nickname($this->arg('id'));
                 $local = Local_group::staticGet('nickname', $nickname);
                 if (empty($local)) {
                     return null;
                 } else {
                     return User_group::staticGet('id', $local->id);
                 }
             } else {
                 if ($this->arg('group_id')) {
                     // This is to ensure that a non-numeric user_id still
                     // overrides screen_name even if it doesn't get used
                     if (is_numeric($this->arg('group_id'))) {
                         return User_group::staticGet('id', $this->arg('group_id'));
                     }
                 } else {
                     if ($this->arg('group_name')) {
                         $nickname = common_canonical_nickname($this->arg('group_name'));
                         $local = Local_group::staticGet('nickname', $nickname);
                         if (empty($local)) {
                             return null;
                         } else {
                             return User_group::staticGet('id', $local->group_id);
                         }
                     }
                 }
             }
         }
     } else {
         if (is_numeric($id)) {
             return User_group::staticGet($id);
         } else {
             $nickname = common_canonical_nickname($id);
             $local = Local_group::staticGet('nickname', $nickname);
             if (empty($local)) {
                 return null;
             } else {
                 return User_group::staticGet('id', $local->group_id);
             }
         }
     }
 }
コード例 #21
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;
 }
コード例 #22
0
 /**
  * Utility function to check if the given URI is a canonical group profile
  * page, and if so return the ID number.
  *
  * @param string $url
  * @return mixed int or false
  */
 public static function localGroupFromUrl($url)
 {
     $group = User_group::staticGet('uri', $url);
     if ($group) {
         $local = Local_group::staticGet('group_id', $group->id);
         if ($local) {
             return $group->id;
         }
     } else {
         // To find local groups which haven't had their uri fields filled out...
         // If the domain has changed since a subscriber got the URI, it'll
         // be broken.
         $template = common_local_url('groupbyid', array('id' => '31337'));
         $template = preg_quote($template, '/');
         $template = str_replace('31337', '(\\d+)', $template);
         if (preg_match("/{$template}/", $url, $matches)) {
             return intval($matches[1]);
         }
     }
     return false;
 }
コード例 #23
0
Adds a local user to a local group.

  -i --id       ID of user to add
  -n --nickname nickname of the user to add
  -g --group    nickname or alias of group
  -G --group-id ID of group

END_OF_HELP;
require_once INSTALLDIR . '/scripts/commandline.inc';
try {
    $user = getUser();
    $lgroup = null;
    if (have_option('G', 'group-id')) {
        $gid = get_option_value('G', 'group-id');
        $lgroup = Local_group::staticGet('group_id', $gid);
    } else {
        if (have_option('g', 'group')) {
            $gnick = get_option_value('g', 'group');
            $lgroup = Local_group::staticGet('nickname', $gnick);
        }
    }
    if (empty($lgroup)) {
        throw new Exception("No such local group: {$gnick}");
    }
    $group = User_group::staticGet('id', $lgroup->group_id);
    $user->joinGroup($group);
    print "OK\n";
} catch (Exception $e) {
    print $e->getMessage() . "\n";
    exit(1);
}
コード例 #24
0
$encProfile = $oprofile->escape($profileTemplate, true);
$encProfile = str_replace($marker, '%', $encProfile);
echo "  LIKE '{$encProfile}'\n";
$groupTemplate = common_local_url('groupbyid', array('id' => $marker));
$encGroup = $oprofile->escape($groupTemplate, true);
$encGroup = str_replace($marker, '%', $encGroup);
echo "  LIKE '{$encGroup}'\n";
$sql = "SELECT * FROM ostatus_profile WHERE uri LIKE '%s' OR uri LIKE '%s'";
$oprofile->query(sprintf($sql, $encProfile, $encGroup));
$count = $oprofile->N;
echo "Found {$count}...\n";
while ($oprofile->fetch()) {
    $uri = $oprofile->uri;
    if (preg_match('!/group/(\\d+)/id!', $oprofile->uri, $matches)) {
        $id = intval($matches[1]);
        $group = Local_group::staticGet('group_id', $id);
        if ($group) {
            $nick = $group->nickname;
        } else {
            $nick = '<deleted>';
        }
        echo "group {$id} ({$nick}) hidden by {$uri}";
    } else {
        if (preg_match('!/user/(\\d+)!', $uri, $matches)) {
            $id = intval($matches[1]);
            $user = User::staticGet('id', $id);
            if ($user) {
                $nick = $user->nickname;
            } else {
                $nick = '<deleted>';
            }
コード例 #25
0
ファイル: User_group.php プロジェクト: Br3nda/StatusNet
 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;
 }
コード例 #26
0
ファイル: createGroup.php プロジェクト: Grasia/bolotweet
// 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";
コード例 #27
0
ファイル: ostatusinit.php プロジェクト: Grasia/bolotweet
 /**
  * Build the canonical profile URI+URL of the requested user or group
  */
 function targetProfile()
 {
     if ($this->nickname) {
         $user = User::staticGet('nickname', $this->nickname);
         if ($user) {
             return common_local_url('userbyid', array('id' => $user->id));
         } else {
             // TRANS: Client error.
             $this->clientError(_m('No such user.'));
         }
     } else {
         if ($this->group) {
             $group = Local_group::staticGet('nickname', $this->group);
             if ($group) {
                 return common_local_url('groupbyid', array('id' => $group->group_id));
             } else {
                 // TRANS: Client error.
                 $this->clientError(_m('No such group.'));
             }
         } else {
             if ($this->peopletag && $this->tagger) {
                 $user = User::staticGet('nickname', $this->tagger);
                 if (empty($user)) {
                     // TRANS: Client error.
                     $this->clientError(_m('No such user.'));
                 }
                 $peopletag = Profile_list::getByTaggerAndTag($user->id, $this->peopletag);
                 if ($peopletag) {
                     return common_local_url('profiletagbyid', array('tagger_id' => $user->id, 'id' => $peopletag->id));
                 }
                 // TRANS: Client error.
                 $this->clientError(_m('No such list.'));
             } else {
                 // TRANS: Client error.
                 $this->clientError(_m('No local user or group nickname provided.'));
             }
         }
     }
 }
コード例 #28
0
ファイル: User_group.php プロジェクト: stevertiqo/StatusNet
 /**
  * Handle cascading deletion, on the model of notice and profile.
  *
  * This should handle freeing up cached entries for the group's
  * id, nickname, URI, and aliases. There may be other areas that
  * are not de-cached in the UI, including the sidebar lists on
  * GroupsAction
  */
 function delete()
 {
     if ($this->id) {
         // Safe to delete in bulk for now
         $related = array('Group_inbox', 'Group_block', 'Group_member', 'Related_group');
         Event::handle('UserGroupDeleteRelated', array($this, &$related));
         foreach ($related as $cls) {
             $inst = new $cls();
             $inst->group_id = $this->id;
             if ($inst->find()) {
                 while ($inst->fetch()) {
                     $dup = clone $inst;
                     $dup->delete();
                 }
             }
         }
         // And related groups in the other direction...
         $inst = new Related_group();
         $inst->related_group_id = $this->id;
         $inst->delete();
         // Aliases and the local_group entry need to be cleared explicitly
         // or we'll miss clearing some cache keys; that can make it hard
         // to create a new group with one of those names or aliases.
         $this->setAliases(array());
         $local = Local_group::staticGet('group_id', $this->id);
         if ($local) {
             $local->delete();
         }
         // blow the cached ids
         self::blow('user_group:notice_ids:%d', $this->id);
     } else {
         common_log(LOG_WARN, "Ambiguous user_group->delete(); skipping related tables.");
     }
     parent::delete();
 }
コード例 #29
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;
 }