]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/shownotice.php
change Laconica and Control Yourself to StatusNet in PHP files
[quix0rs-gnu-social.git] / actions / shownotice.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Show a single notice
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   StatusNet
24  * @author    Evan Prodromou <evan@controlyourself.ca>
25  * @copyright 2008-2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://laconi.ca/
28  */
29
30 if (!defined('LACONICA')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR.'/lib/personalgroupnav.php';
35 require_once INSTALLDIR.'/lib/noticelist.php';
36 require_once INSTALLDIR.'/lib/feedlist.php';
37
38 /**
39  * Show a single notice
40  *
41  * @category Personal
42  * @package  StatusNet
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 ShownoticeAction extends OwnerDesignAction
49 {
50     /**
51      * Notice object to show
52      */
53
54     var $notice = null;
55
56     /**
57      * Profile of the notice object
58      */
59
60     var $profile = null;
61
62     /**
63      * Avatar of the profile of the notice object
64      */
65
66     var $avatar = null;
67
68     /**
69      * Load attributes based on database arguments
70      *
71      * Loads all the DB stuff
72      *
73      * @param array $args $_REQUEST array
74      *
75      * @return success flag
76      */
77
78     function prepare($args)
79     {
80         parent::prepare($args);
81
82         $id = $this->arg('notice');
83
84         $this->notice = Notice::staticGet($id);
85
86         if (empty($this->notice)) {
87             $this->clientError(_('No such notice.'), 404);
88             return false;
89         }
90
91         $this->profile = $this->notice->getProfile();
92
93         if (empty($this->profile)) {
94             $this->serverError(_('Notice has no profile'), 500);
95             return false;
96         }
97
98         $this->user = User::staticGet('id', $this->profile->id);
99
100         if (! $this->notice->is_local) {
101             common_redirect($this->notice->uri);
102             return false;
103         }
104
105         $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
106
107         return true;
108     }
109
110     /**
111      * Is this action read-only?
112      *
113      * @return boolean true
114      */
115
116     function isReadOnly($args)
117     {
118         return true;
119     }
120
121     /**
122      * Last-modified date for page
123      *
124      * When was the content of this page last modified? Based on notice,
125      * profile, avatar.
126      *
127      * @return int last-modified date as unix timestamp
128      */
129
130     function lastModified()
131     {
132         return max(strtotime($this->notice->modified),
133                    strtotime($this->profile->modified),
134                    ($this->avatar) ? strtotime($this->avatar->modified) : 0);
135     }
136
137     /**
138      * An entity tag for this page
139      *
140      * Shows the ETag for the page, based on the notice ID and timestamps
141      * for the notice, profile, and avatar. It's weak, since we change
142      * the date text "one hour ago", etc.
143      *
144      * @return string etag
145      */
146
147     function etag()
148     {
149         $avtime = ($this->avatar) ?
150           strtotime($this->avatar->modified) : 0;
151
152         return 'W/"' . implode(':', array($this->arg('action'),
153                                           common_language(),
154                                           $this->notice->id,
155                                           strtotime($this->notice->created),
156                                           strtotime($this->profile->modified),
157                                           $avtime)) . '"';
158     }
159
160     /**
161      * Title of the page
162      *
163      * @return string title of the page
164      */
165
166     function title()
167     {
168         if (!empty($this->profile->fullname)) {
169             $base = $this->profile->fullname . ' (' . $this->user->nickname . ') ';
170         } else {
171             $base = $this->user->nickname;
172         }
173
174         return sprintf(_('%1$s\'s status on %2$s'),
175                        $base,
176                        common_exact_date($this->notice->created));
177     }
178
179     /**
180      * Handle input
181      *
182      * Only handles get, so just show the page.
183      *
184      * @param array $args $_REQUEST data (unused)
185      *
186      * @return void
187      */
188
189     function handle($args)
190     {
191         parent::handle($args);
192
193         if ($this->notice->is_local == Notice::REMOTE_OMB) {
194             if (!empty($this->notice->url)) {
195                 common_redirect($this->notice->url, 301);
196             } else if (!empty($this->notice->uri) && preg_match('/^https?:/', $this->notice->uri)) {
197                 common_redirect($this->notice->uri, 301);
198             }
199         } else {
200             $this->showPage();
201         }
202     }
203
204     /**
205      * Don't show local navigation
206      *
207      * @return void
208      */
209
210     function showLocalNavBlock()
211     {
212     }
213
214     /**
215      * Fill the content area of the page
216      *
217      * Shows a single notice list item.
218      *
219      * @return void
220      */
221
222     function showContent()
223     {
224         $this->elementStart('ol', array('class' => 'notices xoxo'));
225         $nli = new SingleNoticeItem($this->notice, $this);
226         $nli->show();
227         $this->elementEnd('ol');
228     }
229
230     /**
231      * Don't show page notice
232      *
233      * @return void
234      */
235
236     function showPageNoticeBlock()
237     {
238     }
239
240     /**
241      * Don't show aside
242      *
243      * @return void
244      */
245
246     function showAside() {
247     }
248
249     /**
250      * Extra <head> content
251      *
252      * We show the microid(s) for the author, if any.
253      *
254      * @return void
255      */
256
257     function extraHead()
258     {
259         $user = User::staticGet($this->profile->id);
260
261         if (!$user) {
262             return;
263         }
264
265         if ($user->emailmicroid && $user->email && $this->notice->uri) {
266             $id = new Microid('mailto:'. $user->email,
267                               $this->notice->uri);
268             $this->element('meta', array('name' => 'microid',
269                                          'content' => $id->toString()));
270         }
271
272         if ($user->jabbermicroid && $user->jabber && $this->notice->uri) {
273             $id = new Microid('xmpp:', $user->jabber,
274                               $this->notice->uri);
275             $this->element('meta', array('name' => 'microid',
276                                          'content' => $id->toString()));
277         }
278         $this->element('link',array('rel'=>'alternate',
279             'type'=>'application/json+oembed',
280             'href'=>common_local_url(
281                 'oembed',
282                 array(),
283                 array('format'=>'json','url'=>$this->notice->uri)),
284             'title'=>'oEmbed'),null);
285         $this->element('link',array('rel'=>'alternate',
286             'type'=>'text/xml+oembed',
287             'href'=>common_local_url(
288                 'oembed',
289                 array(),
290                 array('format'=>'xml','url'=>$this->notice->uri)),
291             'title'=>'oEmbed'),null);
292     }
293 }
294
295 class SingleNoticeItem extends NoticeListItem
296 {
297     /**
298      * recipe function for displaying a single notice.
299      *
300      * We overload to show attachments.
301      *
302      * @return void
303      */
304
305     function show()
306     {
307         $this->showStart();
308         $this->showNotice();
309         $this->showNoticeAttachments();
310         $this->showNoticeInfo();
311         $this->showNoticeOptions();
312         $this->showEnd();
313     }
314
315     function showNoticeAttachments() {
316         $al = new AttachmentList($this->notice, $this->out);
317         $al->show();
318     }
319 }