2008-09-17 18:47:41 +01:00
|
|
|
<?php
|
2019-08-19 22:51:51 +01:00
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2009-01-21 01:49:47 +00:00
|
|
|
/**
|
2019-08-19 22:51:51 +01:00
|
|
|
* GNUsocial implementation of Direct Messages
|
2008-09-17 18:47:41 +01:00
|
|
|
*
|
2019-08-19 22:51:51 +01:00
|
|
|
* @package GNUsocial
|
|
|
|
* @author Mikael Nordfeldth <mmn@hethane.se>
|
|
|
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
|
|
|
* @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
|
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
2008-09-17 18:47:41 +01:00
|
|
|
*/
|
2009-01-26 13:05:59 +00:00
|
|
|
|
2019-08-19 22:51:51 +01:00
|
|
|
defined('GNUSOCIAL') || die();
|
2008-09-17 18:47:41 +01:00
|
|
|
|
2009-01-21 01:49:47 +00:00
|
|
|
/**
|
|
|
|
* Action for posting new direct messages
|
|
|
|
*
|
2019-08-19 22:51:51 +01:00
|
|
|
* @category Plugin
|
|
|
|
* @package GNUsocial
|
2009-08-25 23:19:04 +01:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @author Zach Copley <zach@status.net>
|
|
|
|
* @author Sarven Capadisli <csarven@status.net>
|
2019-08-19 22:51:51 +01:00
|
|
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
2009-01-21 01:49:47 +00:00
|
|
|
*/
|
2013-09-02 09:59:02 +01:00
|
|
|
class NewmessageAction extends FormAction
|
2008-12-23 19:49:23 +00:00
|
|
|
{
|
2019-08-19 22:51:51 +01:00
|
|
|
protected $form = 'Message';
|
|
|
|
protected $to = null;
|
|
|
|
protected $content = null;
|
2015-01-21 12:02:46 +00:00
|
|
|
|
2009-01-21 01:49:47 +00:00
|
|
|
/**
|
2019-08-19 22:51:51 +01:00
|
|
|
* Title of the page.
|
|
|
|
* Note that this usually doesn't get called unless something went wrong.
|
2009-01-21 01:49:47 +00:00
|
|
|
*
|
|
|
|
* @return string page title
|
|
|
|
*/
|
2019-08-19 22:51:51 +01:00
|
|
|
function title() : string
|
2009-01-21 01:49:47 +00:00
|
|
|
{
|
2011-03-04 23:12:38 +00:00
|
|
|
// TRANS: Page title for new direct message page.
|
2009-01-21 01:49:47 +00:00
|
|
|
return _('New message');
|
|
|
|
}
|
2009-01-26 13:05:59 +00:00
|
|
|
|
2015-03-08 19:41:42 +00:00
|
|
|
protected function doPreparation()
|
2008-12-23 19:33:23 +00:00
|
|
|
{
|
2019-08-19 22:51:51 +01:00
|
|
|
if ($this->trimmed('to')) {
|
|
|
|
$this->to = Profile::getKV('id', $this->trimmed('to'));
|
|
|
|
if (!$this->to instanceof Profile) {
|
2011-03-04 23:12:38 +00:00
|
|
|
// TRANS: Client error displayed trying to send a direct message to a non-existing user.
|
2009-11-08 22:10:44 +00:00
|
|
|
$this->clientError(_('No such user.'), 404);
|
2009-01-26 13:05:59 +00:00
|
|
|
}
|
|
|
|
|
2019-08-19 22:51:51 +01:00
|
|
|
$this->formOpts['to'] = $this->to;
|
|
|
|
}
|
2014-04-29 19:37:58 +01:00
|
|
|
|
2019-08-19 22:51:51 +01:00
|
|
|
if ($this->trimmed('content')) {
|
|
|
|
$this->content = $this->trimmed('content');
|
|
|
|
$this->formOpts['content'] = $this->content;
|
2009-01-26 13:05:59 +00:00
|
|
|
}
|
|
|
|
|
2019-08-19 22:51:51 +01:00
|
|
|
if ($this->trimmed('to-box')) {
|
|
|
|
$selected = explode(':', $this->trimmed('to-box'));
|
|
|
|
|
|
|
|
if (sizeof($selected) == 2) {
|
|
|
|
$this->to = Profile::getKV('id', $selected[1]);
|
|
|
|
// validating later
|
|
|
|
}
|
|
|
|
}
|
2009-01-26 13:05:59 +00:00
|
|
|
}
|
|
|
|
|
2015-03-08 19:41:42 +00:00
|
|
|
protected function doPost()
|
2009-01-26 13:05:59 +00:00
|
|
|
{
|
2014-04-29 19:37:58 +01:00
|
|
|
assert($this->scoped instanceof Profile); // XXX: maybe an error instead...
|
2009-01-26 13:05:59 +00:00
|
|
|
|
2015-03-08 19:41:42 +00:00
|
|
|
if (empty($this->content)) {
|
2011-03-04 23:12:38 +00:00
|
|
|
// TRANS: Form validator error displayed trying to send a direct message without content.
|
2013-09-02 09:59:02 +01:00
|
|
|
$this->clientError(_('No content!'));
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
|
|
|
|
2015-03-08 19:41:42 +00:00
|
|
|
$content_shortened = $this->scoped->shortenLinks($this->content);
|
|
|
|
|
2019-08-19 22:51:51 +01:00
|
|
|
if (MessageModel::contentTooLong($content_shortened)) {
|
2015-03-08 19:41:42 +00:00
|
|
|
// TRANS: Form validation error displayed when message content is too long.
|
|
|
|
// TRANS: %d is the maximum number of characters for a message.
|
|
|
|
$this->clientError(sprintf(_m('That\'s too long. Maximum message size is %d character.',
|
|
|
|
'That\'s too long. Maximum message size is %d characters.',
|
2019-08-19 22:51:51 +01:00
|
|
|
MessageModel::maxContent()),
|
|
|
|
MessageModel::maxContent()));
|
2015-03-08 19:41:42 +00:00
|
|
|
}
|
|
|
|
|
2019-08-19 22:51:51 +01:00
|
|
|
// validate recipients
|
|
|
|
if (!$this->to instanceof Profile) {
|
|
|
|
$mentions = common_find_mentions($this->content, $this->scoped);
|
|
|
|
if (empty($mentions)) {
|
|
|
|
$this->clientError(_('No recipients specified.'));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// push to-box profile to the content message, will be
|
|
|
|
// detected during Notice save
|
|
|
|
try {
|
|
|
|
if ($this->to->isLocal()) {
|
|
|
|
$this->content = "@{$this->to->getNickname()} {$this->content}";
|
|
|
|
} else {
|
|
|
|
$this->content = '@' . substr($this->to->getAcctUri(), 5) . " {$this->content}";
|
|
|
|
}
|
|
|
|
} catch (ProfileNoAcctUriException $e) {
|
|
|
|
// well, I'm no magician
|
|
|
|
}
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
2009-01-26 13:05:59 +00:00
|
|
|
|
2019-08-19 22:51:51 +01:00
|
|
|
$message = MessageModel::saveNew($this->scoped, $this->content);
|
|
|
|
Event::handle('SendDirectMessage', [$message]);
|
|
|
|
mail_notify_message($message);
|
2008-12-23 19:19:07 +00:00
|
|
|
|
2015-03-08 19:41:42 +00:00
|
|
|
if (GNUsocial::isAjax()) {
|
|
|
|
// TRANS: Confirmation text after sending a direct message.
|
|
|
|
// TRANS: %s is the direct message recipient.
|
2019-08-19 22:51:51 +01:00
|
|
|
return sprintf(_('Direct message to %s sent.'), $this->to->getNickname());
|
2009-10-31 15:14:38 +00:00
|
|
|
}
|
2009-01-26 12:46:04 +00:00
|
|
|
|
2015-03-08 19:41:42 +00:00
|
|
|
$url = common_local_url('outbox', array('nickname' => $this->scoped->getNickname()));
|
|
|
|
common_redirect($url, 303);
|
2009-01-26 12:46:04 +00:00
|
|
|
}
|
2009-01-26 13:05:59 +00:00
|
|
|
|
|
|
|
function showNoticeForm()
|
|
|
|
{
|
2015-03-08 19:41:42 +00:00
|
|
|
// Just don't show a NoticeForm
|
2009-01-26 13:05:59 +00:00
|
|
|
}
|
2008-09-17 18:47:41 +01:00
|
|
|
}
|