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 );
31 info( t('Message sent.') . EOL );
36 function message_content(&$a) {
39 nav_set_selected('messages');
42 notice( t('Permission denied.') . EOL);
46 $myprofile = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
48 if (($a->argc > 1) && ($a->argv[1] === 'new')) {
50 } else if ($a->argc == 2 && $a->argv[1] === 'sent') {
56 $tpl = get_markup_template('mail_head.tpl');
57 $header = replace_macros($tpl, array(
58 '$messages' => t('Messages'),
59 '$inbox' => t('Inbox'),
60 '$outbox' => t('Outbox'),
61 '$new' => t('New Message'),
66 if(($a->argc == 3) && ($a->argv[1] === 'drop' || $a->argv[1] === 'dropconv')) {
67 if(! intval($a->argv[2]))
71 $r = q("DELETE FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1",
76 info( t('Message deleted.') . EOL );
78 goaway($a->get_baseurl() . '/message' );
81 $r = q("SELECT `parent-uri` FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1",
86 $parent = $r[0]['parent-uri'];
87 $r = q("DELETE FROM `mail` WHERE `parent-uri` = '%s' AND `uid` = %d ",
92 info( t('Conversation removed.') . EOL );
94 goaway($a->get_baseurl() . '/message' );
99 if(($a->argc > 1) && ($a->argv[1] === 'new')) {
103 $tpl = get_markup_template('msg-header.tpl');
105 $a->page['htmlhead'] .= replace_macros($tpl, array(
106 '$baseurl' => $a->get_baseurl(),
107 '$nickname' => $a->user['nickname'],
108 '$linkurl' => t('Please enter a link URL:')
111 $preselect = (isset($a->argv[2])?array($a->argv[2]):false);
113 $select = contact_select('messageto','message-to-select', $preselect, 4, true);
114 $tpl = get_markup_template('prv_message.tpl');
115 $o .= replace_macros($tpl,array(
116 '$header' => t('Send Private Message'),
118 '$subject' => t('Subject:'),
121 '$yourmessage' => t('Your message:'),
122 '$select' => $select,
124 '$upload' => t('Upload photo'),
125 '$insert' => t('Insert web link'),
126 '$wait' => t('Please wait')
132 if(($a->argc == 1) || ($a->argc == 2 && $a->argv[1] === 'sent')) {
137 $eq = '='; // I'm not going to bother escaping this.
139 $eq = '!='; // or this.
141 $r = q("SELECT count(*) AS `total` FROM `mail`
142 WHERE `mail`.`uid` = %d AND `from-url` $eq '%s' GROUP BY `parent-uri` ORDER BY `created` DESC",
143 intval(local_user()),
147 $a->set_pager_total($r[0]['total']);
149 $r = q("SELECT max(`mail`.`created`) AS `mailcreated`, min(`mail`.`seen`) AS `mailseen`,
150 `mail`.* , `contact`.`name`, `contact`.`url`, `contact`.`thumb`
151 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
152 WHERE `mail`.`uid` = %d AND `from-url` $eq '%s' GROUP BY `parent-uri` ORDER BY `created` DESC LIMIT %d , %d ",
153 intval(local_user()),
155 intval($a->pager['start']),
156 intval($a->pager['itemspage'])
159 info( t('No messages.') . EOL);
163 $tpl = get_markup_template('mail_list.tpl');
165 $o .= replace_macros($tpl, array(
167 '$from_name' =>$rr['from-name'],
168 '$from_url' => $a->get_baseurl() . '/redir/' . $rr['contact-id'],
169 '$sparkle' => ' sparkle',
170 '$from_photo' => $rr['thumb'],
171 '$subject' => template_escape((($rr['mailseen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>')),
172 '$delete' => t('Delete conversation'),
173 '$body' => template_escape($rr['body']),
174 '$to_name' => template_escape($rr['name']),
175 '$date' => datetime_convert('UTC',date_default_timezone_get(),$rr['mailcreated'], t('D, d M Y - g:i A'))
182 if(($a->argc > 1) && (intval($a->argv[1]))) {
186 $r = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
187 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
188 WHERE `mail`.`uid` = %d AND `mail`.`id` = %d LIMIT 1",
189 intval(local_user()),
193 $contact_id = $r[0]['contact-id'];
194 $messages = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
195 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
196 WHERE `mail`.`uid` = %d AND `mail`.`parent-uri` = '%s' ORDER BY `mail`.`created` ASC",
197 intval(local_user()),
198 dbesc($r[0]['parent-uri'])
201 if(! count($messages)) {
202 notice( t('Message not available.') . EOL );
206 $r = q("UPDATE `mail` SET `seen` = 1 WHERE `parent-uri` = '%s' AND `uid` = %d",
207 dbesc($r[0]['parent-uri']),
211 require_once("include/bbcode.php");
213 $tpl = get_markup_template('msg-header.tpl');
215 $a->page['htmlhead'] .= replace_macros($tpl, array(
216 '$nickname' => $a->user['nickname'],
217 '$baseurl' => $a->get_baseurl()
221 $tpl = get_markup_template('mail_conv.tpl');
222 foreach($messages as $message) {
223 if($message['from-url'] == $myprofile) {
224 $from_url = $myprofile;
228 $from_url = $a->get_baseurl() . '/redir/' . $message['contact-id'];
229 $sparkle = ' sparkle';
231 $o .= replace_macros($tpl, array(
232 '$id' => $message['id'],
233 '$from_name' => template_escape($message['from-name']),
234 '$from_url' => $from_url,
235 '$sparkle' => $sparkle,
236 '$from_photo' => $message['from-photo'],
237 '$subject' => template_escape($message['title']),
238 '$body' => template_escape(smilies(bbcode($message['body']))),
239 '$delete' => t('Delete message'),
240 '$to_name' => template_escape($message['name']),
241 '$date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A')
245 $select = $message['name'] . '<input type="hidden" name="messageto" value="' . $contact_id . '" />';
246 $parent = '<input type="hidden" name="replyto" value="' . $message['parent-uri'] . '" />';
247 $tpl = get_markup_template('prv_message.tpl');
248 $o .= replace_macros($tpl,array(
249 '$header' => t('Send Reply'),
251 '$subject' => t('Subject:'),
252 '$subjtxt' => template_escape($message['title']),
253 '$readonly' => ' readonly="readonly" style="background: #BBBBBB;" ',
254 '$yourmessage' => t('Your message:'),
255 '$select' => $select,
256 '$parent' => $parent,
257 '$upload' => t('Upload photo'),
258 '$insert' => t('Insert web link'),
259 '$wait' => t('Please wait')