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