2 // send a private message
7 function send_message($recipient=0, $body='', $subject='', $replyto=''){
10 if(! $recipient) return -1;
12 if(! strlen($subject))
13 $subject = t('[no subject]');
15 $me = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
18 $contact = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
23 if(! (count($me) && (count($contact)))) {
27 $hash = random_string();
28 $uri = 'urn:X-dfrn:' . $a->get_baseurl() . ':' . local_user() . ':' . $hash ;
30 if(! strlen($replyto))
33 $r = q("INSERT INTO `mail` ( `uid`, `from-name`, `from-photo`, `from-url`,
34 `contact-id`, `title`, `body`, `seen`, `replied`, `uri`, `parent-uri`, `created`)
35 VALUES ( %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, '%s', '%s', '%s' )",
37 dbesc($me[0]['name']),
38 dbesc($me[0]['thumb']),
49 $r = q("SELECT * FROM `mail` WHERE `uri` = '%s' and `uid` = %d LIMIT 1",
54 $post_id = $r[0]['id'];
58 * When a photo was uploaded into the message using the (profile wall) ajax
59 * uploader, The permissions are initially set to disallow anybody but the
60 * owner from seeing it. This is because the permissions may not yet have been
61 * set for the post. If it's private, the photo permissions should be set
62 * appropriately. But we didn't know the final permissions on the post until
63 * now. So now we'll look for links of uploaded messages that are in the
64 * post and set them to the same permissions as the post itself.
70 if(preg_match_all("/\[img\](.*?)\[\/img\]/",$body,$match)) {
73 foreach($images as $image) {
74 if(! stristr($image,$a->get_baseurl() . '/photo/'))
76 $image_uri = substr($image,strrpos($image,'/') + 1);
77 $image_uri = substr($image_uri,0, strpos($image_uri,'-'));
78 $r = q("UPDATE `photo` SET `allow_cid` = '%s'
79 WHERE `resource-id` = '%s' AND `album` = '%s' AND `uid` = %d ",
80 dbesc('<' . $recipient . '>'),
82 dbesc( t('Wall Photos')),
90 proc_run('php',"include/notifier.php","mail","$post_id");
91 return intval($post_id);