]> git.mxchange.org Git - friendica.git/blob - mod/wallmessage.php
Merge pull request #3112 from Quix0r/rewrites/coding-convention
[friendica.git] / mod / wallmessage.php
1 <?php
2
3 require_once('include/message.php');
4
5 function wallmessage_post(App $a) {
6
7         $replyto = get_my_url();
8         if (! $replyto) {
9                 notice( t('Permission denied.') . EOL);
10                 return;
11         }
12
13         $subject   = ((x($_REQUEST,'subject'))   ? notags(trim($_REQUEST['subject']))   : '');
14         $body      = ((x($_REQUEST,'body'))      ? escape_tags(trim($_REQUEST['body'])) : '');
15
16         $recipient = (($a->argc > 1) ? notags($a->argv[1]) : '');
17         if ((! $recipient) || (! $body)) {
18                 return;
19         }
20
21         $r = q("select * from user where nickname = '%s' limit 1",
22                 dbesc($recipient)
23         );
24
25         if (! dbm::is_result($r)) {
26                 logger('wallmessage: no recipient');
27                 return;
28         }
29
30         $user = $r[0];
31
32         if (! intval($user['unkmail'])) {
33                 notice( t('Permission denied.') . EOL);
34                 return;
35         }
36
37         $r = q("select count(*) as total from mail where uid = %d and created > UTC_TIMESTAMP() - INTERVAL 1 day and unknown = 1",
38                         intval($user['uid'])
39         );
40
41         if ($r[0]['total'] > $user['cntunkmail']) {
42                 notice( sprintf( t('Number of daily wall messages for %s exceeded. Message failed.', $user['username'])));
43                 return;
44         }
45
46         $ret = send_wallmessage($user, $body, $subject, $replyto);
47
48         switch($ret){
49                 case -1:
50                         notice( t('No recipient selected.') . EOL );
51                         break;
52                 case -2:
53                         notice( t('Unable to check your home location.') . EOL );
54                         break;
55                 case -3:
56                         notice( t('Message could not be sent.') . EOL );
57                         break;
58                 case -4:
59                         notice( t('Message collection failure.') . EOL );
60                         break;
61                 default:
62                         info( t('Message sent.') . EOL );
63         }
64
65         goaway('profile/'.$user['nickname']);
66
67 }
68
69
70 function wallmessage_content(App $a) {
71
72         if (! get_my_url()) {
73                 notice( t('Permission denied.') . EOL);
74                 return;
75         }
76
77         $recipient = (($a->argc > 1) ? $a->argv[1] : '');
78
79         if (! $recipient) {
80                 notice( t('No recipient.') . EOL);
81                 return;
82         }
83
84         $r = q("select * from user where nickname = '%s' limit 1",
85                 dbesc($recipient)
86         );
87
88         if (! dbm::is_result($r)) {
89                 notice( t('No recipient.') . EOL);
90                 logger('wallmessage: no recipient');
91                 return;
92         }
93
94         $user = $r[0];
95
96         if (! intval($user['unkmail'])) {
97                 notice( t('Permission denied.') . EOL);
98                 return;
99         }
100
101         $r = q("SELECT COUNT(*) AS `total` FROM `mail` WHERE `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 1 DAY AND `unknown` = 1",
102                         intval($user['uid'])
103         );
104
105         if (!dbm::is_result($r)) {
106                 ///@TODO Output message to use of failed query
107                 return;
108         } elseif ($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' => $a->get_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' => $a->get_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 }