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 showLocalNav()
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->showGroupNotices();
188 * Show the group notices
192 function showGroupNotices()
194 $notice = $this->group->getNotices(($this->page-1)*NOTICES_PER_PAGE,
195 NOTICES_PER_PAGE + 1);
197 $nl = new NoticeList($notice, $this);
200 $this->pagination($this->page > 1,
201 $cnt > NOTICES_PER_PAGE,
204 array('nickname' => $this->group->nickname));
208 * Show the group profile
210 * Information about the group
214 function showGroupProfile()
216 $this->elementStart('div', array('id' => 'i',
217 'class' => 'entity_profile vcard author'));
219 // TRANS: Group profile header (h2). Text hidden by default.
220 $this->element('h2', null, _('Group profile'));
222 $this->elementStart('dl', 'entity_depiction');
223 // TRANS: Label for group avatar (dt). Text hidden by default.
224 $this->element('dt', null, _('Avatar'));
225 $this->elementStart('dd');
227 $logo = ($this->group->homepage_logo) ?
228 $this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
230 $this->element('img', array('src' => $logo,
231 'class' => 'photo avatar',
232 'width' => AVATAR_PROFILE_SIZE,
233 'height' => AVATAR_PROFILE_SIZE,
234 'alt' => $this->group->nickname));
235 $this->elementEnd('dd');
236 $this->elementEnd('dl');
238 $this->elementStart('dl', 'entity_nickname');
239 // TRANS: Label for group nickname (dt). Text hidden by default.
240 $this->element('dt', null, _('Nickname'));
241 $this->elementStart('dd');
242 $hasFN = ($this->group->fullname) ? 'nickname url uid' : 'fn org nickname url uid';
243 $this->element('a', array('href' => $this->group->homeUrl(),
244 'rel' => 'me', 'class' => $hasFN),
245 $this->group->nickname);
246 $this->elementEnd('dd');
247 $this->elementEnd('dl');
249 if ($this->group->fullname) {
250 $this->elementStart('dl', 'entity_fn');
251 // TRANS: Label for full group name (dt). Text hidden by default.
252 $this->element('dt', null, _('Full name'));
253 $this->elementStart('dd');
254 $this->element('span', 'fn org', $this->group->fullname);
255 $this->elementEnd('dd');
256 $this->elementEnd('dl');
259 if ($this->group->location) {
260 $this->elementStart('dl', 'entity_location');
261 // TRANS: Label for group location (dt). Text hidden by default.
262 $this->element('dt', null, _('Location'));
263 $this->element('dd', 'label', $this->group->location);
264 $this->elementEnd('dl');
267 if ($this->group->homepage) {
268 $this->elementStart('dl', 'entity_url');
269 // TRANS: Label for group URL (dt). Text hidden by default.
270 $this->element('dt', null, _('URL'));
271 $this->elementStart('dd');
272 $this->element('a', array('href' => $this->group->homepage,
273 'rel' => 'me', 'class' => 'url'),
274 $this->group->homepage);
275 $this->elementEnd('dd');
276 $this->elementEnd('dl');
279 if ($this->group->description) {
280 $this->elementStart('dl', 'entity_note');
281 // TRANS: Label for group description or group note (dt). Text hidden by default.
282 $this->element('dt', null, _('Note'));
283 $this->element('dd', 'note', $this->group->description);
284 $this->elementEnd('dl');
287 if (common_config('group', 'maxaliases') > 0) {
288 $aliases = $this->group->getAliases();
290 if (!empty($aliases)) {
291 $this->elementStart('dl', 'entity_aliases');
292 // TRANS: Label for group aliases (dt). Text hidden by default.
293 $this->element('dt', null, _('Aliases'));
294 $this->element('dd', 'aliases', implode(' ', $aliases));
295 $this->elementEnd('dl');
299 $this->elementEnd('div');
301 $cur = common_current_user();
302 $this->elementStart('div', 'entity_actions');
303 // TRANS: Group actions header (h2). Text hidden by default.
304 $this->element('h2', null, _('Group actions'));
305 $this->elementStart('ul');
306 $this->elementStart('li', 'entity_subscribe');
307 if (Event::handle('StartGroupSubscribe', array($this, $this->group))) {
309 if ($cur->isMember($this->group)) {
310 $lf = new LeaveForm($this, $this->group);
312 } else if (!Group_block::isBlocked($this->group, $cur->getProfile())) {
313 $jf = new JoinForm($this, $this->group);
317 Event::handle('EndGroupSubscribe', array($this, $this->group));
319 $this->elementEnd('li');
320 if ($cur && $cur->hasRight(Right::DELETEGROUP)) {
321 $this->elementStart('li', 'entity_delete');
322 $df = new DeleteGroupForm($this, $this->group);
324 $this->elementEnd('li');
326 $this->elementEnd('ul');
327 $this->elementEnd('div');
331 * Get a list of the feeds for this page
338 common_local_url('grouprss',
339 array('nickname' => $this->group->nickname));
341 return array(new Feed(Feed::RSS1,
342 common_local_url('grouprss',
343 array('nickname' => $this->group->nickname)),
344 // TRANS: Tooltip for feed link. %s is a group nickname.
345 sprintf(_('Notice feed for %s group (RSS 1.0)'),
346 $this->group->nickname)),
348 common_local_url('ApiTimelineGroup',
349 array('format' => 'rss',
350 'id' => $this->group->id)),
351 // TRANS: Tooltip for feed link. %s is a group nickname.
352 sprintf(_('Notice feed for %s group (RSS 2.0)'),
353 $this->group->nickname)),
355 common_local_url('ApiTimelineGroup',
356 array('format' => 'atom',
357 'id' => $this->group->id)),
358 // TRANS: Tooltip for feed link. %s is a group nickname.
359 sprintf(_('Notice feed for %s group (Atom)'),
360 $this->group->nickname)),
362 common_local_url('foafgroup',
363 array('nickname' => $this->group->nickname)),
364 // TRANS: Tooltip for feed link. %s is a group nickname.
365 sprintf(_('FOAF for %s group'),
366 $this->group->nickname)));
370 * Fill in the sidebar.
374 function showSections()
376 $this->showMembers();
377 $this->showStatistics();
379 $cloud = new GroupTagCloudSection($this, $this->group);
384 * Show mini-list of members
388 function showMembers()
390 $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
396 $this->elementStart('div', array('id' => 'entity_members',
397 'class' => 'section'));
399 if (Event::handle('StartShowGroupMembersMiniList', array($this))) {
401 // TRANS: Header for mini list of group members on a group page (h2).
402 $this->element('h2', null, _('Members'));
404 $gmml = new GroupMembersMiniList($member, $this);
405 $cnt = $gmml->show();
407 // TRANS: Description for mini list of group members on a group page when the group has no members.
408 $this->element('p', null, _('(None)'));
411 // @todo FIXME: Should be shown if a group has more than 27 members, but I do not see it displayed at
412 // for example http://identi.ca/group/statusnet. Broken?
413 if ($cnt > MEMBERS_PER_SECTION) {
414 $this->element('a', array('href' => common_local_url('groupmembers',
415 array('nickname' => $this->group->nickname))),
416 // TRANS: Link to all group members from mini list of group members if group has more than n members.
420 Event::handle('EndShowGroupMembersMiniList', array($this));
423 $this->elementEnd('div');
427 * Show list of admins
431 function showAdmins()
433 $adminSection = new GroupAdminSection($this, $this->group);
434 $adminSection->show();
438 * Show some statistics
442 function showStatistics()
444 $this->elementStart('div', array('id' => 'entity_statistics',
445 'class' => 'section'));
447 // TRANS: Header for group statistics on a group page (h2).
448 $this->element('h2', null, _('Statistics'));
450 $this->elementStart('dl', 'entity_created');
451 // @todo FIXME: i18n issue. This label gets a colon added from somewhere. Should be part of the message.
452 // TRANS: Label for creation date in statistics on group page.
453 $this->element('dt', null, _m('LABEL','Created'));
454 $this->element('dd', null, date('j M Y',
455 strtotime($this->group->created)));
456 $this->elementEnd('dl');
458 $this->elementStart('dl', 'entity_members');
459 // @todo FIXME: i18n issue. This label gets a colon added from somewhere. Should be part of the message.
460 // TRANS: Label for member count in statistics on group page.
461 $this->element('dt', null, _m('LABEL','Members'));
462 $this->element('dd', null, $this->group->getMemberCount());
463 $this->elementEnd('dl');
465 $this->elementEnd('div');
468 function showAnonymousMessage()
470 if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
471 // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
472 // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept new registrations.
473 // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
474 // TRANS: %%%%action.register%%%% is the URL for registration, %%%%doc.help%%%% is a URL to help.
475 // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
476 $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
477 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
478 'short messages about their life and interests. '.
479 '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
480 $this->group->nickname);
482 // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
483 // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept no new registrations.
484 // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
485 // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
486 $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
487 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
488 'short messages about their life and interests. '),
489 $this->group->nickname);
491 $this->elementStart('div', array('id' => 'anon_notice'));
492 $this->raw(common_markup_to_html($m));
493 $this->elementEnd('div');
497 class GroupAdminSection extends ProfileSection
501 function __construct($out, $group)
503 parent::__construct($out);
504 $this->group = $group;
507 function getProfiles()
509 return $this->group->getAdmins();
514 // TRANS: Header for list of group administrators on a group page (h2).
520 return 'group_admins';
529 class GroupMembersMiniList extends ProfileMiniList
531 function newListItem($profile)
533 return new GroupMembersMiniListItem($profile, $this->action);
537 class GroupMembersMiniListItem extends ProfileMiniListItem
539 function linkAttributes()
541 $aAttrs = parent::linkAttributes();
543 if (common_config('nofollow', 'members')) {
544 $aAttrs['rel'] .= ' nofollow';