]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showgroup.php
9fa86761566f0ecf0a0634bc4c49c02d789b63fe
[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  Personal
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 /**
39  * Group main page
40  *
41  * @category Personal
42  * @package  Laconica
43  * @author   Evan Prodromou <evan@controlyourself.ca>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://laconi.ca/
46  */
47
48 class ShowgroupAction extends Action
49 {
50     /** group we're viewing. */
51     var $group = null;
52     /** page we're viewing. */
53     var $page = null;
54
55     /**
56      * Title of the page
57      *
58      * @return string page title, with page number
59      */
60
61     function title()
62     {
63         if ($this->page == 1) {
64             return sprintf(_("%s group"), $this->group->nickname);
65         } else {
66             return sprintf(_("%s group, page %d"),
67                            $this->group->nickname,
68                            $this->page);
69         }
70     }
71
72     /**
73      * Prepare the action
74      *
75      * Reads and validates arguments and instantiates the attributes.
76      *
77      * @param array $args $_REQUEST args
78      *
79      * @return boolean success flag
80      */
81
82     function prepare($args)
83     {
84         parent::prepare($args);
85
86         if (!common_config('inboxes','enabled')) {
87             $this->serverError(_('Inboxes must be enabled for groups to work'));
88             return false;
89         }
90
91         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
92
93         $nickname_arg = $this->arg('nickname');
94         $nickname = common_canonical_nickname($nickname_arg);
95
96         // Permanent redirect on non-canonical nickname
97
98         if ($nickname_arg != $nickname) {
99             $args = array('nickname' => $nickname);
100             if ($this->page != 1) {
101                 $args['page'] = $this->page;
102             }
103             common_redirect(common_local_url('showgroup', $args), 301);
104             return false;
105         }
106
107         if (!$nickname) {
108             $this->clientError(_('No nickname'), 404);
109             return false;
110         }
111
112         $this->group = User_group::staticGet('nickname', $nickname);
113
114         if (!$this->group) {
115             $this->clientError(_('No such group'), 404);
116             return false;
117         }
118
119         return true;
120     }
121
122     /**
123      * Handle the request
124      *
125      * Shows a profile for the group, some controls, and a list of
126      * group notices.
127      *
128      * @return void
129      */
130
131     function handle($args)
132     {
133         $this->showPage();
134     }
135
136     /**
137      * Show the page content
138      *
139      * Shows a group profile and a list of group notices
140      */
141
142     function showContent()
143     {
144         $this->showGroupProfile();
145         $this->showGroupNotices();
146     }
147
148     /**
149      * Show the group notices
150      *
151      * @return void
152      */
153
154     function showGroupNotices()
155     {
156         $notice = $this->group->getNotices(($this->page-1)*NOTICES_PER_PAGE,
157                                            NOTICES_PER_PAGE + 1);
158
159         $nl = new NoticeList($notice, $this);
160         $cnt = $nl->show();
161
162         $this->pagination($this->page > 1,
163                           $cnt > NOTICES_PER_PAGE,
164                           $this->page,
165                           'showgroup',
166                           array('nickname' => $this->group->nickname));
167     }
168
169     /**
170      * Show the group profile
171      *
172      * Information about the group
173      *
174      * @return void
175      */
176
177     function showGroupProfile()
178     {
179         $this->elementStart('div', array('id' => 'group_profile',
180                                          'class' => 'vcard author'));
181
182         $this->element('h2', null, _('Group profile'));
183
184         $this->elementStart('dl', 'group_depiction');
185         $this->element('dt', null, _('Photo'));
186         $this->elementStart('dd');
187
188         $logo = ($this->group->homepage_logo) ?
189           $this->group->homepage_logo : User_group::defaultLogo(AVATAR_PROFILE_SIZE);
190
191         $this->element('img', array('src' => $logo,
192                                     'class' => 'photo avatar',
193                                     'width' => AVATAR_PROFILE_SIZE,
194                                     'height' => AVATAR_PROFILE_SIZE,
195                                     'alt' => $this->group->nickname));
196         $this->elementEnd('dd');
197         $this->elementEnd('dl');
198
199         $this->elementStart('dl', 'group_nickname');
200         $this->element('dt', null, _('Nickname'));
201         $this->elementStart('dd');
202         $hasFN = ($this->group->fullname) ? 'nickname url uid' : 'fn nickname url uid';
203         $this->element('a', array('href' => $this->group->homeUrl(),
204                                   'rel' => 'me', 'class' => $hasFN),
205                             $this->group->nickname);
206         $this->elementEnd('dd');
207         $this->elementEnd('dl');
208
209         if ($this->group->fullname) {
210             $this->elementStart('dl', 'group_fn');
211             $this->element('dt', null, _('Full name'));
212             $this->elementStart('dd');
213             $this->element('span', 'fn', $this->group->fullname);
214             $this->elementEnd('dd');
215             $this->elementEnd('dl');
216         }
217
218         if ($this->group->location) {
219             $this->elementStart('dl', 'group_location');
220             $this->element('dt', null, _('Location'));
221             $this->element('dd', 'location', $this->group->location);
222             $this->elementEnd('dl');
223         }
224
225         if ($this->group->homepage) {
226             $this->elementStart('dl', 'group_url');
227             $this->element('dt', null, _('URL'));
228             $this->elementStart('dd');
229             $this->element('a', array('href' => $this->group->homepage,
230                                       'rel' => 'me', 'class' => 'url'),
231                            $this->group->homepage);
232             $this->elementEnd('dd');
233             $this->elementEnd('dl');
234         }
235
236         if ($this->group->description) {
237             $this->elementStart('dl', 'group_note');
238             $this->element('dt', null, _('Note'));
239             $this->element('dd', 'note', $this->group->description);
240             $this->elementEnd('dl');
241         }
242
243         $this->elementEnd('div');
244
245         $this->elementStart('div', array('id' => 'group_actions'));
246         $this->element('h2', null, _('Group actions'));
247         $this->elementStart('ul');
248         $this->elementStart('li', array('id' => 'group_subscribe'));
249         $cur = common_current_user();
250         if ($cur) {
251             if ($cur->isMember($this->group)) {
252                 $lf = new LeaveForm($this, $this->group);
253                 $lf->show();
254                 if ($cur->isAdmin($this->group)) {
255                     $edit = common_local_url('editgroup',
256                                              array('nickname' => $this->group->nickname));
257                     $this->element('a',
258                                    array('href' => $edit,
259                                          'id' => 'group_admin'),
260                                    _('Admin'));
261                 }
262             } else {
263                 $jf = new JoinForm($this, $this->group);
264                 $jf->show();
265             }
266         }
267
268         $this->elementEnd('li');
269
270         $this->elementEnd('ul');
271         $this->elementEnd('div');
272     }
273
274     /**
275      * Show a list of links to feeds this page produces
276      *
277      * @return void
278      */
279
280     function showExportData()
281     {
282         $fl = new FeedList($this);
283         $fl->show(array(0=>array('href'=>common_local_url('grouprss',
284                                                           array('nickname' => $this->group->nickname)),
285                                  'type' => 'rss',
286                                  'version' => 'RSS 1.0',
287                                  'item' => 'notices')));
288     }
289
290     /**
291      * Show a list of links to feeds this page produces
292      *
293      * @return void
294      */
295
296     function showFeeds()
297     {
298         $url =
299           common_local_url('grouprss',
300                            array('nickname' => $this->group->nickname));
301
302         $this->element('link', array('rel' => 'alternate',
303                                      'href' => $url,
304                                      'type' => 'application/rss+xml',
305                                      'title' => sprintf(_('Notice feed for %s group'),
306                                                         $this->group->nickname)));
307     }
308 }