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/
50 class ShowgroupAction extends GroupDesignAction
53 /** page we're viewing. */
57 * Is this page read-only?
59 * @return boolean true
62 function isReadOnly($args)
70 * @return string page title, with page number
75 if (!empty($this->group->fullname)) {
76 $base = $this->group->fullname . ' (' . $this->group->nickname . ')';
78 $base = $this->group->nickname;
81 if ($this->page == 1) {
82 return sprintf(_("%s group"), $base);
84 return sprintf(_("%s group, page %d"),
93 * Reads and validates arguments and instantiates the attributes.
95 * @param array $args $_REQUEST args
97 * @return boolean success flag
100 function prepare($args)
102 parent::prepare($args);
104 if (!common_config('inboxes','enabled')) {
105 $this->serverError(_('Inboxes must be enabled for groups to work'));
109 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
111 $nickname_arg = $this->arg('nickname');
112 $nickname = common_canonical_nickname($nickname_arg);
114 // Permanent redirect on non-canonical nickname
116 if ($nickname_arg != $nickname) {
117 $args = array('nickname' => $nickname);
118 if ($this->page != 1) {
119 $args['page'] = $this->page;
121 common_redirect(common_local_url('showgroup', $args), 301);
126 $this->clientError(_('No nickname'), 404);
130 $this->group = User_group::staticGet('nickname', $nickname);
133 $alias = Group_alias::staticGet('alias', $nickname);
135 $args = array('id' => $alias->group_id);
136 if ($this->page != 1) {
137 $args['page'] = $this->page;
139 common_redirect(common_local_url('groupbyid', $args), 301);
142 $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
161 function handle($args)
172 function showLocalNav()
174 $nav = new GroupNav($this, $this->group);
179 * Show the page content
181 * Shows a group profile and a list of group notices
184 function showContent()
186 $this->showGroupProfile();
187 $this->showGroupNotices();
191 * Show the group notices
196 function showGroupNotices()
198 $notice = $this->group->getNotices(($this->page-1)*NOTICES_PER_PAGE,
199 NOTICES_PER_PAGE + 1);
201 $nl = new NoticeList($notice, $this);
204 $this->pagination($this->page > 1,
205 $cnt > NOTICES_PER_PAGE,
208 array('nickname' => $this->group->nickname));
212 * Show the group profile
214 * Information about the group
219 function showGroupProfile()
221 $this->elementStart('div', 'entity_profile vcard author');
223 $this->element('h2', null, _('Group profile'));
225 $this->elementStart('dl', 'entity_depiction');
226 $this->element('dt', null, _('Avatar'));
227 $this->elementStart('dd');
229 $logo = ($this->group->homepage_logo) ?
230 $this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
232 $this->element('img', array('src' => $logo,
233 'class' => 'photo avatar',
234 'width' => AVATAR_PROFILE_SIZE,
235 'height' => AVATAR_PROFILE_SIZE,
236 'alt' => $this->group->nickname));
237 $this->elementEnd('dd');
238 $this->elementEnd('dl');
240 $this->elementStart('dl', 'entity_nickname');
241 $this->element('dt', null, _('Nickname'));
242 $this->elementStart('dd');
243 $hasFN = ($this->group->fullname) ? 'nickname url uid' : 'fn org nickname url uid';
244 $this->element('a', array('href' => $this->group->homeUrl(),
245 'rel' => 'me', 'class' => $hasFN),
246 $this->group->nickname);
247 $this->elementEnd('dd');
248 $this->elementEnd('dl');
250 if ($this->group->fullname) {
251 $this->elementStart('dl', 'entity_fn');
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 $this->element('dt', null, _('Location'));
262 $this->element('dd', 'label', $this->group->location);
263 $this->elementEnd('dl');
266 if ($this->group->homepage) {
267 $this->elementStart('dl', 'entity_url');
268 $this->element('dt', null, _('URL'));
269 $this->elementStart('dd');
270 $this->element('a', array('href' => $this->group->homepage,
271 'rel' => 'me', 'class' => 'url'),
272 $this->group->homepage);
273 $this->elementEnd('dd');
274 $this->elementEnd('dl');
277 if ($this->group->description) {
278 $this->elementStart('dl', 'entity_note');
279 $this->element('dt', null, _('Note'));
280 $this->element('dd', 'note', $this->group->description);
281 $this->elementEnd('dl');
284 if (common_config('group', 'maxaliases') > 0) {
285 $aliases = $this->group->getAliases();
287 if (!empty($aliases)) {
288 $this->elementStart('dl', 'entity_aliases');
289 $this->element('dt', null, _('Aliases'));
290 $this->element('dd', 'aliases', implode(' ', $aliases));
291 $this->elementEnd('dl');
295 $this->elementEnd('div');
297 $this->elementStart('div', 'entity_actions');
298 $this->element('h2', null, _('Group actions'));
299 $this->elementStart('ul');
300 $this->elementStart('li', 'entity_subscribe');
301 $cur = common_current_user();
303 if ($cur->isMember($this->group)) {
304 $lf = new LeaveForm($this, $this->group);
306 } else if (!Group_block::isBlocked($this->group, $cur->getProfile())) {
307 $jf = new JoinForm($this, $this->group);
312 $this->elementEnd('li');
314 $this->elementEnd('ul');
315 $this->elementEnd('div');
319 * Get a list of the feeds for this page
327 common_local_url('grouprss',
328 array('nickname' => $this->group->nickname));
330 return array(new Feed(Feed::RSS1,
331 common_local_url('grouprss',
332 array('nickname' => $this->group->nickname)),
333 sprintf(_('Notice feed for %s group (RSS 1.0)'),
334 $this->group->nickname)),
336 common_local_url('api',
337 array('apiaction' => 'groups',
338 'method' => 'timeline',
339 'argument' => $this->group->nickname.'.rss')),
340 sprintf(_('Notice feed for %s group (RSS 2.0)'),
341 $this->group->nickname)),
343 common_local_url('api',
344 array('apiaction' => 'groups',
345 'method' => 'timeline',
346 'argument' => $this->group->nickname.'.atom')),
347 sprintf(_('Notice feed for %s group (Atom)'),
348 $this->group->nickname)));
352 * Fill in the sidebar.
357 function showSections()
359 $this->showMembers();
360 $this->showStatistics();
362 $cloud = new GroupTagCloudSection($this, $this->group);
367 * Show mini-list of members
372 function showMembers()
374 $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
380 $this->elementStart('div', array('id' => 'entity_members',
381 'class' => 'section'));
383 $this->element('h2', null, _('Members'));
385 $pml = new ProfileMiniList($member, $this);
388 $this->element('p', null, _('(None)'));
391 if ($cnt > MEMBERS_PER_SECTION) {
392 $this->element('a', array('href' => common_local_url('groupmembers',
393 array('nickname' => $this->group->nickname))),
397 $this->elementEnd('div');
401 * Show list of admins
406 function showAdmins()
408 $adminSection = new GroupAdminSection($this, $this->group);
409 $adminSection->show();
413 * Show some statistics
418 function showStatistics()
420 // XXX: WORM cache this
421 $members = $this->group->getMembers();
423 /** $member->count() doesn't work. */
424 while ($members->fetch()) {
428 $this->elementStart('div', array('id' => 'entity_statistics',
429 'class' => 'section'));
431 $this->element('h2', null, _('Statistics'));
433 $this->elementStart('dl', 'entity_created');
434 $this->element('dt', null, _('Created'));
435 $this->element('dd', null, date('j M Y',
436 strtotime($this->group->created)));
437 $this->elementEnd('dl');
439 $this->elementStart('dl', 'entity_members');
440 $this->element('dt', null, _('Members'));
441 $this->element('dd', null, (is_int($members_count)) ? $members_count : '0');
442 $this->elementEnd('dl');
444 $this->elementEnd('div');
447 function showAnonymousMessage()
449 if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
450 $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
451 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
452 'short messages about their life and interests. '.
453 '[Join now](%%%%action.%s%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
454 $this->group->nickname,
455 (!common_config('site','openidonly')) ? 'register' : 'openidlogin');
457 $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
458 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
459 'short messages about their life and interests. '),
460 $this->group->nickname);
462 $this->elementStart('div', array('id' => 'anon_notice'));
463 $this->raw(common_markup_to_html($m));
464 $this->elementEnd('div');
468 class GroupAdminSection extends ProfileSection
472 function __construct($out, $group)
474 parent::__construct($out);
475 $this->group = $group;
478 function getProfiles()
480 return $this->group->getAdmins();
490 return 'group_admins';