]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/shownotice.php
move opening brace of class declaration to next line
[quix0rs-gnu-social.git] / actions / shownotice.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 require_once(INSTALLDIR.'/lib/stream.php');
23
24 class ShownoticeAction extends StreamAction
25 {
26
27     var $notice = null;
28     var $profile = null;
29     var $avatar = null;
30
31     function prepare($args)
32     {
33
34         parent::prepare($args);
35
36         $id = $this->arg('notice');
37         $this->notice = Notice::staticGet($id);
38
39         if (!$this->notice) {
40             $this->client_error(_('No such notice.'), 404);
41             return false;
42         }
43
44         $this->profile = $this->notice->getProfile();
45
46         if (!$this->profile) {
47             $this->server_error(_('Notice has no profile'), 500);
48             return false;
49         }
50
51         $this->avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
52
53         return true;
54     }
55
56     function last_modified()
57     {
58         return max(strtotime($this->notice->created),
59                    strtotime($this->profile->modified),
60                    ($this->avatar) ? strtotime($this->avatar->modified) : 0);
61     }
62
63     function etag()
64     {
65         return 'W/"' . implode(':', array($this->arg('action'),
66                                           common_language(),
67                                           $this->notice->id,
68                                           strtotime($this->notice->created),
69                                           strtotime($this->profile->modified),
70                                           ($this->avatar) ? strtotime($this->avatar->modified) : 0)) . '"';
71     }
72
73     function handle($args)
74     {
75
76         parent::handle($args);
77
78         common_show_header(sprintf(_('%1$s\'s status on %2$s'),
79                                    $this->profile->nickname,
80                                    common_exact_date($this->notice->created)),
81                            array($this, 'show_header'), null,
82                            array($this, 'show_top'));
83
84         common_element_start('ul', array('id' => 'notices'));
85         $nli = new NoticeListItem($this->notice);
86         $nli->show();
87         common_element_end('ul');
88
89         common_show_footer();
90     }
91
92     function show_header()
93     {
94
95         $user = User::staticGet($this->profile->id);
96
97         if (!$user) {
98             return;
99         }
100
101         if ($user->emailmicroid && $user->email && $this->notice->uri) {
102             common_element('meta', array('name' => 'microid',
103                                          'content' => "mailto+http:sha1:" . sha1(sha1('mailto:' . $user->email) . sha1($this->notice->uri))));
104         }
105
106         if ($user->jabbermicroid && $user->jabber && $this->notice->uri) {
107             common_element('meta', array('name' => 'microid',
108                                          'content' => "xmpp+http:sha1:" . sha1(sha1('xmpp:' . $user->jabber) . sha1($this->notice->uri))));
109         }
110     }
111
112     function show_top()
113     {
114         $cur = common_current_user();
115         if ($cur && $cur->id == $this->profile->id) {
116             common_notice_form();
117         }
118     }
119
120     function no_such_notice()
121     {
122         common_user_error(_('No such notice.'));
123     }
124 }