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'];
49 $tpl = get_markup_template('mail_head.tpl');
50 $header = replace_macros($tpl, array(
51 '$messages' => t('Messages'),
52 '$inbox' => t('Inbox'),
53 '$outbox' => t('Outbox'),
54 '$new' => t('New Message')
58 if(($a->argc == 3) && ($a->argv[1] === 'drop' || $a->argv[1] === 'dropconv')) {
59 if(! intval($a->argv[2]))
63 $r = q("DELETE FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1",
68 info( t('Message deleted.') . EOL );
70 goaway($a->get_baseurl() . '/message' );
73 $r = q("SELECT `parent-uri` FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1",
78 $parent = $r[0]['parent-uri'];
79 $r = q("DELETE FROM `mail` WHERE `parent-uri` = '%s' AND `uid` = %d ",
84 info( t('Conversation removed.') . EOL );
86 goaway($a->get_baseurl() . '/message' );
91 if(($a->argc > 1) && ($a->argv[1] === 'new')) {
93 $tpl = get_markup_template('msg-header.tpl');
95 $a->page['htmlhead'] .= replace_macros($tpl, array(
96 '$baseurl' => $a->get_baseurl(),
97 '$nickname' => $a->user['nickname'],
98 '$linkurl' => t('Please enter a link URL:')
101 $preselect = (isset($a->argv[2])?array($a->argv[2]):false);
103 $select = contact_select('messageto','message-to-select', $preselect, 4, true);
104 $tpl = get_markup_template('prv_message.tpl');
105 $o .= replace_macros($tpl,array(
106 '$header' => t('Send Private Message'),
108 '$subject' => t('Subject:'),
111 '$yourmessage' => t('Your message:'),
112 '$select' => $select,
114 '$upload' => t('Upload photo'),
115 '$insert' => t('Insert web link'),
116 '$wait' => t('Please wait')
123 if(($a->argc == 1) || ($a->argc == 2 && $a->argv[1] === 'sent')) {
128 $eq = '='; // I'm not going to bother escaping this.
130 $eq = '!='; // or this.
132 $r = q("SELECT count(*) AS `total` FROM `mail`
133 WHERE `mail`.`uid` = %d AND `from-url` $eq '%s' GROUP BY `parent-uri` ORDER BY `created` DESC",
134 intval(local_user()),
138 $a->set_pager_total($r[0]['total']);
140 $r = q("SELECT max(`mail`.`created`) AS `mailcreated`, min(`mail`.`seen`) AS `mailseen`,
141 `mail`.* , `contact`.`name`, `contact`.`url`, `contact`.`thumb`
142 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
143 WHERE `mail`.`uid` = %d AND `from-url` $eq '%s' GROUP BY `parent-uri` ORDER BY `created` DESC LIMIT %d , %d ",
144 intval(local_user()),
146 intval($a->pager['start']),
147 intval($a->pager['itemspage'])
150 info( t('No messages.') . EOL);
154 $tpl = get_markup_template('mail_list.tpl');
156 $o .= replace_macros($tpl, array(
158 '$from_name' =>$rr['from-name'],
159 '$from_url' => $a->get_baseurl() . '/redir/' . $rr['contact-id'],
160 '$sparkle' => ' sparkle',
161 '$from_photo' => $rr['thumb'],
162 '$subject' => (($rr['mailseen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>'),
163 '$delete' => t('Delete conversation'),
164 '$body' => $rr['body'],
165 '$to_name' => $rr['name'],
166 '$date' => datetime_convert('UTC',date_default_timezone_get(),$rr['mailcreated'], t('D, d M Y - g:i A'))
173 if(($a->argc > 1) && (intval($a->argv[1]))) {
177 $r = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
178 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
179 WHERE `mail`.`uid` = %d AND `mail`.`id` = %d LIMIT 1",
180 intval(local_user()),
184 $contact_id = $r[0]['contact-id'];
185 $messages = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
186 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
187 WHERE `mail`.`uid` = %d AND `mail`.`parent-uri` = '%s' ORDER BY `mail`.`created` ASC",
188 intval(local_user()),
189 dbesc($r[0]['parent-uri'])
192 if(! count($messages)) {
193 notice( t('Message not available.') . EOL );
197 $r = q("UPDATE `mail` SET `seen` = 1 WHERE `parent-uri` = '%s' AND `uid` = %d",
198 dbesc($r[0]['parent-uri']),
202 require_once("include/bbcode.php");
204 $tpl = get_markup_template('msg-header.tpl');
206 $a->page['htmlhead'] .= replace_macros($tpl, array(
207 '$nickname' => $a->user['nickname'],
208 '$baseurl' => $a->get_baseurl()
212 $tpl = get_markup_template('mail_conv.tpl');
213 foreach($messages as $message) {
214 if($message['from-url'] == $myprofile) {
215 $from_url = $myprofile;
219 $from_url = $a->get_baseurl() . '/redir/' . $message['contact-id'];
220 $sparkle = ' sparkle';
222 $o .= replace_macros($tpl, array(
223 '$id' => $message['id'],
224 '$from_name' =>$message['from-name'],
225 '$from_url' => $from_url,
226 '$sparkle' => $sparkle,
227 '$from_photo' => $message['from-photo'],
228 '$subject' => $message['title'],
229 '$body' => smilies(bbcode($message['body'])),
230 '$delete' => t('Delete message'),
231 '$to_name' => $message['name'],
232 '$date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A')
236 $select = $message['name'] . '<input type="hidden" name="messageto" value="' . $contact_id . '" />';
237 $parent = '<input type="hidden" name="replyto" value="' . $message['parent-uri'] . '" />';
238 $tpl = get_markup_template('prv_message.tpl');
239 $o .= replace_macros($tpl,array(
240 '$header' => t('Send Reply'),
242 '$subject' => t('Subject:'),
243 '$subjtxt' => $message['title'],
244 '$readonly' => ' readonly="readonly" style="background: #BBBBBB;" ',
245 '$yourmessage' => t('Your message:'),
246 '$select' => $select,
247 '$parent' => $parent,
248 '$upload' => t('Upload photo'),
249 '$insert' => t('Insert web link'),
250 '$wait' => t('Please wait')