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 $this->group = User_group::staticGet('nickname', $nickname);
83 $this->clientError(_('No such group.'), 404);
92 if ($this->page == 1) {
93 return sprintf(_('%s group members'),
94 $this->group->nickname);
96 return sprintf(_('%1$s group members, page %2$d'),
97 $this->group->nickname,
102 function handle($args)
104 parent::handle($args);
108 function showPageNotice()
110 $this->element('p', 'instructions',
111 _('A list of the users in this group.'));
114 function showLocalNav()
116 $nav = new GroupNav($this, $this->group);
120 function showContent()
122 $offset = ($this->page-1) * PROFILES_PER_PAGE;
123 $limit = PROFILES_PER_PAGE + 1;
127 $members = $this->group->getMembers($offset, $limit);
130 $member_list = new GroupMemberList($members, $this->group, $this);
131 $cnt = $member_list->show();
136 $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
137 $this->page, 'groupmembers',
138 array('nickname' => $this->group->nickname));
142 class GroupMemberList extends ProfileList
146 function __construct($profile, $group, $action)
148 parent::__construct($profile, $action);
150 $this->group = $group;
153 function newListItem($profile)
155 return new GroupMemberListItem($profile, $this->group, $this->action);
159 class GroupMemberListItem extends ProfileListItem
163 function __construct($profile, $group, $action)
165 parent::__construct($profile, $action);
167 $this->group = $group;
170 function showFullName()
172 parent::showFullName();
173 if ($this->profile->isAdmin($this->group)) {
174 $this->out->text(' ');
175 $this->out->element('span', 'role', _('Admin'));
179 function showActions()
181 $this->startActions();
182 if (Event::handle('StartProfileListItemActionElements', array($this))) {
183 $this->showSubscribeButton();
184 $this->showMakeAdminForm();
185 $this->showGroupBlockForm();
186 Event::handle('EndProfileListItemActionElements', array($this));
191 function showMakeAdminForm()
193 $user = common_current_user();
196 $user->id != $this->profile->id &&
197 ($user->isAdmin($this->group) || $user->hasRight(Right::MAKEGROUPADMIN)) &&
198 !$this->profile->isAdmin($this->group)) {
199 $this->out->elementStart('li', 'entity_make_admin');
200 $maf = new MakeAdminForm($this->out, $this->profile, $this->group,
201 array('action' => 'groupmembers',
202 'nickname' => $this->group->nickname));
204 $this->out->elementEnd('li');
208 function showGroupBlockForm()
210 $user = common_current_user();
212 if (!empty($user) && $user->id != $this->profile->id && $user->isAdmin($this->group)) {
213 $this->out->elementStart('li', 'entity_block');
214 $bf = new GroupBlockForm($this->out, $this->profile, $this->group,
215 array('action' => 'groupmembers',
216 'nickname' => $this->group->nickname));
218 $this->out->elementEnd('li');
225 * Form for blocking a user from a group
229 * @author Evan Prodromou <evan@status.net>
230 * @author Sarven Capadisli <csarven@status.net>
231 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
232 * @link http://status.net/
237 class GroupBlockForm extends Form
240 * Profile of user to block
246 * Group to block the user from
260 * @param HTMLOutputter $out output channel
261 * @param Profile $profile profile of user to block
262 * @param User_group $group group to block user from
263 * @param array $args return-to args
266 function __construct($out=null, $profile=null, $group=null, $args=null)
268 parent::__construct($out);
270 $this->profile = $profile;
271 $this->group = $group;
278 * @return int ID of the form
283 // This should be unique for the page.
284 return 'block-' . $this->profile->id;
290 * @return string class of the form
295 return 'form_group_block';
301 * @return string URL of the action
306 return common_local_url('groupblock');
314 function formLegend()
316 $this->out->element('legend', null, _('Block user from group'));
320 * Data elements of the form
327 $this->out->hidden('blockto-' . $this->profile->id,
330 $this->out->hidden('blockgroup-' . $this->group->id,
334 foreach ($this->args as $k => $v) {
335 $this->out->hidden('returnto-' . $k, $v);
346 function formActions()
348 $this->out->submit('submit', _('Block'), 'submit', null, _('Block this user'));
353 * Form for making a user an admin for a group
357 * @author Evan Prodromou <evan@status.net>
358 * @author Sarven Capadisli <csarven@status.net>
359 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
360 * @link http://status.net/
363 class MakeAdminForm extends Form
366 * Profile of user to block
372 * Group to block the user from
386 * @param HTMLOutputter $out output channel
387 * @param Profile $profile profile of user to block
388 * @param User_group $group group to block user from
389 * @param array $args return-to args
392 function __construct($out=null, $profile=null, $group=null, $args=null)
394 parent::__construct($out);
396 $this->profile = $profile;
397 $this->group = $group;
404 * @return int ID of the form
409 // This should be unique for the page.
410 return 'makeadmin-' . $this->profile->id;
416 * @return string class of the form
421 return 'form_make_admin';
427 * @return string URL of the action
432 return common_local_url('makeadmin', array('nickname' => $this->group->nickname));
441 function formLegend()
443 $this->out->element('legend', null, _('Make user an admin of the group'));
447 * Data elements of the form
454 $this->out->hidden('profileid-' . $this->profile->id,
457 $this->out->hidden('groupid-' . $this->group->id,
461 foreach ($this->args as $k => $v) {
462 $this->out->hidden('returnto-' . $k, $v);
473 function formActions()
475 $this->out->submit('submit', _('Make Admin'), 'submit', null, _('Make this user an admin'));