3 require_once('view/acl_selectors.php');
5 function message_init(&$a) {
10 function message_post(&$a) {
13 notice( t('Permission denied.') . EOL);
17 $replyto = notags(trim($_POST['replyto']));
18 $recipient = intval($_POST['messageto']);
19 $subject = notags(trim($_POST['subject']));
20 $body = escape_tags(trim($_POST['body']));
23 notice( t('No recipient selected.') . EOL );
27 $me = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
28 intval($_SESSION['uid'])
30 $contact = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
32 intval($_SESSION['uid'])
35 if(! (count($me) && (count($contact)))) {
36 notice( t('Unable to locate contact information.') . EOL );
40 $hash = random_string();
41 $uri = 'urn:X-dfrn:' . $a->get_baseurl() . ':' . $_SESSION['uid'] . ':' . $hash ;
43 if(! strlen($replyto))
46 $r = q("INSERT INTO `mail` ( `uid`, `from-name`, `from-photo`, `from-url`,
47 `contact-id`, `title`, `body`, `delivered`, `seen`, `replied`, `uri`, `parent-uri`, `created`)
48 VALUES ( %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, %d, '%s', '%s', '%s' )",
49 intval($_SESSION['uid']),
50 dbesc($me[0]['name']),
51 dbesc($me[0]['thumb']),
63 $r = q("SELECT * FROM `mail` WHERE `uri` = '%s' and `uid` = %d LIMIT 1",
65 intval($_SESSION['uid'])
68 $post_id = $r[0]['id'];
70 $url = $a->get_baseurl();
73 proc_close(proc_open("php include/notifier.php \"$url\" \"mail\" \"$post_id\" > mail.log &",
75 notice( t('Message sent.') . EOL );
78 notice( t('Message could not be sent.') . EOL );
84 function message_content(&$a) {
87 notice( t('Permission denied.') . EOL);
91 $myprofile = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
93 if(($a->argc > 1) && ($a->argv[1] == 'new')) {
95 $tpl = file_get_contents('view/jot-header.tpl');
97 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
99 $select .= contact_select('messageto','message-to-select', false, 4, true);
100 $tpl = file_get_contents('view/prv_message.tpl');
101 $o = replace_macros($tpl,array(
102 '$header' => t('Send Private Message'),
104 '$subject' => t('Subject:'),
105 '$yourmessage' => t('Your message:'),
106 '$select' => $select,
107 '$upload' => t('Upload photo'),
108 '$insert' => t('Insert web link'),
109 '$wait' => t('Please wait')
118 $r = q("SELECT count(*) AS `total` FROM `mail`
119 WHERE `mail`.`uid` = %d AND `from-url` != '%s' ",
120 intval($_SESSION['uid']),
124 $a->set_pager_total($r[0]['total']);
126 $r = q("SELECT `mail`.*, `contact`.`name`, `contact`.`url`, `contact`.`thumb`
127 FROM `mail` LEFT JOIN `contact` ON `mail`.`contact-id` = `contact`.`id`
128 WHERE `mail`.`uid` = %d AND `from-url` != '%s' LIMIT %d , %d ",
129 intval($_SESSION['uid']),
131 intval($a->pager['start']),
132 intval($a->pager['itemspage'])
135 notice( t('No messages.') . EOL);
139 $tpl = file_get_contents('view/mail_list.tpl');
141 $o .= replace_macros($tpl, array(
143 '$from_name' =>$rr['from-name'],
144 '$from_url' => $a->get_baseurl() . '/redir/' . $rr['contact-id'],
145 '$from_photo' => $rr['from-photo'],
146 '$subject' => (($rr['seen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>'),
147 '$to_name' => $rr['name'],
148 '$date' => datetime_convert('UTC',date_default_timezone_get(),$rr['created'],'D, d M Y - g:i A')