]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/shownotice.php
Changed ul to ol and added xoxo for notice lists.
[quix0rs-gnu-social.git] / actions / shownotice.php
1 <?php
2 /**
3  * Laconica, 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   Laconica
24  * @author    Evan Prodromou <evan@controlyourself.ca>
25  * @copyright 2008-2009 Control Yourself, 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  Laconica
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 Action
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 (!$this->notice) {
87             $this->clientError(_('No such notice.'), 404);
88             return false;
89         }
90
91         $this->profile = $this->notice->getProfile();
92
93         if (!$this->profile) {
94             $this->serverError(_('Notice has no profile'), 500);
95             return false;
96         }
97
98         $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
99
100         return true;
101     }
102
103     /**
104      * Is this action read-only?
105      *
106      * @return boolean true
107      */
108
109     function isReadOnly($args)
110     {
111         return true;
112     }
113
114     /**
115      * Last-modified date for page
116      *
117      * When was the content of this page last modified? Based on notice,
118      * profile, avatar.
119      *
120      * @return int last-modified date as unix timestamp
121      */
122
123     function lastModified()
124     {
125         return max(strtotime($this->notice->created),
126                    strtotime($this->profile->modified),
127                    ($this->avatar) ? strtotime($this->avatar->modified) : 0);
128     }
129
130     /**
131      * An entity tag for this page
132      *
133      * Shows the ETag for the page, based on the notice ID and timestamps
134      * for the notice, profile, and avatar. It's weak, since we change
135      * the date text "one hour ago", etc.
136      *
137      * @return string etag
138      */
139
140     function etag()
141     {
142         $avtime = ($this->avatar) ?
143           strtotime($this->avatar->modified) : 0;
144
145         return 'W/"' . implode(':', array($this->arg('action'),
146                                           common_language(),
147                                           $this->notice->id,
148                                           strtotime($this->notice->created),
149                                           strtotime($this->profile->modified),
150                                           $avtime)) . '"';
151     }
152
153     /**
154      * Title of the page
155      *
156      * @return string title of the page
157      */
158
159     function title()
160     {
161         return sprintf(_('%1$s\'s status on %2$s'),
162                        $this->profile->nickname,
163                        common_exact_date($this->notice->created));
164     }
165
166     /**
167      * Handle input
168      *
169      * Only handles get, so just show the page.
170      *
171      * @param array $args $_REQUEST data (unused)
172      *
173      * @return void
174      */
175
176     function handle($args)
177     {
178         parent::handle($args);
179
180         if ($this->notice->is_local == 0) {
181             if (!empty($this->notice->url)) {
182                 common_redirect($this->notice->url, 301);
183             } else if (!empty($this->notice->uri) && preg_match('/^https?:/', $this->notice->uri)) {
184                 common_redirect($this->notice->uri, 301);
185             }
186         } else {
187             $this->showPage();
188         }
189     }
190
191     /**
192      * Don't show local navigation
193      *
194      * @return void
195      */
196
197     function showLocalNavBlock()
198     {
199     }
200
201     /**
202      * Fill the content area of the page
203      *
204      * Shows a single notice list item.
205      *
206      * @return void
207      */
208
209     function showContent()
210     {
211         $this->elementStart('ol', array('class' => 'notices xoxo'));
212         $nli = new NoticeListItem($this->notice, $this);
213         $nli->show();
214         $this->elementEnd('ol');
215     }
216
217     /**
218      * Don't show page notice
219      *
220      * @return void
221      */
222
223     function showPageNoticeBlock()
224     {
225     }
226
227     /**
228      * Don't show aside
229      *
230      * @return void
231      */
232
233     function showAside() {
234     }
235
236     /**
237      * Extra <head> content
238      *
239      * We show the microid(s) for the author, if any.
240      *
241      * @return void
242      */
243
244     function extraHead()
245     {
246         $user = User::staticGet($this->profile->id);
247
248         if (!$user) {
249             return;
250         }
251
252         if ($user->emailmicroid && $user->email && $this->notice->uri) {
253             $id = new Microid('mailto:'. $user->email,
254                               $this->notice->uri);
255             $this->element('meta', array('name' => 'microid',
256                                          'content' => $id->toString()));
257         }
258
259         if ($user->jabbermicroid && $user->jabber && $this->notice->uri) {
260             $id = new Microid('xmpp:', $user->jabber,
261                               $this->notice->uri);
262             $this->element('meta', array('name' => 'microid',
263                                          'content' => $id->toString()));
264         }
265     }
266 }