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 return sprintf(_('%s group members'),
101 $this->group->nickname);
103 return sprintf(_('%1$s group members, page %2$d'),
104 $this->group->nickname,
109 function handle($args)
111 parent::handle($args);
115 function showPageNotice()
117 $this->element('p', 'instructions',
118 _('A list of the users in this group.'));
121 function showLocalNav()
123 $nav = new GroupNav($this, $this->group);
127 function showContent()
129 $offset = ($this->page-1) * PROFILES_PER_PAGE;
130 $limit = PROFILES_PER_PAGE + 1;
134 $members = $this->group->getMembers($offset, $limit);
137 $member_list = new GroupMemberList($members, $this->group, $this);
138 $cnt = $member_list->show();
143 $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
144 $this->page, 'groupmembers',
145 array('nickname' => $this->group->nickname));
149 class GroupMemberList extends ProfileList
153 function __construct($profile, $group, $action)
155 parent::__construct($profile, $action);
157 $this->group = $group;
160 function newListItem($profile)
162 return new GroupMemberListItem($profile, $this->group, $this->action);
166 class GroupMemberListItem extends ProfileListItem
170 function __construct($profile, $group, $action)
172 parent::__construct($profile, $action);
174 $this->group = $group;
177 function showFullName()
179 parent::showFullName();
180 if ($this->profile->isAdmin($this->group)) {
181 $this->out->text(' ');
182 $this->out->element('span', 'role', _('Admin'));
186 function showActions()
188 $this->startActions();
189 if (Event::handle('StartProfileListItemActionElements', array($this))) {
190 $this->showSubscribeButton();
191 $this->showMakeAdminForm();
192 $this->showGroupBlockForm();
193 Event::handle('EndProfileListItemActionElements', array($this));
198 function showMakeAdminForm()
200 $user = common_current_user();
203 $user->id != $this->profile->id &&
204 ($user->isAdmin($this->group) || $user->hasRight(Right::MAKEGROUPADMIN)) &&
205 !$this->profile->isAdmin($this->group)) {
206 $this->out->elementStart('li', 'entity_make_admin');
207 $maf = new MakeAdminForm($this->out, $this->profile, $this->group,
208 $this->returnToArgs());
210 $this->out->elementEnd('li');
215 function showGroupBlockForm()
217 $user = common_current_user();
219 if (!empty($user) && $user->id != $this->profile->id && $user->isAdmin($this->group)) {
220 $this->out->elementStart('li', 'entity_block');
221 $bf = new GroupBlockForm($this->out, $this->profile, $this->group,
222 $this->returnToArgs());
224 $this->out->elementEnd('li');
228 function linkAttributes()
230 $aAttrs = parent::linkAttributes();
232 if (common_config('nofollow', 'members')) {
233 $aAttrs['rel'] .= ' nofollow';
239 function homepageAttributes()
241 $aAttrs = parent::linkAttributes();
243 if (common_config('nofollow', 'members')) {
244 $aAttrs['rel'] = 'nofollow';
251 * Fetch necessary return-to arguments for the profile forms
252 * to return to this list when they're done.
256 protected function returnToArgs()
258 $args = array('action' => 'groupmembers',
259 'nickname' => $this->group->nickname);
260 $page = $this->out->arg('page');
262 $args['param-page'] = $page;
269 * Form for blocking a user from a group
273 * @author Evan Prodromou <evan@status.net>
274 * @author Sarven Capadisli <csarven@status.net>
275 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
276 * @link http://status.net/
281 class GroupBlockForm extends Form
284 * Profile of user to block
290 * Group to block the user from
304 * @param HTMLOutputter $out output channel
305 * @param Profile $profile profile of user to block
306 * @param User_group $group group to block user from
307 * @param array $args return-to args
310 function __construct($out=null, $profile=null, $group=null, $args=null)
312 parent::__construct($out);
314 $this->profile = $profile;
315 $this->group = $group;
322 * @return int ID of the form
327 // This should be unique for the page.
328 return 'block-' . $this->profile->id;
334 * @return string class of the form
339 return 'form_group_block';
345 * @return string URL of the action
350 return common_local_url('groupblock');
358 function formLegend()
360 $this->out->element('legend', null, _('Block user from group'));
364 * Data elements of the form
371 $this->out->hidden('blockto-' . $this->profile->id,
374 $this->out->hidden('blockgroup-' . $this->group->id,
378 foreach ($this->args as $k => $v) {
379 $this->out->hidden('returnto-' . $k, $v);
390 function formActions()
392 $this->out->submit('submit', _('Block'), 'submit', null, _('Block this user'));
397 * Form for making a user an admin for a group
401 * @author Evan Prodromou <evan@status.net>
402 * @author Sarven Capadisli <csarven@status.net>
403 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
404 * @link http://status.net/
407 class MakeAdminForm extends Form
410 * Profile of user to block
416 * Group to block the user from
430 * @param HTMLOutputter $out output channel
431 * @param Profile $profile profile of user to block
432 * @param User_group $group group to block user from
433 * @param array $args return-to args
436 function __construct($out=null, $profile=null, $group=null, $args=null)
438 parent::__construct($out);
440 $this->profile = $profile;
441 $this->group = $group;
448 * @return int ID of the form
453 // This should be unique for the page.
454 return 'makeadmin-' . $this->profile->id;
460 * @return string class of the form
465 return 'form_make_admin';
471 * @return string URL of the action
476 return common_local_url('makeadmin', array('nickname' => $this->group->nickname));
485 function formLegend()
487 $this->out->element('legend', null, _('Make user an admin of the group'));
491 * 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);
517 function formActions()
519 $this->out->submit('submit', _('Make Admin'), 'submit', null, _('Make this user an admin'));