]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showgroup.php
Merge branch 'master' into 0.8.x
[quix0rs-gnu-social.git] / actions / showgroup.php
1 <?php
2 /**
3  * Laconica, 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   Laconica
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/
29  */
30
31 if (!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  Laconica
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/
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             $this->clientError(_('No such group'), 404);
134             return false;
135         }
136
137         common_set_returnto($this->selfUrl());
138
139         return true;
140     }
141
142     /**
143      * Handle the request
144      *
145      * Shows a profile for the group, some controls, and a list of
146      * group notices.
147      *
148      * @return void
149      */
150
151     function handle($args)
152     {
153         $this->showPage();
154     }
155
156     /**
157      * Local menu
158      *
159      * @return void
160      */
161
162     function showLocalNav()
163     {
164         $nav = new GroupNav($this, $this->group);
165         $nav->show();
166     }
167
168     /**
169      * Show the page content
170      *
171      * Shows a group profile and a list of group notices
172      */
173
174     function showContent()
175     {
176         $this->showGroupProfile();
177         $this->showGroupNotices();
178     }
179
180     /**
181      * Show the group notices
182      *
183      * @return void
184      */
185
186     function showGroupNotices()
187     {
188         $notice = $this->group->getNotices(($this->page-1)*NOTICES_PER_PAGE,
189                                            NOTICES_PER_PAGE + 1);
190
191         $nl = new NoticeList($notice, $this);
192         $cnt = $nl->show();
193
194         $this->pagination($this->page > 1,
195                           $cnt > NOTICES_PER_PAGE,
196                           $this->page,
197                           'showgroup',
198                           array('nickname' => $this->group->nickname));
199     }
200
201     /**
202      * Show the group profile
203      *
204      * Information about the group
205      *
206      * @return void
207      */
208
209     function showGroupProfile()
210     {
211         $this->elementStart('div', 'entity_profile vcard author');
212
213         $this->element('h2', null, _('Group profile'));
214
215         $this->elementStart('dl', 'entity_depiction');
216         $this->element('dt', null, _('Avatar'));
217         $this->elementStart('dd');
218
219         $logo = ($this->group->homepage_logo) ?
220           $this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
221
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');
229
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');
239
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');
247         }
248
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');
254         }
255
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');
265         }
266
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');
272         }
273
274         if (common_config('group', 'maxaliases') > 0) {
275             $aliases = $this->group->getAliases();
276
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');
282             }
283         }
284
285         $this->elementEnd('div');
286
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();
292         if ($cur) {
293             if ($cur->isMember($this->group)) {
294                 $lf = new LeaveForm($this, $this->group);
295                 $lf->show();
296             } else if (!Group_block::isBlocked($this->group, $cur->getProfile())) {
297                 $jf = new JoinForm($this, $this->group);
298                 $jf->show();
299             }
300         }
301
302         $this->elementEnd('li');
303
304         $this->elementEnd('ul');
305         $this->elementEnd('div');
306     }
307
308     /**
309      * Get a list of the feeds for this page
310      *
311      * @return void
312      */
313
314     function getFeeds()
315     {
316         $url =
317           common_local_url('grouprss',
318                            array('nickname' => $this->group->nickname));
319
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)),
325                      new Feed(Feed::RSS2,
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)),
332                      new Feed(Feed::ATOM,
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)));
339     }
340
341     /**
342      * Fill in the sidebar.
343      *
344      * @return void
345      */
346
347     function showSections()
348     {
349         $this->showMembers();
350         $this->showStatistics();
351         $this->showAdmins();
352         $cloud = new GroupTagCloudSection($this, $this->group);
353         $cloud->show();
354     }
355
356     /**
357      * Show mini-list of members
358      *
359      * @return void
360      */
361
362     function showMembers()
363     {
364         $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
365
366         if (!$member) {
367             return;
368         }
369
370         $this->elementStart('div', array('id' => 'entity_members',
371                                          'class' => 'section'));
372
373         $this->element('h2', null, _('Members'));
374
375         $pml = new ProfileMiniList($member, $this);
376         $cnt = $pml->show();
377         if ($cnt == 0) {
378              $this->element('p', null, _('(None)'));
379         }
380
381         if ($cnt > MEMBERS_PER_SECTION) {
382             $this->element('a', array('href' => common_local_url('groupmembers',
383                                                                  array('nickname' => $this->group->nickname))),
384                            _('All members'));
385         }
386
387         $this->elementEnd('div');
388     }
389
390     /**
391      * Show list of admins
392      *
393      * @return void
394      */
395
396     function showAdmins()
397     {
398         $adminSection = new GroupAdminSection($this, $this->group);
399         $adminSection->show();
400     }
401
402     /**
403      * Show some statistics
404      *
405      * @return void
406      */
407
408     function showStatistics()
409     {
410         // XXX: WORM cache this
411         $members = $this->group->getMembers();
412         $members_count = 0;
413         /** $member->count() doesn't work. */
414         while ($members->fetch()) {
415             $members_count++;
416         }
417
418         $this->elementStart('div', array('id' => 'entity_statistics',
419                                          'class' => 'section'));
420
421         $this->element('h2', null, _('Statistics'));
422
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');
428
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');
433
434         $this->elementEnd('div');
435     }
436
437     function showAnonymousMessage()
438     {
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.%s%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
444                      $this->group->nickname,
445                      (!common_config('site','openidonly')) ? 'register' : 'openidlogin');
446         } else {
447             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
448                 'based on the Free Software [Laconica](http://laconi.ca/) tool. Its members share ' .
449                 'short messages about their life and interests. '),
450                      $this->group->nickname);
451         }
452         $this->elementStart('div', array('id' => 'anon_notice'));
453         $this->raw(common_markup_to_html($m));
454         $this->elementEnd('div');
455     }
456 }
457
458 class GroupAdminSection extends ProfileSection
459 {
460     var $group;
461
462     function __construct($out, $group)
463     {
464         parent::__construct($out);
465         $this->group = $group;
466     }
467
468     function getProfiles()
469     {
470         return $this->group->getAdmins();
471     }
472
473     function title()
474     {
475         return _('Admins');
476     }
477
478     function divId()
479     {
480         return 'group_admins';
481     }
482
483     function moreUrl()
484     {
485         return null;
486     }
487 }