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