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 Action
52 /** group we're viewing. */
54 /** page we're viewing. */
58 * Is this page read-only?
60 * @return boolean true
63 function isReadOnly($args)
71 * @return string page title, with page number
76 if (!empty($this->group->fullname)) {
77 $base = $this->group->fullname . ' (' . $this->group->nickname . ')';
79 $base = $this->group->nickname;
82 if ($this->page == 1) {
83 return sprintf(_("%s group"), $base);
85 return sprintf(_("%s group, page %d"),
94 * Reads and validates arguments and instantiates the attributes.
96 * @param array $args $_REQUEST args
98 * @return boolean success flag
101 function prepare($args)
103 parent::prepare($args);
105 if (!common_config('inboxes','enabled')) {
106 $this->serverError(_('Inboxes must be enabled for groups to work'));
110 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
112 $nickname_arg = $this->arg('nickname');
113 $nickname = common_canonical_nickname($nickname_arg);
115 // Permanent redirect on non-canonical nickname
117 if ($nickname_arg != $nickname) {
118 $args = array('nickname' => $nickname);
119 if ($this->page != 1) {
120 $args['page'] = $this->page;
122 common_redirect(common_local_url('showgroup', $args), 301);
127 $this->clientError(_('No nickname'), 404);
131 $this->group = User_group::staticGet('nickname', $nickname);
134 $this->clientError(_('No such group'), 404);
138 common_set_returnto($this->selfUrl());
146 * Shows a profile for the group, some controls, and a list of
152 function handle($args)
163 function showLocalNav()
165 $nav = new GroupNav($this, $this->group);
170 * Show the page content
172 * Shows a group profile and a list of group notices
175 function showContent()
177 $this->showGroupProfile();
178 $this->showGroupNotices();
182 * Show the group notices
187 function showGroupNotices()
189 $notice = $this->group->getNotices(($this->page-1)*NOTICES_PER_PAGE,
190 NOTICES_PER_PAGE + 1);
192 $nl = new NoticeList($notice, $this);
195 $this->pagination($this->page > 1,
196 $cnt > NOTICES_PER_PAGE,
199 array('nickname' => $this->group->nickname));
203 * Show the group profile
205 * Information about the group
210 function showGroupProfile()
212 $this->elementStart('div', 'entity_profile vcard author');
214 $this->element('h2', null, _('Group profile'));
216 $this->elementStart('dl', 'entity_depiction');
217 $this->element('dt', null, _('Avatar'));
218 $this->elementStart('dd');
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',
225 'width' => AVATAR_PROFILE_SIZE,
226 'height' => AVATAR_PROFILE_SIZE,
227 'alt' => $this->group->nickname));
228 $this->elementEnd('dd');
229 $this->elementEnd('dl');
231 $this->elementStart('dl', 'entity_nickname');
232 $this->element('dt', null, _('Nickname'));
233 $this->elementStart('dd');
234 $hasFN = ($this->group->fullname) ? 'nickname url uid' : 'fn org nickname url uid';
235 $this->element('a', array('href' => $this->group->homeUrl(),
236 'rel' => 'me', 'class' => $hasFN),
237 $this->group->nickname);
238 $this->elementEnd('dd');
239 $this->elementEnd('dl');
241 if ($this->group->fullname) {
242 $this->elementStart('dl', 'entity_fn');
243 $this->element('dt', null, _('Full name'));
244 $this->elementStart('dd');
245 $this->element('span', 'fn org', $this->group->fullname);
246 $this->elementEnd('dd');
247 $this->elementEnd('dl');
250 if ($this->group->location) {
251 $this->elementStart('dl', 'entity_location');
252 $this->element('dt', null, _('Location'));
253 $this->element('dd', 'label', $this->group->location);
254 $this->elementEnd('dl');
257 if ($this->group->homepage) {
258 $this->elementStart('dl', 'entity_url');
259 $this->element('dt', null, _('URL'));
260 $this->elementStart('dd');
261 $this->element('a', array('href' => $this->group->homepage,
262 'rel' => 'me', 'class' => 'url'),
263 $this->group->homepage);
264 $this->elementEnd('dd');
265 $this->elementEnd('dl');
268 if ($this->group->description) {
269 $this->elementStart('dl', 'entity_note');
270 $this->element('dt', null, _('Note'));
271 $this->element('dd', 'note', $this->group->description);
272 $this->elementEnd('dl');
275 $this->elementEnd('div');
277 $this->elementStart('div', 'entity_actions');
278 $this->element('h2', null, _('Group actions'));
279 $this->elementStart('ul');
280 $this->elementStart('li', 'entity_subscribe');
281 $cur = common_current_user();
283 if ($cur->isMember($this->group)) {
284 $lf = new LeaveForm($this, $this->group);
287 $jf = new JoinForm($this, $this->group);
292 $this->elementEnd('li');
294 $this->elementEnd('ul');
295 $this->elementEnd('div');
299 * Get a list of the feeds for this page
307 common_local_url('grouprss',
308 array('nickname' => $this->group->nickname));
310 return array(new Feed(Feed::RSS1, $url, sprintf(_('Notice feed for %s group'),
311 $this->group->nickname)));
315 * Output document relationship links
319 function showRelationshipLinks()
321 $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME
322 $this->page, 'showgroup', array('nickname' => $this->group->nickname));
326 * Fill in the sidebar.
331 function showSections()
333 $this->showMembers();
334 $this->showStatistics();
335 $cloud = new GroupTagCloudSection($this, $this->group);
340 * Show mini-list of members
345 function showMembers()
347 $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
353 $this->elementStart('div', array('id' => 'entity_members',
354 'class' => 'section'));
356 $this->element('h2', null, _('Members'));
358 $pml = new ProfileMiniList($member, null, $this);
361 $this->element('p', null, _('(None)'));
364 if ($cnt > MEMBERS_PER_SECTION) {
365 $this->element('a', array('href' => common_local_url('groupmembers',
366 array('nickname' => $this->group->nickname))),
370 $this->elementEnd('div');
374 * Show some statistics
379 function showStatistics()
381 // XXX: WORM cache this
382 $members = $this->group->getMembers();
384 /** $member->count() doesn't work. */
385 while ($members->fetch()) {
389 $this->elementStart('div', array('id' => 'entity_statistics',
390 'class' => 'section'));
392 $this->element('h2', null, _('Statistics'));
394 $this->elementStart('dl', 'entity_created');
395 $this->element('dt', null, _('Created'));
396 $this->element('dd', null, date('j M Y',
397 strtotime($this->group->created)));
398 $this->elementEnd('dl');
400 $this->elementStart('dl', 'entity_members');
401 $this->element('dt', null, _('Members'));
402 $this->element('dd', null, (is_int($members_count)) ? $members_count : '0');
403 $this->elementEnd('dl');
405 $this->elementEnd('div');
408 function showAnonymousMessage()
410 if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
411 $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
412 'based on the Free Software [Laconica](http://laconi.ca/) tool. Its members share ' .
413 'short messages about their life and interests. '.
414 '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
415 $this->group->nickname);
417 $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
418 'based on the Free Software [Laconica](http://laconi.ca/) tool. Its members share ' .
419 'short messages about their life and interests. '),
420 $this->group->nickname);
422 $this->elementStart('div', array('id' => 'anon_notice'));
423 $this->raw(common_markup_to_html($m));
424 $this->elementEnd('div');