]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showgroup.php
Merge branch '0.9.x' of git://gitorious.org/statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / actions / showgroup.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Group main page
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Group
23  * @package   StatusNet
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/
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/noticelist.php';
36 require_once INSTALLDIR.'/lib/feedlist.php';
37
38 define('MEMBERS_PER_SECTION', 27);
39
40 /**
41  * Group main page
42  *
43  * @category Group
44  * @package  StatusNet
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/
48  */
49
50 class ShowgroupAction extends GroupDesignAction
51 {
52
53     /** page we're viewing. */
54     var $page = null;
55
56     /**
57      * Is this page read-only?
58      *
59      * @return boolean true
60      */
61
62     function isReadOnly($args)
63     {
64         return true;
65     }
66
67     /**
68      * Title of the page
69      *
70      * @return string page title, with page number
71      */
72
73     function title()
74     {
75         if (!empty($this->group->fullname)) {
76             $base = $this->group->fullname . ' (' . $this->group->nickname . ')';
77         } else {
78             $base = $this->group->nickname;
79         }
80
81         if ($this->page == 1) {
82             return sprintf(_("%s group"), $base);
83         } else {
84             return sprintf(_("%s group, page %d"),
85                            $base,
86                            $this->page);
87         }
88     }
89
90     /**
91      * Prepare the action
92      *
93      * Reads and validates arguments and instantiates the attributes.
94      *
95      * @param array $args $_REQUEST args
96      *
97      * @return boolean success flag
98      */
99
100     function prepare($args)
101     {
102         parent::prepare($args);
103
104         if (!common_config('inboxes','enabled')) {
105             $this->serverError(_('Inboxes must be enabled for groups to work'));
106             return false;
107         }
108
109         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
110
111         $nickname_arg = $this->arg('nickname');
112         $nickname = common_canonical_nickname($nickname_arg);
113
114         // Permanent redirect on non-canonical nickname
115
116         if ($nickname_arg != $nickname) {
117             $args = array('nickname' => $nickname);
118             if ($this->page != 1) {
119                 $args['page'] = $this->page;
120             }
121             common_redirect(common_local_url('showgroup', $args), 301);
122             return false;
123         }
124
125         if (!$nickname) {
126             $this->clientError(_('No nickname'), 404);
127             return false;
128         }
129
130         $this->group = User_group::staticGet('nickname', $nickname);
131
132         if (!$this->group) {
133             $alias = Group_alias::staticGet('alias', $nickname);
134             if ($alias) {
135                 $args = array('id' => $alias->group_id);
136                 if ($this->page != 1) {
137                     $args['page'] = $this->page;
138                 }
139                 common_redirect(common_local_url('groupbyid', $args), 301);
140                 return false;
141             } else {
142                 $this->clientError(_('No such group'), 404);
143                 return false;
144             }
145         }
146
147         common_set_returnto($this->selfUrl());
148
149         return true;
150     }
151
152     /**
153      * Handle the request
154      *
155      * Shows a profile for the group, some controls, and a list of
156      * group notices.
157      *
158      * @return void
159      */
160
161     function handle($args)
162     {
163         $this->showPage();
164     }
165
166     /**
167      * Local menu
168      *
169      * @return void
170      */
171
172     function showLocalNav()
173     {
174         $nav = new GroupNav($this, $this->group);
175         $nav->show();
176     }
177
178     /**
179      * Show the page content
180      *
181      * Shows a group profile and a list of group notices
182      */
183
184     function showContent()
185     {
186         $this->showGroupProfile();
187         $this->showGroupNotices();
188     }
189
190     /**
191      * Show the group notices
192      *
193      * @return void
194      */
195
196     function showGroupNotices()
197     {
198         $notice = $this->group->getNotices(($this->page-1)*NOTICES_PER_PAGE,
199                                            NOTICES_PER_PAGE + 1);
200
201         $nl = new NoticeList($notice, $this);
202         $cnt = $nl->show();
203
204         $this->pagination($this->page > 1,
205                           $cnt > NOTICES_PER_PAGE,
206                           $this->page,
207                           'showgroup',
208                           array('nickname' => $this->group->nickname));
209     }
210
211     /**
212      * Show the group profile
213      *
214      * Information about the group
215      *
216      * @return void
217      */
218
219     function showGroupProfile()
220     {
221         $this->elementStart('div', 'entity_profile vcard author');
222
223         $this->element('h2', null, _('Group profile'));
224
225         $this->elementStart('dl', 'entity_depiction');
226         $this->element('dt', null, _('Avatar'));
227         $this->elementStart('dd');
228
229         $logo = ($this->group->homepage_logo) ?
230           $this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
231
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');
239
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');
249
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');
257         }
258
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');
264         }
265
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');
275         }
276
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');
282         }
283
284         if (common_config('group', 'maxaliases') > 0) {
285             $aliases = $this->group->getAliases();
286
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');
292             }
293         }
294
295         $this->elementEnd('div');
296
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();
302         if ($cur) {
303             if ($cur->isMember($this->group)) {
304                 $lf = new LeaveForm($this, $this->group);
305                 $lf->show();
306             } else if (!Group_block::isBlocked($this->group, $cur->getProfile())) {
307                 $jf = new JoinForm($this, $this->group);
308                 $jf->show();
309             }
310         }
311
312         $this->elementEnd('li');
313
314         $this->elementEnd('ul');
315         $this->elementEnd('div');
316     }
317
318     /**
319      * Get a list of the feeds for this page
320      *
321      * @return void
322      */
323
324     function getFeeds()
325     {
326         $url =
327           common_local_url('grouprss',
328                            array('nickname' => $this->group->nickname));
329
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)),
335                      new Feed(Feed::RSS2,
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)),
342                      new Feed(Feed::ATOM,
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)),
349                      new Feed(Feed::FOAF,
350                               common_local_url('foafgroup',
351                                                array('nickname' => $this->group->nickname)),
352                               sprintf(_('FOAF for %s group'),
353                                        $this->group->nickname)));
354     }
355
356     /**
357      * Fill in the sidebar.
358      *
359      * @return void
360      */
361
362     function showSections()
363     {
364         $this->showMembers();
365         $this->showStatistics();
366         $this->showAdmins();
367         $cloud = new GroupTagCloudSection($this, $this->group);
368         $cloud->show();
369     }
370
371     /**
372      * Show mini-list of members
373      *
374      * @return void
375      */
376
377     function showMembers()
378     {
379         $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
380
381         if (!$member) {
382             return;
383         }
384
385         $this->elementStart('div', array('id' => 'entity_members',
386                                          'class' => 'section'));
387
388         $this->element('h2', null, _('Members'));
389
390         $pml = new ProfileMiniList($member, $this);
391         $cnt = $pml->show();
392         if ($cnt == 0) {
393              $this->element('p', null, _('(None)'));
394         }
395
396         if ($cnt > MEMBERS_PER_SECTION) {
397             $this->element('a', array('href' => common_local_url('groupmembers',
398                                                                  array('nickname' => $this->group->nickname))),
399                            _('All members'));
400         }
401
402         $this->elementEnd('div');
403     }
404
405     /**
406      * Show list of admins
407      *
408      * @return void
409      */
410
411     function showAdmins()
412     {
413         $adminSection = new GroupAdminSection($this, $this->group);
414         $adminSection->show();
415     }
416
417     /**
418      * Show some statistics
419      *
420      * @return void
421      */
422
423     function showStatistics()
424     {
425         // XXX: WORM cache this
426         $members = $this->group->getMembers();
427         $members_count = 0;
428         /** $member->count() doesn't work. */
429         while ($members->fetch()) {
430             $members_count++;
431         }
432
433         $this->elementStart('div', array('id' => 'entity_statistics',
434                                          'class' => 'section'));
435
436         $this->element('h2', null, _('Statistics'));
437
438         $this->elementStart('dl', 'entity_created');
439         $this->element('dt', null, _('Created'));
440         $this->element('dd', null, date('j M Y',
441                                                  strtotime($this->group->created)));
442         $this->elementEnd('dl');
443
444         $this->elementStart('dl', 'entity_members');
445         $this->element('dt', null, _('Members'));
446         $this->element('dd', null, (is_int($members_count)) ? $members_count : '0');
447         $this->elementEnd('dl');
448
449         $this->elementEnd('div');
450     }
451
452     function showAnonymousMessage()
453     {
454         if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
455             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
456                 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
457                 'short messages about their life and interests. '.
458                 '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
459                      $this->group->nickname);
460         } else {
461             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
462                 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
463                 'short messages about their life and interests. '),
464                      $this->group->nickname);
465         }
466         $this->elementStart('div', array('id' => 'anon_notice'));
467         $this->raw(common_markup_to_html($m));
468         $this->elementEnd('div');
469     }
470 }
471
472 class GroupAdminSection extends ProfileSection
473 {
474     var $group;
475
476     function __construct($out, $group)
477     {
478         parent::__construct($out);
479         $this->group = $group;
480     }
481
482     function getProfiles()
483     {
484         return $this->group->getAdmins();
485     }
486
487     function title()
488     {
489         return _('Admins');
490     }
491
492     function divId()
493     {
494         return 'group_admins';
495     }
496
497     function moreUrl()
498     {
499         return null;
500     }
501 }