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