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\Util\Strings;
31 function wallmessage_post(App $a) {
33 $replyto = Profile::getMyURL();
35 notice(DI::l10n()->t('Permission denied.'));
39 $subject = (!empty($_REQUEST['subject']) ? Strings::escapeTags(trim($_REQUEST['subject'])) : '');
40 $body = (!empty($_REQUEST['body']) ? Strings::escapeHtml(trim($_REQUEST['body'])) : '');
42 $recipient = (($a->argc > 1) ? Strings::escapeTags($a->argv[1]) : '');
43 if ((! $recipient) || (! $body)) {
47 $r = q("select * from user where nickname = '%s' limit 1",
48 DBA::escape($recipient)
51 if (! DBA::isResult($r)) {
52 Logger::log('wallmessage: no recipient');
58 if (! intval($user['unkmail'])) {
59 notice(DI::l10n()->t('Permission denied.'));
63 $r = q("select count(*) as total from mail where uid = %d and created > UTC_TIMESTAMP() - INTERVAL 1 day and unknown = 1",
67 if ($r[0]['total'] > $user['cntunkmail']) {
68 notice(DI::l10n()->t('Number of daily wall messages for %s exceeded. Message failed.', $user['username']));
72 $ret = Mail::sendWall($user, $body, $subject, $replyto);
76 notice(DI::l10n()->t('No recipient selected.'));
79 notice(DI::l10n()->t('Unable to check your home location.'));
82 notice(DI::l10n()->t('Message could not be sent.'));
85 notice(DI::l10n()->t('Message collection failure.'));
89 DI::baseUrl()->redirect('profile/'.$user['nickname']);
93 function wallmessage_content(App $a) {
95 if (!Profile::getMyURL()) {
96 notice(DI::l10n()->t('Permission denied.'));
100 $recipient = (($a->argc > 1) ? $a->argv[1] : '');
103 notice(DI::l10n()->t('No recipient.'));
107 $r = q("select * from user where nickname = '%s' limit 1",
108 DBA::escape($recipient)
111 if (! DBA::isResult($r)) {
112 notice(DI::l10n()->t('No recipient.'));
113 Logger::log('wallmessage: no recipient');
119 if (!intval($user['unkmail'])) {
120 notice(DI::l10n()->t('Permission denied.'));
124 $r = q("select count(*) as total from mail where uid = %d and created > UTC_TIMESTAMP() - INTERVAL 1 day and unknown = 1",
128 if ($r[0]['total'] > $user['cntunkmail']) {
129 notice(DI::l10n()->t('Number of daily wall messages for %s exceeded. Message failed.', $user['username']));
133 $tpl = Renderer::getMarkupTemplate('wallmsg-header.tpl');
134 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [
135 '$baseurl' => DI::baseUrl()->get(true),
136 '$nickname' => $user['nickname'],
137 '$linkurl' => DI::l10n()->t('Please enter a link URL:')
140 $tpl = Renderer::getMarkupTemplate('wallmessage.tpl');
141 $o = Renderer::replaceMacros($tpl, [
142 '$header' => DI::l10n()->t('Send Private Message'),
143 '$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']),
144 '$to' => DI::l10n()->t('To:'),
145 '$subject' => DI::l10n()->t('Subject:'),
146 '$recipname' => $user['username'],
147 '$nickname' => $user['nickname'],
148 '$subjtxt' => $_REQUEST['subject'] ?? '',
149 '$text' => $_REQUEST['body'] ?? '',
151 '$yourmessage'=> DI::l10n()->t('Your message:'),
153 '$upload' => DI::l10n()->t('Upload photo'),
154 '$insert' => DI::l10n()->t('Insert web link'),
155 '$wait' => DI::l10n()->t('Please wait')