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'];
51 'label' => t('Inbox'),
52 'url'=> $a->get_baseurl() . '/message',
53 'sel'=> (($a->argc == 1) ? 'active' : ''),
56 'label' => t('Outbox'),
57 'url' => $a->get_baseurl() . '/message/sent',
58 'sel'=> (($a->argv[1] == 'sent') ? 'active' : ''),
61 'label' => t('New Message'),
62 'url' => $a->get_baseurl() . '/message/new',
63 'sel'=> (($a->argv[1] == 'new') ? 'active' : ''),
66 $tpl = get_markup_template('common_tabs.tpl');
67 $tab_content = replace_macros($tpl, array('$tabs'=>$tabs));
70 $tpl = get_markup_template('mail_head.tpl');
71 $header = replace_macros($tpl, array(
72 '$messages' => t('Messages'),
73 '$tab_content' => $tab_content
77 if(($a->argc == 3) && ($a->argv[1] === 'drop' || $a->argv[1] === 'dropconv')) {
78 if(! intval($a->argv[2]))
82 $r = q("DELETE FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1",
87 info( t('Message deleted.') . EOL );
89 goaway($a->get_baseurl() . '/message' );
92 $r = q("SELECT `parent-uri` FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1",
97 $parent = $r[0]['parent-uri'];
98 $r = q("DELETE FROM `mail` WHERE `parent-uri` = '%s' AND `uid` = %d ",
103 info( t('Conversation removed.') . EOL );
105 goaway($a->get_baseurl() . '/message' );
110 if(($a->argc > 1) && ($a->argv[1] === 'new')) {
114 $tpl = get_markup_template('msg-header.tpl');
116 $a->page['htmlhead'] .= replace_macros($tpl, array(
117 '$baseurl' => $a->get_baseurl(),
118 '$nickname' => $a->user['nickname'],
119 '$linkurl' => t('Please enter a link URL:')
122 $preselect = (isset($a->argv[2])?array($a->argv[2]):false);
124 $select = contact_select('messageto','message-to-select', $preselect, 4, true);
125 $tpl = get_markup_template('prv_message.tpl');
126 $o .= replace_macros($tpl,array(
127 '$header' => t('Send Private Message'),
129 '$subject' => t('Subject:'),
132 '$yourmessage' => t('Your message:'),
133 '$select' => $select,
135 '$upload' => t('Upload photo'),
136 '$insert' => t('Insert web link'),
137 '$wait' => t('Please wait')
143 if(($a->argc == 1) || ($a->argc == 2 && $a->argv[1] === 'sent')) {
148 $eq = '='; // I'm not going to bother escaping this.
150 $eq = '!='; // or this.
152 $r = q("SELECT count(*) AS `total` FROM `mail`
153 WHERE `mail`.`uid` = %d AND `from-url` $eq '%s' GROUP BY `parent-uri` ORDER BY `created` DESC",
154 intval(local_user()),
158 $a->set_pager_total($r[0]['total']);
160 $r = q("SELECT max(`mail`.`created`) AS `mailcreated`, min(`mail`.`seen`) AS `mailseen`,
161 `mail`.* , `contact`.`name`, `contact`.`url`, `contact`.`thumb`
162 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
163 WHERE `mail`.`uid` = %d AND `from-url` $eq '%s' GROUP BY `parent-uri` ORDER BY `created` DESC LIMIT %d , %d ",
164 intval(local_user()),
166 intval($a->pager['start']),
167 intval($a->pager['itemspage'])
170 info( t('No messages.') . EOL);
174 $tpl = get_markup_template('mail_list.tpl');
176 $o .= replace_macros($tpl, array(
178 '$from_name' =>$rr['from-name'],
179 '$from_url' => $a->get_baseurl() . '/redir/' . $rr['contact-id'],
180 '$sparkle' => ' sparkle',
181 '$from_photo' => $rr['thumb'],
182 '$subject' => template_escape((($rr['mailseen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>')),
183 '$delete' => t('Delete conversation'),
184 '$body' => template_escape($rr['body']),
185 '$to_name' => template_escape($rr['name']),
186 '$date' => datetime_convert('UTC',date_default_timezone_get(),$rr['mailcreated'], t('D, d M Y - g:i A'))
193 if(($a->argc > 1) && (intval($a->argv[1]))) {
197 $r = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
198 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
199 WHERE `mail`.`uid` = %d AND `mail`.`id` = %d LIMIT 1",
200 intval(local_user()),
204 $contact_id = $r[0]['contact-id'];
205 $messages = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
206 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
207 WHERE `mail`.`uid` = %d AND `mail`.`parent-uri` = '%s' ORDER BY `mail`.`created` ASC",
208 intval(local_user()),
209 dbesc($r[0]['parent-uri'])
212 if(! count($messages)) {
213 notice( t('Message not available.') . EOL );
217 $r = q("UPDATE `mail` SET `seen` = 1 WHERE `parent-uri` = '%s' AND `uid` = %d",
218 dbesc($r[0]['parent-uri']),
222 require_once("include/bbcode.php");
224 $tpl = get_markup_template('msg-header.tpl');
226 $a->page['htmlhead'] .= replace_macros($tpl, array(
227 '$nickname' => $a->user['nickname'],
228 '$baseurl' => $a->get_baseurl()
232 $tpl = get_markup_template('mail_conv.tpl');
233 foreach($messages as $message) {
234 if($message['from-url'] == $myprofile) {
235 $from_url = $myprofile;
239 $from_url = $a->get_baseurl() . '/redir/' . $message['contact-id'];
240 $sparkle = ' sparkle';
242 $o .= replace_macros($tpl, array(
243 '$id' => $message['id'],
244 '$from_name' => template_escape($message['from-name']),
245 '$from_url' => $from_url,
246 '$sparkle' => $sparkle,
247 '$from_photo' => $message['from-photo'],
248 '$subject' => template_escape($message['title']),
249 '$body' => template_escape(smilies(bbcode($message['body']))),
250 '$delete' => t('Delete message'),
251 '$to_name' => template_escape($message['name']),
252 '$date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A')
256 $select = $message['name'] . '<input type="hidden" name="messageto" value="' . $contact_id . '" />';
257 $parent = '<input type="hidden" name="replyto" value="' . $message['parent-uri'] . '" />';
258 $tpl = get_markup_template('prv_message.tpl');
259 $o .= replace_macros($tpl,array(
260 '$header' => t('Send Reply'),
262 '$subject' => t('Subject:'),
263 '$subjtxt' => template_escape($message['title']),
264 '$readonly' => ' readonly="readonly" style="background: #BBBBBB;" ',
265 '$yourmessage' => t('Your message:'),
266 '$select' => $select,
267 '$parent' => $parent,
268 '$upload' => t('Upload photo'),
269 '$insert' => t('Insert web link'),
270 '$wait' => t('Please wait')