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