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($_POST,'replyto')) ? notags(trim($_POST['replyto'])) : '');
14 $subject = ((x($_POST,'subject')) ? notags(trim($_POST['subject'])) : '');
15 $body = ((x($_POST,'body')) ? escape_tags(trim($_POST['body'])) : '');
16 $recipient = ((x($_POST,'messageto')) ? intval($_POST['messageto']) : 0 );
19 $ret = send_message($recipient, $body, $subject, $replyto);
23 notice( t('No recipient selected.') . EOL );
26 notice( t('Unable to locate contact information.') . EOL );
29 notice( t('Message could not be sent.') . EOL );
32 notice( t('Message collection failure.') . EOL );
35 info( t('Message sent.') . EOL );
40 function message_content(&$a) {
43 nav_set_selected('messages');
46 notice( t('Permission denied.') . EOL);
50 $myprofile = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
55 'label' => t('Inbox'),
56 'url'=> $a->get_baseurl() . '/message',
57 'sel'=> (($a->argc == 1) ? 'active' : ''),
60 'label' => t('Outbox'),
61 'url' => $a->get_baseurl() . '/message/sent',
62 'sel'=> (($a->argv[1] == 'sent') ? 'active' : ''),
65 'label' => t('New Message'),
66 'url' => $a->get_baseurl() . '/message/new',
67 'sel'=> (($a->argv[1] == 'new') ? 'active' : ''),
70 $tpl = get_markup_template('common_tabs.tpl');
71 $tab_content = replace_macros($tpl, array('$tabs'=>$tabs));
74 $tpl = get_markup_template('mail_head.tpl');
75 $header = replace_macros($tpl, array(
76 '$messages' => t('Messages'),
77 '$tab_content' => $tab_content
81 if(($a->argc == 3) && ($a->argv[1] === 'drop' || $a->argv[1] === 'dropconv')) {
82 if(! intval($a->argv[2]))
86 $r = q("DELETE FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1",
91 info( t('Message deleted.') . EOL );
93 goaway($a->get_baseurl() . '/message' );
96 $r = q("SELECT `parent-uri`,`convid` FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1",
101 $parent = $r[0]['parent-uri'];
102 $convid = $r[0]['convid'];
104 $r = q("DELETE FROM `mail` WHERE `parent-uri` = '%s' AND `uid` = %d ",
109 // remove diaspora conversation pointer
110 // Actually if we do this, we can never receive another reply to that conversation,
111 // as we will never again have the info we need to re-create it.
112 // We'll just have to orphan it.
115 // q("delete from conv where id = %d limit 1",
121 info( t('Conversation removed.') . EOL );
123 goaway($a->get_baseurl() . '/message' );
128 if(($a->argc > 1) && ($a->argv[1] === 'new')) {
132 $tpl = get_markup_template('msg-header.tpl');
134 $a->page['htmlhead'] .= replace_macros($tpl, array(
135 '$baseurl' => $a->get_baseurl(),
136 '$nickname' => $a->user['nickname'],
137 '$linkurl' => t('Please enter a link URL:')
140 $preselect = (isset($a->argv[2])?array($a->argv[2]):false);
142 $select = contact_select('messageto','message-to-select', $preselect, 4, true);
143 $tpl = get_markup_template('prv_message.tpl');
144 $o .= replace_macros($tpl,array(
145 '$header' => t('Send Private Message'),
147 '$subject' => t('Subject:'),
150 '$yourmessage' => t('Your message:'),
151 '$select' => $select,
153 '$upload' => t('Upload photo'),
154 '$insert' => t('Insert web link'),
155 '$wait' => t('Please wait')
161 if(($a->argc == 1) || ($a->argc == 2 && $a->argv[1] === 'sent')) {
166 $eq = '='; // I'm not going to bother escaping this.
168 $eq = '!='; // or this.
170 $r = q("SELECT count(*) AS `total` FROM `mail`
171 WHERE `mail`.`uid` = %d AND `from-url` $eq '%s' GROUP BY `parent-uri` ORDER BY `created` DESC",
172 intval(local_user()),
176 $a->set_pager_total($r[0]['total']);
178 $r = q("SELECT max(`mail`.`created`) AS `mailcreated`, min(`mail`.`seen`) AS `mailseen`,
179 `mail`.* , `contact`.`name`, `contact`.`url`, `contact`.`thumb`
180 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
181 WHERE `mail`.`uid` = %d AND `from-url` $eq '%s' GROUP BY `parent-uri` ORDER BY `created` DESC LIMIT %d , %d ",
182 intval(local_user()),
184 intval($a->pager['start']),
185 intval($a->pager['itemspage'])
188 info( t('No messages.') . EOL);
192 $tpl = get_markup_template('mail_list.tpl');
194 $o .= replace_macros($tpl, array(
196 '$from_name' =>$rr['from-name'],
197 '$from_url' => (($rr['network'] === NETWORK_DFRN) ? $a->get_baseurl() . '/redir/' . $rr['contact-id'] : $rr['url']),
198 '$sparkle' => ' sparkle',
199 '$from_photo' => $rr['thumb'],
200 '$subject' => template_escape((($rr['mailseen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>')),
201 '$delete' => t('Delete conversation'),
202 '$body' => template_escape($rr['body']),
203 '$to_name' => template_escape($rr['name']),
204 '$date' => datetime_convert('UTC',date_default_timezone_get(),$rr['mailcreated'], t('D, d M Y - g:i A'))
211 if(($a->argc > 1) && (intval($a->argv[1]))) {
215 $r = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
216 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
217 WHERE `mail`.`uid` = %d AND `mail`.`id` = %d LIMIT 1",
218 intval(local_user()),
222 $contact_id = $r[0]['contact-id'];
223 $convid = $r[0]['convid'];
225 $sql_extra = sprintf(" and `mail`.`parent-uri` = '%s' ", dbesc($r[0]['parent-uri']));
227 $sql_extra = sprintf(" and ( `mail`.`parent-uri` = '%s' OR `mail`.`convid` = '%d' ) ",
228 dbesc($r[0]['parent-uri']),
232 $messages = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
233 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
234 WHERE `mail`.`uid` = %d $sql_extra ORDER BY `mail`.`created` ASC",
238 if(! count($messages)) {
239 notice( t('Message not available.') . EOL );
243 $r = q("UPDATE `mail` SET `seen` = 1 WHERE `parent-uri` = '%s' AND `uid` = %d",
244 dbesc($r[0]['parent-uri']),
248 require_once("include/bbcode.php");
250 $tpl = get_markup_template('msg-header.tpl');
252 $a->page['htmlhead'] .= replace_macros($tpl, array(
253 '$nickname' => $a->user['nickname'],
254 '$baseurl' => $a->get_baseurl()
258 $tpl = get_markup_template('mail_conv.tpl');
259 foreach($messages as $message) {
260 if($message['from-url'] == $myprofile) {
261 $from_url = $myprofile;
265 $from_url = $a->get_baseurl() . '/redir/' . $message['contact-id'];
266 $sparkle = ' sparkle';
268 $o .= replace_macros($tpl, array(
269 '$id' => $message['id'],
270 '$from_name' => template_escape($message['from-name']),
271 '$from_url' => $from_url,
272 '$sparkle' => $sparkle,
273 '$from_photo' => $message['from-photo'],
274 '$subject' => template_escape($message['title']),
275 '$body' => template_escape(smilies(bbcode($message['body']))),
276 '$delete' => t('Delete message'),
277 '$to_name' => template_escape($message['name']),
278 '$date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A')
282 $select = $message['name'] . '<input type="hidden" name="messageto" value="' . $contact_id . '" />';
283 $parent = '<input type="hidden" name="replyto" value="' . $message['parent-uri'] . '" />';
284 $tpl = get_markup_template('prv_message.tpl');
285 $o .= replace_macros($tpl,array(
286 '$header' => t('Send Reply'),
288 '$subject' => t('Subject:'),
289 '$subjtxt' => template_escape($message['title']),
290 '$readonly' => ' readonly="readonly" style="background: #BBBBBB;" ',
291 '$yourmessage' => t('Your message:'),
292 '$select' => $select,
293 '$parent' => $parent,
294 '$upload' => t('Upload photo'),
295 '$insert' => t('Insert web link'),
296 '$wait' => t('Please wait')