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/
47 class GroupmembersAction extends GroupDesignAction
51 function isReadOnly($args)
56 function prepare($args)
58 parent::prepare($args);
59 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
61 $nickname_arg = $this->arg('nickname');
62 $nickname = common_canonical_nickname($nickname_arg);
64 // Permanent redirect on non-canonical nickname
66 if ($nickname_arg != $nickname) {
67 $args = array('nickname' => $nickname);
68 if ($this->page != 1) {
69 $args['page'] = $this->page;
71 common_redirect(common_local_url('groupmembers', $args), 301);
76 $this->clientError(_('No nickname.'), 404);
80 $local = Local_group::staticGet('nickname', $nickname);
83 $this->clientError(_('No such group.'), 404);
87 $this->group = User_group::staticGet('id', $local->group_id);
90 $this->clientError(_('No such group.'), 404);
99 if ($this->page == 1) {
100 // TRANS: Title of the page showing group members.
101 // TRANS: %s is the name of the group.
102 return sprintf(_('%s group members'),
103 $this->group->nickname);
105 // TRANS: Title of the page showing group members.
106 // TRANS: %1$s is the name of the group, %2$d is the page number of the members list.
107 return sprintf(_('%1$s group members, page %2$d'),
108 $this->group->nickname,
113 function handle($args)
115 parent::handle($args);
119 function showPageNotice()
121 $this->element('p', 'instructions',
122 _('A list of the users in this group.'));
125 function showLocalNav()
127 $nav = new GroupNav($this, $this->group);
131 function showContent()
133 $offset = ($this->page-1) * PROFILES_PER_PAGE;
134 $limit = PROFILES_PER_PAGE + 1;
138 $members = $this->group->getMembers($offset, $limit);
141 $member_list = new GroupMemberList($members, $this->group, $this);
142 $cnt = $member_list->show();
147 $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
148 $this->page, 'groupmembers',
149 array('nickname' => $this->group->nickname));
153 class GroupMemberList extends ProfileList
157 function __construct($profile, $group, $action)
159 parent::__construct($profile, $action);
161 $this->group = $group;
164 function newListItem($profile)
166 return new GroupMemberListItem($profile, $this->group, $this->action);
170 class GroupMemberListItem extends ProfileListItem
174 function __construct($profile, $group, $action)
176 parent::__construct($profile, $action);
178 $this->group = $group;
181 function showFullName()
183 parent::showFullName();
184 if ($this->profile->isAdmin($this->group)) {
185 $this->out->text(' ');
186 $this->out->element('span', 'role', _('Admin'));
190 function showActions()
192 $this->startActions();
193 if (Event::handle('StartProfileListItemActionElements', array($this))) {
194 $this->showSubscribeButton();
195 $this->showMakeAdminForm();
196 $this->showGroupBlockForm();
197 Event::handle('EndProfileListItemActionElements', array($this));
202 function showMakeAdminForm()
204 $user = common_current_user();
207 $user->id != $this->profile->id &&
208 ($user->isAdmin($this->group) || $user->hasRight(Right::MAKEGROUPADMIN)) &&
209 !$this->profile->isAdmin($this->group)) {
210 $this->out->elementStart('li', 'entity_make_admin');
211 $maf = new MakeAdminForm($this->out, $this->profile, $this->group,
212 $this->returnToArgs());
214 $this->out->elementEnd('li');
219 function showGroupBlockForm()
221 $user = common_current_user();
223 if (!empty($user) && $user->id != $this->profile->id && $user->isAdmin($this->group)) {
224 $this->out->elementStart('li', 'entity_block');
225 $bf = new GroupBlockForm($this->out, $this->profile, $this->group,
226 $this->returnToArgs());
228 $this->out->elementEnd('li');
232 function linkAttributes()
234 $aAttrs = parent::linkAttributes();
236 if (common_config('nofollow', 'members')) {
237 $aAttrs['rel'] .= ' nofollow';
243 function homepageAttributes()
245 $aAttrs = parent::linkAttributes();
247 if (common_config('nofollow', 'members')) {
248 $aAttrs['rel'] = 'nofollow';
255 * Fetch necessary return-to arguments for the profile forms
256 * to return to this list when they're done.
260 protected function returnToArgs()
262 $args = array('action' => 'groupmembers',
263 'nickname' => $this->group->nickname);
264 $page = $this->out->arg('page');
266 $args['param-page'] = $page;
273 * Form for blocking a user from a group
277 * @author Evan Prodromou <evan@status.net>
278 * @author Sarven Capadisli <csarven@status.net>
279 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
280 * @link http://status.net/
285 class GroupBlockForm extends Form
288 * Profile of user to block
294 * Group to block the user from
308 * @param HTMLOutputter $out output channel
309 * @param Profile $profile profile of user to block
310 * @param User_group $group group to block user from
311 * @param array $args return-to args
314 function __construct($out=null, $profile=null, $group=null, $args=null)
316 parent::__construct($out);
318 $this->profile = $profile;
319 $this->group = $group;
326 * @return int ID of the form
331 // This should be unique for the page.
332 return 'block-' . $this->profile->id;
338 * @return string class of the form
343 return 'form_group_block';
349 * @return string URL of the action
354 return common_local_url('groupblock');
362 function formLegend()
364 $this->out->element('legend', null, _('Block user from group'));
368 * Data elements of the form
375 $this->out->hidden('blockto-' . $this->profile->id,
378 $this->out->hidden('blockgroup-' . $this->group->id,
382 foreach ($this->args as $k => $v) {
383 $this->out->hidden('returnto-' . $k, $v);
394 function formActions()
398 // TRANS: Button text for the form that will block a user from a group.
399 _m('BUTTON','Block'),
402 // TRANS: Submit button title.
403 _m('TOOLTIP',_('Block this user'));
408 * Form for making a user an admin for a group
412 * @author Evan Prodromou <evan@status.net>
413 * @author Sarven Capadisli <csarven@status.net>
414 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
415 * @link http://status.net/
418 class MakeAdminForm extends Form
421 * Profile of user to block
427 * Group to block the user from
441 * @param HTMLOutputter $out output channel
442 * @param Profile $profile profile of user to block
443 * @param User_group $group group to block user from
444 * @param array $args return-to args
447 function __construct($out=null, $profile=null, $group=null, $args=null)
449 parent::__construct($out);
451 $this->profile = $profile;
452 $this->group = $group;
459 * @return int ID of the form
464 // This should be unique for the page.
465 return 'makeadmin-' . $this->profile->id;
471 * @return string class of the form
476 return 'form_make_admin';
482 * @return string URL of the action
487 return common_local_url('makeadmin', array('nickname' => $this->group->nickname));
496 function formLegend()
498 $this->out->element('legend', null, _('Make user an admin of the group'));
502 * Data elements of the form
509 $this->out->hidden('profileid-' . $this->profile->id,
512 $this->out->hidden('groupid-' . $this->group->id,
516 foreach ($this->args as $k => $v) {
517 $this->out->hidden('returnto-' . $k, $v);
528 function formActions()
532 // TRANS: Button text for the form that will make a user administrator.
533 _m('BUTTON','Make Admin'),
536 // TRANS: Submit button title.
537 _m('TOOLTIP','Make this user an admin'));