]> git.mxchange.org Git - friendica.git/blob - mod/wallmessage.php
Test the license check
[friendica.git] / mod / wallmessage.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, 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\DateTimeFormat;
31 use Friendica\Util\Strings;
32
33 function wallmessage_post(App $a) {
34
35         $replyto = Profile::getMyURL();
36         if (!$replyto) {
37                 notice(DI::l10n()->t('Permission denied.'));
38                 return;
39         }
40
41         $subject   = trim($_REQUEST['subject'] ?? '');
42         $body      = Strings::escapeHtml(trim($_REQUEST['body'] ?? ''));
43
44         $recipient = ((DI::args()->getArgc() > 1) ? DI::args()->getArgv()[1] : '');
45         if ((! $recipient) || (! $body)) {
46                 return;
47         }
48
49         $user = User::getByNickname($recipient);
50         if (empty($r)) {
51                 Logger::notice('wallmessage: no recipient');
52                 return;
53         }
54
55         if (!$user['unkmail']) {
56                 notice(DI::l10n()->t('Permission denied.'));
57                 return;
58         }
59
60         $total = DBA::count('mail', ["`uid` = ? AND `created` > ? AND `unknown`", $user['uid'], DateTimeFormat::utc('now - 1 day')]);
61         if ($total > $user['cntunkmail']) {
62                 notice(DI::l10n()->t('Number of daily wall messages for %s exceeded. Message failed.', $user['username']));
63                 return;
64         }
65
66         $ret = Mail::sendWall($user, $body, $subject, $replyto);
67
68         switch ($ret) {
69                 case -1:
70                         notice(DI::l10n()->t('No recipient selected.'));
71                         break;
72                 case -2:
73                         notice(DI::l10n()->t('Unable to check your home location.'));
74                         break;
75                 case -3:
76                         notice(DI::l10n()->t('Message could not be sent.'));
77                         break;
78                 case -4:
79                         notice(DI::l10n()->t('Message collection failure.'));
80                         break;
81         }
82
83         DI::baseUrl()->redirect('profile/'.$user['nickname']);
84 }
85
86
87 function wallmessage_content(App $a) {
88
89         if (!Profile::getMyURL()) {
90                 notice(DI::l10n()->t('Permission denied.'));
91                 return;
92         }
93
94         $recipient = ((DI::args()->getArgc() > 1) ? DI::args()->getArgv()[1] : '');
95
96         if (!$recipient) {
97                 notice(DI::l10n()->t('No recipient.'));
98                 return;
99         }
100
101         $user = User::getByNickname($recipient);
102
103         if (empty($user)) {
104                 notice(DI::l10n()->t('No recipient.'));
105                 Logger::notice('wallmessage: no recipient');
106                 return;
107         }
108
109         if (!$user['unkmail']) {
110                 notice(DI::l10n()->t('Permission denied.'));
111                 return;
112         }
113
114         $total = DBA::count('mail', ["`uid` = ? AND `created` > ? AND `unknown`", $user['uid'], DateTimeFormat::utc('now - 1 day')]);
115         if ($total > $user['cntunkmail']) {
116                 notice(DI::l10n()->t('Number of daily wall messages for %s exceeded. Message failed.', $user['username']));
117                 return;
118         }
119
120         $tpl = Renderer::getMarkupTemplate('wallmsg-header.tpl');
121         DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [
122                 '$baseurl' => DI::baseUrl()->get(true),
123                 '$nickname' => $user['nickname'],
124                 '$linkurl' => DI::l10n()->t('Please enter a link URL:')
125         ]);
126
127         $tpl = Renderer::getMarkupTemplate('wallmessage.tpl');
128         $o = Renderer::replaceMacros($tpl, [
129                 '$header'     => DI::l10n()->t('Send Private Message'),
130                 '$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']),
131                 '$to'         => DI::l10n()->t('To:'),
132                 '$subject'    => DI::l10n()->t('Subject:'),
133                 '$recipname'  => $user['username'],
134                 '$nickname'   => $user['nickname'],
135                 '$subjtxt'    => $_REQUEST['subject'] ?? '',
136                 '$text'       => $_REQUEST['body'] ?? '',
137                 '$readonly'   => '',
138                 '$yourmessage'=> DI::l10n()->t('Your message:'),
139                 '$parent'     => '',
140                 '$upload'     => DI::l10n()->t('Upload photo'),
141                 '$insert'     => DI::l10n()->t('Insert web link'),
142                 '$wait'       => DI::l10n()->t('Please wait')
143         ]);
144
145         return $o;
146 }