]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/shownotice.php
Merge branch 'inblob' of git@gitorious.org:~evan/statusnet/evans-mainline into inblob
[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@status.net>
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://status.net/
28  */
29
30 if (!defined('STATUSNET') && !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@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
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             // Did we used to have it, and it got deleted?
88             $deleted = Deleted_notice::staticGet($id);
89             if (!empty($deleted)) {
90                 $this->clientError(_('Notice deleted.'), 410);
91             } else {
92                 $this->clientError(_('No such notice.'), 404);
93             }
94             return false;
95         }
96
97         $this->profile = $this->notice->getProfile();
98
99         if (empty($this->profile)) {
100             $this->serverError(_('Notice has no profile'), 500);
101             return false;
102         }
103
104         $this->user = User::staticGet('id', $this->profile->id);
105
106         if ($this->notice->is_local == Notice::REMOTE_OMB) {
107             common_redirect($this->notice->uri);
108             return false;
109         }
110
111         $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
112
113         return true;
114     }
115
116     /**
117      * Is this action read-only?
118      *
119      * @return boolean true
120      */
121
122     function isReadOnly($args)
123     {
124         return true;
125     }
126
127     /**
128      * Last-modified date for page
129      *
130      * When was the content of this page last modified? Based on notice,
131      * profile, avatar.
132      *
133      * @return int last-modified date as unix timestamp
134      */
135
136     function lastModified()
137     {
138         return max(strtotime($this->notice->modified),
139                    strtotime($this->profile->modified),
140                    ($this->avatar) ? strtotime($this->avatar->modified) : 0);
141     }
142
143     /**
144      * An entity tag for this page
145      *
146      * Shows the ETag for the page, based on the notice ID and timestamps
147      * for the notice, profile, and avatar. It's weak, since we change
148      * the date text "one hour ago", etc.
149      *
150      * @return string etag
151      */
152
153     function etag()
154     {
155         $avtime = ($this->avatar) ?
156           strtotime($this->avatar->modified) : 0;
157
158         return 'W/"' . implode(':', array($this->arg('action'),
159                                           common_language(),
160                                           $this->notice->id,
161                                           strtotime($this->notice->created),
162                                           strtotime($this->profile->modified),
163                                           $avtime)) . '"';
164     }
165
166     /**
167      * Title of the page
168      *
169      * @return string title of the page
170      */
171
172     function title()
173     {
174         if (!empty($this->profile->fullname)) {
175             $base = $this->profile->fullname . ' (' . $this->profile->nickname . ') ';
176         } else {
177             $base = $this->profile->nickname;
178         }
179
180         return sprintf(_('%1$s\'s status on %2$s'),
181                        $base,
182                        common_exact_date($this->notice->created));
183     }
184
185     /**
186      * Handle input
187      *
188      * Only handles get, so just show the page.
189      *
190      * @param array $args $_REQUEST data (unused)
191      *
192      * @return void
193      */
194
195     function handle($args)
196     {
197         parent::handle($args);
198
199         if ($this->notice->is_local == Notice::REMOTE_OMB) {
200             if (!empty($this->notice->url)) {
201                 common_redirect($this->notice->url, 301);
202             } else if (!empty($this->notice->uri) && preg_match('/^https?:/', $this->notice->uri)) {
203                 common_redirect($this->notice->uri, 301);
204             }
205         } else {
206             $this->showPage();
207         }
208     }
209
210     /**
211      * Don't show local navigation
212      *
213      * @return void
214      */
215
216     function showLocalNavBlock()
217     {
218     }
219
220     /**
221      * Fill the content area of the page
222      *
223      * Shows a single notice list item.
224      *
225      * @return void
226      */
227
228     function showContent()
229     {
230         $this->elementStart('ol', array('class' => 'notices xoxo'));
231         $nli = new SingleNoticeItem($this->notice, $this);
232         $nli->show();
233         $this->elementEnd('ol');
234     }
235
236     /**
237      * Don't show page notice
238      *
239      * @return void
240      */
241
242     function showPageNoticeBlock()
243     {
244     }
245
246     /**
247      * Don't show aside
248      *
249      * @return void
250      */
251
252     function showAside() {
253     }
254
255     /**
256      * Extra <head> content
257      *
258      * We show the microid(s) for the author, if any.
259      *
260      * @return void
261      */
262
263     function extraHead()
264     {
265         $user = User::staticGet($this->profile->id);
266
267         if (!$user) {
268             return;
269         }
270
271         if ($user->emailmicroid && $user->email && $this->notice->uri) {
272             $id = new Microid('mailto:'. $user->email,
273                               $this->notice->uri);
274             $this->element('meta', array('name' => 'microid',
275                                          'content' => $id->toString()));
276         }
277
278         if ($user->jabbermicroid && $user->jabber && $this->notice->uri) {
279             $id = new Microid('xmpp:', $user->jabber,
280                               $this->notice->uri);
281             $this->element('meta', array('name' => 'microid',
282                                          'content' => $id->toString()));
283         }
284         $this->element('link',array('rel'=>'alternate',
285             'type'=>'application/json+oembed',
286             'href'=>common_local_url(
287                 'oembed',
288                 array(),
289                 array('format'=>'json','url'=>$this->notice->uri)),
290             'title'=>'oEmbed'),null);
291         $this->element('link',array('rel'=>'alternate',
292             'type'=>'text/xml+oembed',
293             'href'=>common_local_url(
294                 'oembed',
295                 array(),
296                 array('format'=>'xml','url'=>$this->notice->uri)),
297             'title'=>'oEmbed'),null);
298     }
299 }
300
301 class SingleNoticeItem extends NoticeListItem
302 {
303     /**
304      * recipe function for displaying a single notice.
305      *
306      * We overload to show attachments.
307      *
308      * @return void
309      */
310
311     function show()
312     {
313         $this->showStart();
314         $this->showNotice();
315         $this->showNoticeAttachments();
316         $this->showNoticeInfo();
317         $this->showNoticeOptions();
318         $this->showEnd();
319     }
320
321     function showNoticeAttachments() {
322         $al = new AttachmentList($this->notice, $this->out);
323         $al->show();
324     }
325 }