]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/shownotice.php
don't attempt to read a user's ldap password
[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_language(),
155                                           $this->notice->id,
156                                           strtotime($this->notice->created),
157                                           strtotime($this->profile->modified),
158                                           $avtime)) . '"';
159     }
160
161     /**
162      * Title of the page
163      *
164      * @return string title of the page
165      */
166
167     function title()
168     {
169         if (!empty($this->profile->fullname)) {
170             $base = $this->profile->fullname . ' (' . $this->profile->nickname . ')';
171         } else {
172             $base = $this->profile->nickname;
173         }
174
175         return sprintf(_('%1$s\'s status on %2$s'),
176                        $base,
177                        common_exact_date($this->notice->created));
178     }
179
180     /**
181      * Handle input
182      *
183      * Only handles get, so just show the page.
184      *
185      * @param array $args $_REQUEST data (unused)
186      *
187      * @return void
188      */
189
190     function handle($args)
191     {
192         parent::handle($args);
193
194         if ($this->notice->is_local == Notice::REMOTE_OMB) {
195             if (!empty($this->notice->url)) {
196                 $target = $this->notice->url;
197             } else if (!empty($this->notice->uri) && preg_match('/^https?:/', $this->notice->uri)) {
198                 // Old OMB posts saved the remote URL only into the URI field.
199                 $target = $this->notice->uri;
200             } else {
201                 // Shouldn't happen.
202                 $target = false;
203             }
204             if ($target && $target != $this->selfUrl()) {
205                 common_redirect($target, 301);
206                 return false;
207             }
208         }
209         $this->showPage();
210     }
211
212     /**
213      * Don't show local navigation
214      *
215      * @return void
216      */
217
218     function showLocalNavBlock()
219     {
220     }
221
222     /**
223      * Fill the content area of the page
224      *
225      * Shows a single notice list item.
226      *
227      * @return void
228      */
229
230     function showContent()
231     {
232         $this->elementStart('ol', array('class' => 'notices xoxo'));
233         $nli = new SingleNoticeItem($this->notice, $this);
234         $nli->show();
235         $this->elementEnd('ol');
236     }
237
238     /**
239      * Don't show page notice
240      *
241      * @return void
242      */
243
244     function showPageNoticeBlock()
245     {
246     }
247
248     /**
249      * Don't show aside
250      *
251      * @return void
252      */
253
254     function showAside() {
255     }
256
257     /**
258      * Extra <head> content
259      *
260      * We show the microid(s) for the author, if any.
261      *
262      * @return void
263      */
264
265     function extraHead()
266     {
267         $user = User::staticGet($this->profile->id);
268
269         if (!$user) {
270             return;
271         }
272
273         if ($user->emailmicroid && $user->email && $this->notice->uri) {
274             $id = new Microid('mailto:'. $user->email,
275                               $this->notice->uri);
276             $this->element('meta', array('name' => 'microid',
277                                          'content' => $id->toString()));
278         }
279
280         if ($user->jabbermicroid && $user->jabber && $this->notice->uri) {
281             $id = new Microid('xmpp:', $user->jabber,
282                               $this->notice->uri);
283             $this->element('meta', array('name' => 'microid',
284                                          'content' => $id->toString()));
285         }
286         $this->element('link',array('rel'=>'alternate',
287             'type'=>'application/json+oembed',
288             'href'=>common_local_url(
289                 'oembed',
290                 array(),
291                 array('format'=>'json','url'=>$this->notice->uri)),
292             'title'=>'oEmbed'),null);
293         $this->element('link',array('rel'=>'alternate',
294             'type'=>'text/xml+oembed',
295             'href'=>common_local_url(
296                 'oembed',
297                 array(),
298                 array('format'=>'xml','url'=>$this->notice->uri)),
299             'title'=>'oEmbed'),null);
300     }
301 }
302
303 class SingleNoticeItem extends NoticeListItem
304 {
305     /**
306      * recipe function for displaying a single notice.
307      *
308      * We overload to show attachments.
309      *
310      * @return void
311      */
312
313     function show()
314     {
315         $this->showStart();
316         $this->showNotice();
317         $this->showNoticeAttachments();
318         $this->showNoticeInfo();
319         $this->showNoticeOptions();
320         $this->showEnd();
321     }
322
323     function showNoticeAttachments() {
324         $al = new AttachmentList($this->notice, $this->out);
325         $al->show();
326     }
327 }