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('GNUSOCIAL')) { exit(1); }
32 define('MEMBERS_PER_SECTION', 27);
35 * Base class for group actions, similar to ProfileAction
39 * @author Zach Copley <zach@status.net>
40 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41 * @link http://status.net/
43 class GroupAction extends Action
47 protected function prepare(array $args=array())
49 parent::prepare($args);
51 $nickname_arg = $this->arg('nickname');
52 $nickname = common_canonical_nickname($nickname_arg);
54 // Permanent redirect on non-canonical nickname
56 if ($nickname_arg != $nickname) {
57 $args = array('nickname' => $nickname);
58 if ($this->page != 1) {
59 $args['page'] = $this->page;
61 common_redirect(common_local_url('showgroup', $args), 301);
65 // TRANS: Client error displayed if no nickname argument was given requesting a group page.
66 $this->clientError(_('No nickname.'), 404);
69 $local = Local_group::getKV('nickname', $nickname);
72 $alias = Group_alias::getKV('alias', $nickname);
74 $args = array('id' => $alias->group_id);
75 if ($this->page != 1) {
76 $args['page'] = $this->page;
78 common_redirect(common_local_url('groupbyid', $args), 301);
80 common_log(LOG_NOTICE, "Couldn't find local group for nickname '$nickname'");
81 // TRANS: Client error displayed if no remote group with a given name was found requesting group page.
82 $this->clientError(_('No such group.'), 404);
86 $this->group = User_group::getKV('id', $local->group_id);
88 if (!$this->group instanceof User_group) {
89 // TRANS: Client error displayed if no local group with a given name was found requesting group page.
90 $this->clientError(_('No such group.'), 404);
94 function showProfileBlock()
96 $block = new GroupProfileBlock($this, $this->group);
101 * Fill in the sidebar.
105 function showSections()
107 $this->showMembers();
108 $cur = common_current_user();
109 if ($cur && $cur->isAdmin($this->group)) {
110 $this->showPending();
111 $this->showBlocked();
116 if (!common_config('performance', 'high')) {
117 $cloud = new GroupTagCloudSection($this, $this->group);
123 * Show mini-list of members
127 function showMembers()
129 $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
135 $this->elementStart('div', array('id' => 'entity_members',
136 'class' => 'section'));
138 if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
139 $this->elementStart('h2');
141 $this->element('a', array('href' => common_local_url('groupmembers', array('nickname' =>
142 $this->group->nickname))),
143 // TRANS: Header for mini list of group members on a group page (h2).
148 $this->text($this->group->getMemberCount());
150 $this->elementEnd('h2');
152 $gmml = new GroupMembersMiniList($member, $this);
153 $cnt = $gmml->show();
155 // TRANS: Description for mini list of group members on a group page when the group has no members.
156 $this->element('p', null, _('(None)'));
159 // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
160 // for example http://identi.ca/group/statusnet. Broken?
161 if ($cnt > MEMBERS_PER_SECTION) {
162 $this->element('a', array('href' => common_local_url('groupmembers',
163 array('nickname' => $this->group->nickname))),
164 // TRANS: Link to all group members from mini list of group members if group has more than n members.
168 Event::handle('EndShowGroupMembersMiniList', array($this));
171 $this->elementEnd('div');
174 function showPending()
176 if ($this->group->join_policy != User_group::JOIN_POLICY_MODERATE) {
180 $pending = $this->group->getQueueCount();
186 $request = $this->group->getRequests(0, MEMBERS_PER_SECTION);
192 $this->elementStart('div', array('id' => 'entity_pending',
193 'class' => 'section'));
195 if (Event::handle('StartShowGroupPendingMiniList', array($this))) {
197 $this->elementStart('h2');
199 $this->element('a', array('href' => common_local_url('groupqueue', array('nickname' =>
200 $this->group->nickname))),
201 // TRANS: Header for mini list of users with a pending membership request on a group page (h2).
206 $this->text($pending);
208 $this->elementEnd('h2');
210 $gmml = new ProfileMiniList($request, $this);
213 Event::handle('EndShowGroupPendingMiniList', array($this));
216 $this->elementEnd('div');
219 function showBlocked()
221 $blocked = $this->group->getBlocked(0, MEMBERS_PER_SECTION);
223 $this->elementStart('div', array('id' => 'entity_blocked',
224 'class' => 'section'));
226 if (Event::handle('StartShowGroupBlockedMiniList', array($this))) {
228 $this->elementStart('h2');
230 $this->element('a', array('href' => common_local_url('blockedfromgroup', array('nickname' =>
231 $this->group->nickname))),
232 // TRANS: Header for mini list of users that are blocked in a group page (h2).
237 $this->text($this->group->getBlockedCount());
239 $this->elementEnd('h2');
241 $gmml = new GroupBlockedMiniList($blocked, $this);
242 $cnt = $gmml->show();
244 // TRANS: Description for mini list of group members on a group page when the group has no members.
245 $this->element('p', null, _('(None)'));
248 // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
249 // for example http://identi.ca/group/statusnet. Broken?
250 if ($cnt > MEMBERS_PER_SECTION) {
251 $this->element('a', array('href' => common_local_url('blockedfromgroup',
252 array('nickname' => $this->group->nickname))),
253 // TRANS: Link to all group members from mini list of group members if group has more than n members.
257 Event::handle('EndShowGroupBlockedMiniList', array($this));
260 $this->elementEnd('div');
264 * Show list of admins
268 function showAdmins()
270 $adminSection = new GroupAdminSection($this, $this->group);
271 $adminSection->show();
274 function noticeFormOptions()
276 $options = parent::noticeFormOptions();
277 $cur = common_current_user();
279 if (!empty($cur) && $cur->isMember($this->group)) {
280 $options['to_group'] = $this->group;