3 * StatusNet, the distributed open-source microblogging tool
5 * List of group members
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @copyright 2008-2009 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
34 require_once(INSTALLDIR.'/lib/profilelist.php');
35 require_once INSTALLDIR.'/lib/publicgroupnav.php';
38 * List of group members
42 * @author Evan Prodromou <evan@status.net>
43 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44 * @link http://status.net/
46 class GroupmembersAction extends GroupDesignAction
50 function isReadOnly($args)
55 function prepare($args)
57 parent::prepare($args);
58 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
60 $nickname_arg = $this->arg('nickname');
61 $nickname = common_canonical_nickname($nickname_arg);
63 // Permanent redirect on non-canonical nickname
65 if ($nickname_arg != $nickname) {
66 $args = array('nickname' => $nickname);
67 if ($this->page != 1) {
68 $args['page'] = $this->page;
70 common_redirect(common_local_url('groupmembers', $args), 301);
75 // TRANS: Client error displayed when trying to view group members without providing a group nickname.
76 $this->clientError(_('No nickname.'), 404);
80 $local = Local_group::staticGet('nickname', $nickname);
83 // TRANS: Client error displayed when trying to view group members for a non-existing group.
84 $this->clientError(_('No such group.'), 404);
88 $this->group = User_group::staticGet('id', $local->group_id);
91 // TRANS: Client error displayed when trying to view group members for an object that is not a group.
92 $this->clientError(_('No such group.'), 404);
101 if ($this->page == 1) {
102 // TRANS: Title of the page showing group members.
103 // TRANS: %s is the name of the group.
104 return sprintf(_('%s group members'),
105 $this->group->nickname);
107 // TRANS: Title of the page showing group members.
108 // TRANS: %1$s is the name of the group, %2$d is the page number of the members list.
109 return sprintf(_('%1$s group members, page %2$d'),
110 $this->group->nickname,
115 function handle($args)
117 parent::handle($args);
121 function showPageNotice()
123 $this->element('p', 'instructions',
124 // TRANS: Page notice for group members page.
125 _('A list of the users in this group.'));
128 function showLocalNav()
130 $nav = new GroupNav($this, $this->group);
134 function showContent()
136 $offset = ($this->page-1) * PROFILES_PER_PAGE;
137 $limit = PROFILES_PER_PAGE + 1;
141 $members = $this->group->getMembers($offset, $limit);
144 $member_list = new GroupMemberList($members, $this->group, $this);
145 $cnt = $member_list->show();
150 $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
151 $this->page, 'groupmembers',
152 array('nickname' => $this->group->nickname));
156 class GroupMemberList extends ProfileList
160 function __construct($profile, $group, $action)
162 parent::__construct($profile, $action);
164 $this->group = $group;
167 function newListItem($profile)
169 return new GroupMemberListItem($profile, $this->group, $this->action);
173 class GroupMemberListItem extends ProfileListItem
177 function __construct($profile, $group, $action)
179 parent::__construct($profile, $action);
181 $this->group = $group;
184 function showFullName()
186 parent::showFullName();
187 if ($this->profile->isAdmin($this->group)) {
188 $this->out->text(' '); // for separating the classes.
189 // TRANS: Indicator in group members list that this user is a group administrator.
190 $this->out->element('span', 'role', _('Admin'));
194 function showActions()
196 $this->startActions();
197 if (Event::handle('StartProfileListItemActionElements', array($this))) {
198 $this->showSubscribeButton();
199 $this->showMakeAdminForm();
200 $this->showGroupBlockForm();
201 Event::handle('EndProfileListItemActionElements', array($this));
206 function showMakeAdminForm()
208 $user = common_current_user();
211 $user->id != $this->profile->id &&
212 ($user->isAdmin($this->group) || $user->hasRight(Right::MAKEGROUPADMIN)) &&
213 !$this->profile->isAdmin($this->group)) {
214 $this->out->elementStart('li', 'entity_make_admin');
215 $maf = new MakeAdminForm($this->out, $this->profile, $this->group,
216 $this->returnToArgs());
218 $this->out->elementEnd('li');
223 function showGroupBlockForm()
225 $user = common_current_user();
227 if (!empty($user) && $user->id != $this->profile->id && $user->isAdmin($this->group)) {
228 $this->out->elementStart('li', 'entity_block');
229 $bf = new GroupBlockForm($this->out, $this->profile, $this->group,
230 $this->returnToArgs());
232 $this->out->elementEnd('li');
236 function linkAttributes()
238 $aAttrs = parent::linkAttributes();
240 if (common_config('nofollow', 'members')) {
241 $aAttrs['rel'] .= ' nofollow';
247 function homepageAttributes()
249 $aAttrs = parent::linkAttributes();
251 if (common_config('nofollow', 'members')) {
252 $aAttrs['rel'] = 'nofollow';
259 * Fetch necessary return-to arguments for the profile forms
260 * to return to this list when they're done.
264 protected function returnToArgs()
266 $args = array('action' => 'groupmembers',
267 'nickname' => $this->group->nickname);
268 $page = $this->out->arg('page');
270 $args['param-page'] = $page;
277 * Form for blocking a user from a group
281 * @author Evan Prodromou <evan@status.net>
282 * @author Sarven Capadisli <csarven@status.net>
283 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
284 * @link http://status.net/
288 class GroupBlockForm extends Form
291 * Profile of user to block
297 * Group to block the user from
311 * @param HTMLOutputter $out output channel
312 * @param Profile $profile profile of user to block
313 * @param User_group $group group to block user from
314 * @param array $args return-to args
316 function __construct($out=null, $profile=null, $group=null, $args=null)
318 parent::__construct($out);
320 $this->profile = $profile;
321 $this->group = $group;
328 * @return int ID of the form
332 // This should be unique for the page.
333 return 'block-' . $this->profile->id;
339 * @return string class of the form
343 return 'form_group_block';
349 * @return string URL of the action
353 return common_local_url('groupblock');
361 function formLegend()
363 // TRANS: Form legend for form to block user from a group.
364 $this->out->element('legend', null, _('Block user from group'));
368 * Data elements of the form
374 $this->out->hidden('blockto-' . $this->profile->id,
377 $this->out->hidden('blockgroup-' . $this->group->id,
381 foreach ($this->args as $k => $v) {
382 $this->out->hidden('returnto-' . $k, $v);
392 function formActions()
396 // TRANS: Button text for the form that will block a user from a group.
397 _m('BUTTON','Block'),
400 // TRANS: Submit button title.
401 _m('TOOLTIP', 'Block this user'));
406 * Form for making a user an admin for a group
410 * @author Evan Prodromou <evan@status.net>
411 * @author Sarven Capadisli <csarven@status.net>
412 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
413 * @link http://status.net/
415 class MakeAdminForm extends Form
418 * Profile of user to block
423 * Group to block the user from
435 * @param HTMLOutputter $out output channel
436 * @param Profile $profile profile of user to block
437 * @param User_group $group group to block user from
438 * @param array $args return-to args
440 function __construct($out=null, $profile=null, $group=null, $args=null)
442 parent::__construct($out);
444 $this->profile = $profile;
445 $this->group = $group;
452 * @return int ID of the form
456 // This should be unique for the page.
457 return 'makeadmin-' . $this->profile->id;
463 * @return string class of the form
467 return 'form_make_admin';
473 * @return string URL of the action
477 return common_local_url('makeadmin', array('nickname' => $this->group->nickname));
485 function formLegend()
487 // TRANS: Form legend for form to make a user a group admin.
488 $this->out->element('legend', null, _('Make user an admin of the group'));
492 * Data elements of the form
498 $this->out->hidden('profileid-' . $this->profile->id,
501 $this->out->hidden('groupid-' . $this->group->id,
505 foreach ($this->args as $k => $v) {
506 $this->out->hidden('returnto-' . $k, $v);
516 function formActions()
520 // TRANS: Button text for the form that will make a user administrator.
521 _m('BUTTON','Make Admin'),
524 // TRANS: Submit button title.
525 _m('TOOLTIP','Make this user an admin'));