]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showmessage.php
Merge branch 'master' of gitorious.org:statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / actions / showmessage.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Show a single message
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 if (!defined('STATUSNET') && !defined('LACONICA')) {
30     exit(1);
31 }
32
33 require_once INSTALLDIR.'/lib/mailbox.php';
34
35 /**
36  * Show a single message
37  *
38  * // XXX: It is totally weird how this works!
39  *
40  * @category Personal
41  * @package  StatusNet
42  * @author   Evan Prodromou <evan@status.net>
43  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44  * @link     http://status.net/
45  */
46 class ShowmessageAction extends MailboxAction
47 {
48     /**
49      * Message object to show
50      */
51     var $message = null;
52
53     /**
54      * The current user
55      */
56
57     var $user = null;
58
59     /**
60      * Load attributes based on database arguments
61      *
62      * Loads all the DB stuff
63      *
64      * @param array $args $_REQUEST array
65      *
66      * @return success flag
67      */
68     function prepare($args)
69     {
70         parent::prepare($args);
71
72         $this->page = 1;
73
74         $id            = $this->trimmed('message');
75         $this->message = Message::staticGet('id', $id);
76
77         if (!$this->message) {
78             // TRANS: Client error displayed requesting a single message that does not exist.
79             $this->clientError(_('No such message.'), 404);
80             return false;
81         }
82
83         $this->user = common_current_user();
84
85         return true;
86     }
87
88     function handle($args)
89     {
90         Action::handle($args);
91
92         if ($this->user && ($this->user->id == $this->message->from_profile ||
93             $this->user->id == $this->message->to_profile)) {
94                 $this->showPage();
95         } else {
96             // TRANS: Client error displayed requesting a single direct message the requesting user was not a party in.
97             $this->clientError(_('Only the sender and recipient ' .
98                 'may read this message.'), 403);
99             return;
100         }
101     }
102
103     function title()
104     {
105         if ($this->user->id == $this->message->from_profile) {
106             $to = $this->message->getTo();
107             // @todo FIXME: Might be nice if the timestamp could be localised.
108             // TRANS: Page title for single direct message display when viewing user is the sender.
109             // TRANS: %1$s is the addressed user's nickname, $2$s is a timestamp.
110             return sprintf(_('Message to %1$s on %2$s'),
111                              $to->nickname,
112                              common_exact_date($this->message->created));
113         } else if ($this->user->id == $this->message->to_profile) {
114             $from = $this->message->getFrom();
115             // @todo FIXME: Might be nice if the timestamp could be localised.
116             // TRANS: Page title for single message display.
117             // TRANS: %1$s is the sending user's nickname, $2$s is a timestamp.
118             return sprintf(_('Message from %1$s on %2$s'),
119                              $from->nickname,
120                              common_exact_date($this->message->created));
121         }
122     }
123
124     function getMessages()
125     {
126         $message     = new Message();
127         $message->id = $this->message->id;
128         $message->find();
129         return $message;
130     }
131
132     function getMessageProfile()
133     {
134         if ($this->user->id == $this->message->from_profile) {
135             return $this->message->getTo();
136         } else if ($this->user->id == $this->message->to_profile) {
137             return $this->message->getFrom();
138         } else {
139             // This shouldn't happen
140             return null;
141         }
142     }
143
144     /**
145      * Don't show local navigation
146      *
147      * @return void
148      */
149     function showLocalNavBlock()
150     {
151     }
152
153     /**
154      * Don't show page notice
155      *
156      * @return void
157      */
158     function showPageNoticeBlock()
159     {
160     }
161
162     /**
163      * Don't show aside
164      *
165      * @return void
166      */
167     function showAside()
168     {
169     }
170
171     /**
172      * Don't show any instructions
173      *
174      * @return string
175      */
176     function getInstructions()
177     {
178         return '';
179     }
180
181     function isReadOnly($args)
182     {
183         return true;
184     }
185 }