]> git.mxchange.org Git - friendica.git/blob - mod/wallmessage.php
Merge pull request #8019 from nupplaphil/task/replace_getClass
[friendica.git] / mod / wallmessage.php
1 <?php
2 /**
3  * @file mod/wallmessage.php
4  */
5 use Friendica\App;
6 use Friendica\Core\L10n;
7 use Friendica\Core\Logger;
8 use Friendica\Core\Renderer;
9 use Friendica\Core\System;
10 use Friendica\Database\DBA;
11 use Friendica\DI;
12 use Friendica\Model\Mail;
13 use Friendica\Model\Profile;
14 use Friendica\Util\Strings;
15
16 function wallmessage_post(App $a) {
17
18         $replyto = Profile::getMyURL();
19         if (!$replyto) {
20                 notice(L10n::t('Permission denied.') . EOL);
21                 return;
22         }
23
24         $subject   = (!empty($_REQUEST['subject'])   ? Strings::escapeTags(trim($_REQUEST['subject']))   : '');
25         $body      = (!empty($_REQUEST['body'])      ? Strings::escapeHtml(trim($_REQUEST['body'])) : '');
26
27         $recipient = (($a->argc > 1) ? Strings::escapeTags($a->argv[1]) : '');
28         if ((! $recipient) || (! $body)) {
29                 return;
30         }
31
32         $r = q("select * from user where nickname = '%s' limit 1",
33                 DBA::escape($recipient)
34         );
35
36         if (! DBA::isResult($r)) {
37                 Logger::log('wallmessage: no recipient');
38                 return;
39         }
40
41         $user = $r[0];
42
43         if (! intval($user['unkmail'])) {
44                 notice(L10n::t('Permission denied.') . EOL);
45                 return;
46         }
47
48         $r = q("select count(*) as total from mail where uid = %d and created > UTC_TIMESTAMP() - INTERVAL 1 day and unknown = 1",
49                         intval($user['uid'])
50         );
51
52         if ($r[0]['total'] > $user['cntunkmail']) {
53                 notice(L10n::t('Number of daily wall messages for %s exceeded. Message failed.', $user['username']));
54                 return;
55         }
56
57         $ret = Mail::sendWall($user, $body, $subject, $replyto);
58
59         switch ($ret) {
60                 case -1:
61                         notice(L10n::t('No recipient selected.') . EOL);
62                         break;
63                 case -2:
64                         notice(L10n::t('Unable to check your home location.') . EOL);
65                         break;
66                 case -3:
67                         notice(L10n::t('Message could not be sent.') . EOL);
68                         break;
69                 case -4:
70                         notice(L10n::t('Message collection failure.') . EOL);
71                         break;
72                 default:
73                         info(L10n::t('Message sent.') . EOL);
74         }
75
76         DI::baseUrl()->redirect('profile/'.$user['nickname']);
77 }
78
79
80 function wallmessage_content(App $a) {
81
82         if (!Profile::getMyURL()) {
83                 notice(L10n::t('Permission denied.') . EOL);
84                 return;
85         }
86
87         $recipient = (($a->argc > 1) ? $a->argv[1] : '');
88
89         if (!$recipient) {
90                 notice(L10n::t('No recipient.') . EOL);
91                 return;
92         }
93
94         $r = q("select * from user where nickname = '%s' limit 1",
95                 DBA::escape($recipient)
96         );
97
98         if (! DBA::isResult($r)) {
99                 notice(L10n::t('No recipient.') . EOL);
100                 Logger::log('wallmessage: no recipient');
101                 return;
102         }
103
104         $user = $r[0];
105
106         if (!intval($user['unkmail'])) {
107                 notice(L10n::t('Permission denied.') . EOL);
108                 return;
109         }
110
111         $r = q("select count(*) as total from mail where uid = %d and created > UTC_TIMESTAMP() - INTERVAL 1 day and unknown = 1",
112                         intval($user['uid'])
113         );
114
115         if ($r[0]['total'] > $user['cntunkmail']) {
116                 notice(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         $a->page['htmlhead'] .= Renderer::replaceMacros($tpl, [
122                 '$baseurl' => System::baseUrl(true),
123                 '$nickname' => $user['nickname'],
124                 '$linkurl' => L10n::t('Please enter a link URL:')
125         ]);
126
127         $tpl = Renderer::getMarkupTemplate('wallmessage.tpl');
128         $o = Renderer::replaceMacros($tpl, [
129                 '$header'     => L10n::t('Send Private Message'),
130                 '$subheader'  => 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'         => L10n::t('To:'),
132                 '$subject'    => L10n::t('Subject:'),
133                 '$recipname'  => $user['username'],
134                 '$nickname'   => $user['nickname'],
135                 '$subjtxt'    => $_REQUEST['subject'] ?? '',
136                 '$text'       => $_REQUEST['body'] ?? '',
137                 '$readonly'   => '',
138                 '$yourmessage'=> L10n::t('Your message:'),
139                 '$parent'     => '',
140                 '$upload'     => L10n::t('Upload photo'),
141                 '$insert'     => L10n::t('Insert web link'),
142                 '$wait'       => L10n::t('Please wait')
143         ]);
144
145         return $o;
146 }