3 * StatusNet, the distributed open-source microblogging tool
5 * Base class for group actions
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 Zach Copley <zach@status.net>
25 * @copyright 2009-2011 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 define('MEMBERS_PER_SECTION', 27);
37 * Base class for group actions, similar to ProfileAction
41 * @author Zach Copley <zach@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43 * @link http://status.net/
46 class GroupAction extends Action
50 function prepare($args)
52 parent::prepare($args);
54 $nickname_arg = $this->arg('nickname');
55 $nickname = common_canonical_nickname($nickname_arg);
57 // Permanent redirect on non-canonical nickname
59 if ($nickname_arg != $nickname) {
60 $args = array('nickname' => $nickname);
61 if ($this->page != 1) {
62 $args['page'] = $this->page;
64 common_redirect(common_local_url('showgroup', $args), 301);
69 // TRANS: Client error displayed if no nickname argument was given requesting a group page.
70 $this->clientError(_('No nickname.'), 404);
74 $local = Local_group::staticGet('nickname', $nickname);
77 $alias = Group_alias::staticGet('alias', $nickname);
79 $args = array('id' => $alias->group_id);
80 if ($this->page != 1) {
81 $args['page'] = $this->page;
83 common_redirect(common_local_url('groupbyid', $args), 301);
86 common_log(LOG_NOTICE, "Couldn't find local group for nickname '$nickname'");
87 // TRANS: Client error displayed if no remote group with a given name was found requesting group page.
88 $this->clientError(_('No such group.'), 404);
93 $this->group = User_group::staticGet('id', $local->group_id);
96 // TRANS: Client error displayed if no local group with a given name was found requesting group page.
97 $this->clientError(_('No such group.'), 404);
102 function showProfileBlock()
104 $block = new GroupProfileBlock($this, $this->group);
109 * Fill in the sidebar.
113 function showSections()
115 $this->showMembers();
116 $cur = common_current_user();
117 if ($cur && $cur->isAdmin($this->group)) {
118 $this->showPending();
119 $this->showBlocked();
122 $cloud = new GroupTagCloudSection($this, $this->group);
127 * Show mini-list of members
131 function showMembers()
133 $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
139 $this->elementStart('div', array('id' => 'entity_members',
140 'class' => 'section'));
142 if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
144 // TRANS: Header for mini list of group members on a group page (h2).
145 $this->elementStart('h2');
147 $this->element('a', array('href' => common_local_url('groupmembers', array('nickname' =>
148 $this->group->nickname))),
153 $this->text($this->group->getMemberCount());
155 $this->elementEnd('h2');
157 $gmml = new GroupMembersMiniList($member, $this);
158 $cnt = $gmml->show();
160 // TRANS: Description for mini list of group members on a group page when the group has no members.
161 $this->element('p', null, _('(None)'));
164 // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
165 // for example http://identi.ca/group/statusnet. Broken?
166 if ($cnt > MEMBERS_PER_SECTION) {
167 $this->element('a', array('href' => common_local_url('groupmembers',
168 array('nickname' => $this->group->nickname))),
169 // TRANS: Link to all group members from mini list of group members if group has more than n members.
173 Event::handle('EndShowGroupMembersMiniList', array($this));
176 $this->elementEnd('div');
180 function showPending()
182 if ($this->group->join_policy != User_group::JOIN_POLICY_MODERATE) {
186 $pending = $this->group->getQueueCount();
192 $request = $this->group->getRequests(0, MEMBERS_PER_SECTION);
198 $this->elementStart('div', array('id' => 'entity_pending',
199 'class' => 'section'));
201 if (Event::handle('StartShowGroupPendingMiniList', array($this))) {
203 $this->elementStart('h2');
205 $this->element('a', array('href' => common_local_url('groupqueue', array('nickname' =>
206 $this->group->nickname))),
211 $this->text($pending);
213 $this->elementEnd('h2');
215 $gmml = new ProfileMiniList($request, $this);
218 Event::handle('EndShowGroupPendingMiniList', array($this));
221 $this->elementEnd('div');
224 function showBlocked()
226 $blocked = $this->group->getBlocked(0, MEMBERS_PER_SECTION);
232 $this->elementStart('div', array('id' => 'entity_blocked',
233 'class' => 'section'));
235 if (Event::handle('StartShowGroupBlockedMiniList', array($this))) {
237 $this->elementStart('h2');
239 $this->element('a', array('href' => common_local_url('blockedfromgroup', array('nickname' =>
240 $this->group->nickname))),
245 $this->text($this->group->getBlockedCount());
247 $this->elementEnd('h2');
249 $gmml = new GroupBlockedMiniList($blocked, $this);
250 $cnt = $gmml->show();
252 // TRANS: Description for mini list of group members on a group page when the group has no members.
253 $this->element('p', null, _('(None)'));
256 // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
257 // for example http://identi.ca/group/statusnet. Broken?
258 if ($cnt > MEMBERS_PER_SECTION) {
259 $this->element('a', array('href' => common_local_url('blockedfromgroup',
260 array('nickname' => $this->group->nickname))),
261 // TRANS: Link to all group members from mini list of group members if group has more than n members.
265 Event::handle('EndShowGroupBlockedMiniList', array($this));
268 $this->elementEnd('div');
272 * Show list of admins
276 function showAdmins()
278 $adminSection = new GroupAdminSection($this, $this->group);
279 $adminSection->show();
283 function noticeFormOptions()
285 $options = parent::noticeFormOptions();
286 $cur = common_current_user();
288 if (!empty($cur) && $cur->isMember($this->group)) {
289 $options['to_group'] = $this->group;
296 class GroupAdminSection extends ProfileSection
300 function __construct($out, $group)
302 parent::__construct($out);
303 $this->group = $group;
306 function getProfiles()
308 return $this->group->getAdmins();
313 // TRANS: Title for list of group administrators on a group page.
314 return _m('TITLE','Admins');
319 return 'group_admins';
328 class GroupMembersMiniList extends ProfileMiniList
330 function newListItem($profile)
332 return new GroupMembersMiniListItem($profile, $this->action);
336 class GroupMembersMiniListItem extends ProfileMiniListItem
338 function linkAttributes()
340 $aAttrs = parent::linkAttributes();
342 if (common_config('nofollow', 'members')) {
343 $aAttrs['rel'] .= ' nofollow';
350 class GroupBlockedMiniList extends ProfileMiniList
352 function newListItem($profile)
354 return new GroupBlockedMiniListItem($profile, $this->action);
358 class GroupBlockedMiniListItem extends ProfileMiniListItem
360 function linkAttributes()
362 $aAttrs = parent::linkAttributes();
364 if (common_config('nofollow', 'members')) {
365 $aAttrs['rel'] .= ' nofollow';
372 class ThreadingGroupNoticeStream extends ThreadingNoticeStream
374 function __construct($group, $profile)
376 parent::__construct(new GroupNoticeStream($group, $profile));