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