]> git.mxchange.org Git - friendica.git/blob - mod/wallmessage.php
Merge pull request #4243 from MrPetovan/task/switch-to-array-new-style
[friendica.git] / mod / wallmessage.php
1 <?php
2 /**
3  * @file mod/wallmessage.php
4  */
5 use Friendica\App;
6 use Friendica\Core\System;
7 use Friendica\Database\DBM;
8 use Friendica\Model\Mail;
9 use Friendica\Model\Profile;
10
11 function wallmessage_post(App $a) {
12
13         $replyto = Profile::getMyURL();
14         if(! $replyto) {
15                 notice( t('Permission denied.') . EOL);
16                 return;
17         }
18
19         $subject   = ((x($_REQUEST,'subject'))   ? notags(trim($_REQUEST['subject']))   : '');
20         $body      = ((x($_REQUEST,'body'))      ? escape_tags(trim($_REQUEST['body'])) : '');
21
22         $recipient = (($a->argc > 1) ? notags($a->argv[1]) : '');
23         if((! $recipient) || (! $body)) {
24                 return;
25         }
26
27         $r = q("select * from user where nickname = '%s' limit 1",
28                 dbesc($recipient)
29         );
30
31         if (! DBM::is_result($r)) {
32                 logger('wallmessage: no recipient');
33                 return;
34         }
35
36         $user = $r[0];
37
38         if(! intval($user['unkmail'])) {
39                 notice( t('Permission denied.') . EOL);
40                 return;
41         }
42
43         $r = q("select count(*) as total from mail where uid = %d and created > UTC_TIMESTAMP() - INTERVAL 1 day and unknown = 1",
44                         intval($user['uid'])
45         );
46
47         if($r[0]['total'] > $user['cntunkmail']) {
48                 notice( sprintf( t('Number of daily wall messages for %s exceeded. Message failed.', $user['username'])));
49                 return;
50         }
51
52         $ret = Mail::sendWall($user, $body, $subject, $replyto);
53
54         switch($ret){
55                 case -1:
56                         notice( t('No recipient selected.') . EOL );
57                         break;
58                 case -2:
59                         notice( t('Unable to check your home location.') . EOL );
60                         break;
61                 case -3:
62                         notice( t('Message could not be sent.') . EOL );
63                         break;
64                 case -4:
65                         notice( t('Message collection failure.') . EOL );
66                         break;
67                 default:
68                         info( t('Message sent.') . EOL );
69         }
70
71         goaway('profile/'.$user['nickname']);
72
73 }
74
75
76 function wallmessage_content(App $a) {
77
78         if (!Profile::getMyURL()) {
79                 notice(t('Permission denied.') . EOL);
80                 return;
81         }
82
83         $recipient = (($a->argc > 1) ? $a->argv[1] : '');
84
85         if(! $recipient) {
86                 notice( t('No recipient.') . EOL);
87                 return;
88         }
89
90         $r = q("select * from user where nickname = '%s' limit 1",
91                 dbesc($recipient)
92         );
93
94         if (! DBM::is_result($r)) {
95                 notice( 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( 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( sprintf( 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' => 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' => t('Please enter a link URL:')
128         ]);
129
130         $tpl = get_markup_template('wallmessage.tpl');
131         $o .= replace_macros($tpl,[
132                 '$header' => t('Send Private Message'),
133                 '$subheader' => sprintf( 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' => t('To:'),
135                 '$subject' => 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' => t('Your message:'),
142                 '$select' => $select,
143                 '$parent' => '',
144                 '$upload' => t('Upload photo'),
145                 '$insert' => t('Insert web link'),
146                 '$wait' => t('Please wait')
147         ]);
148
149         return $o;
150 }