]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showgroup.php
Merge branch 'streammode' into 1.0.x
[quix0rs-gnu-social.git] / actions / showgroup.php
1 <?php
2 /**
3  * StatusNet, 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   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @author    Sarven Capadisli <csarven@status.net>
26  * @copyright 2008-2011 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET') && !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 Group
42  * @package  StatusNet
43  * @author   Evan Prodromou <evan@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://status.net/
46  */
47 class ShowgroupAction extends GroupAction
48 {
49     /** page we're viewing. */
50     var $page = null;
51     var $userProfile = null;
52     var $notice = null;
53
54     /**
55      * Is this page read-only?
56      *
57      * @return boolean true
58      */
59     function isReadOnly($args)
60     {
61         return true;
62     }
63
64     /**
65      * Title of the page
66      *
67      * @return string page title, with page number
68      */
69     function title()
70     {
71         $base = $this->group->getFancyName();
72
73         if ($this->page == 1) {
74             // TRANS: Page title for first group page. %s is a group name.
75             return sprintf(_('%s group'), $base);
76         } else {
77             // TRANS: Page title for any but first group page.
78             // TRANS: %1$s is a group name, $2$s is a page number.
79             return sprintf(_('%1$s group, page %2$d'),
80                            $base,
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     function prepare($args)
95     {
96         parent::prepare($args);
97
98         $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
99
100         $this->userProfile = Profile::current();
101
102         $user = common_current_user();
103
104         if (!empty($user) && $user->streamModeOnly()) {
105             $stream = new GroupNoticeStream($this->group, $this->userProfile);
106         } else {
107             $stream = new ThreadingGroupNoticeStream($this->group, $this->userProfile);
108         }
109
110         $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE,
111                                             NOTICES_PER_PAGE + 1);
112
113         common_set_returnto($this->selfUrl());
114
115         return true;
116     }
117
118     /**
119      * Handle the request
120      *
121      * Shows a profile for the group, some controls, and a list of
122      * group notices.
123      *
124      * @return void
125      */
126     function handle($args)
127     {
128         $this->showPage();
129     }
130
131     /**
132      * Show the page content
133      *
134      * Shows a group profile and a list of group notices
135      */
136     function showContent()
137     {
138         $this->showGroupNotices();
139     }
140
141     /**
142      * Show the group notices
143      *
144      * @return void
145      */
146     function showGroupNotices()
147     {
148         $user = common_current_user();
149
150         if (!empty($user) && $user->streamModeOnly()) {
151             $nl = new NoticeList($this->notice, $this);
152         } else {
153             $nl = new ThreadedNoticeList($this->notice, $this, $this->userProfile);
154         } 
155
156         $cnt = $nl->show();
157
158         $this->pagination($this->page > 1,
159                           $cnt > NOTICES_PER_PAGE,
160                           $this->page,
161                           'showgroup',
162                           array('nickname' => $this->group->nickname));
163     }
164
165     /**
166      * Get a list of the feeds for this page
167      *
168      * @return void
169      */
170     function getFeeds()
171     {
172         $url =
173           common_local_url('grouprss',
174                            array('nickname' => $this->group->nickname));
175
176         return array(new Feed(Feed::JSON,
177                               common_local_url('ApiTimelineGroup',
178                                                array('format' => 'as',
179                                                      'id' => $this->group->id)),
180                               // TRANS: Tooltip for feed link. %s is a group nickname.
181                               sprintf(_('Notice feed for %s group (Activity Streams JSON)'),
182                                       $this->group->nickname)),
183                     new Feed(Feed::RSS1,
184                               common_local_url('grouprss',
185                                                array('nickname' => $this->group->nickname)),
186                               // TRANS: Tooltip for feed link. %s is a group nickname.
187                               sprintf(_('Notice feed for %s group (RSS 1.0)'),
188                                       $this->group->nickname)),
189                      new Feed(Feed::RSS2,
190                               common_local_url('ApiTimelineGroup',
191                                                array('format' => 'rss',
192                                                      'id' => $this->group->id)),
193                               // TRANS: Tooltip for feed link. %s is a group nickname.
194                               sprintf(_('Notice feed for %s group (RSS 2.0)'),
195                                       $this->group->nickname)),
196                      new Feed(Feed::ATOM,
197                               common_local_url('ApiTimelineGroup',
198                                                array('format' => 'atom',
199                                                      'id' => $this->group->id)),
200                               // TRANS: Tooltip for feed link. %s is a group nickname.
201                               sprintf(_('Notice feed for %s group (Atom)'),
202                                       $this->group->nickname)),
203                      new Feed(Feed::FOAF,
204                               common_local_url('foafgroup',
205                                                array('nickname' => $this->group->nickname)),
206                               // TRANS: Tooltip for feed link. %s is a group nickname.
207                               sprintf(_('FOAF for %s group'),
208                                        $this->group->nickname)));
209     }
210
211     function showAnonymousMessage()
212     {
213         if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
214             // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
215             // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept new registrations.
216             // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
217             // TRANS: %%%%action.register%%%% is the URL for registration, %%%%doc.help%%%% is a URL to help.
218             // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
219             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
220                 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
221                 'short messages about their life and interests. '.
222                 '[Join now](%%%%action.register%%%%) to become part of this group and many more! ([Read more](%%%%doc.help%%%%))'),
223                      $this->group->nickname);
224         } else {
225             // @todo FIXME: use group full name here if available instead of (uglier) primary alias.
226             // TRANS: Notice on group pages for anonymous users for StatusNet sites that accept no new registrations.
227             // TRANS: **%s** is the group alias, %%%%site.name%%%% is the site name,
228             // TRANS: This message contains Markdown links. Ensure they are formatted correctly: [Description](link).
229             $m = sprintf(_('**%s** is a user group on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
230                 'based on the Free Software [StatusNet](http://status.net/) tool. Its members share ' .
231                 'short messages about their life and interests. '),
232                      $this->group->nickname);
233         }
234         $this->elementStart('div', array('id' => 'anon_notice'));
235         $this->raw(common_markup_to_html($m));
236         $this->elementEnd('div');
237     }
238 }