3 * StatusNet, the distributed open-source microblogging tool
5 * Handler for posting new messages
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.
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.
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/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @author Zach Copley <zach@status.net>
26 * @author Sarven Capadisli <csarven@status.net>
27 * @copyright 2008-2009 StatusNet, Inc.
28 * @copyright 2013 Free Software Foundation, Inc.
29 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
30 * @link http://status.net/
33 if (!defined('STATUSNET')) {
38 * Action for posting new direct messages
42 * @author Evan Prodromou <evan@status.net>
43 * @author Zach Copley <zach@status.net>
44 * @author Sarven Capadisli <csarven@status.net>
45 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
46 * @link http://status.net/
49 class NewmessageAction extends FormAction
55 protected $form = 'message'; // will become MessageForm later
60 * Note that this usually doesn't get called unless something went wrong
62 * @return string page title
67 // TRANS: Page title for new direct message page.
68 return _('New message');
72 * Handle input, produce output
74 * @param array $args $_REQUEST contents
79 protected function prepare(array $args=array())
81 parent::prepare($args);
83 $this->content = $this->trimmed('content');
84 $this->to = $this->trimmed('to');
88 $this->other = Profile::getKV('id', $this->to);
90 if (!$this->other instanceof Profile) {
91 // TRANS: Client error displayed trying to send a direct message to a non-existing user.
92 $this->clientError(_('No such user.'), 404);
95 if (!$this->other->isLocal()) {
96 // TRANS: Explains that current federation does not support direct, private messages yet.
97 $this->clientError(_('You cannot send direct messages to federated users yet.'));
100 if (!$this->scoped->mutuallySubscribed($this->other)) {
101 // TRANS: Client error displayed trying to send a direct message to a user while sender and
102 // TRANS: receiver are not subscribed to each other.
103 $this->clientError(_('You cannot send a message to this user.'), 404);
110 protected function handlePost()
112 parent::handlePost();
114 assert($this->scoped instanceof Profile); // XXX: maybe an error instead...
116 if (!$this->content) {
117 // TRANS: Form validator error displayed trying to send a direct message without content.
118 $this->clientError(_('No content!'));
120 $content_shortened = $this->scoped->shortenLinks($this->content);
122 if (Message::contentTooLong($content_shortened)) {
123 // TRANS: Form validation error displayed when message content is too long.
124 // TRANS: %d is the maximum number of characters for a message.
125 $this->clientError(sprintf(_m('That\'s too long. Maximum message size is %d character.',
126 'That\'s too long. Maximum message size is %d characters.',
127 Message::maxContent()),
128 Message::maxContent()));
133 // TRANS: Form validation error displayed trying to send a direct message without specifying a recipient.
134 $this->clientError(_('No recipient specified.'));
135 } else if (!$this->scoped->mutuallySubscribed($this->other)) {
136 // TRANS: Client error displayed trying to send a direct message to a user while sender and
137 // TRANS: receiver are not subscribed to each other.
138 $this->clientError(_('You cannot send a message to this user.'), 404);
139 } else if ($this->scoped->id == $this->other->id) {
140 // TRANS: Client error displayed trying to send a direct message to self.
141 $this->clientError(_('Do not send a message to yourself; ' .
142 'just say it to yourself quietly instead.'), 403);
145 $message = Message::saveNew($this->scoped->id, $this->other->id, $this->content, 'web');
148 if ($this->boolean('ajax')) {
149 $this->startHTML('text/xml;charset=utf-8');
150 $this->elementStart('head');
151 // TRANS: Page title after sending a direct message.
152 $this->element('title', null, _('Message sent'));
153 $this->elementEnd('head');
154 $this->elementStart('body');
155 $this->element('p', array('id' => 'command_result'),
156 // TRANS: Confirmation text after sending a direct message.
157 // TRANS: %s is the direct message recipient.
158 sprintf(_('Direct message to %s sent.'),
159 $this->other->nickname));
160 $this->elementEnd('body');
163 $url = common_local_url('outbox',
164 array('nickname' => $this->scoped->nickname));
165 common_redirect($url, 303);
170 * Show an Ajax-y error message
172 * Goes back to the browser, where it's shown in a popup.
174 * @param string $msg Message to show
179 function ajaxErrorMsg($msg)
181 $this->startHTML('text/xml;charset=utf-8', true);
182 $this->elementStart('head');
183 // TRANS: Page title after an AJAX error occurred on the "send direct message" page.
184 $this->element('title', null, _('Ajax Error'));
185 $this->elementEnd('head');
186 $this->elementStart('body');
187 $this->element('p', array('id' => 'error'), $msg);
188 $this->elementEnd('body');
192 function showForm($msg = null)
194 if ($msg && $this->boolean('ajax')) {
195 $this->ajaxErrorMsg($msg);
200 if ($this->trimmed('ajax')) {
201 $this->startHTML('text/xml;charset=utf-8');
202 $this->elementStart('head');
203 // TRANS: Page title on page for sending a direct message.
204 $this->element('title', null, _('New message'));
205 $this->elementEnd('head');
206 $this->elementStart('body');
207 $this->showNoticeForm();
208 $this->elementEnd('body');
216 function showPageNotice()
219 $this->element('p', 'error', $this->msg);
223 // Do nothing (override)
225 function showNoticeForm()
227 $message_form = new MessageForm($this, $this->other, $this->content);
228 $message_form->show();