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);
114 function showObjectNav()
116 $nav = new GroupNav($this, $this->group);
122 * Fill in the sidebar.
126 function showSections()
128 $this->showMembers();
129 $this->showStatistics();
131 $cloud = new GroupTagCloudSection($this, $this->group);
136 * Show mini-list of members
140 function showMembers()
142 $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
148 $this->elementStart('div', array('id' => 'entity_members',
149 'class' => 'section'));
151 if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
153 // TRANS: Header for mini list of group members on a group page (h2).
154 $this->element('h2', null, _('Members'));
156 $gmml = new GroupMembersMiniList($member, $this);
157 $cnt = $gmml->show();
159 // TRANS: Description for mini list of group members on a group page when the group has no members.
160 $this->element('p', null, _('(None)'));
163 // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
164 // for example http://identi.ca/group/statusnet. Broken?
165 if ($cnt > MEMBERS_PER_SECTION) {
166 $this->element('a', array('href' => common_local_url('groupmembers',
167 array('nickname' => $this->group->nickname))),
168 // TRANS: Link to all group members from mini list of group members if group has more than n members.
172 Event::handle('EndShowGroupMembersMiniList', array($this));
175 $this->elementEnd('div');
179 * Show list of admins
183 function showAdmins()
185 $adminSection = new GroupAdminSection($this, $this->group);
186 $adminSection->show();
190 * Show some statistics
194 function showStatistics()
196 $this->elementStart('div', array('id' => 'entity_statistics',
197 'class' => 'section'));
199 // TRANS: Header for group statistics on a group page (h2).
200 $this->element('h2', null, _('Statistics'));
202 $this->elementStart('dl');
204 // TRANS: Label for group creation date.
205 $this->element('dt', null, _m('LABEL','Created'));
206 $this->element('dd', 'entity_created', date('j M Y',
207 strtotime($this->group->created)));
208 // @todo FIXME: i18n issue. This label gets a colon added from somewhere. Should be part of the message.
209 // TRANS: Label for member count in statistics on group page.
210 $this->element('dt', null, _m('LABEL','Members'));
211 $this->element('dd', null, $this->group->getMemberCount());
212 $this->elementEnd('dl');
214 $this->elementEnd('div');
218 function noticeFormOptions()
220 $options = parent::noticeFormOptions();
221 $cur = common_current_user();
223 if (!empty($cur) && $cur->isMember($this->group)) {
224 $options['to_group'] = $this->group;
231 class GroupAdminSection extends ProfileSection
235 function __construct($out, $group)
237 parent::__construct($out);
238 $this->group = $group;
241 function getProfiles()
243 return $this->group->getAdmins();
248 // TRANS: Title for list of group administrators on a group page.
249 return _m('TITLE','Admins');
254 return 'group_admins';
263 class GroupMembersMiniList extends ProfileMiniList
265 function newListItem($profile)
267 return new GroupMembersMiniListItem($profile, $this->action);
271 class GroupMembersMiniListItem extends ProfileMiniListItem
273 function linkAttributes()
275 $aAttrs = parent::linkAttributes();
277 if (common_config('nofollow', 'members')) {
278 $aAttrs['rel'] .= ' nofollow';
285 class ThreadingGroupNoticeStream extends ThreadingNoticeStream
287 function __construct($group, $profile)
289 parent::__construct(new GroupNoticeStream($group, $profile));