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', 81);
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
71 * @return string page title, with page number
76 if ($this->page == 1) {
77 return sprintf(_("%s group"), $this->group->nickname);
79 return sprintf(_("%s group, page %d"),
80 $this->group->nickname,
88 * Reads and validates arguments and instantiates the attributes.
90 * @param array $args $_REQUEST args
92 * @return boolean success flag
95 function prepare($args)
97 parent::prepare($args);
99 if (!common_config('inboxes','enabled')) {
100 $this->serverError(_('Inboxes must be enabled for groups to work'));
104 $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
106 $nickname_arg = $this->arg('nickname');
107 $nickname = common_canonical_nickname($nickname_arg);
109 // Permanent redirect on non-canonical nickname
111 if ($nickname_arg != $nickname) {
112 $args = array('nickname' => $nickname);
113 if ($this->page != 1) {
114 $args['page'] = $this->page;
116 common_redirect(common_local_url('showgroup', $args), 301);
121 $this->clientError(_('No nickname'), 404);
125 $this->group = User_group::staticGet('nickname', $nickname);
128 $this->clientError(_('No such group'), 404);
132 common_set_returnto($this->selfUrl());
140 * Shows a profile for the group, some controls, and a list of
146 function handle($args)
157 function showLocalNav()
159 $nav = new GroupNav($this, $this->group);
164 * Show the page content
166 * Shows a group profile and a list of group notices
169 function showContent()
171 $this->showGroupProfile();
172 $this->showGroupNotices();
176 * Show the group notices
181 function showGroupNotices()
183 $notice = $this->group->getNotices(($this->page-1)*NOTICES_PER_PAGE,
184 NOTICES_PER_PAGE + 1);
186 $nl = new NoticeList($notice, $this);
189 $this->pagination($this->page > 1,
190 $cnt > NOTICES_PER_PAGE,
193 array('nickname' => $this->group->nickname));
197 * Show the group profile
199 * Information about the group
204 function showGroupProfile()
206 $this->elementStart('div', 'entity_profile vcard author');
208 $this->element('h2', null, _('Group profile'));
210 $this->elementStart('dl', 'entity_depiction');
211 $this->element('dt', null, _('Avatar'));
212 $this->elementStart('dd');
214 $logo = ($this->group->homepage_logo) ?
215 $this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
217 $this->element('img', array('src' => $logo,
218 'class' => 'photo avatar',
219 'width' => AVATAR_PROFILE_SIZE,
220 'height' => AVATAR_PROFILE_SIZE,
221 'alt' => $this->group->nickname));
222 $this->elementEnd('dd');
223 $this->elementEnd('dl');
225 $this->elementStart('dl', 'entity_nickname');
226 $this->element('dt', null, _('Nickname'));
227 $this->elementStart('dd');
228 $hasFN = ($this->group->fullname) ? 'nickname url uid' : 'fn org nickname url uid';
229 $this->element('a', array('href' => $this->group->homeUrl(),
230 'rel' => 'me', 'class' => $hasFN),
231 $this->group->nickname);
232 $this->elementEnd('dd');
233 $this->elementEnd('dl');
235 if ($this->group->fullname) {
236 $this->elementStart('dl', 'entity_fn');
237 $this->element('dt', null, _('Full name'));
238 $this->elementStart('dd');
239 $this->element('span', 'fn org', $this->group->fullname);
240 $this->elementEnd('dd');
241 $this->elementEnd('dl');
244 if ($this->group->location) {
245 $this->elementStart('dl', 'entity_location');
246 $this->element('dt', null, _('Location'));
247 $this->element('dd', 'label', $this->group->location);
248 $this->elementEnd('dl');
251 if ($this->group->homepage) {
252 $this->elementStart('dl', 'entity_url');
253 $this->element('dt', null, _('URL'));
254 $this->elementStart('dd');
255 $this->element('a', array('href' => $this->group->homepage,
256 'rel' => 'me', 'class' => 'url'),
257 $this->group->homepage);
258 $this->elementEnd('dd');
259 $this->elementEnd('dl');
262 if ($this->group->description) {
263 $this->elementStart('dl', 'entity_note');
264 $this->element('dt', null, _('Note'));
265 $this->element('dd', 'note', $this->group->description);
266 $this->elementEnd('dl');
269 $this->elementEnd('div');
271 $this->elementStart('div', 'entity_actions');
272 $this->element('h2', null, _('Group actions'));
273 $this->elementStart('ul');
274 $this->elementStart('li', 'entity_subscribe');
275 $cur = common_current_user();
277 if ($cur->isMember($this->group)) {
278 if (!$cur->isAdmin($this->group)) {
279 $lf = new LeaveForm($this, $this->group);
283 $jf = new JoinForm($this, $this->group);
288 $this->elementEnd('li');
290 $this->elementEnd('ul');
291 $this->elementEnd('div');
295 * Get a list of the feeds for this page
303 common_local_url('grouprss',
304 array('nickname' => $this->group->nickname));
306 return array(new Feed(Feed::RSS1, $url, sprintf(_('Notice feed for %s group'),
307 $this->group->nickname)));
311 * Fill in the sidebar.
316 function showSections()
318 $this->showMembers();
319 $this->showStatistics();
320 $cloud = new GroupTagCloudSection($this, $this->group);
325 * Show mini-list of members
330 function showMembers()
332 $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
338 $this->elementStart('div', array('id' => 'entity_members',
339 'class' => 'section'));
341 $this->element('h2', null, _('Members'));
343 $pml = new ProfileMiniList($member, null, $this);
346 $this->element('p', null, _('(None)'));
349 if ($cnt == MEMBERS_PER_SECTION) {
350 $this->element('a', array('href' => common_local_url('groupmembers',
351 array('nickname' => $this->group->nickname))),
355 $this->elementEnd('div');
359 * Show some statistics
364 function showStatistics()
366 // XXX: WORM cache this
367 $members = $this->group->getMembers();
369 /** $member->count() doesn't work. */
370 while ($members->fetch()) {
374 $this->elementStart('div', array('id' => 'entity_statistics',
375 'class' => 'section'));
377 $this->element('h2', null, _('Statistics'));
379 $this->elementStart('dl', 'entity_created');
380 $this->element('dt', null, _('Created'));
381 $this->element('dd', null, date('j M Y',
382 strtotime($this->group->created)));
383 $this->elementEnd('dl');
385 $this->elementStart('dl', 'entity_members');
386 $this->element('dt', null, _('Members'));
387 $this->element('dd', null, (is_int($members_count)) ? $members_count : '0');
388 $this->elementEnd('dl');
390 $this->elementEnd('div');
393 function showAnonymousMessage()
395 $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
396 'based on the Free Software [Laconica](http://laconi.ca/) tool. Its members share ' .
397 'short messages about their life and interests. '.
398 '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
399 $this->group->nickname);
400 $this->elementStart('div', array('id' => 'anon_notice'));
401 $this->raw(common_markup_to_html($m));
402 $this->elementEnd('div');