3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 use Friendica\Core\Logger;
24 use Friendica\Core\Renderer;
25 use Friendica\Database\DBA;
27 use Friendica\Model\Mail;
28 use Friendica\Model\Profile;
29 use Friendica\Model\User;
30 use Friendica\Util\Strings;
32 function wallmessage_post(App $a) {
34 $replyto = Profile::getMyURL();
36 notice(DI::l10n()->t('Permission denied.'));
40 $subject = trim($_REQUEST['subject'] ?? '');
41 $body = Strings::escapeHtml(trim($_REQUEST['body'] ?? ''));
43 $recipient = ((DI::args()->getArgc() > 1) ? DI::args()->getArgv()[1] : '');
44 if ((! $recipient) || (! $body)) {
48 $user = User::getByNickname($recipient);
50 Logger::notice('wallmessage: no recipient');
54 if (!$user['unkmail']) {
55 notice(DI::l10n()->t('Permission denied.'));
59 $total = DBA::count('mail', ["`uid` = ? AND `created` > UTC_TIMESTAMP() - INTERVAL 1 DAY AND `unknown`", $user['uid']]);
60 if ($total > $user['cntunkmail']) {
61 notice(DI::l10n()->t('Number of daily wall messages for %s exceeded. Message failed.', $user['username']));
65 $ret = Mail::sendWall($user, $body, $subject, $replyto);
69 notice(DI::l10n()->t('No recipient selected.'));
72 notice(DI::l10n()->t('Unable to check your home location.'));
75 notice(DI::l10n()->t('Message could not be sent.'));
78 notice(DI::l10n()->t('Message collection failure.'));
82 DI::baseUrl()->redirect('profile/'.$user['nickname']);
86 function wallmessage_content(App $a) {
88 if (!Profile::getMyURL()) {
89 notice(DI::l10n()->t('Permission denied.'));
93 $recipient = ((DI::args()->getArgc() > 1) ? DI::args()->getArgv()[1] : '');
96 notice(DI::l10n()->t('No recipient.'));
100 $user = User::getByNickname($recipient);
103 notice(DI::l10n()->t('No recipient.'));
104 Logger::notice('wallmessage: no recipient');
108 if (!$user['unkmail']) {
109 notice(DI::l10n()->t('Permission denied.'));
113 $total = DBA::count('mail', ["`uid` = ? AND `created` > UTC_TIMESTAMP() - INTERVAL 1 DAY AND `unknown`", $user['uid']]);
114 if ($total > $user['cntunkmail']) {
115 notice(DI::l10n()->t('Number of daily wall messages for %s exceeded. Message failed.', $user['username']));
119 $tpl = Renderer::getMarkupTemplate('wallmsg-header.tpl');
120 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [
121 '$baseurl' => DI::baseUrl()->get(true),
122 '$nickname' => $user['nickname'],
123 '$linkurl' => DI::l10n()->t('Please enter a link URL:')
126 $tpl = Renderer::getMarkupTemplate('wallmessage.tpl');
127 $o = Renderer::replaceMacros($tpl, [
128 '$header' => DI::l10n()->t('Send Private Message'),
129 '$subheader' => DI::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']),
130 '$to' => DI::l10n()->t('To:'),
131 '$subject' => DI::l10n()->t('Subject:'),
132 '$recipname' => $user['username'],
133 '$nickname' => $user['nickname'],
134 '$subjtxt' => $_REQUEST['subject'] ?? '',
135 '$text' => $_REQUEST['body'] ?? '',
137 '$yourmessage'=> DI::l10n()->t('Your message:'),
139 '$upload' => DI::l10n()->t('Upload photo'),
140 '$insert' => DI::l10n()->t('Insert web link'),
141 '$wait' => DI::l10n()->t('Please wait')