]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showgroup.php
Merge commit 'br3nda/0.8.x-noticesfix' 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, $url, sprintf(_('Notice feed for %s group'),
321                                                         $this->group->nickname)));
322     }
323
324     /**
325      * Fill in the sidebar.
326      *
327      * @return void
328      */
329
330     function showSections()
331     {
332         $this->showMembers();
333         $this->showStatistics();
334         $this->showAdmins();
335         $cloud = new GroupTagCloudSection($this, $this->group);
336         $cloud->show();
337     }
338
339     /**
340      * Show mini-list of members
341      *
342      * @return void
343      */
344
345     function showMembers()
346     {
347         $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
348
349         if (!$member) {
350             return;
351         }
352
353         $this->elementStart('div', array('id' => 'entity_members',
354                                          'class' => 'section'));
355
356         $this->element('h2', null, _('Members'));
357
358         $pml = new ProfileMiniList($member, $this);
359         $cnt = $pml->show();
360         if ($cnt == 0) {
361              $this->element('p', null, _('(None)'));
362         }
363
364         if ($cnt > MEMBERS_PER_SECTION) {
365             $this->element('a', array('href' => common_local_url('groupmembers',
366                                                                  array('nickname' => $this->group->nickname))),
367                            _('All members'));
368         }
369
370         $this->elementEnd('div');
371     }
372
373     /**
374      * Show list of admins
375      *
376      * @return void
377      */
378
379     function showAdmins()
380     {
381         $adminSection = new GroupAdminSection($this, $this->group);
382         $adminSection->show();
383     }
384
385     /**
386      * Show some statistics
387      *
388      * @return void
389      */
390
391     function showStatistics()
392     {
393         // XXX: WORM cache this
394         $members = $this->group->getMembers();
395         $members_count = 0;
396         /** $member->count() doesn't work. */
397         while ($members->fetch()) {
398             $members_count++;
399         }
400
401         $this->elementStart('div', array('id' => 'entity_statistics',
402                                          'class' => 'section'));
403
404         $this->element('h2', null, _('Statistics'));
405
406         $this->elementStart('dl', 'entity_created');
407         $this->element('dt', null, _('Created'));
408         $this->element('dd', null, date('j M Y',
409                                                  strtotime($this->group->created)));
410         $this->elementEnd('dl');
411
412         $this->elementStart('dl', 'entity_members');
413         $this->element('dt', null, _('Members'));
414         $this->element('dd', null, (is_int($members_count)) ? $members_count : '0');
415         $this->elementEnd('dl');
416
417         $this->elementEnd('div');
418     }
419
420     function showAnonymousMessage()
421     {
422         if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
423             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
424                 'based on the Free Software [Laconica](http://laconi.ca/) tool. Its members share ' .
425                 'short messages about their life and interests. '.
426                 '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
427                      $this->group->nickname);
428         } else {
429             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
430                 'based on the Free Software [Laconica](http://laconi.ca/) tool. Its members share ' .
431                 'short messages about their life and interests. '),
432                      $this->group->nickname);
433         }
434         $this->elementStart('div', array('id' => 'anon_notice'));
435         $this->raw(common_markup_to_html($m));
436         $this->elementEnd('div');
437     }
438 }
439
440 class GroupAdminSection extends ProfileSection
441 {
442     var $group;
443
444     function __construct($out, $group)
445     {
446         parent::__construct($out);
447         $this->group = $group;
448     }
449
450     function getProfiles()
451     {
452         return $this->group->getAdmins();
453     }
454
455     function title()
456     {
457         return _('Admins');
458     }
459
460     function divId()
461     {
462         return 'group_admins';
463     }
464
465     function moreUrl()
466     {
467         return null;
468     }
469 }