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 array('action' => 'groupmembers',
209 'nickname' => $this->group->nickname));
211 $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 array('action' => 'groupmembers',
223 'nickname' => $this->group->nickname));
225 $this->out->elementEnd('li');
232 * Form for blocking a user from a group
236 * @author Evan Prodromou <evan@status.net>
237 * @author Sarven Capadisli <csarven@status.net>
238 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
239 * @link http://status.net/
244 class GroupBlockForm extends Form
247 * Profile of user to block
253 * Group to block the user from
267 * @param HTMLOutputter $out output channel
268 * @param Profile $profile profile of user to block
269 * @param User_group $group group to block user from
270 * @param array $args return-to args
273 function __construct($out=null, $profile=null, $group=null, $args=null)
275 parent::__construct($out);
277 $this->profile = $profile;
278 $this->group = $group;
285 * @return int ID of the form
290 // This should be unique for the page.
291 return 'block-' . $this->profile->id;
297 * @return string class of the form
302 return 'form_group_block';
308 * @return string URL of the action
313 return common_local_url('groupblock');
321 function formLegend()
323 $this->out->element('legend', null, _('Block user from group'));
327 * Data elements of the form
334 $this->out->hidden('blockto-' . $this->profile->id,
337 $this->out->hidden('blockgroup-' . $this->group->id,
341 foreach ($this->args as $k => $v) {
342 $this->out->hidden('returnto-' . $k, $v);
353 function formActions()
355 $this->out->submit('submit', _('Block'), 'submit', null, _('Block this user'));
360 * Form for making a user an admin for a group
364 * @author Evan Prodromou <evan@status.net>
365 * @author Sarven Capadisli <csarven@status.net>
366 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
367 * @link http://status.net/
370 class MakeAdminForm extends Form
373 * Profile of user to block
379 * Group to block the user from
393 * @param HTMLOutputter $out output channel
394 * @param Profile $profile profile of user to block
395 * @param User_group $group group to block user from
396 * @param array $args return-to args
399 function __construct($out=null, $profile=null, $group=null, $args=null)
401 parent::__construct($out);
403 $this->profile = $profile;
404 $this->group = $group;
411 * @return int ID of the form
416 // This should be unique for the page.
417 return 'makeadmin-' . $this->profile->id;
423 * @return string class of the form
428 return 'form_make_admin';
434 * @return string URL of the action
439 return common_local_url('makeadmin', array('nickname' => $this->group->nickname));
448 function formLegend()
450 $this->out->element('legend', null, _('Make user an admin of the group'));
454 * Data elements of the form
461 $this->out->hidden('profileid-' . $this->profile->id,
464 $this->out->hidden('groupid-' . $this->group->id,
468 foreach ($this->args as $k => $v) {
469 $this->out->hidden('returnto-' . $k, $v);
480 function formActions()
482 $this->out->submit('submit', _('Make Admin'), 'submit', null, _('Make this user an admin'));