3 * StatusNet, the distributed open-source microblogging tool
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 Evan Prodromou <evan@status.net>
25 * @author Sarven Capadisli <csarven@status.net>
26 * @copyright 2008-2009 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
35 require_once INSTALLDIR.'/lib/noticelist.php';
36 require_once INSTALLDIR.'/lib/feedlist.php';
38 define('MEMBERS_PER_SECTION', 27);
45 * @author Evan Prodromou <evan@status.net>
46 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
47 * @link http://status.net/
49 class ShowgroupAction extends GroupDesignAction
51 /** page we're viewing. */
53 var $userProfile = null;
57 * Is this page read-only?
59 * @return boolean true
61 function isReadOnly($args)
69 * @return string page title, with page number
73 $base = $this->group->getFancyName();
75 if ($this->page == 1) {
76 // TRANS: Page title for first group page. %s is a group name.
77 return sprintf(_('%s group'), $base);
79 // TRANS: Page title for any but first group page.
80 // TRANS: %1$s is a group name, $2$s is a page number.
81 return sprintf(_('%1$s group, page %2$d'),
90 * Reads and validates arguments and instantiates the attributes.
92 * @param array $args $_REQUEST args
94 * @return boolean success flag
96 function prepare($args)
98 parent::prepare($args);
100 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
102 $nickname_arg = $this->arg('nickname');
103 $nickname = common_canonical_nickname($nickname_arg);
105 // Permanent redirect on non-canonical nickname
107 if ($nickname_arg != $nickname) {
108 $args = array('nickname' => $nickname);
109 if ($this->page != 1) {
110 $args['page'] = $this->page;
112 common_redirect(common_local_url('showgroup', $args), 301);
117 // TRANS: Client error displayed if no nickname argument was given requesting a group page.
118 $this->clientError(_('No nickname.'), 404);
122 $local = Local_group::staticGet('nickname', $nickname);
125 $alias = Group_alias::staticGet('alias', $nickname);
127 $args = array('id' => $alias->group_id);
128 if ($this->page != 1) {
129 $args['page'] = $this->page;
131 common_redirect(common_local_url('groupbyid', $args), 301);
134 common_log(LOG_NOTICE, "Couldn't find local group for nickname '$nickname'");
135 // TRANS: Client error displayed if no remote group with a given name was found requesting group page.
136 $this->clientError(_('No such group.'), 404);
141 $this->group = User_group::staticGet('id', $local->group_id);
144 // TRANS: Client error displayed if no local group with a given name was found requesting group page.
145 $this->clientError(_('No such group.'), 404);
149 $this->userProfile = Profile::current();
151 $stream = new GroupNoticeStream($this->group, $this->userProfile);
153 $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
154 NOTICES_PER_PAGE + 1);
156 common_set_returnto($this->selfUrl());
164 * Shows a profile for the group, some controls, and a list of
169 function handle($args)
179 function showObjectNav()
181 $nav = new GroupNav($this, $this->group);
186 * Show the page content
188 * Shows a group profile and a list of group notices
190 function showContent()
192 $this->showGroupNotices();
196 * Show the group notices
200 function showGroupNotices()
202 $nl = new ThreadedNoticeList($this->notice, $this, $this->userProfile);
205 $this->pagination($this->page > 1,
206 $cnt > NOTICES_PER_PAGE,
209 array('nickname' => $this->group->nickname));
213 * Get a list of the feeds for this page
220 common_local_url('grouprss',
221 array('nickname' => $this->group->nickname));
223 return array(new Feed(Feed::RSS1,
224 common_local_url('grouprss',
225 array('nickname' => $this->group->nickname)),
226 // TRANS: Tooltip for feed link. %s is a group nickname.
227 sprintf(_('Notice feed for %s group (RSS 1.0)'),
228 $this->group->nickname)),
230 common_local_url('ApiTimelineGroup',
231 array('format' => 'rss',
232 'id' => $this->group->id)),
233 // TRANS: Tooltip for feed link. %s is a group nickname.
234 sprintf(_('Notice feed for %s group (RSS 2.0)'),
235 $this->group->nickname)),
237 common_local_url('ApiTimelineGroup',
238 array('format' => 'atom',
239 'id' => $this->group->id)),
240 // TRANS: Tooltip for feed link. %s is a group nickname.
241 sprintf(_('Notice feed for %s group (Atom)'),
242 $this->group->nickname)),
244 common_local_url('foafgroup',
245 array('nickname' => $this->group->nickname)),
246 // TRANS: Tooltip for feed link. %s is a group nickname.
247 sprintf(_('FOAF for %s group'),
248 $this->group->nickname)));
252 * Fill in the sidebar.
256 function showSections()
258 $this->showMembers();
259 $this->showStatistics();
261 $cloud = new GroupTagCloudSection($this, $this->group);
266 * Show mini-list of members
270 function showMembers()
272 $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
278 $this->elementStart('div', array('id' => 'entity_members',
279 'class' => 'section'));
281 if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
283 // TRANS: Header for mini list of group members on a group page (h2).
284 $this->element('h2', null, _('Members'));
286 $gmml = new GroupMembersMiniList($member, $this);
287 $cnt = $gmml->show();
289 // TRANS: Description for mini list of group members on a group page when the group has no members.
290 $this->element('p', null, _('(None)'));
293 // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
294 // for example http://identi.ca/group/statusnet. Broken?
295 if ($cnt > MEMBERS_PER_SECTION) {
296 $this->element('a', array('href' => common_local_url('groupmembers',
297 array('nickname' => $this->group->nickname))),
298 // TRANS: Link to all group members from mini list of group members if group has more than n members.
302 Event::handle('EndShowGroupMembersMiniList', array($this));
305 $this->elementEnd('div');
309 * Show list of admins
313 function showAdmins()
315 $adminSection = new GroupAdminSection($this, $this->group);
316 $adminSection->show();
320 * Show some statistics
324 function showStatistics()
326 $this->elementStart('div', array('id' => 'entity_statistics',
327 'class' => 'section'));
329 // TRANS: Header for group statistics on a group page (h2).
330 $this->element('h2', null, _('Statistics'));
332 $this->elementStart('dl');
334 // TRANS: Label for group creation date.
335 $this->element('dt', null, _m('LABEL','Created'));
336 $this->element('dd', 'entity_created', date('j M Y',
337 strtotime($this->group->created)));
338 // @todo FIXME: i18n issue. This label gets a colon added from somewhere. Should be part of the message.
339 // TRANS: Label for member count in statistics on group page.
340 $this->element('dt', null, _m('LABEL','Members'));
341 $this->element('dd', null, $this->group->getMemberCount());
342 $this->elementEnd('dl');
344 $this->elementEnd('div');
347 function showAnonymousMessage()
349 if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
350 // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
351 // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept new registrations.
352 // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
353 // TRANS: %%%%action.register%%%% is the URL for registration, %%%%doc.help%%%% is a URL to help.
354 // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
355 $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
356 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
357 'short messages about their life and interests. '.
358 '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
359 $this->group->nickname);
361 // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
362 // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept no new registrations.
363 // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
364 // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
365 $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
366 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
367 'short messages about their life and interests. '),
368 $this->group->nickname);
370 $this->elementStart('div', array('id' => 'anon_notice'));
371 $this->raw(common_markup_to_html($m));
372 $this->elementEnd('div');
375 function noticeFormOptions()
377 $options = parent::noticeFormOptions();
378 $cur = common_current_user();
380 if (!empty($cur) && $cur->isMember($this->group)) {
381 $options['to_group'] = $this->group;
388 class GroupAdminSection extends ProfileSection
392 function __construct($out, $group)
394 parent::__construct($out);
395 $this->group = $group;
398 function getProfiles()
400 return $this->group->getAdmins();
405 // TRANS: Title for list of group administrators on a group page.
406 return _m('TITLE','Admins');
411 return 'group_admins';
420 class GroupMembersMiniList extends ProfileMiniList
422 function newListItem($profile)
424 return new GroupMembersMiniListItem($profile, $this->action);
428 class GroupMembersMiniListItem extends ProfileMiniListItem
430 function linkAttributes()
432 $aAttrs = parent::linkAttributes();
434 if (common_config('nofollow', 'members')) {
435 $aAttrs['rel'] .= ' nofollow';