]> git.mxchange.org Git - friendica.git/blob - mod/wallmessage.php
Merge pull request #2151 from annando/1512-misconfigured-friendica
[friendica.git] / mod / wallmessage.php
1 <?php
2
3 require_once('include/message.php');
4
5 function wallmessage_post(&$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(! count($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         // Work around doubled linefeeds in Tinymce 3.5b2
47
48         $body = str_replace("\r\n","\n",$body);
49         $body = str_replace("\n\n","\n",$body);
50
51         
52         $ret = send_wallmessage($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($a->get_baseurl() . '/profile/' . $user['nickname']);
72         
73 }
74
75
76 function wallmessage_content(&$a) {
77
78         if(! get_my_url()) {
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(! count($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
117
118         $editselect = 'none';
119         if( feature_enabled(local_user(), 'richtext') )
120                 $editselect = '/(profile-jot-text|prvmail-text)/';
121
122         $tpl = get_markup_template('wallmsg-header.tpl');
123         $a->page['htmlhead'] .= replace_macros($tpl, array(
124                 '$baseurl' => $a->get_baseurl(true),
125                 '$editselect' => $editselect,
126                 '$nickname' => $user['nickname'],
127                 '$linkurl' => t('Please enter a link URL:')
128         ));
129
130         $tpl = get_markup_template('wallmsg-end.tpl');
131         $a->page['end'] .= replace_macros($tpl, array(
132                 '$baseurl' => $a->get_baseurl(true),
133                 '$editselect' => $editselect,
134                 '$nickname' => $user['nickname'],
135                 '$linkurl' => t('Please enter a link URL:')
136         ));
137         
138
139         
140         $tpl = get_markup_template('wallmessage.tpl');
141         $o .= replace_macros($tpl,array(
142                 '$header' => t('Send Private Message'),
143                 '$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']),
144                 '$to' => t('To:'),
145                 '$subject' => t('Subject:'),
146                 '$recipname' => $user['username'],
147                 '$nickname' => $user['nickname'],
148                 '$subjtxt' => ((x($_REQUEST,'subject')) ? strip_tags($_REQUEST['subject']) : ''),
149                 '$text' => ((x($_REQUEST,'body')) ? escape_tags(htmlspecialchars($_REQUEST['body'])) : ''),
150                 '$readonly' => '',
151                 '$yourmessage' => t('Your message:'),
152                 '$select' => $select,
153                 '$parent' => '',
154                 '$upload' => t('Upload photo'),
155                 '$insert' => t('Insert web link'),
156                 '$wait' => t('Please wait')
157         ));
158
159         return $o;
160 }