3 require_once('include/acl_selectors.php');
4 require_once('include/message.php');
6 function message_post(&$a) {
9 notice( t('Permission denied.') . EOL);
13 $replyto = ((x($_REQUEST,'replyto')) ? notags(trim($_REQUEST['replyto'])) : '');
14 $subject = ((x($_REQUEST,'subject')) ? notags(trim($_REQUEST['subject'])) : '');
15 $body = ((x($_REQUEST,'body')) ? escape_tags(trim($_REQUEST['body'])) : '');
16 $recipient = ((x($_REQUEST,'messageto')) ? intval($_REQUEST['messageto']) : 0 );
18 // Work around doubled linefeeds in Tinymce 3.5b2
20 $plaintext = intval(get_pconfig(local_user(),'system','plaintext'));
22 $body = str_replace("\r\n","\n",$body);
23 $body = str_replace("\n\n","\n",$body);
26 $ret = send_message($recipient, $body, $subject, $replyto);
31 notice( t('No recipient selected.') . EOL );
35 notice( t('Unable to locate contact information.') . EOL );
38 notice( t('Message could not be sent.') . EOL );
41 notice( t('Message collection failure.') . EOL );
44 info( t('Message sent.') . EOL );
47 // fake it to go back to the input form if no recipient listed
56 function message_content(&$a) {
59 nav_set_selected('messages');
62 notice( t('Permission denied.') . EOL);
66 $myprofile = $a->get_baseurl(true) . '/profile/' . $a->user['nickname'];
71 'label' => t('Inbox'),
72 'url'=> $a->get_baseurl(true) . '/message',
73 'sel'=> (($a->argc == 1) ? 'active' : ''),
76 'label' => t('Outbox'),
77 'url' => $a->get_baseurl(true) . '/message/sent',
78 'sel'=> (($a->argv[1] == 'sent') ? 'active' : ''),
81 'label' => t('New Message'),
82 'url' => $a->get_baseurl(true) . '/message/new',
83 'sel'=> (($a->argv[1] == 'new') ? 'active' : ''),
86 $tpl = get_markup_template('common_tabs.tpl');
87 $tab_content = replace_macros($tpl, array('$tabs'=>$tabs));
90 $tpl = get_markup_template('mail_head.tpl');
91 $header = replace_macros($tpl, array(
92 '$messages' => t('Messages'),
93 '$tab_content' => $tab_content
97 if(($a->argc == 3) && ($a->argv[1] === 'drop' || $a->argv[1] === 'dropconv')) {
98 if(! intval($a->argv[2]))
101 if($cmd === 'drop') {
102 $r = q("DELETE FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1",
107 info( t('Message deleted.') . EOL );
109 goaway($a->get_baseurl(true) . '/message' );
112 $r = q("SELECT `parent-uri`,`convid` FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1",
117 $parent = $r[0]['parent-uri'];
118 $convid = $r[0]['convid'];
120 $r = q("DELETE FROM `mail` WHERE `parent-uri` = '%s' AND `uid` = %d ",
125 // remove diaspora conversation pointer
126 // Actually if we do this, we can never receive another reply to that conversation,
127 // as we will never again have the info we need to re-create it.
128 // We'll just have to orphan it.
131 // q("delete from conv where id = %d limit 1",
137 info( t('Conversation removed.') . EOL );
139 goaway($a->get_baseurl(true) . '/message' );
144 if(($a->argc > 1) && ($a->argv[1] === 'new')) {
149 if(intval(get_pconfig(local_user(),'system','plaintext')))
153 $tpl = get_markup_template('msg-header.tpl');
155 $a->page['htmlhead'] .= replace_macros($tpl, array(
156 '$baseurl' => $a->get_baseurl(true),
157 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
158 '$nickname' => $a->user['nickname'],
159 '$linkurl' => t('Please enter a link URL:')
162 $preselect = (isset($a->argv[2])?array($a->argv[2]):false);
164 $select = contact_select('messageto','message-to-select', $preselect, 4, true, false, false, 10);
165 $tpl = get_markup_template('prv_message.tpl');
166 $o .= replace_macros($tpl,array(
167 '$header' => t('Send Private Message'),
169 '$subject' => t('Subject:'),
170 '$subjtxt' => ((x($_REQUEST,'subject')) ? strip_tags($_REQUEST['subject']) : ''),
171 '$text' => ((x($_REQUEST,'body')) ? escape_tags(htmlspecialchars($_REQUEST['body'])) : ''),
173 '$yourmessage' => t('Your message:'),
174 '$select' => $select,
176 '$upload' => t('Upload photo'),
177 '$insert' => t('Insert web link'),
178 '$wait' => t('Please wait')
184 if(($a->argc == 1) || ($a->argc == 2 && $a->argv[1] === 'sent')) {
189 $eq = '='; // I'm not going to bother escaping this.
191 $eq = '!='; // or this.
193 $r = q("SELECT count(*) AS `total` FROM `mail`
194 WHERE `mail`.`uid` = %d AND `from-url` $eq '%s' GROUP BY `parent-uri` ORDER BY `created` DESC",
195 intval(local_user()),
199 $a->set_pager_total($r[0]['total']);
201 $r = q("SELECT max(`mail`.`created`) AS `mailcreated`, min(`mail`.`seen`) AS `mailseen`,
202 `mail`.* , `contact`.`name`, `contact`.`url`, `contact`.`thumb` , `contact`.`network`
203 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
204 WHERE `mail`.`uid` = %d AND `from-url` $eq '%s' GROUP BY `parent-uri` ORDER BY `mailcreated` DESC LIMIT %d , %d ",
205 intval(local_user()),
207 intval($a->pager['start']),
208 intval($a->pager['itemspage'])
211 info( t('No messages.') . EOL);
215 $tpl = get_markup_template('mail_list.tpl');
217 $o .= replace_macros($tpl, array(
219 '$from_name' =>$rr['from-name'],
220 '$from_url' => (($rr['network'] === NETWORK_DFRN) ? $a->get_baseurl(true) . '/redir/' . $rr['contact-id'] : $rr['url']),
221 '$sparkle' => ' sparkle',
222 '$from_photo' => $rr['thumb'],
223 '$subject' => template_escape((($rr['mailseen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>')),
224 '$delete' => t('Delete conversation'),
225 '$body' => template_escape($rr['body']),
226 '$to_name' => template_escape($rr['name']),
227 '$date' => datetime_convert('UTC',date_default_timezone_get(),$rr['mailcreated'], t('D, d M Y - g:i A'))
234 if(($a->argc > 1) && (intval($a->argv[1]))) {
238 $r = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
239 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
240 WHERE `mail`.`uid` = %d AND `mail`.`id` = %d LIMIT 1",
241 intval(local_user()),
245 $contact_id = $r[0]['contact-id'];
246 $convid = $r[0]['convid'];
248 $sql_extra = sprintf(" and `mail`.`parent-uri` = '%s' ", dbesc($r[0]['parent-uri']));
250 $sql_extra = sprintf(" and ( `mail`.`parent-uri` = '%s' OR `mail`.`convid` = '%d' ) ",
251 dbesc($r[0]['parent-uri']),
255 $messages = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
256 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
257 WHERE `mail`.`uid` = %d $sql_extra ORDER BY `mail`.`created` ASC",
261 if(! count($messages)) {
262 notice( t('Message not available.') . EOL );
266 $r = q("UPDATE `mail` SET `seen` = 1 WHERE `parent-uri` = '%s' AND `uid` = %d",
267 dbesc($r[0]['parent-uri']),
271 require_once("include/bbcode.php");
273 $tpl = get_markup_template('msg-header.tpl');
275 $a->page['htmlhead'] .= replace_macros($tpl, array(
276 '$nickname' => $a->user['nickname'],
277 '$baseurl' => $a->get_baseurl(true)
281 $tpl = get_markup_template('mail_conv.tpl');
282 foreach($messages as $message) {
283 if($message['from-url'] == $myprofile) {
284 $from_url = $myprofile;
288 $from_url = $a->get_baseurl(true) . '/redir/' . $message['contact-id'];
289 $sparkle = ' sparkle';
291 $o .= replace_macros($tpl, array(
292 '$id' => $message['id'],
293 '$from_name' => template_escape($message['from-name']),
294 '$from_url' => $from_url,
295 '$sparkle' => $sparkle,
296 '$from_photo' => $message['from-photo'],
297 '$subject' => template_escape($message['title']),
298 '$body' => template_escape(smilies(bbcode($message['body']))),
299 '$delete' => t('Delete message'),
300 '$to_name' => template_escape($message['name']),
301 '$date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A')
305 $select = $message['name'] . '<input type="hidden" name="messageto" value="' . $contact_id . '" />';
306 $parent = '<input type="hidden" name="replyto" value="' . $message['parent-uri'] . '" />';
307 $tpl = get_markup_template('prv_message.tpl');
308 $o .= replace_macros($tpl,array(
309 '$header' => t('Send Reply'),
311 '$subject' => t('Subject:'),
312 '$subjtxt' => template_escape($message['title']),
313 '$readonly' => ' readonly="readonly" style="background: #BBBBBB;" ',
314 '$yourmessage' => t('Your message:'),
316 '$select' => $select,
317 '$parent' => $parent,
318 '$upload' => t('Upload photo'),
319 '$insert' => t('Insert web link'),
320 '$wait' => t('Please wait')