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