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 ShowstreamAction
47 protected function doPreparation()
49 $nickname_arg = $this->arg('nickname');
50 $nickname = common_canonical_nickname($nickname_arg);
52 // Permanent redirect on non-canonical nickname
54 if ($nickname_arg !== $nickname) {
55 $args = array('nickname' => $nickname);
56 if ($this->page != 1) {
57 $args['page'] = $this->page;
59 common_redirect(common_local_url($this->getActionName(), $args), 301);
63 // TRANS: Client error displayed if no nickname argument was given requesting a group page.
64 $this->clientError(_('No nickname.'), 404);
67 $local = Local_group::getKV('nickname', $nickname);
70 $alias = Group_alias::getKV('alias', $nickname);
72 $args = array('id' => $alias->group_id);
73 if ($this->page != 1) {
74 $args['page'] = $this->page;
76 common_redirect(common_local_url('groupbyid', $args), 301);
78 common_log(LOG_NOTICE, "Couldn't find local group for nickname '$nickname'");
79 // TRANS: Client error displayed if no remote group with a given name was found requesting group page.
80 throw new ClientException(_('No such group.'), 404);
84 $this->group = User_group::getKV('id', $local->group_id);
85 $this->target = $this->group->getProfile();
87 if (!$this->group instanceof User_group) {
88 // TRANS: Client error displayed if no local group with a given name was found requesting group page.
89 throw new ClientException(_('No such group.'), 404);
93 function showProfileBlock()
95 $block = new GroupProfileBlock($this, $this->group);
100 * Fill in the sidebar.
104 function showSections()
106 $this->showMembers();
107 if ($this->scoped instanceof Profile && $this->scoped->isAdmin($this->group)) {
108 $this->showPending();
109 $this->showBlocked();
116 * Show mini-list of members
120 function showMembers()
122 $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
128 $this->elementStart('div', array('id' => 'entity_members',
129 'class' => 'section'));
131 if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
132 $this->elementStart('h2');
134 $this->element('a', array('href' => common_local_url('groupmembers', array('nickname' =>
135 $this->group->nickname))),
136 // TRANS: Header for mini list of group members on a group page (h2).
141 $this->text($this->group->getMemberCount());
143 $this->elementEnd('h2');
145 $gmml = new GroupMembersMiniList($member, $this);
146 $cnt = $gmml->show();
148 // TRANS: Description for mini list of group members on a group page when the group has no members.
149 $this->element('p', null, _('(None)'));
152 // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
153 // for example http://identi.ca/group/statusnet. Broken?
154 if ($cnt > MEMBERS_PER_SECTION) {
155 $this->element('a', array('href' => common_local_url('groupmembers',
156 array('nickname' => $this->group->nickname))),
157 // TRANS: Link to all group members from mini list of group members if group has more than n members.
161 Event::handle('EndShowGroupMembersMiniList', array($this));
164 $this->elementEnd('div');
167 function showPending()
169 if ($this->group->join_policy != User_group::JOIN_POLICY_MODERATE) {
173 $pending = $this->group->getQueueCount();
179 $request = $this->group->getRequests(0, MEMBERS_PER_SECTION);
185 $this->elementStart('div', array('id' => 'entity_pending',
186 'class' => 'section'));
188 if (Event::handle('StartShowGroupPendingMiniList', array($this))) {
190 $this->elementStart('h2');
192 $this->element('a', array('href' => common_local_url('groupqueue', array('nickname' =>
193 $this->group->nickname))),
194 // TRANS: Header for mini list of users with a pending membership request on a group page (h2).
199 $this->text($pending);
201 $this->elementEnd('h2');
203 $gmml = new ProfileMiniList($request, $this);
206 Event::handle('EndShowGroupPendingMiniList', array($this));
209 $this->elementEnd('div');
212 function showBlocked()
214 $blocked = $this->group->getBlocked(0, MEMBERS_PER_SECTION);
216 $this->elementStart('div', array('id' => 'entity_blocked',
217 'class' => 'section'));
219 if (Event::handle('StartShowGroupBlockedMiniList', array($this))) {
221 $this->elementStart('h2');
223 $this->element('a', array('href' => common_local_url('blockedfromgroup', array('nickname' =>
224 $this->group->nickname))),
225 // TRANS: Header for mini list of users that are blocked in a group page (h2).
230 $this->text($this->group->getBlockedCount());
232 $this->elementEnd('h2');
234 $gmml = new GroupBlockedMiniList($blocked, $this);
235 $cnt = $gmml->show();
237 // TRANS: Description for mini list of group members on a group page when the group has no members.
238 $this->element('p', null, _('(None)'));
241 // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
242 // for example http://identi.ca/group/statusnet. Broken?
243 if ($cnt > MEMBERS_PER_SECTION) {
244 $this->element('a', array('href' => common_local_url('blockedfromgroup',
245 array('nickname' => $this->group->nickname))),
246 // TRANS: Link to all group members from mini list of group members if group has more than n members.
250 Event::handle('EndShowGroupBlockedMiniList', array($this));
253 $this->elementEnd('div');
257 * Show list of admins
261 function showAdmins()
263 $adminSection = new GroupAdminSection($this, $this->group);
264 $adminSection->show();
267 function noticeFormOptions()
269 $options = parent::noticeFormOptions();
270 $cur = common_current_user();
272 if (!empty($cur) && $cur->isMember($this->group)) {
273 $options['to_group'] = $this->group;