]> git.mxchange.org Git - friendica.git/blob - mod/wallmessage.php
Move /profile_photo to Module\Settings\Profile\Photo
[friendica.git] / mod / wallmessage.php
1 <?php
2 /**
3  * @file mod/wallmessage.php
4  */
5 use Friendica\App;
6 use Friendica\Core\Logger;
7 use Friendica\Core\Renderer;
8 use Friendica\Database\DBA;
9 use Friendica\DI;
10 use Friendica\Model\Mail;
11 use Friendica\Model\Profile;
12 use Friendica\Util\Strings;
13
14 function wallmessage_post(App $a) {
15
16         $replyto = Profile::getMyURL();
17         if (!$replyto) {
18                 notice(DI::l10n()->t('Permission denied.') . EOL);
19                 return;
20         }
21
22         $subject   = (!empty($_REQUEST['subject'])   ? Strings::escapeTags(trim($_REQUEST['subject']))   : '');
23         $body      = (!empty($_REQUEST['body'])      ? Strings::escapeHtml(trim($_REQUEST['body'])) : '');
24
25         $recipient = (($a->argc > 1) ? Strings::escapeTags($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(DI::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(DI::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(DI::l10n()->t('No recipient selected.') . EOL);
60                         break;
61                 case -2:
62                         notice(DI::l10n()->t('Unable to check your home location.') . EOL);
63                         break;
64                 case -3:
65                         notice(DI::l10n()->t('Message could not be sent.') . EOL);
66                         break;
67                 case -4:
68                         notice(DI::l10n()->t('Message collection failure.') . EOL);
69                         break;
70                 default:
71                         info(DI::l10n()->t('Message sent.') . EOL);
72         }
73
74         DI::baseUrl()->redirect('profile/'.$user['nickname']);
75 }
76
77
78 function wallmessage_content(App $a) {
79
80         if (!Profile::getMyURL()) {
81                 notice(DI::l10n()->t('Permission denied.') . EOL);
82                 return;
83         }
84
85         $recipient = (($a->argc > 1) ? $a->argv[1] : '');
86
87         if (!$recipient) {
88                 notice(DI::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(DI::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(DI::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(DI::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         DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl, [
120                 '$baseurl' => DI::baseUrl()->get(true),
121                 '$nickname' => $user['nickname'],
122                 '$linkurl' => DI::l10n()->t('Please enter a link URL:')
123         ]);
124
125         $tpl = Renderer::getMarkupTemplate('wallmessage.tpl');
126         $o = Renderer::replaceMacros($tpl, [
127                 '$header'     => DI::l10n()->t('Send Private Message'),
128                 '$subheader'  => DI::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'         => DI::l10n()->t('To:'),
130                 '$subject'    => DI::l10n()->t('Subject:'),
131                 '$recipname'  => $user['username'],
132                 '$nickname'   => $user['nickname'],
133                 '$subjtxt'    => $_REQUEST['subject'] ?? '',
134                 '$text'       => $_REQUEST['body'] ?? '',
135                 '$readonly'   => '',
136                 '$yourmessage'=> DI::l10n()->t('Your message:'),
137                 '$parent'     => '',
138                 '$upload'     => DI::l10n()->t('Upload photo'),
139                 '$insert'     => DI::l10n()->t('Insert web link'),
140                 '$wait'       => DI::l10n()->t('Please wait')
141         ]);
142
143         return $o;
144 }