Create Profile\UnkMail module class
This commit is contained in:
parent
3865733e18
commit
9561910e83
|
@ -349,7 +349,7 @@ class Profile
|
|||
if ($visitor_is_followed || $visitor_is_following) {
|
||||
$wallmessage_link = $visitor_base_path . '/message/new/' . $profile_contact['id'];
|
||||
} elseif ($visitor_is_authenticated && !empty($profile['unkmail'])) {
|
||||
$wallmessage_link = 'wallmessage/' . $profile['nickname'];
|
||||
$wallmessage_link = 'profile/' . $profile['nickname'] . '/unkmail';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
166
src/Module/Profile/UnkMail.php
Normal file
166
src/Module/Profile/UnkMail.php
Normal file
|
@ -0,0 +1,166 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Module\Profile;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Model\Mail;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Response;
|
||||
use Friendica\Navigation\SystemMessages;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Profiler;
|
||||
use Friendica\Util\Strings;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Unknown Mail module
|
||||
*/
|
||||
class UnkMail extends \Friendica\BaseModule
|
||||
{
|
||||
/** @var IHandleUserSessions */
|
||||
private $userSessions;
|
||||
|
||||
/** @var SystemMessages */
|
||||
private $systemMessages;
|
||||
|
||||
/** @var Database */
|
||||
private $database;
|
||||
|
||||
/** @var App\Page */
|
||||
private $page;
|
||||
|
||||
public function __construct(App\Page $page, Database $database, SystemMessages $systemMessages, IHandleUserSessions $userSessions, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->userSessions = $userSessions;
|
||||
$this->systemMessages = $systemMessages;
|
||||
$this->database = $database;
|
||||
$this->page = $page;
|
||||
}
|
||||
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
$replyto = $this->userSessions->getMyUrl();
|
||||
if (!$replyto) {
|
||||
$this->systemMessages->addNotice($this->l10n->t('Permission denied.'));
|
||||
return;
|
||||
}
|
||||
|
||||
$recipient = $this->parameters['nickname'];
|
||||
$subject = trim($request['subject'] ?? '');
|
||||
$body = Strings::escapeHtml(trim($request['body'] ?? ''));
|
||||
|
||||
if (!$body) {
|
||||
$this->systemMessages->addNotice($this->l10n->t('Empty message body.'));
|
||||
return;
|
||||
}
|
||||
|
||||
$user = User::getByNickname($recipient);
|
||||
if (empty($user)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$user['unkmail']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$total = $this->database->count('mail', ["`uid` = ? AND `created` > ? AND `unknown`", $user['uid'], DateTimeFormat::utc('now - 1 day')]);
|
||||
if ($total > $user['cntunkmail']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$ret = Mail::sendWall($user, $body, $subject, $replyto);
|
||||
|
||||
switch ($ret) {
|
||||
case -1:
|
||||
$this->systemMessages->addNotice($this->l10n->t('No recipient selected.'));
|
||||
break;
|
||||
case -2:
|
||||
$this->systemMessages->addNotice($this->l10n->t('Unable to check your home location.'));
|
||||
break;
|
||||
case -3:
|
||||
$this->systemMessages->addNotice($this->l10n->t('Message could not be sent.'));
|
||||
break;
|
||||
case -4:
|
||||
$this->systemMessages->addNotice($this->l10n->t('Message collection failure.'));
|
||||
break;
|
||||
}
|
||||
|
||||
$this->baseUrl->redirect('profile/' . $user['nickname']);
|
||||
}
|
||||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
$returnUrl = 'profile/' . $this->parameters['nickname'];
|
||||
|
||||
if (!$this->userSessions->getMyUrl()) {
|
||||
$this->systemMessages->addNotice($this->l10n->t('Permission denied.'));
|
||||
$this->baseUrl->redirect($returnUrl);
|
||||
}
|
||||
|
||||
$user = User::getByNickname($this->parameters['nickname']);
|
||||
if (empty($user)) {
|
||||
$this->systemMessages->addNotice($this->l10n->t('Recipient not found.'));
|
||||
$this->baseUrl->redirect($returnUrl);
|
||||
}
|
||||
|
||||
if (!$user['unkmail']) {
|
||||
$this->systemMessages->addNotice($this->l10n->t('Permission denied.'));
|
||||
$this->baseUrl->redirect($returnUrl);
|
||||
}
|
||||
|
||||
$total = $this->database->count('mail', ["`uid` = ? AND `created` > ? AND `unknown`", $user['uid'], DateTimeFormat::utc('now - 1 day')]);
|
||||
if ($total > $user['cntunkmail']) {
|
||||
$this->systemMessages->addNotice($this->l10n->t('Number of daily wall messages for %s exceeded. Message failed.', $user['username']));
|
||||
$this->baseUrl->redirect($returnUrl);
|
||||
}
|
||||
|
||||
$tpl = Renderer::getMarkupTemplate('profile/unkmail-header.tpl');
|
||||
$this->page['htmlhead'] .= Renderer::replaceMacros($tpl, [
|
||||
'$baseurl' => $this->baseUrl->get(true),
|
||||
'$nickname' => $user['nickname'],
|
||||
'$linkurl' => $this->l10n->t('Please enter a link URL:')
|
||||
]);
|
||||
|
||||
$tpl = Renderer::getMarkupTemplate('profile/unkmail.tpl');
|
||||
return Renderer::replaceMacros($tpl, [
|
||||
'$l10n' => [
|
||||
'header' => $this->l10n->t('Send Private Message'),
|
||||
'subheader' => $this->l10n->t('If you wish for %s to respond, please check that the privacy settings on your site allow private mail from unknown senders.', $user['username']),
|
||||
'insert' => $this->l10n->t('Insert web link'),
|
||||
'wait' => $this->l10n->t('Please wait'),
|
||||
'submit' => $this->l10n->t('Submit'),
|
||||
],
|
||||
|
||||
'$nickname' => $user['nickname'],
|
||||
|
||||
'$to' => ['to' , $this->l10n->t('To') , $user['username'], '', '', 'disabled'],
|
||||
'$subject' => ['subject', $this->l10n->t('Subject') , $request['subject'] ?? ''],
|
||||
'$body' => ['body' , $this->l10n->t('Your message'), $request['body'] ?? ''],
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -38,6 +38,7 @@ $profileRoutes = [
|
|||
'/contacts[/{type}]' => [Module\Profile\Contacts::class, [R::GET]],
|
||||
'/status[/{category}[/{date1}[/{date2}]]]' => [Module\Profile\Status::class, [R::GET]],
|
||||
'/media' => [Module\Profile\Media::class, [R::GET]],
|
||||
'/unkmail' => [Module\Profile\UnkMail::class, [R::GET, R::POST]],
|
||||
];
|
||||
|
||||
$apiRoutes = [
|
||||
|
|
15
view/templates/profile/unkmail-header.tpl
Normal file
15
view/templates/profile/unkmail-header.tpl
Normal file
|
@ -0,0 +1,15 @@
|
|||
<script language="javascript" type="text/javascript">
|
||||
$("#id_body").editor_autocomplete(baseurl + '/search/acl');
|
||||
</script>
|
||||
<script>
|
||||
function jotGetLink() {
|
||||
reply = prompt("{{$linkurl}}");
|
||||
if (reply && reply.length) {
|
||||
$('#profile-rotator').show();
|
||||
$.get('parseurl?url=' + reply, function (data) {
|
||||
addeditortext(data);
|
||||
$('#profile-rotator').hide();
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
26
view/templates/profile/unkmail.tpl
Normal file
26
view/templates/profile/unkmail.tpl
Normal file
|
@ -0,0 +1,26 @@
|
|||
<div class="generic-page-wrapper">
|
||||
<h2>{{$l10n.header}}</h2>
|
||||
<p>{{$l10n.subheader}}</p>
|
||||
<div id="prvmail-wrapper">
|
||||
<form id="prvmail-form" action="profile/{{$nickname}}/unkmail" method="post">
|
||||
{{include file="field_input.tpl" field=$to}}
|
||||
|
||||
{{include file="field_input.tpl" field=$subject}}
|
||||
|
||||
{{include file="field_textarea.tpl" field=$body}}
|
||||
|
||||
<div id="prvmail-submit-wrapper">
|
||||
<button type="submit" id="prvmail-submit" class="btn btn-primary" name="submit">
|
||||
{{$l10n.submit}}
|
||||
</button>
|
||||
<div id="prvmail-link-wrapper">
|
||||
<div id="prvmail-link" class="icon border link" title="{{$l10n.insert}}" onclick="jotGetLink();"></div>
|
||||
</div>
|
||||
<div id="prvmail-rotator-wrapper">
|
||||
<img id="prvmail-rotator" src="images/rotator.gif" alt="{{$l10n.wait}}" title="{{$l10n.wait}}" style="display: none;"/>
|
||||
</div>
|
||||
</div>
|
||||
<div id="prvmail-end"></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in a new issue