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 if (!empty($this->group->fullname)) {
72 // @todo FIXME: Needs proper i18n. Maybe use a generic method for this?
73 $base = $this->group->fullname . ' (' . $this->group->nickname . ')';
75 $base = $this->group->nickname;
78 if ($this->page == 1) {
79 // TRANS: Page title for first group page. %s is a group name.
80 return sprintf(_('%s group'), $base);
82 // TRANS: Page title for any but first group page.
83 // TRANS: %1$s is a group name, $2$s is a page number.
84 return sprintf(_('%1$s group, page %2$d'),
93 * Reads and validates arguments and instantiates the attributes.
95 * @param array $args $_REQUEST args
97 * @return boolean success flag
99 function prepare($args)
101 parent::prepare($args);
103 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
105 $nickname_arg = $this->arg('nickname');
106 $nickname = common_canonical_nickname($nickname_arg);
108 // Permanent redirect on non-canonical nickname
110 if ($nickname_arg != $nickname) {
111 $args = array('nickname' => $nickname);
112 if ($this->page != 1) {
113 $args['page'] = $this->page;
115 common_redirect(common_local_url('showgroup', $args), 301);
120 // TRANS: Client error displayed if no nickname argument was given requesting a group page.
121 $this->clientError(_('No nickname.'), 404);
125 $local = Local_group::staticGet('nickname', $nickname);
128 $alias = Group_alias::staticGet('alias', $nickname);
130 $args = array('id' => $alias->group_id);
131 if ($this->page != 1) {
132 $args['page'] = $this->page;
134 common_redirect(common_local_url('groupbyid', $args), 301);
137 common_log(LOG_NOTICE, "Couldn't find local group for nickname '$nickname'");
138 // TRANS: Client error displayed if no remote group with a given name was found requesting group page.
139 $this->clientError(_('No such group.'), 404);
144 $this->group = User_group::staticGet('id', $local->group_id);
147 // TRANS: Client error displayed if no local group with a given name was found requesting group page.
148 $this->clientError(_('No such group.'), 404);
152 common_set_returnto($this->selfUrl());
160 * Shows a profile for the group, some controls, and a list of
165 function handle($args)
175 function showLocalNav()
177 $nav = new GroupNav($this, $this->group);
182 * Show the page content
184 * Shows a group profile and a list of group notices
186 function showContent()
188 $this->showGroupProfile();
189 $this->showGroupNotices();
193 * Show the group notices
197 function showGroupNotices()
199 $notice = $this->group->getNotices(($this->page-1)*NOTICES_PER_PAGE,
200 NOTICES_PER_PAGE + 1);
202 $nl = new NoticeList($notice, $this);
205 $this->pagination($this->page > 1,
206 $cnt > NOTICES_PER_PAGE,
209 array('nickname' => $this->group->nickname));
213 * Show the group profile
215 * Information about the group
219 function showGroupProfile()
221 $this->elementStart('div', array('id' => 'i',
222 'class' => 'entity_profile vcard author'));
224 // TRANS: Group profile header (h2). Text hidden by default.
225 $this->element('h2', null, _('Group profile'));
227 $this->elementStart('dl', 'entity_depiction');
228 // TRANS: Label for group avatar (dt). Text hidden by default.
229 $this->element('dt', null, _('Avatar'));
230 $this->elementStart('dd');
232 $logo = ($this->group->homepage_logo) ?
233 $this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
235 $this->element('img', array('src' => $logo,
236 'class' => 'photo avatar',
237 'width' => AVATAR_PROFILE_SIZE,
238 'height' => AVATAR_PROFILE_SIZE,
239 'alt' => $this->group->nickname));
240 $this->elementEnd('dd');
241 $this->elementEnd('dl');
243 $this->elementStart('dl', 'entity_nickname');
244 // TRANS: Label for group nickname (dt). Text hidden by default.
245 $this->element('dt', null, _('Nickname'));
246 $this->elementStart('dd');
247 $hasFN = ($this->group->fullname) ? 'nickname url uid' : 'fn org nickname url uid';
248 $this->element('a', array('href' => $this->group->homeUrl(),
249 'rel' => 'me', 'class' => $hasFN),
250 $this->group->nickname);
251 $this->elementEnd('dd');
252 $this->elementEnd('dl');
254 if ($this->group->fullname) {
255 $this->elementStart('dl', 'entity_fn');
256 // TRANS: Label for full group name (dt). Text hidden by default.
257 $this->element('dt', null, _('Full name'));
258 $this->elementStart('dd');
259 $this->element('span', 'fn org', $this->group->fullname);
260 $this->elementEnd('dd');
261 $this->elementEnd('dl');
264 if ($this->group->location) {
265 $this->elementStart('dl', 'entity_location');
266 // TRANS: Label for group location (dt). Text hidden by default.
267 $this->element('dt', null, _('Location'));
268 $this->element('dd', 'label', $this->group->location);
269 $this->elementEnd('dl');
272 if ($this->group->homepage) {
273 $this->elementStart('dl', 'entity_url');
274 // TRANS: Label for group URL (dt). Text hidden by default.
275 $this->element('dt', null, _('URL'));
276 $this->elementStart('dd');
277 $this->element('a', array('href' => $this->group->homepage,
278 'rel' => 'me', 'class' => 'url'),
279 $this->group->homepage);
280 $this->elementEnd('dd');
281 $this->elementEnd('dl');
284 if ($this->group->description) {
285 $this->elementStart('dl', 'entity_note');
286 // TRANS: Label for group description or group note (dt). Text hidden by default.
287 $this->element('dt', null, _('Note'));
288 $this->element('dd', 'note', $this->group->description);
289 $this->elementEnd('dl');
292 if (common_config('group', 'maxaliases') > 0) {
293 $aliases = $this->group->getAliases();
295 if (!empty($aliases)) {
296 $this->elementStart('dl', 'entity_aliases');
297 // TRANS: Label for group aliases (dt). Text hidden by default.
298 $this->element('dt', null, _('Aliases'));
299 $this->element('dd', 'aliases', implode(' ', $aliases));
300 $this->elementEnd('dl');
304 $this->elementEnd('div');
306 $cur = common_current_user();
307 $this->elementStart('div', 'entity_actions');
308 // TRANS: Group actions header (h2). Text hidden by default.
309 $this->element('h2', null, _('Group actions'));
310 $this->elementStart('ul');
311 $this->elementStart('li', 'entity_subscribe');
312 if (Event::handle('StartGroupSubscribe', array($this, $this->group))) {
314 if ($cur->isMember($this->group)) {
315 $lf = new LeaveForm($this, $this->group);
317 } else if (!Group_block::isBlocked($this->group, $cur->getProfile())) {
318 $jf = new JoinForm($this, $this->group);
322 Event::handle('EndGroupSubscribe', array($this, $this->group));
324 $this->elementEnd('li');
325 if ($cur && $cur->hasRight(Right::DELETEGROUP)) {
326 $this->elementStart('li', 'entity_delete');
327 $df = new DeleteGroupForm($this, $this->group);
329 $this->elementEnd('li');
331 $this->elementEnd('ul');
332 $this->elementEnd('div');
336 * Get a list of the feeds for this page
343 common_local_url('grouprss',
344 array('nickname' => $this->group->nickname));
346 return array(new Feed(Feed::RSS1,
347 common_local_url('grouprss',
348 array('nickname' => $this->group->nickname)),
349 // TRANS: Tooltip for feed link. %s is a group nickname.
350 sprintf(_('Notice feed for %s group (RSS 1.0)'),
351 $this->group->nickname)),
353 common_local_url('ApiTimelineGroup',
354 array('format' => 'rss',
355 'id' => $this->group->id)),
356 // TRANS: Tooltip for feed link. %s is a group nickname.
357 sprintf(_('Notice feed for %s group (RSS 2.0)'),
358 $this->group->nickname)),
360 common_local_url('ApiTimelineGroup',
361 array('format' => 'atom',
362 'id' => $this->group->id)),
363 // TRANS: Tooltip for feed link. %s is a group nickname.
364 sprintf(_('Notice feed for %s group (Atom)'),
365 $this->group->nickname)),
367 common_local_url('foafgroup',
368 array('nickname' => $this->group->nickname)),
369 // TRANS: Tooltip for feed link. %s is a group nickname.
370 sprintf(_('FOAF for %s group'),
371 $this->group->nickname)));
375 * Fill in the sidebar.
379 function showSections()
381 $this->showMembers();
382 $this->showStatistics();
384 $cloud = new GroupTagCloudSection($this, $this->group);
389 * Show mini-list of members
393 function showMembers()
395 $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
401 $this->elementStart('div', array('id' => 'entity_members',
402 'class' => 'section'));
404 if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
406 // TRANS: Header for mini list of group members on a group page (h2).
407 $this->element('h2', null, _('Members'));
409 $gmml = new GroupMembersMiniList($member, $this);
410 $cnt = $gmml->show();
412 // TRANS: Description for mini list of group members on a group page when the group has no members.
413 $this->element('p', null, _('(None)'));
416 // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
417 // for example http://identi.ca/group/statusnet. Broken?
418 if ($cnt > MEMBERS_PER_SECTION) {
419 $this->element('a', array('href' => common_local_url('groupmembers',
420 array('nickname' => $this->group->nickname))),
421 // TRANS: Link to all group members from mini list of group members if group has more than n members.
425 Event::handle('EndShowGroupMembersMiniList', array($this));
428 $this->elementEnd('div');
432 * Show list of admins
436 function showAdmins()
438 $adminSection = new GroupAdminSection($this, $this->group);
439 $adminSection->show();
443 * Show some statistics
447 function showStatistics()
449 $this->elementStart('div', array('id' => 'entity_statistics',
450 'class' => 'section'));
452 // TRANS: Header for group statistics on a group page (h2).
453 $this->element('h2', null, _('Statistics'));
455 $this->elementStart('dl', 'entity_created');
456 // @todo FIXME: i18n issue. This label gets a colon added from somewhere. Should be part of the message.
457 // TRANS: Label for creation date in statistics on group page.
458 $this->element('dt', null, _m('LABEL','Created'));
459 $this->element('dd', null, date('j M Y',
460 strtotime($this->group->created)));
461 $this->elementEnd('dl');
463 $this->elementStart('dl', 'entity_members');
464 // @todo FIXME: i18n issue. This label gets a colon added from somewhere. Should be part of the message.
465 // TRANS: Label for member count in statistics on group page.
466 $this->element('dt', null, _m('LABEL','Members'));
467 $this->element('dd', null, $this->group->getMemberCount());
468 $this->elementEnd('dl');
470 $this->elementEnd('div');
473 function showAnonymousMessage()
475 if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
476 // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
477 // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept new registrations.
478 // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
479 // TRANS: %%%%action.register%%%% is the URL for registration, %%%%doc.help%%%% is a URL to help.
480 // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
481 $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
482 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
483 'short messages about their life and interests. '.
484 '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
485 $this->group->nickname);
487 // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
488 // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept no new registrations.
489 // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
490 // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
491 $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
492 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
493 'short messages about their life and interests. '),
494 $this->group->nickname);
496 $this->elementStart('div', array('id' => 'anon_notice'));
497 $this->raw(common_markup_to_html($m));
498 $this->elementEnd('div');
502 class GroupAdminSection extends ProfileSection
506 function __construct($out, $group)
508 parent::__construct($out);
509 $this->group = $group;
512 function getProfiles()
514 return $this->group->getAdmins();
519 // TRANS: Header for list of group administrators on a group page (h2).
525 return 'group_admins';
534 class GroupMembersMiniList extends ProfileMiniList
536 function newListItem($profile)
538 return new GroupMembersMiniListItem($profile, $this->action);
542 class GroupMembersMiniListItem extends ProfileMiniListItem
544 function linkAttributes()
546 $aAttrs = parent::linkAttributes();
548 if (common_config('nofollow', 'members')) {
549 $aAttrs['rel'] .= ' nofollow';