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