2008-09-18 02:47:41 +09:00
|
|
|
<?php
|
2019-08-20 06:51:51 +09: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 10:49:47 +09:00
|
|
|
/**
|
2019-08-20 06:51:51 +09:00
|
|
|
* GNUsocial implementation of Direct Messages
|
2008-09-18 02:47:41 +09:00
|
|
|
*
|
2019-08-20 06:51:51 +09: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-18 02:47:41 +09:00
|
|
|
*/
|
2009-01-26 22:05:59 +09:00
|
|
|
|
2019-08-20 06:51:51 +09:00
|
|
|
defined('GNUSOCIAL') || die();
|
2008-09-18 02:47:41 +09:00
|
|
|
|
2009-01-21 10:49:47 +09:00
|
|
|
/**
|
|
|
|
* Action for posting new direct messages
|
|
|
|
*
|
2019-08-20 06:51:51 +09:00
|
|
|
* @category Plugin
|
|
|
|
* @package GNUsocial
|
2009-08-26 07:19:04 +09:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @author Zach Copley <zach@status.net>
|
|
|
|
* @author Sarven Capadisli <csarven@status.net>
|
2019-08-20 06:51:51 +09:00
|
|
|
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
2009-01-21 10:49:47 +09:00
|
|
|
*/
|
2013-09-02 17:59:02 +09:00
|
|
|
class NewmessageAction extends FormAction
|
2008-12-24 04:49:23 +09:00
|
|
|
{
|
2019-08-20 06:51:51 +09:00
|
|
|
protected $form = 'Message';
|
|
|
|
protected $to = null;
|
|
|
|
protected $content = null;
|
2015-01-21 21:02:46 +09:00
|
|
|
|
2009-01-21 10:49:47 +09:00
|
|
|
/**
|
2019-08-20 06:51:51 +09:00
|
|
|
* Title of the page.
|
|
|
|
* Note that this usually doesn't get called unless something went wrong.
|
2009-01-21 10:49:47 +09:00
|
|
|
*
|
|
|
|
* @return string page title
|
|
|
|
*/
|
2019-08-20 06:51:51 +09:00
|
|
|
function title() : string
|
2009-01-21 10:49:47 +09:00
|
|
|
{
|
2011-03-05 08:12:38 +09:00
|
|
|
// TRANS: Page title for new direct message page.
|
2009-01-21 10:49:47 +09:00
|
|
|
return _('New message');
|
|
|
|
}
|
2009-01-26 22:05:59 +09:00
|
|
|
|
2015-03-09 04:41:42 +09:00
|
|
|
protected function doPreparation()
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2019-08-20 06:51:51 +09:00
|
|
|
if ($this->trimmed('to')) {
|
|
|
|
$this->to = Profile::getKV('id', $this->trimmed('to'));
|
|
|
|
if (!$this->to instanceof Profile) {
|
2011-03-05 08:12:38 +09:00
|
|
|
// TRANS: Client error displayed trying to send a direct message to a non-existing user.
|
2009-11-09 07:10:44 +09:00
|
|
|
$this->clientError(_('No such user.'), 404);
|
2009-01-26 22:05:59 +09:00
|
|
|
}
|
|
|
|
|
2019-08-20 06:51:51 +09:00
|
|
|
$this->formOpts['to'] = $this->to;
|
|
|
|
}
|
2014-04-30 03:37:58 +09:00
|
|
|
|
2019-08-20 06:51:51 +09:00
|
|
|
if ($this->trimmed('content')) {
|
|
|
|
$this->content = $this->trimmed('content');
|
|
|
|
$this->formOpts['content'] = $this->content;
|
2009-01-26 22:05:59 +09:00
|
|
|
}
|
|
|
|
|
2019-08-20 06:51:51 +09: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 22:05:59 +09:00
|
|
|
}
|
|
|
|
|
2015-03-09 04:41:42 +09:00
|
|
|
protected function doPost()
|
2009-01-26 22:05:59 +09:00
|
|
|
{
|
2014-04-30 03:37:58 +09:00
|
|
|
assert($this->scoped instanceof Profile); // XXX: maybe an error instead...
|
2009-01-26 22:05:59 +09:00
|
|
|
|
2015-03-09 04:41:42 +09:00
|
|
|
if (empty($this->content)) {
|
2011-03-05 08:12:38 +09:00
|
|
|
// TRANS: Form validator error displayed trying to send a direct message without content.
|
2013-09-02 17:59:02 +09:00
|
|
|
$this->clientError(_('No content!'));
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
|
2015-03-09 04:41:42 +09:00
|
|
|
$content_shortened = $this->scoped->shortenLinks($this->content);
|
|
|
|
|
2019-08-20 06:51:51 +09:00
|
|
|
if (MessageModel::contentTooLong($content_shortened)) {
|
2015-03-09 04:41:42 +09: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-20 06:51:51 +09:00
|
|
|
MessageModel::maxContent()),
|
|
|
|
MessageModel::maxContent()));
|
2015-03-09 04:41:42 +09:00
|
|
|
}
|
|
|
|
|
2019-08-20 06:51:51 +09: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-24 04:19:07 +09:00
|
|
|
}
|
2009-01-26 22:05:59 +09:00
|
|
|
|
2019-08-20 06:51:51 +09:00
|
|
|
$message = MessageModel::saveNew($this->scoped, $this->content);
|
|
|
|
Event::handle('SendDirectMessage', [$message]);
|
|
|
|
mail_notify_message($message);
|
2008-12-24 04:19:07 +09:00
|
|
|
|
2015-03-09 04:41:42 +09:00
|
|
|
if (GNUsocial::isAjax()) {
|
|
|
|
// TRANS: Confirmation text after sending a direct message.
|
|
|
|
// TRANS: %s is the direct message recipient.
|
2019-08-20 06:51:51 +09:00
|
|
|
return sprintf(_('Direct message to %s sent.'), $this->to->getNickname());
|
2009-11-01 00:14:38 +09:00
|
|
|
}
|
2009-01-26 21:46:04 +09:00
|
|
|
|
2015-03-09 04:41:42 +09:00
|
|
|
$url = common_local_url('outbox', array('nickname' => $this->scoped->getNickname()));
|
|
|
|
common_redirect($url, 303);
|
2009-01-26 21:46:04 +09:00
|
|
|
}
|
2009-01-26 22:05:59 +09:00
|
|
|
|
|
|
|
function showNoticeForm()
|
|
|
|
{
|
2015-03-09 04:41:42 +09:00
|
|
|
// Just don't show a NoticeForm
|
2009-01-26 22:05:59 +09:00
|
|
|
}
|
2008-09-18 02:47:41 +09:00
|
|
|
}
|