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 $cur = common_current_user();
151 $this->userProfile = (empty($cur)) ? null : $cur->getProfile();
153 $stream = new GroupNoticeStream($this->group, $this->userProfile);
155 $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
156 NOTICES_PER_PAGE + 1);
158 common_set_returnto($this->selfUrl());
166 * Shows a profile for the group, some controls, and a list of
171 function handle($args)
181 function showObjectNav()
183 $nav = new GroupNav($this, $this->group);
188 * Show the page content
190 * Shows a group profile and a list of group notices
192 function showContent()
194 $this->showGroupNotices();
198 * Show the group notices
202 function showGroupNotices()
204 $nl = new ThreadedNoticeList($notice, $this, $this->userProfile);
207 $this->pagination($this->page > 1,
208 $cnt > NOTICES_PER_PAGE,
211 array('nickname' => $this->group->nickname));
215 * Get a list of the feeds for this page
222 common_local_url('grouprss',
223 array('nickname' => $this->group->nickname));
225 return array(new Feed(Feed::RSS1,
226 common_local_url('grouprss',
227 array('nickname' => $this->group->nickname)),
228 // TRANS: Tooltip for feed link. %s is a group nickname.
229 sprintf(_('Notice feed for %s group (RSS 1.0)'),
230 $this->group->nickname)),
232 common_local_url('ApiTimelineGroup',
233 array('format' => 'rss',
234 'id' => $this->group->id)),
235 // TRANS: Tooltip for feed link. %s is a group nickname.
236 sprintf(_('Notice feed for %s group (RSS 2.0)'),
237 $this->group->nickname)),
239 common_local_url('ApiTimelineGroup',
240 array('format' => 'atom',
241 'id' => $this->group->id)),
242 // TRANS: Tooltip for feed link. %s is a group nickname.
243 sprintf(_('Notice feed for %s group (Atom)'),
244 $this->group->nickname)),
246 common_local_url('foafgroup',
247 array('nickname' => $this->group->nickname)),
248 // TRANS: Tooltip for feed link. %s is a group nickname.
249 sprintf(_('FOAF for %s group'),
250 $this->group->nickname)));
254 * Fill in the sidebar.
258 function showSections()
260 $this->showMembers();
261 $this->showStatistics();
263 $cloud = new GroupTagCloudSection($this, $this->group);
268 * Show mini-list of members
272 function showMembers()
274 $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
280 $this->elementStart('div', array('id' => 'entity_members',
281 'class' => 'section'));
283 if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
285 // TRANS: Header for mini list of group members on a group page (h2).
286 $this->element('h2', null, _('Members'));
288 $gmml = new GroupMembersMiniList($member, $this);
289 $cnt = $gmml->show();
291 // TRANS: Description for mini list of group members on a group page when the group has no members.
292 $this->element('p', null, _('(None)'));
295 // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
296 // for example http://identi.ca/group/statusnet. Broken?
297 if ($cnt > MEMBERS_PER_SECTION) {
298 $this->element('a', array('href' => common_local_url('groupmembers',
299 array('nickname' => $this->group->nickname))),
300 // TRANS: Link to all group members from mini list of group members if group has more than n members.
304 Event::handle('EndShowGroupMembersMiniList', array($this));
307 $this->elementEnd('div');
311 * Show list of admins
315 function showAdmins()
317 $adminSection = new GroupAdminSection($this, $this->group);
318 $adminSection->show();
322 * Show some statistics
326 function showStatistics()
328 $this->elementStart('div', array('id' => 'entity_statistics',
329 'class' => 'section'));
331 // TRANS: Header for group statistics on a group page (h2).
332 $this->element('h2', null, _('Statistics'));
334 $this->elementStart('dl');
336 // TRANS: Label for group creation date.
337 $this->element('dt', null, _m('LABEL','Created'));
338 $this->element('dd', 'entity_created', date('j M Y',
339 strtotime($this->group->created)));
340 // @todo FIXME: i18n issue. This label gets a colon added from somewhere. Should be part of the message.
341 // TRANS: Label for member count in statistics on group page.
342 $this->element('dt', null, _m('LABEL','Members'));
343 $this->element('dd', null, $this->group->getMemberCount());
344 $this->elementEnd('dl');
346 $this->elementEnd('div');
349 function showAnonymousMessage()
351 if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
352 // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
353 // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept new registrations.
354 // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
355 // TRANS: %%%%action.register%%%% is the URL for registration, %%%%doc.help%%%% is a URL to help.
356 // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
357 $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
358 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
359 'short messages about their life and interests. '.
360 '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
361 $this->group->nickname);
363 // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
364 // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept no new registrations.
365 // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
366 // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
367 $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
368 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
369 'short messages about their life and interests. '),
370 $this->group->nickname);
372 $this->elementStart('div', array('id' => 'anon_notice'));
373 $this->raw(common_markup_to_html($m));
374 $this->elementEnd('div');
377 function noticeFormOptions()
379 $options = parent::noticeFormOptions();
380 $cur = common_current_user();
382 if (!empty($cur) && $cur->isMember($this->group)) {
383 $options['to_group'] = $this->group;
390 class GroupAdminSection extends ProfileSection
394 function __construct($out, $group)
396 parent::__construct($out);
397 $this->group = $group;
400 function getProfiles()
402 return $this->group->getAdmins();
407 // TRANS: Title for list of group administrators on a group page.
408 return _m('TITLE','Admins');
413 return 'group_admins';
422 class GroupMembersMiniList extends ProfileMiniList
424 function newListItem($profile)
426 return new GroupMembersMiniListItem($profile, $this->action);
430 class GroupMembersMiniListItem extends ProfileMiniListItem
432 function linkAttributes()
434 $aAttrs = parent::linkAttributes();
436 if (common_config('nofollow', 'members')) {
437 $aAttrs['rel'] .= ' nofollow';