]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showgroup.php
c2cd3d295956c2bcc323508409691a301a9db397
[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         return true;
133     }
134
135     /**
136      * Handle the request
137      *
138      * Shows a profile for the group, some controls, and a list of
139      * group notices.
140      *
141      * @return void
142      */
143
144     function handle($args)
145     {
146         $this->showPage();
147     }
148
149     function showLocalNav()
150     {
151         $nav = new GroupNav($this, $this->group);
152         $nav->show();
153     }
154
155     /**
156      * Show the page content
157      *
158      * Shows a group profile and a list of group notices
159      */
160
161     function showContent()
162     {
163         $this->showGroupProfile();
164         $this->showGroupNotices();
165     }
166
167     /**
168      * Show the group notices
169      *
170      * @return void
171      */
172
173     function showGroupNotices()
174     {
175         $notice = $this->group->getNotices(($this->page-1)*NOTICES_PER_PAGE,
176                                            NOTICES_PER_PAGE + 1);
177
178         $nl = new NoticeList($notice, $this);
179         $cnt = $nl->show();
180
181         $this->pagination($this->page > 1,
182                           $cnt > NOTICES_PER_PAGE,
183                           $this->page,
184                           'showgroup',
185                           array('nickname' => $this->group->nickname));
186     }
187
188     /**
189      * Show the group profile
190      *
191      * Information about the group
192      *
193      * @return void
194      */
195
196     function showGroupProfile()
197     {
198         $this->elementStart('div', array('id' => 'group_profile',
199                                          'class' => 'vcard author'));
200
201         $this->element('h2', null, _('Group profile'));
202
203         $this->elementStart('dl', 'group_depiction');
204         $this->element('dt', null, _('Photo'));
205         $this->elementStart('dd');
206
207         $logo = ($this->group->homepage_logo) ?
208           $this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
209
210         $this->element('img', array('src' => $logo,
211                                     'class' => 'photo avatar',
212                                     'width' => AVATAR_PROFILE_SIZE,
213                                     'height' => AVATAR_PROFILE_SIZE,
214                                     'alt' => $this->group->nickname));
215         $this->elementEnd('dd');
216         $this->elementEnd('dl');
217
218         $this->elementStart('dl', 'group_nickname');
219         $this->element('dt', null, _('Nickname'));
220         $this->elementStart('dd');
221         $hasFN = ($this->group->fullname) ? 'nickname url uid' : 'fn nickname url uid';
222         $this->element('a', array('href' => $this->group->homeUrl(),
223                                   'rel' => 'me', 'class' => $hasFN),
224                             $this->group->nickname);
225         $this->elementEnd('dd');
226         $this->elementEnd('dl');
227
228         if ($this->group->fullname) {
229             $this->elementStart('dl', 'group_fn');
230             $this->element('dt', null, _('Full name'));
231             $this->elementStart('dd');
232             $this->element('span', 'fn', $this->group->fullname);
233             $this->elementEnd('dd');
234             $this->elementEnd('dl');
235         }
236
237         if ($this->group->location) {
238             $this->elementStart('dl', 'group_location');
239             $this->element('dt', null, _('Location'));
240             $this->element('dd', 'location', $this->group->location);
241             $this->elementEnd('dl');
242         }
243
244         if ($this->group->homepage) {
245             $this->elementStart('dl', 'group_url');
246             $this->element('dt', null, _('URL'));
247             $this->elementStart('dd');
248             $this->element('a', array('href' => $this->group->homepage,
249                                       'rel' => 'me', 'class' => 'url'),
250                            $this->group->homepage);
251             $this->elementEnd('dd');
252             $this->elementEnd('dl');
253         }
254
255         if ($this->group->description) {
256             $this->elementStart('dl', 'group_note');
257             $this->element('dt', null, _('Note'));
258             $this->element('dd', 'note', $this->group->description);
259             $this->elementEnd('dl');
260         }
261
262         $this->elementEnd('div');
263
264         $this->elementStart('div', array('id' => 'group_actions'));
265         $this->element('h2', null, _('Group actions'));
266         $this->elementStart('ul');
267         $this->elementStart('li', array('id' => 'group_subscribe'));
268         $cur = common_current_user();
269         if ($cur) {
270             if ($cur->isMember($this->group)) {
271                 $lf = new LeaveForm($this, $this->group);
272                 $lf->show();
273             } else {
274                 $jf = new JoinForm($this, $this->group);
275                 $jf->show();
276             }
277         }
278
279         $this->elementEnd('li');
280
281         $this->elementEnd('ul');
282         $this->elementEnd('div');
283     }
284
285     /**
286      * Show a list of links to feeds this page produces
287      *
288      * @return void
289      */
290
291     function showExportData()
292     {
293         $fl = new FeedList($this);
294         $fl->show(array(0=>array('href'=>common_local_url('grouprss',
295                                                           array('nickname' => $this->group->nickname)),
296                                  'type' => 'rss',
297                                  'version' => 'RSS 1.0',
298                                  'item' => 'notices')));
299     }
300
301     /**
302      * Show a list of links to feeds this page produces
303      *
304      * @return void
305      */
306
307     function showFeeds()
308     {
309         $url =
310           common_local_url('grouprss',
311                            array('nickname' => $this->group->nickname));
312
313         $this->element('link', array('rel' => 'alternate',
314                                      'href' => $url,
315                                      'type' => 'application/rss+xml',
316                                      'title' => sprintf(_('Notice feed for %s group'),
317                                                         $this->group->nickname)));
318     }
319
320     /**
321      * Fill in the sidebar.
322      *
323      * @return void
324      */
325
326     function showSections()
327     {
328         $this->showMembers();
329     }
330
331     /**
332      * Show mini-list of members
333      *
334      * @return void
335      */
336
337     function showMembers()
338     {
339         $member = $this->group->getMembers(0, MEMBERS_PER_SECTION);
340
341         if (!$member) {
342             return;
343         }
344
345         $this->elementStart('div', array('id' => 'user_subscriptions',
346                                          'class' => 'section'));
347
348         $this->element('h2', null, _('Members'));
349
350         if ($member) {
351             $pml = new ProfileMiniList($member, null, $this);
352             $cnt = $pml->show();
353             if ($cnt == 0) {
354                 $this->element('p', null, _('(None)'));
355             }
356         }
357
358         if ($cnt == MEMBERS_PER_SECTION) {
359             $this->element('a', array('href' => common_local_url('groupmembers',
360                                                                  array('nickname' => $this->group->nickname))),
361                            _('All members'));
362         }
363     }
364 }