]> git.mxchange.org Git - friendica.git/blob - mod/wallmessage.php
Update function calls
[friendica.git] / mod / wallmessage.php
1 <?php
2 /**
3  * @file mod/wallmessage.php
4  */
5 use Friendica\App;
6 use Friendica\Core\System;
7 use Friendica\Database\DBM;
8 use Friendica\Model\Profile;
9
10 require_once 'include/message.php';
11
12 function wallmessage_post(App $a) {
13
14         $replyto = Profile::getMyURL();
15         if(! $replyto) {
16                 notice( t('Permission denied.') . EOL);
17                 return;
18         }
19
20         $subject   = ((x($_REQUEST,'subject'))   ? notags(trim($_REQUEST['subject']))   : '');
21         $body      = ((x($_REQUEST,'body'))      ? escape_tags(trim($_REQUEST['body'])) : '');
22
23         $recipient = (($a->argc > 1) ? notags($a->argv[1]) : '');
24         if((! $recipient) || (! $body)) {
25                 return;
26         }
27
28         $r = q("select * from user where nickname = '%s' limit 1",
29                 dbesc($recipient)
30         );
31
32         if (! DBM::is_result($r)) {
33                 logger('wallmessage: no recipient');
34                 return;
35         }
36
37         $user = $r[0];
38
39         if(! intval($user['unkmail'])) {
40                 notice( t('Permission denied.') . EOL);
41                 return;
42         }
43
44         $r = q("select count(*) as total from mail where uid = %d and created > UTC_TIMESTAMP() - INTERVAL 1 day and unknown = 1",
45                         intval($user['uid'])
46         );
47
48         if($r[0]['total'] > $user['cntunkmail']) {
49                 notice( sprintf( t('Number of daily wall messages for %s exceeded. Message failed.', $user['username'])));
50                 return;
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('profile/'.$user['nickname']);
73
74 }
75
76
77 function wallmessage_content(App $a) {
78
79         if (!Profile::getMyURL()) {
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 (! DBM::is_result($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         $tpl = get_markup_template('wallmsg-header.tpl');
118         $a->page['htmlhead'] .= replace_macros($tpl, array(
119                 '$baseurl' => System::baseUrl(true),
120                 '$nickname' => $user['nickname'],
121                 '$linkurl' => t('Please enter a link URL:')
122         ));
123
124         $tpl = get_markup_template('wallmsg-end.tpl');
125         $a->page['end'] .= replace_macros($tpl, array(
126                 '$baseurl' => System::baseUrl(true),
127                 '$nickname' => $user['nickname'],
128                 '$linkurl' => t('Please enter a link URL:')
129         ));
130
131         $tpl = get_markup_template('wallmessage.tpl');
132         $o .= replace_macros($tpl,array(
133                 '$header' => t('Send Private Message'),
134                 '$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']),
135                 '$to' => t('To:'),
136                 '$subject' => t('Subject:'),
137                 '$recipname' => $user['username'],
138                 '$nickname' => $user['nickname'],
139                 '$subjtxt' => ((x($_REQUEST,'subject')) ? strip_tags($_REQUEST['subject']) : ''),
140                 '$text' => ((x($_REQUEST,'body')) ? escape_tags(htmlspecialchars($_REQUEST['body'])) : ''),
141                 '$readonly' => '',
142                 '$yourmessage' => t('Your message:'),
143                 '$select' => $select,
144                 '$parent' => '',
145                 '$upload' => t('Upload photo'),
146                 '$insert' => t('Insert web link'),
147                 '$wait' => t('Please wait')
148         ));
149
150         return $o;
151 }