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`,`convid` FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1",
97 $parent = $r[0]['parent-uri'];
98 $convid = $r[0]['convid'];
100 $r = q("DELETE FROM `mail` WHERE `parent-uri` = '%s' AND `uid` = %d ",
105 // remove diaspora conversation pointer
108 q("delete from conv where id = %d limit 1",
114 info( t('Conversation removed.') . EOL );
116 goaway($a->get_baseurl() . '/message' );
121 if(($a->argc > 1) && ($a->argv[1] === 'new')) {
125 $tpl = get_markup_template('msg-header.tpl');
127 $a->page['htmlhead'] .= replace_macros($tpl, array(
128 '$baseurl' => $a->get_baseurl(),
129 '$nickname' => $a->user['nickname'],
130 '$linkurl' => t('Please enter a link URL:')
133 $preselect = (isset($a->argv[2])?array($a->argv[2]):false);
135 $select = contact_select('messageto','message-to-select', $preselect, 4, true);
136 $tpl = get_markup_template('prv_message.tpl');
137 $o .= replace_macros($tpl,array(
138 '$header' => t('Send Private Message'),
140 '$subject' => t('Subject:'),
143 '$yourmessage' => t('Your message:'),
144 '$select' => $select,
146 '$upload' => t('Upload photo'),
147 '$insert' => t('Insert web link'),
148 '$wait' => t('Please wait')
154 if(($a->argc == 1) || ($a->argc == 2 && $a->argv[1] === 'sent')) {
159 $eq = '='; // I'm not going to bother escaping this.
161 $eq = '!='; // or this.
163 $r = q("SELECT count(*) AS `total` FROM `mail`
164 WHERE `mail`.`uid` = %d AND `from-url` $eq '%s' GROUP BY `parent-uri` ORDER BY `created` DESC",
165 intval(local_user()),
169 $a->set_pager_total($r[0]['total']);
171 $r = q("SELECT max(`mail`.`created`) AS `mailcreated`, min(`mail`.`seen`) AS `mailseen`,
172 `mail`.* , `contact`.`name`, `contact`.`url`, `contact`.`thumb`
173 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
174 WHERE `mail`.`uid` = %d AND `from-url` $eq '%s' GROUP BY `parent-uri` ORDER BY `created` DESC LIMIT %d , %d ",
175 intval(local_user()),
177 intval($a->pager['start']),
178 intval($a->pager['itemspage'])
181 info( t('No messages.') . EOL);
185 $tpl = get_markup_template('mail_list.tpl');
187 $o .= replace_macros($tpl, array(
189 '$from_name' =>$rr['from-name'],
190 '$from_url' => (($rr['network'] === NETWORK_DFRN) ? $a->get_baseurl() . '/redir/' . $rr['contact-id'] : $rr['url']),
191 '$sparkle' => ' sparkle',
192 '$from_photo' => $rr['thumb'],
193 '$subject' => template_escape((($rr['mailseen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>')),
194 '$delete' => t('Delete conversation'),
195 '$body' => template_escape($rr['body']),
196 '$to_name' => template_escape($rr['name']),
197 '$date' => datetime_convert('UTC',date_default_timezone_get(),$rr['mailcreated'], t('D, d M Y - g:i A'))
204 if(($a->argc > 1) && (intval($a->argv[1]))) {
208 $r = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
209 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
210 WHERE `mail`.`uid` = %d AND `mail`.`id` = %d LIMIT 1",
211 intval(local_user()),
215 $contact_id = $r[0]['contact-id'];
216 $messages = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
217 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
218 WHERE `mail`.`uid` = %d AND `mail`.`parent-uri` = '%s' ORDER BY `mail`.`created` ASC",
219 intval(local_user()),
220 dbesc($r[0]['parent-uri'])
223 if(! count($messages)) {
224 notice( t('Message not available.') . EOL );
228 $r = q("UPDATE `mail` SET `seen` = 1 WHERE `parent-uri` = '%s' AND `uid` = %d",
229 dbesc($r[0]['parent-uri']),
233 require_once("include/bbcode.php");
235 $tpl = get_markup_template('msg-header.tpl');
237 $a->page['htmlhead'] .= replace_macros($tpl, array(
238 '$nickname' => $a->user['nickname'],
239 '$baseurl' => $a->get_baseurl()
243 $tpl = get_markup_template('mail_conv.tpl');
244 foreach($messages as $message) {
245 if($message['from-url'] == $myprofile) {
246 $from_url = $myprofile;
250 $from_url = $a->get_baseurl() . '/redir/' . $message['contact-id'];
251 $sparkle = ' sparkle';
253 $o .= replace_macros($tpl, array(
254 '$id' => $message['id'],
255 '$from_name' => template_escape($message['from-name']),
256 '$from_url' => $from_url,
257 '$sparkle' => $sparkle,
258 '$from_photo' => $message['from-photo'],
259 '$subject' => template_escape($message['title']),
260 '$body' => template_escape(smilies(bbcode($message['body']))),
261 '$delete' => t('Delete message'),
262 '$to_name' => template_escape($message['name']),
263 '$date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A')
267 $select = $message['name'] . '<input type="hidden" name="messageto" value="' . $contact_id . '" />';
268 $parent = '<input type="hidden" name="replyto" value="' . $message['parent-uri'] . '" />';
269 $tpl = get_markup_template('prv_message.tpl');
270 $o .= replace_macros($tpl,array(
271 '$header' => t('Send Reply'),
273 '$subject' => t('Subject:'),
274 '$subjtxt' => template_escape($message['title']),
275 '$readonly' => ' readonly="readonly" style="background: #BBBBBB;" ',
276 '$yourmessage' => t('Your message:'),
277 '$select' => $select,
278 '$parent' => $parent,
279 '$upload' => t('Upload photo'),
280 '$insert' => t('Insert web link'),
281 '$wait' => t('Please wait')