]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showgroup.php
Merge branch '0.9.x' into TwitterBridgePlugin
[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         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
105
106         $nickname_arg = $this->arg('nickname');
107         $nickname = common_canonical_nickname($nickname_arg);
108
109         // Permanent redirect on non-canonical nickname
110
111         if ($nickname_arg != $nickname) {
112             $args = array('nickname' => $nickname);
113             if ($this->page != 1) {
114                 $args['page'] = $this->page;
115             }
116             common_redirect(common_local_url('showgroup', $args), 301);
117             return false;
118         }
119
120         if (!$nickname) {
121             $this->clientError(_('No nickname'), 404);
122             return false;
123         }
124
125         $this->group = User_group::staticGet('nickname', $nickname);
126
127         if (!$this->group) {
128             $alias = Group_alias::staticGet('alias', $nickname);
129             if ($alias) {
130                 $args = array('id' => $alias->group_id);
131                 if ($this->page != 1) {
132                     $args['page'] = $this->page;
133                 }
134                 common_redirect(common_local_url('groupbyid', $args), 301);
135                 return false;
136             } else {
137                 $this->clientError(_('No such group'), 404);
138                 return false;
139             }
140         }
141
142         common_set_returnto($this->selfUrl());
143
144         return true;
145     }
146
147     /**
148      * Handle the request
149      *
150      * Shows a profile for the group, some controls, and a list of
151      * group notices.
152      *
153      * @return void
154      */
155
156     function handle($args)
157     {
158         $this->showPage();
159     }
160
161     /**
162      * Local menu
163      *
164      * @return void
165      */
166
167     function showLocalNav()
168     {
169         $nav = new GroupNav($this, $this->group);
170         $nav->show();
171     }
172
173     /**
174      * Show the page content
175      *
176      * Shows a group profile and a list of group notices
177      */
178
179     function showContent()
180     {
181         $this->showGroupProfile();
182         $this->showGroupNotices();
183     }
184
185     /**
186      * Show the group notices
187      *
188      * @return void
189      */
190
191     function showGroupNotices()
192     {
193         $notice = $this->group->getNotices(($this->page-1)*NOTICES_PER_PAGE,
194                                            NOTICES_PER_PAGE + 1);
195
196         $nl = new NoticeList($notice, $this);
197         $cnt = $nl->show();
198
199         $this->pagination($this->page > 1,
200                           $cnt > NOTICES_PER_PAGE,
201                           $this->page,
202                           'showgroup',
203                           array('nickname' => $this->group->nickname));
204     }
205
206     /**
207      * Show the group profile
208      *
209      * Information about the group
210      *
211      * @return void
212      */
213
214     function showGroupProfile()
215     {
216         $this->elementStart('div', 'entity_profile vcard author');
217
218         $this->element('h2', null, _('Group profile'));
219
220         $this->elementStart('dl', 'entity_depiction');
221         $this->element('dt', null, _('Avatar'));
222         $this->elementStart('dd');
223
224         $logo = ($this->group->homepage_logo) ?
225           $this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
226
227         $this->element('img', array('src' => $logo,
228                                     'class' => 'photo avatar',
229                                     'width' => AVATAR_PROFILE_SIZE,
230                                     'height' => AVATAR_PROFILE_SIZE,
231                                     'alt' => $this->group->nickname));
232         $this->elementEnd('dd');
233         $this->elementEnd('dl');
234
235         $this->elementStart('dl', 'entity_nickname');
236         $this->element('dt', null, _('Nickname'));
237         $this->elementStart('dd');
238         $hasFN = ($this->group->fullname) ? 'nickname url uid' : 'fn org nickname url uid';
239         $this->element('a', array('href' => $this->group->homeUrl(),
240                                   'rel' => 'me', 'class' => $hasFN),
241                             $this->group->nickname);
242         $this->elementEnd('dd');
243         $this->elementEnd('dl');
244
245         if ($this->group->fullname) {
246             $this->elementStart('dl', 'entity_fn');
247             $this->element('dt', null, _('Full name'));
248             $this->elementStart('dd');
249             $this->element('span', 'fn org', $this->group->fullname);
250             $this->elementEnd('dd');
251             $this->elementEnd('dl');
252         }
253
254         if ($this->group->location) {
255             $this->elementStart('dl', 'entity_location');
256             $this->element('dt', null, _('Location'));
257             $this->element('dd', 'label', $this->group->location);
258             $this->elementEnd('dl');
259         }
260
261         if ($this->group->homepage) {
262             $this->elementStart('dl', 'entity_url');
263             $this->element('dt', null, _('URL'));
264             $this->elementStart('dd');
265             $this->element('a', array('href' => $this->group->homepage,
266                                       'rel' => 'me', 'class' => 'url'),
267                            $this->group->homepage);
268             $this->elementEnd('dd');
269             $this->elementEnd('dl');
270         }
271
272         if ($this->group->description) {
273             $this->elementStart('dl', 'entity_note');
274             $this->element('dt', null, _('Note'));
275             $this->element('dd', 'note', $this->group->description);
276             $this->elementEnd('dl');
277         }
278
279         if (common_config('group', 'maxaliases') > 0) {
280             $aliases = $this->group->getAliases();
281
282             if (!empty($aliases)) {
283                 $this->elementStart('dl', 'entity_aliases');
284                 $this->element('dt', null, _('Aliases'));
285                 $this->element('dd', 'aliases', implode(' ', $aliases));
286                 $this->elementEnd('dl');
287             }
288         }
289
290         $this->elementEnd('div');
291
292         $this->elementStart('div', 'entity_actions');
293         $this->element('h2', null, _('Group actions'));
294         $this->elementStart('ul');
295         $this->elementStart('li', 'entity_subscribe');
296         $cur = common_current_user();
297         if ($cur) {
298             if ($cur->isMember($this->group)) {
299                 $lf = new LeaveForm($this, $this->group);
300                 $lf->show();
301             } else if (!Group_block::isBlocked($this->group, $cur->getProfile())) {
302                 $jf = new JoinForm($this, $this->group);
303                 $jf->show();
304             }
305         }
306
307         $this->elementEnd('li');
308
309         $this->elementEnd('ul');
310         $this->elementEnd('div');
311     }
312
313     /**
314      * Get a list of the feeds for this page
315      *
316      * @return void
317      */
318
319     function getFeeds()
320     {
321         $url =
322           common_local_url('grouprss',
323                            array('nickname' => $this->group->nickname));
324
325         return array(new Feed(Feed::RSS1,
326                               common_local_url('grouprss',
327                                                array('nickname' => $this->group->nickname)),
328                               sprintf(_('Notice feed for %s group (RSS 1.0)'),
329                                       $this->group->nickname)),
330                      new Feed(Feed::RSS2,
331                               common_local_url('api',
332                                                array('apiaction' => 'groups',
333                                                      'method' => 'timeline',
334                                                      'argument' => $this->group->nickname.'.rss')),
335                               sprintf(_('Notice feed for %s group (RSS 2.0)'),
336                                       $this->group->nickname)),
337                      new Feed(Feed::ATOM,
338                               common_local_url('api',
339                                                array('apiaction' => 'groups',
340                                                      'method' => 'timeline',
341                                                      'argument' => $this->group->nickname.'.atom')),
342                               sprintf(_('Notice feed for %s group (Atom)'),
343                                       $this->group->nickname)),
344                      new Feed(Feed::FOAF,
345                               common_local_url('foafgroup',
346                                                array('nickname' => $this->group->nickname)),
347                               sprintf(_('FOAF for %s group'),
348                                        $this->group->nickname)));
349     }
350
351     /**
352      * Fill in the sidebar.
353      *
354      * @return void
355      */
356
357     function showSections()
358     {
359         $this->showMembers();
360         $this->showStatistics();
361         $this->showAdmins();
362         $cloud = new GroupTagCloudSection($this, $this->group);
363         $cloud->show();
364     }
365
366     /**
367      * Show mini-list of members
368      *
369      * @return void
370      */
371
372     function showMembers()
373     {
374         $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
375
376         if (!$member) {
377             return;
378         }
379
380         $this->elementStart('div', array('id' => 'entity_members',
381                                          'class' => 'section'));
382
383         $this->element('h2', null, _('Members'));
384
385         $pml = new ProfileMiniList($member, $this);
386         $cnt = $pml->show();
387         if ($cnt == 0) {
388              $this->element('p', null, _('(None)'));
389         }
390
391         if ($cnt > MEMBERS_PER_SECTION) {
392             $this->element('a', array('href' => common_local_url('groupmembers',
393                                                                  array('nickname' => $this->group->nickname))),
394                            _('All members'));
395         }
396
397         $this->elementEnd('div');
398     }
399
400     /**
401      * Show list of admins
402      *
403      * @return void
404      */
405
406     function showAdmins()
407     {
408         $adminSection = new GroupAdminSection($this, $this->group);
409         $adminSection->show();
410     }
411
412     /**
413      * Show some statistics
414      *
415      * @return void
416      */
417
418     function showStatistics()
419     {
420         // XXX: WORM cache this
421         $members = $this->group->getMembers();
422         $members_count = 0;
423         /** $member->count() doesn't work. */
424         while ($members->fetch()) {
425             $members_count++;
426         }
427
428         $this->elementStart('div', array('id' => 'entity_statistics',
429                                          'class' => 'section'));
430
431         $this->element('h2', null, _('Statistics'));
432
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');
438
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');
443
444         $this->elementEnd('div');
445     }
446
447     function showAnonymousMessage()
448     {
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.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
454                      $this->group->nickname);
455         } else {
456             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
457                 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
458                 'short messages about their life and interests. '),
459                      $this->group->nickname);
460         }
461         $this->elementStart('div', array('id' => 'anon_notice'));
462         $this->raw(common_markup_to_html($m));
463         $this->elementEnd('div');
464     }
465 }
466
467 class GroupAdminSection extends ProfileSection
468 {
469     var $group;
470
471     function __construct($out, $group)
472     {
473         parent::__construct($out);
474         $this->group = $group;
475     }
476
477     function getProfiles()
478     {
479         return $this->group->getAdmins();
480     }
481
482     function title()
483     {
484         return _('Admins');
485     }
486
487     function divId()
488     {
489         return 'group_admins';
490     }
491
492     function moreUrl()
493     {
494         return null;
495     }
496 }