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-2011 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 Action
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 ThreadingGroupNoticeStream($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::JSON,
224 common_local_url('ApiTimelineGroup',
225 array('format' => 'as',
226 'id' => $this->group->id)),
227 // TRANS: Tooltip for feed link. %s is a group nickname.
228 sprintf(_('Notice feed for %s group (Activity Streams JSON)'),
229 $this->group->nickname)),
231 common_local_url('grouprss',
232 array('nickname' => $this->group->nickname)),
233 // TRANS: Tooltip for feed link. %s is a group nickname.
234 sprintf(_('Notice feed for %s group (RSS 1.0)'),
235 $this->group->nickname)),
237 common_local_url('ApiTimelineGroup',
238 array('format' => 'rss',
239 'id' => $this->group->id)),
240 // TRANS: Tooltip for feed link. %s is a group nickname.
241 sprintf(_('Notice feed for %s group (RSS 2.0)'),
242 $this->group->nickname)),
244 common_local_url('ApiTimelineGroup',
245 array('format' => 'atom',
246 'id' => $this->group->id)),
247 // TRANS: Tooltip for feed link. %s is a group nickname.
248 sprintf(_('Notice feed for %s group (Atom)'),
249 $this->group->nickname)),
251 common_local_url('foafgroup',
252 array('nickname' => $this->group->nickname)),
253 // TRANS: Tooltip for feed link. %s is a group nickname.
254 sprintf(_('FOAF for %s group'),
255 $this->group->nickname)));
259 * Fill in the sidebar.
263 function showSections()
265 $this->showMembers();
266 $this->showStatistics();
268 $cloud = new GroupTagCloudSection($this, $this->group);
273 * Show mini-list of members
277 function showMembers()
279 $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
285 $this->elementStart('div', array('id' => 'entity_members',
286 'class' => 'section'));
288 if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
290 // TRANS: Header for mini list of group members on a group page (h2).
291 $this->element('h2', null, _('Members'));
293 $gmml = new GroupMembersMiniList($member, $this);
294 $cnt = $gmml->show();
296 // TRANS: Description for mini list of group members on a group page when the group has no members.
297 $this->element('p', null, _('(None)'));
300 // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
301 // for example http://identi.ca/group/statusnet. Broken?
302 if ($cnt > MEMBERS_PER_SECTION) {
303 $this->element('a', array('href' => common_local_url('groupmembers',
304 array('nickname' => $this->group->nickname))),
305 // TRANS: Link to all group members from mini list of group members if group has more than n members.
309 Event::handle('EndShowGroupMembersMiniList', array($this));
312 $this->elementEnd('div');
316 * Show list of admins
320 function showAdmins()
322 $adminSection = new GroupAdminSection($this, $this->group);
323 $adminSection->show();
327 * Show some statistics
331 function showStatistics()
333 $this->elementStart('div', array('id' => 'entity_statistics',
334 'class' => 'section'));
336 // TRANS: Header for group statistics on a group page (h2).
337 $this->element('h2', null, _('Statistics'));
339 $this->elementStart('dl');
341 // TRANS: Label for group creation date.
342 $this->element('dt', null, _m('LABEL','Created'));
343 $this->element('dd', 'entity_created', date('j M Y',
344 strtotime($this->group->created)));
345 // @todo FIXME: i18n issue. This label gets a colon added from somewhere. Should be part of the message.
346 // TRANS: Label for member count in statistics on group page.
347 $this->element('dt', null, _m('LABEL','Members'));
348 $this->element('dd', null, $this->group->getMemberCount());
349 $this->elementEnd('dl');
351 $this->elementEnd('div');
354 function showAnonymousMessage()
356 if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
357 // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
358 // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept new registrations.
359 // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
360 // TRANS: %%%%action.register%%%% is the URL for registration, %%%%doc.help%%%% is a URL to help.
361 // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
362 $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
363 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
364 'short messages about their life and interests. '.
365 '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
366 $this->group->nickname);
368 // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
369 // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept no new registrations.
370 // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
371 // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
372 $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
373 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
374 'short messages about their life and interests. '),
375 $this->group->nickname);
377 $this->elementStart('div', array('id' => 'anon_notice'));
378 $this->raw(common_markup_to_html($m));
379 $this->elementEnd('div');
382 function noticeFormOptions()
384 $options = parent::noticeFormOptions();
385 $cur = common_current_user();
387 if (!empty($cur) && $cur->isMember($this->group)) {
388 $options['to_group'] = $this->group;
395 class GroupAdminSection extends ProfileSection
399 function __construct($out, $group)
401 parent::__construct($out);
402 $this->group = $group;
405 function getProfiles()
407 return $this->group->getAdmins();
412 // TRANS: Title for list of group administrators on a group page.
413 return _m('TITLE','Admins');
418 return 'group_admins';
427 class GroupMembersMiniList extends ProfileMiniList
429 function newListItem($profile)
431 return new GroupMembersMiniListItem($profile, $this->action);
435 class GroupMembersMiniListItem extends ProfileMiniListItem
437 function linkAttributes()
439 $aAttrs = parent::linkAttributes();
441 if (common_config('nofollow', 'members')) {
442 $aAttrs['rel'] .= ' nofollow';
449 class ThreadingGroupNoticeStream extends ThreadingNoticeStream
451 function __construct($group, $profile)
453 parent::__construct(new GroupNoticeStream($group, $profile));