]> git.mxchange.org Git - friendica.git/blob - mod/wallmessage.php
"escapeTags" is finally removed
[friendica.git] / mod / wallmessage.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 use Friendica\App;
23 use Friendica\Core\Logger;
24 use Friendica\Core\Renderer;
25 use Friendica\Database\DBA;
26 use Friendica\DI;
27 use Friendica\Model\Mail;
28 use Friendica\Model\Profile;
29 use Friendica\Model\User;
30 use Friendica\Util\Strings;
31
32 function wallmessage_post(App $a) {
33
34         $replyto = Profile::getMyURL();
35         if (!$replyto) {
36                 notice(DI::l10n()->t('Permission denied.'));
37                 return;
38         }
39
40         $subject   = trim($_REQUEST['subject'] ?? '');
41         $body      = Strings::escapeHtml(trim($_REQUEST['body'] ?? ''));
42
43         $recipient = ((DI::args()->getArgc() > 1) ? DI::args()->getArgv()[1] : '');
44         if ((! $recipient) || (! $body)) {
45                 return;
46         }
47
48         $user = User::getByNickname($recipient);
49         if (empty($r)) {
50                 Logger::notice('wallmessage: no recipient');
51                 return;
52         }
53
54         if (!$user['unkmail']) {
55                 notice(DI::l10n()->t('Permission denied.'));
56                 return;
57         }
58
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']));
62                 return;
63         }
64
65         $ret = Mail::sendWall($user, $body, $subject, $replyto);
66
67         switch ($ret) {
68                 case -1:
69                         notice(DI::l10n()->t('No recipient selected.'));
70                         break;
71                 case -2:
72                         notice(DI::l10n()->t('Unable to check your home location.'));
73                         break;
74                 case -3:
75                         notice(DI::l10n()->t('Message could not be sent.'));
76                         break;
77                 case -4:
78                         notice(DI::l10n()->t('Message collection failure.'));
79                         break;
80         }
81
82         DI::baseUrl()->redirect('profile/'.$user['nickname']);
83 }
84
85
86 function wallmessage_content(App $a) {
87
88         if (!Profile::getMyURL()) {
89                 notice(DI::l10n()->t('Permission denied.'));
90                 return;
91         }
92
93         $recipient = ((DI::args()->getArgc() > 1) ? DI::args()->getArgv()[1] : '');
94
95         if (!$recipient) {
96                 notice(DI::l10n()->t('No recipient.'));
97                 return;
98         }
99
100         $user = User::getByNickname($recipient);
101
102         if (empty($user)) {
103                 notice(DI::l10n()->t('No recipient.'));
104                 Logger::notice('wallmessage: no recipient');
105                 return;
106         }
107
108         if (!$user['unkmail']) {
109                 notice(DI::l10n()->t('Permission denied.'));
110                 return;
111         }
112
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']));
116                 return;
117         }
118
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:')
124         ]);
125
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'] ?? '',
136                 '$readonly'   => '',
137                 '$yourmessage'=> DI::l10n()->t('Your message:'),
138                 '$parent'     => '',
139                 '$upload'     => DI::l10n()->t('Upload photo'),
140                 '$insert'     => DI::l10n()->t('Insert web link'),
141                 '$wait'       => DI::l10n()->t('Please wait')
142         ]);
143
144         return $o;
145 }