]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showgroup.php
Merge branch 'mgrdcm-review' into 0.7.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 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($args)
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 (!empty($this->group->fullname)) {
77             $base = $this->group->fullname . ' (' . $this->group->nickname . ')';
78         } else {
79             $base = $this->group->nickname;
80         }
81
82         if ($this->page == 1) {
83             return sprintf(_("%s group"), $base);
84         } else {
85             return sprintf(_("%s group, page %d"),
86                            $base,
87                            $this->page);
88         }
89     }
90
91     /**
92      * Prepare the action
93      *
94      * Reads and validates arguments and instantiates the attributes.
95      *
96      * @param array $args $_REQUEST args
97      *
98      * @return boolean success flag
99      */
100
101     function prepare($args)
102     {
103         parent::prepare($args);
104
105         if (!common_config('inboxes','enabled')) {
106             $this->serverError(_('Inboxes must be enabled for groups to work'));
107             return false;
108         }
109
110         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
111
112         $nickname_arg = $this->arg('nickname');
113         $nickname = common_canonical_nickname($nickname_arg);
114
115         // Permanent redirect on non-canonical nickname
116
117         if ($nickname_arg != $nickname) {
118             $args = array('nickname' => $nickname);
119             if ($this->page != 1) {
120                 $args['page'] = $this->page;
121             }
122             common_redirect(common_local_url('showgroup', $args), 301);
123             return false;
124         }
125
126         if (!$nickname) {
127             $this->clientError(_('No nickname'), 404);
128             return false;
129         }
130
131         $this->group = User_group::staticGet('nickname', $nickname);
132
133         if (!$this->group) {
134             $this->clientError(_('No such group'), 404);
135             return false;
136         }
137
138         common_set_returnto($this->selfUrl());
139
140         return true;
141     }
142
143     /**
144      * Handle the request
145      *
146      * Shows a profile for the group, some controls, and a list of
147      * group notices.
148      *
149      * @return void
150      */
151
152     function handle($args)
153     {
154         $this->showPage();
155     }
156
157     /**
158      * Local menu
159      *
160      * @return void
161      */
162
163     function showLocalNav()
164     {
165         $nav = new GroupNav($this, $this->group);
166         $nav->show();
167     }
168
169     /**
170      * Show the page content
171      *
172      * Shows a group profile and a list of group notices
173      */
174
175     function showContent()
176     {
177         $this->showGroupProfile();
178         $this->showGroupNotices();
179     }
180
181     /**
182      * Show the group notices
183      *
184      * @return void
185      */
186
187     function showGroupNotices()
188     {
189         $notice = $this->group->getNotices(($this->page-1)*NOTICES_PER_PAGE,
190                                            NOTICES_PER_PAGE + 1);
191
192         $nl = new NoticeList($notice, $this);
193         $cnt = $nl->show();
194
195         $this->pagination($this->page > 1,
196                           $cnt > NOTICES_PER_PAGE,
197                           $this->page,
198                           'showgroup',
199                           array('nickname' => $this->group->nickname));
200     }
201
202     /**
203      * Show the group profile
204      *
205      * Information about the group
206      *
207      * @return void
208      */
209
210     function showGroupProfile()
211     {
212         $this->elementStart('div', 'entity_profile vcard author');
213
214         $this->element('h2', null, _('Group profile'));
215
216         $this->elementStart('dl', 'entity_depiction');
217         $this->element('dt', null, _('Avatar'));
218         $this->elementStart('dd');
219
220         $logo = ($this->group->homepage_logo) ?
221           $this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
222
223         $this->element('img', array('src' => $logo,
224                                     'class' => 'photo avatar',
225                                     'width' => AVATAR_PROFILE_SIZE,
226                                     'height' => AVATAR_PROFILE_SIZE,
227                                     'alt' => $this->group->nickname));
228         $this->elementEnd('dd');
229         $this->elementEnd('dl');
230
231         $this->elementStart('dl', 'entity_nickname');
232         $this->element('dt', null, _('Nickname'));
233         $this->elementStart('dd');
234         $hasFN = ($this->group->fullname) ? 'nickname url uid' : 'fn org nickname url uid';
235         $this->element('a', array('href' => $this->group->homeUrl(),
236                                   'rel' => 'me', 'class' => $hasFN),
237                             $this->group->nickname);
238         $this->elementEnd('dd');
239         $this->elementEnd('dl');
240
241         if ($this->group->fullname) {
242             $this->elementStart('dl', 'entity_fn');
243             $this->element('dt', null, _('Full name'));
244             $this->elementStart('dd');
245             $this->element('span', 'fn org', $this->group->fullname);
246             $this->elementEnd('dd');
247             $this->elementEnd('dl');
248         }
249
250         if ($this->group->location) {
251             $this->elementStart('dl', 'entity_location');
252             $this->element('dt', null, _('Location'));
253             $this->element('dd', 'label', $this->group->location);
254             $this->elementEnd('dl');
255         }
256
257         if ($this->group->homepage) {
258             $this->elementStart('dl', 'entity_url');
259             $this->element('dt', null, _('URL'));
260             $this->elementStart('dd');
261             $this->element('a', array('href' => $this->group->homepage,
262                                       'rel' => 'me', 'class' => 'url'),
263                            $this->group->homepage);
264             $this->elementEnd('dd');
265             $this->elementEnd('dl');
266         }
267
268         if ($this->group->description) {
269             $this->elementStart('dl', 'entity_note');
270             $this->element('dt', null, _('Note'));
271             $this->element('dd', 'note', $this->group->description);
272             $this->elementEnd('dl');
273         }
274
275         $this->elementEnd('div');
276
277         $this->elementStart('div', 'entity_actions');
278         $this->element('h2', null, _('Group actions'));
279         $this->elementStart('ul');
280         $this->elementStart('li', 'entity_subscribe');
281         $cur = common_current_user();
282         if ($cur) {
283             if ($cur->isMember($this->group)) {
284                 $lf = new LeaveForm($this, $this->group);
285                 $lf->show();
286             } else {
287                 $jf = new JoinForm($this, $this->group);
288                 $jf->show();
289             }
290         }
291
292         $this->elementEnd('li');
293
294         $this->elementEnd('ul');
295         $this->elementEnd('div');
296     }
297
298     /**
299      * Get a list of the feeds for this page
300      *
301      * @return void
302      */
303
304     function getFeeds()
305     {
306         $url =
307           common_local_url('grouprss',
308                            array('nickname' => $this->group->nickname));
309
310         return array(new Feed(Feed::RSS1, $url, sprintf(_('Notice feed for %s group'),
311                                                         $this->group->nickname)));
312     }
313
314     /**
315      * Fill in the sidebar.
316      *
317      * @return void
318      */
319
320     function showSections()
321     {
322         $this->showMembers();
323         $this->showStatistics();
324         $cloud = new GroupTagCloudSection($this, $this->group);
325         $cloud->show();
326     }
327
328     /**
329      * Show mini-list of members
330      *
331      * @return void
332      */
333
334     function showMembers()
335     {
336         $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
337
338         if (!$member) {
339             return;
340         }
341
342         $this->elementStart('div', array('id' => 'entity_members',
343                                          'class' => 'section'));
344
345         $this->element('h2', null, _('Members'));
346
347         $pml = new ProfileMiniList($member, null, $this);
348         $cnt = $pml->show();
349         if ($cnt == 0) {
350              $this->element('p', null, _('(None)'));
351         }
352
353         if ($cnt > MEMBERS_PER_SECTION) {
354             $this->element('a', array('href' => common_local_url('groupmembers',
355                                                                  array('nickname' => $this->group->nickname))),
356                            _('All members'));
357         }
358
359         $this->elementEnd('div');
360     }
361
362     /**
363      * Show some statistics
364      *
365      * @return void
366      */
367
368     function showStatistics()
369     {
370         // XXX: WORM cache this
371         $members = $this->group->getMembers();
372         $members_count = 0;
373         /** $member->count() doesn't work. */
374         while ($members->fetch()) {
375             $members_count++;
376         }
377
378         $this->elementStart('div', array('id' => 'entity_statistics',
379                                          'class' => 'section'));
380
381         $this->element('h2', null, _('Statistics'));
382
383         $this->elementStart('dl', 'entity_created');
384         $this->element('dt', null, _('Created'));
385         $this->element('dd', null, date('j M Y',
386                                                  strtotime($this->group->created)));
387         $this->elementEnd('dl');
388
389         $this->elementStart('dl', 'entity_members');
390         $this->element('dt', null, _('Members'));
391         $this->element('dd', null, (is_int($members_count)) ? $members_count : '0');
392         $this->elementEnd('dl');
393
394         $this->elementEnd('div');
395     }
396
397     function showAnonymousMessage()
398     {
399         if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
400             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
401                 'based on the Free Software [Laconica](http://laconi.ca/) tool. Its members share ' .
402                 'short messages about their life and interests. '.
403                 '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
404                      $this->group->nickname);
405         } else {
406             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
407                 'based on the Free Software [Laconica](http://laconi.ca/) tool. Its members share ' .
408                 'short messages about their life and interests. '),
409                      $this->group->nickname);
410         }
411         $this->elementStart('div', array('id' => 'anon_notice'));
412         $this->raw(common_markup_to_html($m));
413         $this->elementEnd('div');
414     }
415 }