]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/DirectMessage/actions/showmessage.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / DirectMessage / 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::getKV('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         }
78
79         $this->user = common_current_user();
80
81         if (empty($this->user) ||
82             ($this->user->id != $this->message->from_profile &&
83              $this->user->id != $this->message->to_profile)) {
84             // TRANS: Client error displayed requesting a single direct message the requesting user was not a party in.
85             throw new ClientException(_('Only the sender and recipient ' .
86                                         'may read this message.'), 403);
87         }
88
89         return true;
90     }
91
92     function handle($args)
93     {
94         $this->showPage();
95     }
96
97     function title()
98     {
99         if ($this->user->id == $this->message->from_profile) {
100             $to = $this->message->getTo();
101             // @todo FIXME: Might be nice if the timestamp could be localised.
102             // TRANS: Page title for single direct message display when viewing user is the sender.
103             // TRANS: %1$s is the addressed user's nickname, $2$s is a timestamp.
104             return sprintf(_('Message to %1$s on %2$s'),
105                              $to->nickname,
106                              common_exact_date($this->message->created));
107         } else if ($this->user->id == $this->message->to_profile) {
108             $from = $this->message->getFrom();
109             // @todo FIXME: Might be nice if the timestamp could be localised.
110             // TRANS: Page title for single message display.
111             // TRANS: %1$s is the sending user's nickname, $2$s is a timestamp.
112             return sprintf(_('Message from %1$s on %2$s'),
113                              $from->nickname,
114                              common_exact_date($this->message->created));
115         }
116     }
117
118
119     function showContent()
120     {
121         $this->elementStart('ul', 'notices messages');
122         $ml = new ShowMessageListItem($this, $this->message, $this->user);
123         $ml->show();
124         $this->elementEnd('ul');
125     }
126
127     function isReadOnly($args)
128     {
129         return true;
130     }
131
132     /**
133      * Don't show aside
134      *
135      * @return void
136      */
137
138     function showAside() {
139     }
140 }
141
142 class ShowMessageListItem extends MessageListItem
143 {
144     var $user;
145
146     function __construct($out, $message, $user)
147     {
148         parent::__construct($out, $message);
149         $this->user = $user;
150     }
151
152     function getMessageProfile()
153     {
154         if ($this->user->id == $this->message->from_profile) {
155             return $this->message->getTo();
156         } else if ($this->user->id == $this->message->to_profile) {
157             return $this->message->getFrom();
158         } else {
159             // This shouldn't happen
160             return null;
161         }
162     }
163 }