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