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/
45 class GroupAction extends Action
49 protected function prepare(array $args=array())
51 parent::prepare($args);
53 $nickname_arg = $this->arg('nickname');
54 $nickname = common_canonical_nickname($nickname_arg);
56 // Permanent redirect on non-canonical nickname
58 if ($nickname_arg != $nickname) {
59 $args = array('nickname' => $nickname);
60 if ($this->page != 1) {
61 $args['page'] = $this->page;
63 common_redirect(common_local_url('showgroup', $args), 301);
67 // TRANS: Client error displayed if no nickname argument was given requesting a group page.
68 $this->clientError(_('No nickname.'), 404);
71 $local = Local_group::getKV('nickname', $nickname);
74 $alias = Group_alias::getKV('alias', $nickname);
76 $args = array('id' => $alias->group_id);
77 if ($this->page != 1) {
78 $args['page'] = $this->page;
80 common_redirect(common_local_url('groupbyid', $args), 301);
82 common_log(LOG_NOTICE, "Couldn't find local group for nickname '$nickname'");
83 // TRANS: Client error displayed if no remote group with a given name was found requesting group page.
84 $this->clientError(_('No such group.'), 404);
88 $this->group = User_group::getKV('id', $local->group_id);
91 // TRANS: Client error displayed if no local group with a given name was found requesting group page.
92 $this->clientError(_('No such group.'), 404);
96 function showProfileBlock()
98 $block = new GroupProfileBlock($this, $this->group);
103 * Fill in the sidebar.
107 function showSections()
109 $this->showMembers();
110 $cur = common_current_user();
111 if ($cur && $cur->isAdmin($this->group)) {
112 $this->showPending();
113 $this->showBlocked();
118 if (!common_config('performance', 'high')) {
119 $cloud = new GroupTagCloudSection($this, $this->group);
125 * Show mini-list of members
129 function showMembers()
131 $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
137 $this->elementStart('div', array('id' => 'entity_members',
138 'class' => 'section'));
140 if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
141 $this->elementStart('h2');
143 $this->element('a', array('href' => common_local_url('groupmembers', array('nickname' =>
144 $this->group->nickname))),
145 // TRANS: Header for mini list of group members on a group page (h2).
150 $this->text($this->group->getMemberCount());
152 $this->elementEnd('h2');
154 $gmml = new GroupMembersMiniList($member, $this);
155 $cnt = $gmml->show();
157 // TRANS: Description for mini list of group members on a group page when the group has no members.
158 $this->element('p', null, _('(None)'));
161 // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
162 // for example http://identi.ca/group/statusnet. Broken?
163 if ($cnt > MEMBERS_PER_SECTION) {
164 $this->element('a', array('href' => common_local_url('groupmembers',
165 array('nickname' => $this->group->nickname))),
166 // TRANS: Link to all group members from mini list of group members if group has more than n members.
170 Event::handle('EndShowGroupMembersMiniList', array($this));
173 $this->elementEnd('div');
176 function showPending()
178 if ($this->group->join_policy != User_group::JOIN_POLICY_MODERATE) {
182 $pending = $this->group->getQueueCount();
188 $request = $this->group->getRequests(0, MEMBERS_PER_SECTION);
194 $this->elementStart('div', array('id' => 'entity_pending',
195 'class' => 'section'));
197 if (Event::handle('StartShowGroupPendingMiniList', array($this))) {
199 $this->elementStart('h2');
201 $this->element('a', array('href' => common_local_url('groupqueue', array('nickname' =>
202 $this->group->nickname))),
203 // TRANS: Header for mini list of users with a pending membership request on a group page (h2).
208 $this->text($pending);
210 $this->elementEnd('h2');
212 $gmml = new ProfileMiniList($request, $this);
215 Event::handle('EndShowGroupPendingMiniList', array($this));
218 $this->elementEnd('div');
221 function showBlocked()
223 $blocked = $this->group->getBlocked(0, MEMBERS_PER_SECTION);
225 $this->elementStart('div', array('id' => 'entity_blocked',
226 'class' => 'section'));
228 if (Event::handle('StartShowGroupBlockedMiniList', array($this))) {
230 $this->elementStart('h2');
232 $this->element('a', array('href' => common_local_url('blockedfromgroup', array('nickname' =>
233 $this->group->nickname))),
234 // TRANS: Header for mini list of users that are blocked in a group page (h2).
239 $this->text($this->group->getBlockedCount());
241 $this->elementEnd('h2');
243 $gmml = new GroupBlockedMiniList($blocked, $this);
244 $cnt = $gmml->show();
246 // TRANS: Description for mini list of group members on a group page when the group has no members.
247 $this->element('p', null, _('(None)'));
250 // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
251 // for example http://identi.ca/group/statusnet. Broken?
252 if ($cnt > MEMBERS_PER_SECTION) {
253 $this->element('a', array('href' => common_local_url('blockedfromgroup',
254 array('nickname' => $this->group->nickname))),
255 // TRANS: Link to all group members from mini list of group members if group has more than n members.
259 Event::handle('EndShowGroupBlockedMiniList', array($this));
262 $this->elementEnd('div');
266 * Show list of admins
270 function showAdmins()
272 $adminSection = new GroupAdminSection($this, $this->group);
273 $adminSection->show();
276 function noticeFormOptions()
278 $options = parent::noticeFormOptions();
279 $cur = common_current_user();
281 if (!empty($cur) && $cur->isMember($this->group)) {
282 $options['to_group'] = $this->group;
294 class GroupAdminSection extends ProfileSection
298 function __construct($out, $group)
300 parent::__construct($out);
301 $this->group = $group;
304 function getProfiles()
306 return $this->group->getAdmins();
311 // TRANS: Title for list of group administrators on a group page.
312 return _m('TITLE','Admins');
317 return 'group_admins';
326 class GroupMembersMiniList extends ProfileMiniList
328 function newListItem($profile)
330 return new GroupMembersMiniListItem($profile, $this->action);
334 class GroupMembersMiniListItem extends ProfileMiniListItem
336 function linkAttributes()
338 $aAttrs = parent::linkAttributes();
340 if (common_config('nofollow', 'members')) {
341 $aAttrs['rel'] .= ' nofollow';
348 class GroupBlockedMiniList extends ProfileMiniList
350 function newListItem($profile)
352 return new GroupBlockedMiniListItem($profile, $this->action);
356 class GroupBlockedMiniListItem extends ProfileMiniListItem
358 function linkAttributes()
360 $aAttrs = parent::linkAttributes();
362 if (common_config('nofollow', 'members')) {
363 $aAttrs['rel'] .= ' nofollow';
370 class ThreadingGroupNoticeStream extends ThreadingNoticeStream
372 function __construct($group, $profile)
374 parent::__construct(new GroupNoticeStream($group, $profile));