]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showgroup.php
7599a8de6ebb62ec10026aea1fb9e9129a0e3b89
[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', 81);
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 Action
51 {
52     /** group we're viewing. */
53     var $group = null;
54     /** page we're viewing. */
55     var $page = null;
56
57     /**
58      * Is this page read-only?
59      *
60      * @return boolean true
61      */
62
63     function isReadOnly()
64     {
65         return true;
66     }
67
68     /**
69      * Title of the page
70      *
71      * @return string page title, with page number
72      */
73
74     function title()
75     {
76         if ($this->page == 1) {
77             return sprintf(_("%s group"), $this->group->nickname);
78         } else {
79             return sprintf(_("%s group, page %d"),
80                            $this->group->nickname,
81                            $this->page);
82         }
83     }
84
85     /**
86      * Prepare the action
87      *
88      * Reads and validates arguments and instantiates the attributes.
89      *
90      * @param array $args $_REQUEST args
91      *
92      * @return boolean success flag
93      */
94
95     function prepare($args)
96     {
97         parent::prepare($args);
98
99         if (!common_config('inboxes','enabled')) {
100             $this->serverError(_('Inboxes must be enabled for groups to work'));
101             return false;
102         }
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             $this->clientError(_('No such group'), 404);
129             return false;
130         }
131
132         common_set_returnto($this->selfUrl());
133
134         return true;
135     }
136
137     /**
138      * Handle the request
139      *
140      * Shows a profile for the group, some controls, and a list of
141      * group notices.
142      *
143      * @return void
144      */
145
146     function handle($args)
147     {
148         $this->showPage();
149     }
150
151     /**
152      * Local menu
153      *
154      * @return void
155      */
156
157     function showLocalNav()
158     {
159         $nav = new GroupNav($this, $this->group);
160         $nav->show();
161     }
162
163     /**
164      * Show the page content
165      *
166      * Shows a group profile and a list of group notices
167      */
168
169     function showContent()
170     {
171         $this->showGroupProfile();
172         $this->showGroupNotices();
173     }
174
175     /**
176      * Show the group notices
177      *
178      * @return void
179      */
180
181     function showGroupNotices()
182     {
183         $notice = $this->group->getNotices(($this->page-1)*NOTICES_PER_PAGE,
184                                            NOTICES_PER_PAGE + 1);
185
186         $nl = new NoticeList($notice, $this);
187         $cnt = $nl->show();
188
189         $this->pagination($this->page > 1,
190                           $cnt > NOTICES_PER_PAGE,
191                           $this->page,
192                           'showgroup',
193                           array('nickname' => $this->group->nickname));
194     }
195
196     /**
197      * Show the group profile
198      *
199      * Information about the group
200      *
201      * @return void
202      */
203
204     function showGroupProfile()
205     {
206         $this->elementStart('div', 'entity_profile vcard author');
207
208         $this->element('h2', null, _('Group profile'));
209
210         $this->elementStart('dl', 'entity_depiction');
211         $this->element('dt', null, _('Avatar'));
212         $this->elementStart('dd');
213
214         $logo = ($this->group->homepage_logo) ?
215           $this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
216
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');
224
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');
234
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');
242         }
243
244         if ($this->group->location) {
245             $this->elementStart('dl', 'entity_location');
246             $this->element('dt', null, _('Location'));
247             $this->element('dd', 'location', $this->group->location);
248             $this->elementEnd('dl');
249         }
250
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');
260         }
261
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');
267         }
268
269         $this->elementEnd('div');
270
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();
276         if ($cur) {
277             if ($cur->isMember($this->group)) {
278                 if (!$cur->isAdmin($this->group)) {
279                     $lf = new LeaveForm($this, $this->group);
280                     $lf->show();
281                 }
282             } else {
283                 $jf = new JoinForm($this, $this->group);
284                 $jf->show();
285             }
286         }
287
288         $this->elementEnd('li');
289
290         $this->elementEnd('ul');
291         $this->elementEnd('div');
292     }
293
294     /**
295      * Show a list of links to feeds this page produces
296      *
297      * @return void
298      */
299
300     function showExportData()
301     {
302         $fl = new FeedList($this);
303         $fl->show(array(0=>array('href'=>common_local_url('grouprss',
304                                                           array('nickname' => $this->group->nickname)),
305                                  'type' => 'rss',
306                                  'version' => 'RSS 1.0',
307                                  'item' => 'notices')));
308     }
309
310     /**
311      * Show a list of links to feeds this page produces
312      *
313      * @return void
314      */
315
316     function showFeeds()
317     {
318         $url =
319           common_local_url('grouprss',
320                            array('nickname' => $this->group->nickname));
321
322         $this->element('link', array('rel' => 'alternate',
323                                      'href' => $url,
324                                      'type' => 'application/rss+xml',
325                                      'title' => sprintf(_('Notice feed for %s group'),
326                                                         $this->group->nickname)));
327     }
328
329     /**
330      * Output document relationship links
331      *
332      * @return void
333      */
334     function showRelationshipLinks()
335     {
336         // Machine-readable pagination
337         if ($this->page > 1) {
338             $this->element('link', array('rel' => 'next',
339                                          'href' => common_local_url('showgroup',
340                                                                     array('nickname' => $this->group->nickname,
341                                                                           'page' => $this->page - 1)),
342                                          'title' => _('Next Notices')));
343         }
344         $this->element('link', array('rel' => 'prev',
345                                      'href' => common_local_url('showgroup',
346                                                                 array('nickname' => $this->group->nickname,
347                                                                       'page' => $this->page + 1)),
348                                      'title' => _('Previous Notices')));
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         $cloud = new GroupTagCloudSection($this, $this->group);
362         $cloud->show();
363     }
364
365     /**
366      * Show mini-list of members
367      *
368      * @return void
369      */
370
371     function showMembers()
372     {
373         $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
374
375         if (!$member) {
376             return;
377         }
378
379         $this->elementStart('div', array('id' => 'entity_members',
380                                          'class' => 'section'));
381
382         $this->element('h2', null, _('Members'));
383
384         $pml = new ProfileMiniList($member, null, $this);
385         $cnt = $pml->show();
386         if ($cnt == 0) {
387              $this->element('p', null, _('(None)'));
388         }
389
390         if ($cnt == MEMBERS_PER_SECTION) {
391             $this->element('a', array('href' => common_local_url('groupmembers',
392                                                                  array('nickname' => $this->group->nickname))),
393                            _('All members'));
394         }
395
396         $this->elementEnd('div');
397     }
398
399     /**
400      * Show some statistics
401      *
402      * @return void
403      */
404
405     function showStatistics()
406     {
407         // XXX: WORM cache this
408         $members = $this->group->getMembers();
409         $members_count = 0;
410         /** $member->count() doesn't work. */
411         while ($members->fetch()) {
412             $members_count++;
413         }
414
415         $this->elementStart('div', array('id' => 'entity_statistics',
416                                          'class' => 'section'));
417
418         $this->element('h2', null, _('Statistics'));
419
420         $this->elementStart('dl', 'entity_created');
421         $this->element('dt', null, _('Created'));
422         $this->element('dd', null, date('j M Y',
423                                                  strtotime($this->group->created)));
424         $this->elementEnd('dl');
425
426         $this->elementStart('dl', 'entity_members');
427         $this->element('dt', null, _('Members'));
428         $this->element('dd', null, (is_int($members_count)) ? $members_count : '0');
429         $this->elementEnd('dl');
430
431         $this->elementEnd('div');
432     }
433
434     function showAnonymousMessage()
435     {
436                 $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
437                        'based on the Free Software [Laconica](http://laconi.ca/) tool. Its members share ' .
438                        'short messages about their life and interests. '.
439                        '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
440                      $this->group->nickname);
441         $this->elementStart('div', array('id' => 'anon_notice'));
442         $this->raw(common_markup_to_html($m));
443         $this->elementEnd('div');
444     }
445 }