]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showmessage.php
Merge branch 'testing'
[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 /**
34  * Show a single message
35  *
36  * @category Personal
37  * @package  StatusNet
38  * @author   Evan Prodromou <evan@status.net>
39  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
40  * @link     http://status.net/
41  */
42
43 class ShowmessageAction extends Action
44 {
45     /**
46      * Message object to show
47      */
48     var $message = null;
49
50     /**
51      * The current user
52      */
53
54     var $user = null;
55
56     /**
57      * Load attributes based on database arguments
58      *
59      * Loads all the DB stuff
60      *
61      * @param array $args $_REQUEST array
62      *
63      * @return success flag
64      */
65     function prepare($args)
66     {
67         parent::prepare($args);
68
69         $this->page = 1;
70
71         $id            = $this->trimmed('message');
72         $this->message = Message::staticGet('id', $id);
73
74         if (!$this->message) {
75             // TRANS: Client error displayed requesting a single message that does not exist.
76             $this->clientError(_('No such message.'), 404);
77             return false;
78         }
79
80         $this->user = common_current_user();
81
82         if (empty($this->user) ||
83             ($this->user->id != $this->message->from_profile &&
84              $this->user->id != $this->message->to_profile)) {
85             // TRANS: Client error displayed requesting a single direct message the requesting user was not a party in.
86             throw new ClientException(_('Only the sender and recipient ' .
87                                         'may read this message.'), 403);
88         }
89
90         return true;
91     }
92
93     function handle($args)
94     {
95         $this->showPage();
96     }
97
98     function title()
99     {
100         if ($this->user->id == $this->message->from_profile) {
101             $to = $this->message->getTo();
102             // @todo FIXME: Might be nice if the timestamp could be localised.
103             // TRANS: Page title for single direct message display when viewing user is the sender.
104             // TRANS: %1$s is the addressed user's nickname, $2$s is a timestamp.
105             return sprintf(_('Message to %1$s on %2$s'),
106                              $to->nickname,
107                              common_exact_date($this->message->created));
108         } else if ($this->user->id == $this->message->to_profile) {
109             $from = $this->message->getFrom();
110             // @todo FIXME: Might be nice if the timestamp could be localised.
111             // TRANS: Page title for single message display.
112             // TRANS: %1$s is the sending user's nickname, $2$s is a timestamp.
113             return sprintf(_('Message from %1$s on %2$s'),
114                              $from->nickname,
115                              common_exact_date($this->message->created));
116         }
117     }
118
119
120     function showContent()
121     {
122         $this->elementStart('ul', 'notices messages');
123         $ml = new ShowMessageListItem($this, $this->message, $this->user);
124         $ml->show();
125         $this->elementEnd('ul');
126     }
127
128     function isReadOnly($args)
129     {
130         return true;
131     }
132
133     /**
134      * Don't show aside
135      *
136      * @return void
137      */
138
139     function showAside() {
140     }
141 }
142
143 class ShowMessageListItem extends MessageListItem
144 {
145     var $user;
146
147     function __construct($out, $message, $user)
148     {
149         parent::__construct($out, $message);
150         $this->user = $user;
151     }
152
153     function getMessageProfile()
154     {
155         if ($this->user->id == $this->message->from_profile) {
156             return $this->message->getTo();
157         } else if ($this->user->id == $this->message->to_profile) {
158             return $this->message->getFrom();
159         } else {
160             // This shouldn't happen
161             return null;
162         }
163     }
164 }