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. */
55 * Is this page read-only?
57 * @return boolean true
59 function isReadOnly($args)
67 * @return string page title, with page number
71 $base = $this->group->getFancyName();
73 if ($this->page == 1) {
74 // TRANS: Page title for first group page. %s is a group name.
75 return sprintf(_('%s group'), $base);
77 // TRANS: Page title for any but first group page.
78 // TRANS: %1$s is a group name, $2$s is a page number.
79 return sprintf(_('%1$s group, page %2$d'),
88 * Reads and validates arguments and instantiates the attributes.
90 * @param array $args $_REQUEST args
92 * @return boolean success flag
94 function prepare($args)
96 parent::prepare($args);
98 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
100 $nickname_arg = $this->arg('nickname');
101 $nickname = common_canonical_nickname($nickname_arg);
103 // Permanent redirect on non-canonical nickname
105 if ($nickname_arg != $nickname) {
106 $args = array('nickname' => $nickname);
107 if ($this->page != 1) {
108 $args['page'] = $this->page;
110 common_redirect(common_local_url('showgroup', $args), 301);
115 // TRANS: Client error displayed if no nickname argument was given requesting a group page.
116 $this->clientError(_('No nickname.'), 404);
120 $local = Local_group::staticGet('nickname', $nickname);
123 $alias = Group_alias::staticGet('alias', $nickname);
125 $args = array('id' => $alias->group_id);
126 if ($this->page != 1) {
127 $args['page'] = $this->page;
129 common_redirect(common_local_url('groupbyid', $args), 301);
132 common_log(LOG_NOTICE, "Couldn't find local group for nickname '$nickname'");
133 // TRANS: Client error displayed if no remote group with a given name was found requesting group page.
134 $this->clientError(_('No such group.'), 404);
139 $this->group = User_group::staticGet('id', $local->group_id);
142 // TRANS: Client error displayed if no local group with a given name was found requesting group page.
143 $this->clientError(_('No such group.'), 404);
147 common_set_returnto($this->selfUrl());
155 * Shows a profile for the group, some controls, and a list of
160 function handle($args)
170 function showObjectNav()
172 $nav = new GroupNav($this, $this->group);
177 * Show the page content
179 * Shows a group profile and a list of group notices
181 function showContent()
183 $this->showGroupProfile();
184 $this->showGroupActions();
185 $this->showGroupNotices();
189 * Show the group notices
193 function showGroupNotices()
195 $notice = $this->group->getNotices(($this->page-1)*NOTICES_PER_PAGE,
196 NOTICES_PER_PAGE + 1);
198 $nl = new ThreadedNoticeList($notice, $this);
201 $this->pagination($this->page > 1,
202 $cnt > NOTICES_PER_PAGE,
205 array('nickname' => $this->group->nickname));
209 * Show the group profile
211 * Information about the group
215 function showGroupProfile()
217 $this->elementStart('div', array('id' => 'i',
218 'class' => 'entity_profile vcard author'));
220 $logo = ($this->group->homepage_logo) ?
221 $this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
223 $this->element('img', array('src' => $logo,
224 'class' => 'photo avatar entity_depiction',
225 'width' => AVATAR_PROFILE_SIZE,
226 'height' => AVATAR_PROFILE_SIZE,
227 'alt' => $this->group->nickname));
229 $hasFN = ($this->group->fullname) ? 'entity_nickname nickname url uid' :
230 'entity_nickname fn org nickname url uid';
231 $this->element('a', array('href' => $this->group->homeUrl(),
232 'rel' => 'me', 'class' => $hasFN),
233 $this->group->nickname);
235 if ($this->group->fullname) {
236 $this->element('div', 'entity_fn fn org', $this->group->fullname);
239 if ($this->group->location) {
240 $this->element('div', 'entity_location label', $this->group->location);
243 if ($this->group->homepage) {
244 $this->element('a', array('href' => $this->group->homepage,
246 'class' => 'url entity_url'),
247 $this->group->homepage);
250 if ($this->group->description) {
251 $this->element('div', 'note entity_note', $this->group->description);
254 if (common_config('group', 'maxaliases') > 0) {
255 $aliases = $this->group->getAliases();
257 if (!empty($aliases)) {
258 $this->element('div',
259 'aliases entity_aliases',
260 implode(' ', $aliases));
263 if ($this->group->description) {
264 $this->elementStart('dl', 'entity_note');
265 // TRANS: Label for group description or group note (dt). Text hidden by default.
266 $this->element('dt', null, _('Note'));
267 $this->element('dd', 'note', $this->group->description);
268 $this->elementEnd('dl');
271 if (common_config('group', 'maxaliases') > 0) {
272 $aliases = $this->group->getAliases();
274 if (!empty($aliases)) {
275 $this->elementStart('dl', 'entity_aliases');
276 // TRANS: Label for group aliases (dt). Text hidden by default.
277 $this->element('dt', null, _('Aliases'));
278 $this->element('dd', 'aliases', implode(' ', $aliases));
279 $this->elementEnd('dl');
283 Event::handle('EndGroupProfileElements', array($this, $this->group));
286 $this->elementEnd('div');
289 function showGroupActions()
291 $cur = common_current_user();
292 $this->elementStart('div', 'entity_actions');
293 // TRANS: Group actions header (h2). Text hidden by default.
294 $this->element('h2', null, _('Group actions'));
295 $this->elementStart('ul');
296 if (Event::handle('StartGroupActionsList', array($this, $this->group))) {
297 $this->elementStart('li', 'entity_subscribe');
298 if (Event::handle('StartGroupSubscribe', array($this, $this->group))) {
300 if ($cur->isMember($this->group)) {
301 $lf = new LeaveForm($this, $this->group);
303 } else if (!Group_block::isBlocked($this->group, $cur->getProfile())) {
304 $jf = new JoinForm($this, $this->group);
308 Event::handle('EndGroupSubscribe', array($this, $this->group));
310 $this->elementEnd('li');
311 if ($cur && $cur->hasRight(Right::DELETEGROUP)) {
312 $this->elementStart('li', 'entity_delete');
313 $df = new DeleteGroupForm($this, $this->group);
315 $this->elementEnd('li');
317 Event::handle('EndGroupActionsList', array($this, $this->group));
319 $this->elementEnd('ul');
320 $this->elementEnd('div');
324 * Get a list of the feeds for this page
331 common_local_url('grouprss',
332 array('nickname' => $this->group->nickname));
334 return array(new Feed(Feed::RSS1,
335 common_local_url('grouprss',
336 array('nickname' => $this->group->nickname)),
337 // TRANS: Tooltip for feed link. %s is a group nickname.
338 sprintf(_('Notice feed for %s group (RSS 1.0)'),
339 $this->group->nickname)),
341 common_local_url('ApiTimelineGroup',
342 array('format' => 'rss',
343 'id' => $this->group->id)),
344 // TRANS: Tooltip for feed link. %s is a group nickname.
345 sprintf(_('Notice feed for %s group (RSS 2.0)'),
346 $this->group->nickname)),
348 common_local_url('ApiTimelineGroup',
349 array('format' => 'atom',
350 'id' => $this->group->id)),
351 // TRANS: Tooltip for feed link. %s is a group nickname.
352 sprintf(_('Notice feed for %s group (Atom)'),
353 $this->group->nickname)),
355 common_local_url('foafgroup',
356 array('nickname' => $this->group->nickname)),
357 // TRANS: Tooltip for feed link. %s is a group nickname.
358 sprintf(_('FOAF for %s group'),
359 $this->group->nickname)));
363 * Fill in the sidebar.
367 function showSections()
369 $this->showMembers();
370 $this->showStatistics();
372 $cloud = new GroupTagCloudSection($this, $this->group);
377 * Show mini-list of members
381 function showMembers()
383 $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
389 $this->elementStart('div', array('id' => 'entity_members',
390 'class' => 'section'));
392 if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
394 // TRANS: Header for mini list of group members on a group page (h2).
395 $this->element('h2', null, _('Members'));
397 $gmml = new GroupMembersMiniList($member, $this);
398 $cnt = $gmml->show();
400 // TRANS: Description for mini list of group members on a group page when the group has no members.
401 $this->element('p', null, _('(None)'));
404 // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
405 // for example http://identi.ca/group/statusnet. Broken?
406 if ($cnt > MEMBERS_PER_SECTION) {
407 $this->element('a', array('href' => common_local_url('groupmembers',
408 array('nickname' => $this->group->nickname))),
409 // TRANS: Link to all group members from mini list of group members if group has more than n members.
413 Event::handle('EndShowGroupMembersMiniList', array($this));
416 $this->elementEnd('div');
420 * Show list of admins
424 function showAdmins()
426 $adminSection = new GroupAdminSection($this, $this->group);
427 $adminSection->show();
431 * Show some statistics
435 function showStatistics()
437 $this->elementStart('div', array('id' => 'entity_statistics',
438 'class' => 'section'));
440 // TRANS: Header for group statistics on a group page (h2).
441 $this->element('h2', null, _('Statistics'));
443 $this->elementEnd('dl');
444 $this->element('dt', null, _m('LABEL','Created'));
445 $this->element('dd', 'entity_created', date('j M Y',
446 strtotime($this->group->created)));
447 // @todo FIXME: i18n issue. This label gets a colon added from somewhere. Should be part of the message.
448 // TRANS: Label for member count in statistics on group page.
449 $this->element('dt', null, _m('LABEL','Members'));
450 $this->element('dd', null, $this->group->getMemberCount());
451 $this->elementEnd('dl');
453 $this->elementEnd('div');
456 function showAnonymousMessage()
458 if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
459 // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
460 // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept new registrations.
461 // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
462 // TRANS: %%%%action.register%%%% is the URL for registration, %%%%doc.help%%%% is a URL to help.
463 // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
464 $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
465 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
466 'short messages about their life and interests. '.
467 '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
468 $this->group->nickname);
470 // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
471 // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept no new registrations.
472 // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
473 // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
474 $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
475 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
476 'short messages about their life and interests. '),
477 $this->group->nickname);
479 $this->elementStart('div', array('id' => 'anon_notice'));
480 $this->raw(common_markup_to_html($m));
481 $this->elementEnd('div');
485 class GroupAdminSection extends ProfileSection
489 function __construct($out, $group)
491 parent::__construct($out);
492 $this->group = $group;
495 function getProfiles()
497 return $this->group->getAdmins();
502 // TRANS: Header for list of group administrators on a group page (h2).
508 return 'group_admins';
517 class GroupMembersMiniList extends ProfileMiniList
519 function newListItem($profile)
521 return new GroupMembersMiniListItem($profile, $this->action);
525 class GroupMembersMiniListItem extends ProfileMiniListItem
527 function linkAttributes()
529 $aAttrs = parent::linkAttributes();
531 if (common_config('nofollow', 'members')) {
532 $aAttrs['rel'] .= ' nofollow';