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($_REQUEST,'replyto')) ? notags(trim($_REQUEST['replyto'])) : '');
14 $subject = ((x($_REQUEST,'subject')) ? notags(trim($_REQUEST['subject'])) : '');
15 $body = ((x($_REQUEST,'body')) ? escape_tags(trim($_REQUEST['body'])) : '');
16 $recipient = ((x($_REQUEST,'messageto')) ? intval($_REQUEST['messageto']) : 0 );
19 $ret = send_message($recipient, $body, $subject, $replyto);
24 notice( t('No recipient selected.') . EOL );
28 notice( t('Unable to locate contact information.') . EOL );
31 notice( t('Message could not be sent.') . EOL );
34 notice( t('Message collection failure.') . EOL );
37 info( t('Message sent.') . EOL );
40 // fake it to go back to the input form if no recipient listed
49 function message_content(&$a) {
52 nav_set_selected('messages');
55 notice( t('Permission denied.') . EOL);
59 $myprofile = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
64 'label' => t('Inbox'),
65 'url'=> $a->get_baseurl() . '/message',
66 'sel'=> (($a->argc == 1) ? 'active' : ''),
69 'label' => t('Outbox'),
70 'url' => $a->get_baseurl() . '/message/sent',
71 'sel'=> (($a->argv[1] == 'sent') ? 'active' : ''),
74 'label' => t('New Message'),
75 'url' => $a->get_baseurl() . '/message/new',
76 'sel'=> (($a->argv[1] == 'new') ? 'active' : ''),
79 $tpl = get_markup_template('common_tabs.tpl');
80 $tab_content = replace_macros($tpl, array('$tabs'=>$tabs));
83 $tpl = get_markup_template('mail_head.tpl');
84 $header = replace_macros($tpl, array(
85 '$messages' => t('Messages'),
86 '$tab_content' => $tab_content
90 if(($a->argc == 3) && ($a->argv[1] === 'drop' || $a->argv[1] === 'dropconv')) {
91 if(! intval($a->argv[2]))
95 $r = q("DELETE FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1",
100 info( t('Message deleted.') . EOL );
102 goaway($a->get_baseurl() . '/message' );
105 $r = q("SELECT `parent-uri`,`convid` FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1",
110 $parent = $r[0]['parent-uri'];
111 $convid = $r[0]['convid'];
113 $r = q("DELETE FROM `mail` WHERE `parent-uri` = '%s' AND `uid` = %d ",
118 // remove diaspora conversation pointer
119 // Actually if we do this, we can never receive another reply to that conversation,
120 // as we will never again have the info we need to re-create it.
121 // We'll just have to orphan it.
124 // q("delete from conv where id = %d limit 1",
130 info( t('Conversation removed.') . EOL );
132 goaway($a->get_baseurl() . '/message' );
137 if(($a->argc > 1) && ($a->argv[1] === 'new')) {
142 if(intval(get_pconfig(local_user(),'system','plaintext')))
146 $tpl = get_markup_template('msg-header.tpl');
148 $a->page['htmlhead'] .= replace_macros($tpl, array(
149 '$baseurl' => $a->get_baseurl(),
150 '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
151 '$nickname' => $a->user['nickname'],
152 '$linkurl' => t('Please enter a link URL:')
155 $preselect = (isset($a->argv[2])?array($a->argv[2]):false);
157 $select = contact_select('messageto','message-to-select', $preselect, 4, true);
158 $tpl = get_markup_template('prv_message.tpl');
159 $o .= replace_macros($tpl,array(
160 '$header' => t('Send Private Message'),
162 '$subject' => t('Subject:'),
163 '$subjtxt' => ((x($_REQUEST,'subject')) ? strip_tags($_REQUEST['subject']) : ''),
164 '$text' => ((x($_REQUEST,'body')) ? escape_tags(htmlspecialchars($_REQUEST['body'])) : ''),
166 '$yourmessage' => t('Your message:'),
167 '$select' => $select,
169 '$upload' => t('Upload photo'),
170 '$insert' => t('Insert web link'),
171 '$wait' => t('Please wait')
177 if(($a->argc == 1) || ($a->argc == 2 && $a->argv[1] === 'sent')) {
182 $eq = '='; // I'm not going to bother escaping this.
184 $eq = '!='; // or this.
186 $r = q("SELECT count(*) AS `total` FROM `mail`
187 WHERE `mail`.`uid` = %d AND `from-url` $eq '%s' GROUP BY `parent-uri` ORDER BY `created` DESC",
188 intval(local_user()),
192 $a->set_pager_total($r[0]['total']);
194 $r = q("SELECT max(`mail`.`created`) AS `mailcreated`, min(`mail`.`seen`) AS `mailseen`,
195 `mail`.* , `contact`.`name`, `contact`.`url`, `contact`.`thumb`
196 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
197 WHERE `mail`.`uid` = %d AND `from-url` $eq '%s' GROUP BY `parent-uri` ORDER BY `created` DESC LIMIT %d , %d ",
198 intval(local_user()),
200 intval($a->pager['start']),
201 intval($a->pager['itemspage'])
204 info( t('No messages.') . EOL);
208 $tpl = get_markup_template('mail_list.tpl');
210 $o .= replace_macros($tpl, array(
212 '$from_name' =>$rr['from-name'],
213 '$from_url' => (($rr['network'] === NETWORK_DFRN) ? $a->get_baseurl() . '/redir/' . $rr['contact-id'] : $rr['url']),
214 '$sparkle' => ' sparkle',
215 '$from_photo' => $rr['thumb'],
216 '$subject' => template_escape((($rr['mailseen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>')),
217 '$delete' => t('Delete conversation'),
218 '$body' => template_escape($rr['body']),
219 '$to_name' => template_escape($rr['name']),
220 '$date' => datetime_convert('UTC',date_default_timezone_get(),$rr['mailcreated'], t('D, d M Y - g:i A'))
227 if(($a->argc > 1) && (intval($a->argv[1]))) {
231 $r = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
232 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
233 WHERE `mail`.`uid` = %d AND `mail`.`id` = %d LIMIT 1",
234 intval(local_user()),
238 $contact_id = $r[0]['contact-id'];
239 $convid = $r[0]['convid'];
241 $sql_extra = sprintf(" and `mail`.`parent-uri` = '%s' ", dbesc($r[0]['parent-uri']));
243 $sql_extra = sprintf(" and ( `mail`.`parent-uri` = '%s' OR `mail`.`convid` = '%d' ) ",
244 dbesc($r[0]['parent-uri']),
248 $messages = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
249 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
250 WHERE `mail`.`uid` = %d $sql_extra ORDER BY `mail`.`created` ASC",
254 if(! count($messages)) {
255 notice( t('Message not available.') . EOL );
259 $r = q("UPDATE `mail` SET `seen` = 1 WHERE `parent-uri` = '%s' AND `uid` = %d",
260 dbesc($r[0]['parent-uri']),
264 require_once("include/bbcode.php");
266 $tpl = get_markup_template('msg-header.tpl');
268 $a->page['htmlhead'] .= replace_macros($tpl, array(
269 '$nickname' => $a->user['nickname'],
270 '$baseurl' => $a->get_baseurl()
274 $tpl = get_markup_template('mail_conv.tpl');
275 foreach($messages as $message) {
276 if($message['from-url'] == $myprofile) {
277 $from_url = $myprofile;
281 $from_url = $a->get_baseurl() . '/redir/' . $message['contact-id'];
282 $sparkle = ' sparkle';
284 $o .= replace_macros($tpl, array(
285 '$id' => $message['id'],
286 '$from_name' => template_escape($message['from-name']),
287 '$from_url' => $from_url,
288 '$sparkle' => $sparkle,
289 '$from_photo' => $message['from-photo'],
290 '$subject' => template_escape($message['title']),
291 '$body' => template_escape(smilies(bbcode($message['body']))),
292 '$delete' => t('Delete message'),
293 '$to_name' => template_escape($message['name']),
294 '$date' => datetime_convert('UTC',date_default_timezone_get(),$message['created'],'D, d M Y - g:i A')
298 $select = $message['name'] . '<input type="hidden" name="messageto" value="' . $contact_id . '" />';
299 $parent = '<input type="hidden" name="replyto" value="' . $message['parent-uri'] . '" />';
300 $tpl = get_markup_template('prv_message.tpl');
301 $o .= replace_macros($tpl,array(
302 '$header' => t('Send Reply'),
304 '$subject' => t('Subject:'),
305 '$subjtxt' => template_escape($message['title']),
306 '$readonly' => ' readonly="readonly" style="background: #BBBBBB;" ',
307 '$yourmessage' => t('Your message:'),
308 '$select' => $select,
309 '$parent' => $parent,
310 '$upload' => t('Upload photo'),
311 '$insert' => t('Insert web link'),
312 '$wait' => t('Please wait')