3 * Laconica, 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@controlyourself.ca>
25 * @author Sarven Capadisli <csarven@controlyourself.ca>
26 * @copyright 2008-2009 Control Yourself, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28 * @link http://laconi.ca/
31 if (!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@controlyourself.ca>
46 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
47 * @link http://laconi.ca/
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 $this->clientError(_('No such group'), 404);
137 common_set_returnto($this->selfUrl());
145 * Shows a profile for the group, some controls, and a list of
151 function handle($args)
162 function showLocalNav()
164 $nav = new GroupNav($this, $this->group);
169 * Show the page content
171 * Shows a group profile and a list of group notices
174 function showContent()
176 $this->showGroupProfile();
177 $this->showGroupNotices();
181 * Show the group notices
186 function showGroupNotices()
188 $notice = $this->group->getNotices(($this->page-1)*NOTICES_PER_PAGE,
189 NOTICES_PER_PAGE + 1);
191 $nl = new NoticeList($notice, $this);
194 $this->pagination($this->page > 1,
195 $cnt > NOTICES_PER_PAGE,
198 array('nickname' => $this->group->nickname));
202 * Show the group profile
204 * Information about the group
209 function showGroupProfile()
211 $this->elementStart('div', 'entity_profile vcard author');
213 $this->element('h2', null, _('Group profile'));
215 $this->elementStart('dl', 'entity_depiction');
216 $this->element('dt', null, _('Avatar'));
217 $this->elementStart('dd');
219 $logo = ($this->group->homepage_logo) ?
220 $this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
222 $this->element('img', array('src' => $logo,
223 'class' => 'photo avatar',
224 'width' => AVATAR_PROFILE_SIZE,
225 'height' => AVATAR_PROFILE_SIZE,
226 'alt' => $this->group->nickname));
227 $this->elementEnd('dd');
228 $this->elementEnd('dl');
230 $this->elementStart('dl', 'entity_nickname');
231 $this->element('dt', null, _('Nickname'));
232 $this->elementStart('dd');
233 $hasFN = ($this->group->fullname) ? 'nickname url uid' : 'fn org nickname url uid';
234 $this->element('a', array('href' => $this->group->homeUrl(),
235 'rel' => 'me', 'class' => $hasFN),
236 $this->group->nickname);
237 $this->elementEnd('dd');
238 $this->elementEnd('dl');
240 if ($this->group->fullname) {
241 $this->elementStart('dl', 'entity_fn');
242 $this->element('dt', null, _('Full name'));
243 $this->elementStart('dd');
244 $this->element('span', 'fn org', $this->group->fullname);
245 $this->elementEnd('dd');
246 $this->elementEnd('dl');
249 if ($this->group->location) {
250 $this->elementStart('dl', 'entity_location');
251 $this->element('dt', null, _('Location'));
252 $this->element('dd', 'label', $this->group->location);
253 $this->elementEnd('dl');
256 if ($this->group->homepage) {
257 $this->elementStart('dl', 'entity_url');
258 $this->element('dt', null, _('URL'));
259 $this->elementStart('dd');
260 $this->element('a', array('href' => $this->group->homepage,
261 'rel' => 'me', 'class' => 'url'),
262 $this->group->homepage);
263 $this->elementEnd('dd');
264 $this->elementEnd('dl');
267 if ($this->group->description) {
268 $this->elementStart('dl', 'entity_note');
269 $this->element('dt', null, _('Note'));
270 $this->element('dd', 'note', $this->group->description);
271 $this->elementEnd('dl');
274 if (common_config('group', 'maxaliases') > 0) {
275 $aliases = $this->group->getAliases();
277 if (!empty($aliases)) {
278 $this->elementStart('dl', 'entity_aliases');
279 $this->element('dt', null, _('Aliases'));
280 $this->element('dd', 'aliases', implode(' ', $aliases));
281 $this->elementEnd('dl');
285 $this->elementEnd('div');
287 $this->elementStart('div', 'entity_actions');
288 $this->element('h2', null, _('Group actions'));
289 $this->elementStart('ul');
290 $this->elementStart('li', 'entity_subscribe');
291 $cur = common_current_user();
293 if ($cur->isMember($this->group)) {
294 $lf = new LeaveForm($this, $this->group);
296 } else if (!Group_block::isBlocked($this->group, $cur->getProfile())) {
297 $jf = new JoinForm($this, $this->group);
302 $this->elementEnd('li');
304 $this->elementEnd('ul');
305 $this->elementEnd('div');
309 * Get a list of the feeds for this page
317 common_local_url('grouprss',
318 array('nickname' => $this->group->nickname));
320 return array(new Feed(Feed::RSS1,
321 common_local_url('grouprss',
322 array('nickname' => $this->group->nickname)),
323 sprintf(_('Notice feed for %s group (RSS 1.0)'),
324 $this->group->nickname)),
326 common_local_url('api',
327 array('apiaction' => 'groups',
328 'method' => 'timeline',
329 'argument' => $this->group->nickname.'.rss')),
330 sprintf(_('Notice feed for %s group (RSS 2.0)'),
331 $this->group->nickname)),
333 common_local_url('api',
334 array('apiaction' => 'groups',
335 'method' => 'timeline',
336 'argument' => $this->group->nickname.'.atom')),
337 sprintf(_('Notice feed for %s group (Atom)'),
338 $this->group->nickname)));
342 * Fill in the sidebar.
347 function showSections()
349 $this->showMembers();
350 $this->showStatistics();
352 $cloud = new GroupTagCloudSection($this, $this->group);
357 * Show mini-list of members
362 function showMembers()
364 $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
370 $this->elementStart('div', array('id' => 'entity_members',
371 'class' => 'section'));
373 $this->element('h2', null, _('Members'));
375 $pml = new ProfileMiniList($member, $this);
378 $this->element('p', null, _('(None)'));
381 if ($cnt > MEMBERS_PER_SECTION) {
382 $this->element('a', array('href' => common_local_url('groupmembers',
383 array('nickname' => $this->group->nickname))),
387 $this->elementEnd('div');
391 * Show list of admins
396 function showAdmins()
398 $adminSection = new GroupAdminSection($this, $this->group);
399 $adminSection->show();
403 * Show some statistics
408 function showStatistics()
410 // XXX: WORM cache this
411 $members = $this->group->getMembers();
413 /** $member->count() doesn't work. */
414 while ($members->fetch()) {
418 $this->elementStart('div', array('id' => 'entity_statistics',
419 'class' => 'section'));
421 $this->element('h2', null, _('Statistics'));
423 $this->elementStart('dl', 'entity_created');
424 $this->element('dt', null, _('Created'));
425 $this->element('dd', null, date('j M Y',
426 strtotime($this->group->created)));
427 $this->elementEnd('dl');
429 $this->elementStart('dl', 'entity_members');
430 $this->element('dt', null, _('Members'));
431 $this->element('dd', null, (is_int($members_count)) ? $members_count : '0');
432 $this->elementEnd('dl');
434 $this->elementEnd('div');
437 function showAnonymousMessage()
439 if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
440 $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
441 'based on the Free Software [Laconica](http://laconi.ca/) tool. Its members share ' .
442 'short messages about their life and interests. '.
443 '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
444 $this->group->nickname);
446 $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
447 'based on the Free Software [Laconica](http://laconi.ca/) tool. Its members share ' .
448 'short messages about their life and interests. '),
449 $this->group->nickname);
451 $this->elementStart('div', array('id' => 'anon_notice'));
452 $this->raw(common_markup_to_html($m));
453 $this->elementEnd('div');
457 class GroupAdminSection extends ProfileSection
461 function __construct($out, $group)
463 parent::__construct($out);
464 $this->group = $group;
467 function getProfiles()
469 return $this->group->getAdmins();
479 return 'group_admins';