]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/shownotice.php
Merge branch 'testing'
[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         $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
107
108         return true;
109     }
110
111     /**
112      * Is this action read-only?
113      *
114      * @return boolean true
115      */
116
117     function isReadOnly($args)
118     {
119         return true;
120     }
121
122     /**
123      * Last-modified date for page
124      *
125      * When was the content of this page last modified? Based on notice,
126      * profile, avatar.
127      *
128      * @return int last-modified date as unix timestamp
129      */
130
131     function lastModified()
132     {
133         return max(strtotime($this->notice->modified),
134                    strtotime($this->profile->modified),
135                    ($this->avatar) ? strtotime($this->avatar->modified) : 0);
136     }
137
138     /**
139      * An entity tag for this page
140      *
141      * Shows the ETag for the page, based on the notice ID and timestamps
142      * for the notice, profile, and avatar. It's weak, since we change
143      * the date text "one hour ago", etc.
144      *
145      * @return string etag
146      */
147
148     function etag()
149     {
150         $avtime = ($this->avatar) ?
151           strtotime($this->avatar->modified) : 0;
152
153         return 'W/"' . implode(':', array($this->arg('action'),
154                                           common_user_cache_hash(),
155                                           common_language(),
156                                           $this->notice->id,
157                                           strtotime($this->notice->created),
158                                           strtotime($this->profile->modified),
159                                           $avtime)) . '"';
160     }
161
162     /**
163      * Title of the page
164      *
165      * @return string title of the page
166      */
167
168     function title()
169     {
170         $base = $this->profile->getFancyName();
171
172         return sprintf(_('%1$s\'s status on %2$s'),
173                        $base,
174                        common_exact_date($this->notice->created));
175     }
176
177     /**
178      * Handle input
179      *
180      * Only handles get, so just show the page.
181      *
182      * @param array $args $_REQUEST data (unused)
183      *
184      * @return void
185      */
186
187     function handle($args)
188     {
189         parent::handle($args);
190
191         if ($this->notice->is_local == Notice::REMOTE_OMB) {
192             if (!empty($this->notice->url)) {
193                 $target = $this->notice->url;
194             } else if (!empty($this->notice->uri) && preg_match('/^https?:/', $this->notice->uri)) {
195                 // Old OMB posts saved the remote URL only into the URI field.
196                 $target = $this->notice->uri;
197             } else {
198                 // Shouldn't happen.
199                 $target = false;
200             }
201             if ($target && $target != $this->selfUrl()) {
202                 common_redirect($target, 301);
203                 return false;
204             }
205         }
206         $this->showPage();
207     }
208
209     /**
210      * Don't show local navigation
211      *
212      * @return void
213      */
214
215     function showLocalNavBlock()
216     {
217     }
218
219     /**
220      * Fill the content area of the page
221      *
222      * Shows a single notice list item.
223      *
224      * @return void
225      */
226
227     function showContent()
228     {
229         $this->elementStart('ol', array('class' => 'notices xoxo'));
230         $nli = new SingleNoticeItem($this->notice, $this);
231         $nli->show();
232         $this->elementEnd('ol');
233     }
234
235     /**
236      * Don't show page notice
237      *
238      * @return void
239      */
240
241     function showPageNoticeBlock()
242     {
243     }
244
245     /**
246      * Don't show aside
247      *
248      * @return void
249      */
250
251     function showAside() {
252     }
253
254     /**
255      * Extra <head> content
256      *
257      * We show the microid(s) for the author, if any.
258      *
259      * @return void
260      */
261
262     function extraHead()
263     {
264         $user = User::staticGet($this->profile->id);
265
266         if (!$user) {
267             return;
268         }
269
270         if ($user->emailmicroid && $user->email && $this->notice->uri) {
271             $id = new Microid('mailto:'. $user->email,
272                               $this->notice->uri);
273             $this->element('meta', array('name' => 'microid',
274                                          'content' => $id->toString()));
275         }
276
277         if ($user->jabbermicroid && $user->jabber && $this->notice->uri) {
278             $id = new Microid('xmpp:', $user->jabber,
279                               $this->notice->uri);
280             $this->element('meta', array('name' => 'microid',
281                                          'content' => $id->toString()));
282         }
283         $this->element('link',array('rel'=>'alternate',
284             'type'=>'application/json+oembed',
285             'href'=>common_local_url(
286                 'oembed',
287                 array(),
288                 array('format'=>'json','url'=>$this->notice->uri)),
289             'title'=>'oEmbed'),null);
290         $this->element('link',array('rel'=>'alternate',
291             'type'=>'text/xml+oembed',
292             'href'=>common_local_url(
293                 'oembed',
294                 array(),
295                 array('format'=>'xml','url'=>$this->notice->uri)),
296             'title'=>'oEmbed'),null);
297
298         // Extras to aid in sharing notices to Facebook
299         $avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
300         $avatarUrl = ($avatar) ?
301                      $avatar->displayUrl() :
302                      Avatar::defaultImage(AVATAR_PROFILE_SIZE);
303         $this->element('meta', array('property' => 'og:image',
304                                      'content' => $avatarUrl));
305         $this->element('meta', array('property' => 'og:description',
306                                      'content' => $this->notice->content));
307     }
308 }
309
310 class SingleNoticeItem extends DoFollowListItem
311 {
312     /**
313      * recipe function for displaying a single notice.
314      *
315      * We overload to show attachments.
316      *
317      * @return void
318      */
319
320     function show()
321     {
322         $this->showStart();
323         if (Event::handle('StartShowNoticeItem', array($this))) {
324             $this->showNotice();
325             $this->showNoticeAttachments();
326             $this->showNoticeInfo();
327             $this->showNoticeOptions();
328             Event::handle('EndShowNoticeItem', array($this));
329         }
330
331         $this->showEnd();
332     }
333
334     /**
335      * For our zoomed-in special case we'll use a fuller list
336      * for the attachment info.
337      */
338     function showNoticeAttachments() {
339         $al = new AttachmentList($this->notice, $this->out);
340         $al->show();
341     }
342
343     /**
344      * show the avatar of the notice's author
345      *
346      * We use the larger size for single notice page.
347      * 
348      * @return void
349      */
350
351     function showAvatar()
352     {
353         $avatar_size = AVATAR_PROFILE_SIZE;
354
355         $avatar = $this->profile->getAvatar($avatar_size);
356
357         $this->out->element('img', array('src' => ($avatar) ?
358                                          $avatar->displayUrl() :
359                                          Avatar::defaultImage($avatar_size),
360                                          'class' => 'avatar photo',
361                                          'width' => $avatar_size,
362                                          'height' => $avatar_size,
363                                          'alt' =>
364                                          ($this->profile->fullname) ?
365                                          $this->profile->fullname :
366                                          $this->profile->nickname));
367     }
368 }