3 require_once('include/crypto.php');
4 require_once('include/items.php');
5 require_once('include/bb2diaspora.php');
6 require_once('include/contact_selectors.php');
7 require_once('include/queue_fn.php');
10 function diaspora_dispatch_public($msg) {
12 $enabled = intval(get_config('system','diaspora_enabled'));
14 logger('mod-diaspora: disabled');
18 $r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN ( SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s' ) AND `account_expired` = 0 ",
19 dbesc(NETWORK_DIASPORA),
24 logger('diaspora_public: delivering to: ' . $rr['username']);
25 diaspora_dispatch($rr,$msg);
29 logger('diaspora_public: no subscribers');
34 function diaspora_dispatch($importer,$msg) {
38 $enabled = intval(get_config('system','diaspora_enabled'));
40 logger('mod-diaspora: disabled');
44 // php doesn't like dashes in variable names
46 $msg['message'] = str_replace(
47 array('<activity_streams-photo>','</activity_streams-photo>'),
48 array('<asphoto>','</asphoto>'),
52 $parsed_xml = parse_xml_string($msg['message'],false);
54 $xmlbase = $parsed_xml->post;
56 logger('diaspora_dispatch: ' . print_r($xmlbase,true), LOGGER_DEBUG);
59 if($xmlbase->request) {
60 $ret = diaspora_request($importer,$xmlbase->request);
62 elseif($xmlbase->status_message) {
63 $ret = diaspora_post($importer,$xmlbase->status_message);
65 elseif($xmlbase->profile) {
66 $ret = diaspora_profile($importer,$xmlbase->profile);
68 elseif($xmlbase->comment) {
69 $ret = diaspora_comment($importer,$xmlbase->comment,$msg);
71 elseif($xmlbase->like) {
72 $ret = diaspora_like($importer,$xmlbase->like,$msg);
74 elseif($xmlbase->asphoto) {
75 $ret = diaspora_asphoto($importer,$xmlbase->asphoto);
77 elseif($xmlbase->reshare) {
78 $ret = diaspora_reshare($importer,$xmlbase->reshare);
80 elseif($xmlbase->retraction) {
81 $ret = diaspora_retraction($importer,$xmlbase->retraction,$msg);
83 elseif($xmlbase->signed_retraction) {
84 $ret = diaspora_signed_retraction($importer,$xmlbase->signed_retraction,$msg);
86 elseif($xmlbase->photo) {
87 $ret = diaspora_photo($importer,$xmlbase->photo,$msg);
89 elseif($xmlbase->conversation) {
90 $ret = diaspora_conversation($importer,$xmlbase->conversation,$msg);
92 elseif($xmlbase->message) {
93 $ret = diaspora_message($importer,$xmlbase->message,$msg);
96 logger('diaspora_dispatch: unknown message type: ' . print_r($xmlbase,true));
101 function diaspora_get_contact_by_handle($uid,$handle) {
102 $r = q("SELECT * FROM `contact` WHERE `network` = '%s' AND `uid` = %d AND `addr` = '%s' LIMIT 1",
103 dbesc(NETWORK_DIASPORA),
112 function find_diaspora_person_by_handle($handle) {
114 $r = q("select * from fcontact where network = '%s' and addr = '%s' limit 1",
115 dbesc(NETWORK_DIASPORA),
119 logger('find_diaspora_person_by handle: in cache ' . print_r($r,true), LOGGER_DEBUG);
120 // update record occasionally so it doesn't get stale
121 $d = strtotime($r[0]['updated'] . ' +00:00');
122 if($d > strtotime('now - 14 days'))
126 logger('find_diaspora_person_by_handle: refresh',LOGGER_DEBUG);
127 require_once('include/Scrape.php');
128 $r = probe_url($handle, PROBE_DIASPORA);
129 if((count($r)) && ($r['network'] === NETWORK_DIASPORA)) {
130 add_fcontact($r,$update);
137 function get_diaspora_key($uri) {
138 logger('Fetching diaspora key for: ' . $uri);
140 $r = find_diaspora_person_by_handle($uri);
147 function diaspora_pubmsg_build($msg,$user,$contact,$prvkey,$pubkey) {
150 logger('diaspora_pubmsg_build: ' . $msg, LOGGER_DATA);
153 $handle = $user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
155 // $b64_data = base64_encode($msg);
156 // $b64url_data = base64url_encode($b64_data);
158 $b64url_data = base64url_encode($msg);
160 $data = str_replace(array("\n","\r"," ","\t"),array('','','',''),$b64url_data);
162 $type = 'application/xml';
163 $encoding = 'base64url';
166 $signable_data = $data . '.' . base64url_encode($type) . '.'
167 . base64url_encode($encoding) . '.' . base64url_encode($alg) ;
169 $signature = rsa_sign($signable_data,$prvkey);
170 $sig = base64url_encode($signature);
173 <?xml version='1.0' encoding='UTF-8'?>
174 <diaspora xmlns="https://joindiaspora.com/protocol" xmlns:me="http://salmon-protocol.org/ns/magic-env" >
176 <author_id>$handle</author_id>
179 <me:encoding>base64url</me:encoding>
180 <me:alg>RSA-SHA256</me:alg>
181 <me:data type="application/xml">$data</me:data>
182 <me:sig>$sig</me:sig>
187 logger('diaspora_pubmsg_build: magic_env: ' . $magic_env, LOGGER_DATA);
195 function diaspora_msg_build($msg,$user,$contact,$prvkey,$pubkey,$public = false) {
199 return diaspora_pubmsg_build($msg,$user,$contact,$prvkey,$pubkey);
201 logger('diaspora_msg_build: ' . $msg, LOGGER_DATA);
203 // without a public key nothing will work
206 logger('diaspora_msg_build: pubkey missing: contact id: ' . $contact['id']);
210 $inner_aes_key = random_string(32);
211 $b_inner_aes_key = base64_encode($inner_aes_key);
212 $inner_iv = random_string(16);
213 $b_inner_iv = base64_encode($inner_iv);
215 $outer_aes_key = random_string(32);
216 $b_outer_aes_key = base64_encode($outer_aes_key);
217 $outer_iv = random_string(16);
218 $b_outer_iv = base64_encode($outer_iv);
220 $handle = $user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
222 $padded_data = pkcs5_pad($msg,16);
223 $inner_encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $inner_aes_key, $padded_data, MCRYPT_MODE_CBC, $inner_iv);
225 $b64_data = base64_encode($inner_encrypted);
228 $b64url_data = base64url_encode($b64_data);
229 $data = str_replace(array("\n","\r"," ","\t"),array('','','',''),$b64url_data);
231 $type = 'application/xml';
232 $encoding = 'base64url';
235 $signable_data = $data . '.' . base64url_encode($type) . '.'
236 . base64url_encode($encoding) . '.' . base64url_encode($alg) ;
238 $signature = rsa_sign($signable_data,$prvkey);
239 $sig = base64url_encode($signature);
241 $decrypted_header = <<< EOT
244 <aes_key>$b_inner_aes_key</aes_key>
245 <author_id>$handle</author_id>
249 $decrypted_header = pkcs5_pad($decrypted_header,16);
251 $ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $outer_aes_key, $decrypted_header, MCRYPT_MODE_CBC, $outer_iv);
253 $outer_json = json_encode(array('iv' => $b_outer_iv,'key' => $b_outer_aes_key));
255 $encrypted_outer_key_bundle = '';
256 openssl_public_encrypt($outer_json,$encrypted_outer_key_bundle,$pubkey);
258 $b64_encrypted_outer_key_bundle = base64_encode($encrypted_outer_key_bundle);
260 logger('outer_bundle: ' . $b64_encrypted_outer_key_bundle . ' key: ' . $pubkey, LOGGER_DATA);
262 $encrypted_header_json_object = json_encode(array('aes_key' => base64_encode($encrypted_outer_key_bundle),
263 'ciphertext' => base64_encode($ciphertext)));
264 $cipher_json = base64_encode($encrypted_header_json_object);
266 $encrypted_header = '<encrypted_header>' . $cipher_json . '</encrypted_header>';
269 <?xml version='1.0' encoding='UTF-8'?>
270 <diaspora xmlns="https://joindiaspora.com/protocol" xmlns:me="http://salmon-protocol.org/ns/magic-env" >
273 <me:encoding>base64url</me:encoding>
274 <me:alg>RSA-SHA256</me:alg>
275 <me:data type="application/xml">$data</me:data>
276 <me:sig>$sig</me:sig>
281 logger('diaspora_msg_build: magic_env: ' . $magic_env, LOGGER_DATA);
288 * diaspora_decode($importer,$xml)
289 * array $importer -> from user table
290 * string $xml -> urldecoded Diaspora salmon
293 * 'message' -> decoded Diaspora XML message
294 * 'author' -> author diaspora handle
295 * 'key' -> author public key (converted to pkcs#8)
297 * Author and key are used elsewhere to save a lookup for verifying replies and likes
301 function diaspora_decode($importer,$xml) {
304 $basedom = parse_xml_string($xml);
306 $children = $basedom->children('https://joindiaspora.com/protocol');
308 if($children->header) {
310 $author_link = str_replace('acct:','',$children->header->author_id);
314 $encrypted_header = json_decode(base64_decode($children->encrypted_header));
316 $encrypted_aes_key_bundle = base64_decode($encrypted_header->aes_key);
317 $ciphertext = base64_decode($encrypted_header->ciphertext);
319 $outer_key_bundle = '';
320 openssl_private_decrypt($encrypted_aes_key_bundle,$outer_key_bundle,$importer['prvkey']);
322 $j_outer_key_bundle = json_decode($outer_key_bundle);
324 $outer_iv = base64_decode($j_outer_key_bundle->iv);
325 $outer_key = base64_decode($j_outer_key_bundle->key);
327 $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $outer_key, $ciphertext, MCRYPT_MODE_CBC, $outer_iv);
330 $decrypted = pkcs5_unpad($decrypted);
333 * $decrypted now contains something like
336 * <iv>8e+G2+ET8l5BPuW0sVTnQw==</iv>
337 * <aes_key>UvSMb4puPeB14STkcDWq+4QE302Edu15oaprAQSkLKU=</aes_key>
342 * <name>Ryan Hughes</name>
343 * <uri>acct:galaxor@diaspora.pirateship.org</uri>
348 * <author_id>galaxor@diaspora.priateship.org</author_id>
352 * </decrypted_header>
355 logger('decrypted: ' . $decrypted, LOGGER_DEBUG);
356 $idom = parse_xml_string($decrypted,false);
358 $inner_iv = base64_decode($idom->iv);
359 $inner_aes_key = base64_decode($idom->aes_key);
361 $author_link = str_replace('acct:','',$idom->author_id);
365 $dom = $basedom->children(NAMESPACE_SALMON_ME);
367 // figure out where in the DOM tree our data is hiding
369 if($dom->provenance->data)
370 $base = $dom->provenance;
371 elseif($dom->env->data)
377 logger('mod-diaspora: unable to locate salmon data in xml ');
378 http_status_exit(400);
382 // Stash the signature away for now. We have to find their key or it won't be good for anything.
383 $signature = base64url_decode($base->sig);
387 // strip whitespace so our data element will return to one big base64 blob
388 $data = str_replace(array(" ","\t","\r","\n"),array("","","",""),$base->data);
391 // stash away some other stuff for later
393 $type = $base->data[0]->attributes()->type[0];
394 $keyhash = $base->sig[0]->attributes()->keyhash[0];
395 $encoding = $base->encoding;
399 $signed_data = $data . '.' . base64url_encode($type) . '.' . base64url_encode($encoding) . '.' . base64url_encode($alg);
403 $data = base64url_decode($data);
407 $inner_decrypted = $data;
411 // Decode the encrypted blob
413 $inner_encrypted = base64_decode($data);
414 $inner_decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $inner_aes_key, $inner_encrypted, MCRYPT_MODE_CBC, $inner_iv);
415 $inner_decrypted = pkcs5_unpad($inner_decrypted);
419 logger('mod-diaspora: Could not retrieve author URI.');
420 http_status_exit(400);
423 // Once we have the author URI, go to the web and try to find their public key
424 // (first this will look it up locally if it is in the fcontact cache)
425 // This will also convert diaspora public key from pkcs#1 to pkcs#8
427 logger('mod-diaspora: Fetching key for ' . $author_link );
428 $key = get_diaspora_key($author_link);
431 logger('mod-diaspora: Could not retrieve author key.');
432 http_status_exit(400);
435 $verify = rsa_verify($signed_data,$signature,$key);
438 logger('mod-diaspora: Message did not verify. Discarding.');
439 http_status_exit(400);
442 logger('mod-diaspora: Message verified.');
444 return array('message' => $inner_decrypted, 'author' => $author_link, 'key' => $key);
449 function diaspora_request($importer,$xml) {
453 $sender_handle = unxmlify($xml->sender_handle);
454 $recipient_handle = unxmlify($xml->recipient_handle);
456 if(! $sender_handle || ! $recipient_handle)
459 $contact = diaspora_get_contact_by_handle($importer['uid'],$sender_handle);
463 // perhaps we were already sharing with this person. Now they're sharing with us.
464 // That makes us friends.
466 if($contact['rel'] == CONTACT_IS_FOLLOWER && $importer['page-flags'] != PAGE_COMMUNITY) {
467 q("UPDATE `contact` SET `rel` = %d, `writable` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1",
468 intval(CONTACT_IS_FRIEND),
469 intval($contact['id']),
470 intval($importer['uid'])
475 $r = q("SELECT `hide-friends` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
476 intval($importer['uid'])
479 if((count($r)) && (! $r[0]['hide-friends']) && (! $contact['hidden'])) {
480 require_once('include/items.php');
482 $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
483 intval($importer['uid'])
486 // they are not CONTACT_IS_FOLLOWER anymore but that's what we have in the array
488 if(count($self) && $contact['rel'] == CONTACT_IS_FOLLOWER) {
491 $arr['uri'] = $arr['parent-uri'] = item_new_uri($a->get_hostname(), $importer['uid']);
492 $arr['uid'] = $importer['uid'];
493 $arr['contact-id'] = $self[0]['id'];
495 $arr['type'] = 'wall';
498 $arr['author-name'] = $arr['owner-name'] = $self[0]['name'];
499 $arr['author-link'] = $arr['owner-link'] = $self[0]['url'];
500 $arr['author-avatar'] = $arr['owner-avatar'] = $self[0]['thumb'];
501 $arr['verb'] = ACTIVITY_FRIEND;
502 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
504 $A = '[url=' . $self[0]['url'] . ']' . $self[0]['name'] . '[/url]';
505 $B = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
506 $BPhoto = '[url=' . $contact['url'] . ']' . '[img]' . $contact['thumb'] . '[/img][/url]';
507 $arr['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto;
509 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $contact['name'] . '</title>'
510 . '<id>' . $contact['url'] . '/' . $contact['name'] . '</id>';
511 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $contact['url'] . '" />' . "\n");
512 $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $contact['thumb'] . '" />' . "\n");
513 $arr['object'] .= '</link></object>' . "\n";
514 $arr['last-child'] = 1;
516 $arr['allow_cid'] = $user[0]['allow_cid'];
517 $arr['allow_gid'] = $user[0]['allow_gid'];
518 $arr['deny_cid'] = $user[0]['deny_cid'];
519 $arr['deny_gid'] = $user[0]['deny_gid'];
521 $i = item_store($arr);
523 proc_run('php',"include/notifier.php","activity","$i");
532 $ret = find_diaspora_person_by_handle($sender_handle);
535 if((! count($ret)) || ($ret['network'] != NETWORK_DIASPORA)) {
536 logger('diaspora_request: Cannot resolve diaspora handle ' . $sender_handle . ' for ' . $recipient_handle);
540 $batch = (($ret['batch']) ? $ret['batch'] : implode('/', array_slice(explode('/',$ret['url']),0,3)) . '/receive/public');
544 $r = q("INSERT INTO `contact` (`uid`, `network`,`addr`,`created`,`url`,`nurl`,`batch`,`name`,`nick`,`photo`,`pubkey`,`notify`,`poll`,`blocked`,`priority`)
545 VALUES ( %d, '%s', '%s', '%s', '%s','%s','%s','%s','%s','%s','%s','%s','%s',%d,%d) ",
546 intval($importer['uid']),
547 dbesc($ret['network']),
551 dbesc(normalise_link($ret['url'])),
555 dbesc($ret['photo']),
556 dbesc($ret['pubkey']),
557 dbesc($ret['notify']),
563 // find the contact record we just created
565 $contact_record = diaspora_get_contact_by_handle($importer['uid'],$sender_handle);
567 if(! $contact_record) {
568 logger('diaspora_request: unable to locate newly created contact record.');
572 if($importer['page-flags'] == PAGE_NORMAL) {
574 $hash = random_string() . (string) time(); // Generate a confirm_key
576 $ret = q("INSERT INTO `intro` ( `uid`, `contact-id`, `blocked`, `knowyou`, `note`, `hash`, `datetime` )
577 VALUES ( %d, %d, %d, %d, '%s', '%s', '%s' )",
578 intval($importer['uid']),
579 intval($contact_record['id']),
582 dbesc( t('Sharing notification from Diaspora network')),
584 dbesc(datetime_convert())
589 // automatic friend approval
591 require_once('include/Photo.php');
593 $photos = import_profile_photo($contact_record['photo'],$importer['uid'],$contact_record['id']);
595 // technically they are sharing with us (CONTACT_IS_SHARING),
596 // but if our page-type is PAGE_COMMUNITY or PAGE_SOAPBOX
597 // we are going to change the relationship and make them a follower.
599 if($importer['page-flags'] == PAGE_FREELOVE)
600 $new_relation = CONTACT_IS_FRIEND;
602 $new_relation = CONTACT_IS_FOLLOWER;
604 $r = q("UPDATE `contact` SET
611 `avatar-date` = '%s',
614 WHERE `id` = %d LIMIT 1
619 intval($new_relation),
620 dbesc(datetime_convert()),
621 dbesc(datetime_convert()),
622 dbesc(datetime_convert()),
623 intval($contact_record['id'])
626 $u = q("select * from user where uid = %d limit 1",intval($importer['uid']));
628 $ret = diaspora_share($u[0],$contact_record);
634 function diaspora_post_allow($importer,$contact) {
635 if(($contact['blocked']) || ($contact['readonly']))
637 if($contact['rel'] == CONTACT_IS_SHARING || $contact['rel'] == CONTACT_IS_FRIEND)
639 if($contact['rel'] == CONTACT_IS_FOLLOWER)
640 if($importer['page-flags'] == PAGE_COMMUNITY)
646 function diaspora_post($importer,$xml) {
649 $guid = notags(unxmlify($xml->guid));
650 $diaspora_handle = notags(unxmlify($xml->diaspora_handle));
652 $contact = diaspora_get_contact_by_handle($importer['uid'],$diaspora_handle);
656 if(! diaspora_post_allow($importer,$contact)) {
657 logger('diaspora_post: Ignoring this author.');
661 $message_id = $diaspora_handle . ':' . $guid;
662 $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `guid` = '%s' LIMIT 1",
663 intval($importer['uid']),
668 logger('diaspora_post: message exists: ' . $guid);
672 // allocate a guid on our system - we aren't fixing any collisions.
673 // we're ignoring them
675 $g = q("select * from guid where guid = '%s' limit 1",
679 q("insert into guid ( guid ) values ( '%s' )",
684 $created = unxmlify($xml->created_at);
685 $private = ((unxmlify($xml->public) == 'false') ? 1 : 0);
687 $body = diaspora2bb($xml->raw_message);
693 $tags = get_tags($body);
696 foreach($tags as $tag) {
697 if(strpos($tag,'#') === 0) {
698 if(strpos($tag,'[url='))
701 // don't link tags that are already embedded in links
703 if(preg_match('/\[(.*?)' . preg_quote($tag,'/') . '(.*?)\]/',$body))
705 if(preg_match('/\[(.*?)\]\((.*?)' . preg_quote($tag,'/') . '(.*?)\)/',$body))
708 $basetag = str_replace('_',' ',substr($tag,1));
709 $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body);
710 if(strlen($str_tags))
712 $str_tags .= '#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
718 $cnt = preg_match_all('/@\[url=(.*?)\[\/url\]/ism',$body,$matches,PREG_SET_ORDER);
720 foreach($matches as $mtch) {
721 if(strlen($str_tags))
723 $str_tags .= '@[url=' . $mtch[1] . '[/url]';
727 $datarray['uid'] = $importer['uid'];
728 $datarray['contact-id'] = $contact['id'];
729 $datarray['wall'] = 0;
730 $datarray['guid'] = $guid;
731 $datarray['uri'] = $datarray['parent-uri'] = $message_id;
732 $datarray['created'] = $datarray['edited'] = datetime_convert('UTC','UTC',$created);
733 $datarray['private'] = $private;
734 $datarray['parent'] = 0;
735 $datarray['owner-name'] = $contact['name'];
736 $datarray['owner-link'] = $contact['url'];
737 $datarray['owner-avatar'] = $contact['thumb'];
738 $datarray['author-name'] = $contact['name'];
739 $datarray['author-link'] = $contact['url'];
740 $datarray['author-avatar'] = $contact['thumb'];
741 $datarray['body'] = $body;
742 $datarray['tag'] = $str_tags;
743 $datarray['app'] = 'Diaspora';
745 // if empty content it might be a photo that hasn't arrived yet. If a photo arrives, we'll make it visible.
747 $datarray['visible'] = ((strlen($body)) ? 1 : 0);
749 $message_id = item_store($datarray);
752 q("update item set plink = '%s' where id = %d limit 1",
753 dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id),
762 function diaspora_reshare($importer,$xml) {
764 logger('diaspora_reshare: init: ' . print_r($xml,true));
767 $guid = notags(unxmlify($xml->guid));
768 $diaspora_handle = notags(unxmlify($xml->diaspora_handle));
771 $contact = diaspora_get_contact_by_handle($importer['uid'],$diaspora_handle);
775 if(! diaspora_post_allow($importer,$contact)) {
776 logger('diaspora_reshare: Ignoring this author: ' . $diaspora_handle . ' ' . print_r($xml,true));
780 $message_id = $diaspora_handle . ':' . $guid;
781 $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `guid` = '%s' LIMIT 1",
782 intval($importer['uid']),
787 logger('diaspora_reshare: message exists: ' . $guid);
791 $orig_author = notags(unxmlify($xml->root_diaspora_id));
792 $orig_guid = notags(unxmlify($xml->root_guid));
794 $source_url = 'https://' . substr($orig_author,strpos($orig_author,'@')+1) . '/p/' . $orig_guid . '.xml';
795 $x = fetch_url($source_url);
797 $x = fetch_url(str_replace('https://','http://',$source_url));
799 logger('diaspora_reshare: unable to fetch source url ' . $source_url);
802 logger('diaspora_reshare: source: ' . $x);
804 $x = str_replace(array('<activity_streams-photo>','</activity_streams-photo>'),array('<asphoto>','</asphoto>'),$x);
805 $source_xml = parse_xml_string($x,false);
807 if(strlen($source_xml->post->asphoto->objectId) && ($source_xml->post->asphoto->objectId != 0) && ($source_xml->post->asphoto->image_url)) {
808 $body = '[url=' . notags(unxmlify($source_xml->post->asphoto->image_url)) . '][img]' . notags(unxmlify($source_xml->post->asphoto->objectId)) . '[/img][/url]' . "\n";
809 $body = scale_external_images($body,false);
811 elseif($source_xml->post->asphoto->image_url) {
812 $body = '[img]' . notags(unxmlify($source_xml->post->asphoto->image_url)) . '[/img]' . "\n";
813 $body = scale_external_images($body);
815 elseif($source_xml->post->status_message) {
816 $body = diaspora2bb($source_xml->post->status_message->raw_message);
817 $body = scale_external_images($body);
821 logger('diaspora_reshare: no reshare content found: ' . print_r($source_xml,true));
825 logger('diaspora_reshare: empty body: source= ' . $x);
829 $person = find_diaspora_person_by_handle($orig_author);
831 if(is_array($person) && x($person,'name') && x($person,'url'))
832 $details = '[url=' . $person['url'] . ']' . $person['name'] . '[/url]';
834 $details = $orig_author;
836 $prefix = '♲ ' . $details . "\n";
839 // allocate a guid on our system - we aren't fixing any collisions.
840 // we're ignoring them
842 $g = q("select * from guid where guid = '%s' limit 1",
846 q("insert into guid ( guid ) values ( '%s' )",
851 $created = unxmlify($xml->created_at);
852 $private = ((unxmlify($xml->public) == 'false') ? 1 : 0);
858 $tags = get_tags($body);
861 foreach($tags as $tag) {
862 if(strpos($tag,'#') === 0) {
863 if(strpos($tag,'[url='))
866 // don't link tags that are already embedded in links
868 if(preg_match('/\[(.*?)' . preg_quote($tag,'/') . '(.*?)\]/',$body))
870 if(preg_match('/\[(.*?)\]\((.*?)' . preg_quote($tag,'/') . '(.*?)\)/',$body))
874 $basetag = str_replace('_',' ',substr($tag,1));
875 $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body);
876 if(strlen($str_tags))
878 $str_tags .= '#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
884 $datarray['uid'] = $importer['uid'];
885 $datarray['contact-id'] = $contact['id'];
886 $datarray['wall'] = 0;
887 $datarray['guid'] = $guid;
888 $datarray['uri'] = $datarray['parent-uri'] = $message_id;
889 $datarray['created'] = $datarray['edited'] = datetime_convert('UTC','UTC',$created);
890 $datarray['private'] = $private;
891 $datarray['parent'] = 0;
892 $datarray['owner-name'] = $contact['name'];
893 $datarray['owner-link'] = $contact['url'];
894 $datarray['owner-avatar'] = $contact['thumb'];
895 $datarray['author-name'] = $contact['name'];
896 $datarray['author-link'] = $contact['url'];
897 $datarray['author-avatar'] = $contact['thumb'];
898 $datarray['body'] = $prefix . $body;
899 $datarray['tag'] = $str_tags;
900 $datarray['app'] = 'Diaspora';
902 $message_id = item_store($datarray);
905 q("update item set plink = '%s' where id = %d limit 1",
906 dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id),
916 function diaspora_asphoto($importer,$xml) {
917 logger('diaspora_asphoto called');
920 $guid = notags(unxmlify($xml->guid));
921 $diaspora_handle = notags(unxmlify($xml->diaspora_handle));
923 $contact = diaspora_get_contact_by_handle($importer['uid'],$diaspora_handle);
927 if(! diaspora_post_allow($importer,$contact)) {
928 logger('diaspora_asphoto: Ignoring this author.');
932 $message_id = $diaspora_handle . ':' . $guid;
933 $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `guid` = '%s' LIMIT 1",
934 intval($importer['uid']),
939 logger('diaspora_asphoto: message exists: ' . $guid);
943 // allocate a guid on our system - we aren't fixing any collisions.
944 // we're ignoring them
946 $g = q("select * from guid where guid = '%s' limit 1",
950 q("insert into guid ( guid ) values ( '%s' )",
955 $created = unxmlify($xml->created_at);
956 $private = ((unxmlify($xml->public) == 'false') ? 1 : 0);
958 if(strlen($xml->objectId) && ($xml->objectId != 0) && ($xml->image_url)) {
959 $body = '[url=' . notags(unxmlify($xml->image_url)) . '][img]' . notags(unxmlify($xml->objectId)) . '[/img][/url]' . "\n";
960 $body = scale_external_images($body,false);
962 elseif($xml->image_url) {
963 $body = '[img]' . notags(unxmlify($xml->image_url)) . '[/img]' . "\n";
964 $body = scale_external_images($body);
967 logger('diaspora_asphoto: no photo url found.');
974 $datarray['uid'] = $importer['uid'];
975 $datarray['contact-id'] = $contact['id'];
976 $datarray['wall'] = 0;
977 $datarray['guid'] = $guid;
978 $datarray['uri'] = $datarray['parent-uri'] = $message_id;
979 $datarray['created'] = $datarray['edited'] = datetime_convert('UTC','UTC',$created);
980 $datarray['private'] = $private;
981 $datarray['parent'] = 0;
982 $datarray['owner-name'] = $contact['name'];
983 $datarray['owner-link'] = $contact['url'];
984 $datarray['owner-avatar'] = $contact['thumb'];
985 $datarray['author-name'] = $contact['name'];
986 $datarray['author-link'] = $contact['url'];
987 $datarray['author-avatar'] = $contact['thumb'];
988 $datarray['body'] = $body;
990 $datarray['app'] = 'Diaspora/Cubbi.es';
992 $message_id = item_store($datarray);
995 q("update item set plink = '%s' where id = %d limit 1",
996 dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id),
1010 function diaspora_comment($importer,$xml,$msg) {
1013 $guid = notags(unxmlify($xml->guid));
1014 $parent_guid = notags(unxmlify($xml->parent_guid));
1015 $diaspora_handle = notags(unxmlify($xml->diaspora_handle));
1016 $target_type = notags(unxmlify($xml->target_type));
1017 $text = unxmlify($xml->text);
1018 $author_signature = notags(unxmlify($xml->author_signature));
1020 $parent_author_signature = (($xml->parent_author_signature) ? notags(unxmlify($xml->parent_author_signature)) : '');
1022 $contact = diaspora_get_contact_by_handle($importer['uid'],$msg['author']);
1024 logger('diaspora_comment: cannot find contact: ' . $msg['author']);
1028 if(! diaspora_post_allow($importer,$contact)) {
1029 logger('diaspora_comment: Ignoring this author.');
1033 $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
1034 intval($importer['uid']),
1038 logger('diaspora_comment: our comment just got relayed back to us (or there was a guid collision) : ' . $guid);
1042 $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
1043 intval($importer['uid']),
1047 logger('diaspora_comment: parent item not found: parent: ' . $parent_guid . ' item: ' . $guid);
1050 $parent_item = $r[0];
1052 $author_signed_data = $guid . ';' . $parent_guid . ';' . $text . ';' . $diaspora_handle;
1054 $author_signature = base64_decode($author_signature);
1056 if(strcasecmp($diaspora_handle,$msg['author']) == 0) {
1061 $person = find_diaspora_person_by_handle($diaspora_handle);
1063 if(is_array($person) && x($person,'pubkey'))
1064 $key = $person['pubkey'];
1066 logger('diaspora_comment: unable to find author details');
1071 if(! rsa_verify($author_signed_data,$author_signature,$key,'sha256')) {
1072 logger('diaspora_comment: verification failed.');
1076 if($parent_author_signature) {
1077 $owner_signed_data = $guid . ';' . $parent_guid . ';' . $text . ';' . $diaspora_handle;
1079 $parent_author_signature = base64_decode($parent_author_signature);
1083 if(! rsa_verify($owner_signed_data,$parent_author_signature,$key,'sha256')) {
1084 logger('diaspora_comment: owner verification failed.');
1089 // Phew! Everything checks out. Now create an item.
1091 $body = diaspora2bb($text);
1093 $message_id = $diaspora_handle . ':' . $guid;
1095 $datarray = array();
1099 $tags = get_tags($body);
1102 foreach($tags as $tag) {
1103 if(strpos($tag,'#') === 0) {
1104 if(strpos($tag,'[url='))
1107 // don't link tags that are already embedded in links
1109 if(preg_match('/\[(.*?)' . preg_quote($tag,'/') . '(.*?)\]/',$body))
1111 if(preg_match('/\[(.*?)\]\((.*?)' . preg_quote($tag,'/') . '(.*?)\)/',$body))
1115 $basetag = str_replace('_',' ',substr($tag,1));
1116 $body = str_replace($tag,'#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]',$body);
1117 if(strlen($str_tags))
1119 $str_tags .= '#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
1125 $datarray['uid'] = $importer['uid'];
1126 $datarray['contact-id'] = $contact['id'];
1127 $datarray['wall'] = $parent_item['wall'];
1128 $datarray['gravity'] = GRAVITY_COMMENT;
1129 $datarray['guid'] = $guid;
1130 $datarray['uri'] = $message_id;
1131 $datarray['parent-uri'] = $parent_item['uri'];
1133 // No timestamps for comments? OK, we'll the use current time.
1134 $datarray['created'] = $datarray['edited'] = datetime_convert();
1135 $datarray['private'] = $parent_item['private'];
1137 $datarray['owner-name'] = $parent_item['owner-name'];
1138 $datarray['owner-link'] = $parent_item['owner-link'];
1139 $datarray['owner-avatar'] = $parent_item['owner-avatar'];
1141 $datarray['author-name'] = $person['name'];
1142 $datarray['author-link'] = $person['url'];
1143 $datarray['author-avatar'] = ((x($person,'thumb')) ? $person['thumb'] : $person['photo']);
1144 $datarray['body'] = $body;
1145 $datarray['tag'] = $str_tags;
1147 // We can't be certain what the original app is if the message is relayed.
1148 if(($parent_item['origin']) && (! $parent_author_signature))
1149 $datarray['app'] = 'Diaspora';
1151 $message_id = item_store($datarray);
1154 q("update item set plink = '%s' where id = %d limit 1",
1155 dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id),
1160 if(($parent_item['origin']) && (! $parent_author_signature)) {
1161 q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
1162 intval($message_id),
1163 dbesc($author_signed_data),
1164 dbesc(base64_encode($author_signature)),
1165 dbesc($diaspora_handle)
1168 // if the message isn't already being relayed, notify others
1169 // the existence of parent_author_signature means the parent_author or owner
1170 // is already relaying.
1172 proc_run('php','include/notifier.php','comment',$message_id);
1175 $myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 ",
1176 dbesc($parent_item['uri']),
1177 intval($importer['uid'])
1180 if(count($myconv)) {
1181 $importer_url = $a->get_baseurl() . '/profile/' . $importer['nickname'];
1183 foreach($myconv as $conv) {
1185 // now if we find a match, it means we're in this conversation
1187 if(! link_compare($conv['author-link'],$importer_url))
1190 require_once('include/enotify.php');
1192 $conv_parent = $conv['parent'];
1195 'type' => NOTIFY_COMMENT,
1196 'notify_flags' => $importer['notify-flags'],
1197 'language' => $importer['language'],
1198 'to_name' => $importer['username'],
1199 'to_email' => $importer['email'],
1200 'uid' => $importer['uid'],
1201 'item' => $datarray,
1202 'link' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id,
1203 'source_name' => $datarray['author-name'],
1204 'source_link' => $datarray['author-link'],
1205 'source_photo' => $datarray['author-avatar'],
1206 'verb' => ACTIVITY_POST,
1208 'parent' => $conv_parent,
1212 // only send one notification
1222 function diaspora_conversation($importer,$xml,$msg) {
1226 $guid = notags(unxmlify($xml->guid));
1227 $subject = notags(unxmlify($xml->subject));
1228 $diaspora_handle = notags(unxmlify($xml->diaspora_handle));
1229 $participant_handles = notags(unxmlify($xml->participant_handles));
1230 $created_at = datetime_convert('UTC','UTC',notags(unxmlify($xml->created_at)));
1232 $parent_uri = $diaspora_handle . ':' . $guid;
1234 $messages = $xml->message;
1236 if(! count($messages)) {
1237 logger('diaspora_conversation: empty conversation');
1241 $contact = diaspora_get_contact_by_handle($importer['uid'],$msg['author']);
1243 logger('diaspora_conversation: cannot find contact: ' . $msg['author']);
1247 if(($contact['rel'] == CONTACT_IS_FOLLOWER) || ($contact['blocked']) || ($contact['readonly'])) {
1248 logger('diaspora_conversation: Ignoring this author.');
1252 $conversation = null;
1254 $c = q("select * from conv where uid = %d and guid = '%s' limit 1",
1255 intval($importer['uid']),
1259 $conversation = $c[0];
1261 $r = q("insert into conv (uid,guid,creator,created,updated,subject,recips) values(%d, '%s', '%s', '%s', '%s', '%s', '%s') ",
1262 intval($importer['uid']),
1264 dbesc($diaspora_handle),
1265 dbesc(datetime_convert('UTC','UTC',$created_at)),
1266 dbesc(datetime_convert()),
1268 dbesc($participant_handles)
1271 $c = q("select * from conv where uid = %d and guid = '%s' limit 1",
1272 intval($importer['uid']),
1276 $conversation = $c[0];
1278 if(! $conversation) {
1279 logger('diaspora_conversation: unable to create conversation.');
1283 foreach($messages as $mesg) {
1287 $msg_guid = notags(unxmlify($mesg->guid));
1288 $msg_parent_guid = notags(unxmlify($mesg->parent_guid));
1289 $msg_parent_author_signature = notags(unxmlify($mesg->parent_author_signature));
1290 $msg_author_signature = notags(unxmlify($mesg->author_signature));
1291 $msg_text = unxmlify($mesg->text);
1292 $msg_created_at = datetime_convert('UTC','UTC',notags(unxmlify($mesg->created_at)));
1293 $msg_diaspora_handle = notags(unxmlify($mesg->diaspora_handle));
1294 $msg_conversation_guid = notags(unxmlify($mesg->conversation_guid));
1295 if($msg_conversation_guid != $guid) {
1296 logger('diaspora_conversation: message conversation guid does not belong to the current conversation. ' . $xml);
1300 $body = diaspora2bb($msg_text);
1301 $message_id = $msg_diaspora_handle . ':' . $msg_guid;
1303 $author_signed_data = $msg_guid . ';' . $msg_parent_guid . ';' . $msg_text . ';' . unxmlify($mesg->created_at) . ';' . $msg_diaspora_handle . ';' . $msg_conversation_guid;
1305 $author_signature = base64_decode($msg_author_signature);
1307 if(strcasecmp($msg_diaspora_handle,$msg['author']) == 0) {
1312 $person = find_diaspora_person_by_handle($msg_diaspora_handle);
1314 if(is_array($person) && x($person,'pubkey'))
1315 $key = $person['pubkey'];
1317 logger('diaspora_conversation: unable to find author details');
1322 if(! rsa_verify($author_signed_data,$author_signature,$key,'sha256')) {
1323 logger('diaspora_conversation: verification failed.');
1327 if($msg_parent_author_signature) {
1328 $owner_signed_data = $msg_guid . ';' . $msg_parent_guid . ';' . $msg_text . ';' . unxmlify($mesg->created_at) . ';' . $msg_diaspora_handle . ';' . $msg_conversation_guid;
1330 $parent_author_signature = base64_decode($msg_parent_author_signature);
1334 if(! rsa_verify($owner_signed_data,$parent_author_signature,$key,'sha256')) {
1335 logger('diaspora_conversation: owner verification failed.');
1340 $r = q("select id from mail where `uri` = '%s' limit 1",
1344 logger('diaspora_conversation: duplicate message already delivered.', LOGGER_DEBUG);
1348 q("insert into mail ( `uid`, `guid`, `convid`, `from-name`,`from-photo`,`from-url`,`contact-id`,`title`,`body`,`seen`,`reply`,`uri`,`parent-uri`,`created`) values ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, '%s','%s','%s')",
1349 intval($importer['uid']),
1351 intval($conversation['id']),
1352 dbesc($person['name']),
1353 dbesc($person['photo']),
1354 dbesc($person['url']),
1355 intval($contact['id']),
1362 dbesc($msg_created_at)
1365 q("update conv set updated = '%s' where id = %d limit 1",
1366 dbesc(datetime_convert()),
1367 intval($conversation['id'])
1370 require_once('include/enotify.php');
1372 'type' => NOTIFY_MAIL,
1373 'notify_flags' => $importer['notify-flags'],
1374 'language' => $importer['language'],
1375 'to_name' => $importer['username'],
1376 'to_email' => $importer['email'],
1377 'uid' =>$importer['importer_uid'],
1378 'item' => array('subject' => $subject, 'body' => $body),
1379 'source_name' => $person['name'],
1380 'source_link' => $person['url'],
1381 'source_photo' => $person['thumb'],
1382 'verb' => ACTIVITY_POST,
1390 function diaspora_message($importer,$xml,$msg) {
1394 $msg_guid = notags(unxmlify($xml->guid));
1395 $msg_parent_guid = notags(unxmlify($xml->parent_guid));
1396 $msg_parent_author_signature = notags(unxmlify($xml->parent_author_signature));
1397 $msg_author_signature = notags(unxmlify($xml->author_signature));
1398 $msg_text = unxmlify($xml->text);
1399 $msg_created_at = datetime_convert('UTC','UTC',notags(unxmlify($xml->created_at)));
1400 $msg_diaspora_handle = notags(unxmlify($xml->diaspora_handle));
1401 $msg_conversation_guid = notags(unxmlify($xml->conversation_guid));
1403 $parent_uri = $diaspora_handle . ':' . $msg_parent_guid;
1405 $contact = diaspora_get_contact_by_handle($importer['uid'],$msg_diaspora_handle);
1407 logger('diaspora_message: cannot find contact: ' . $msg_diaspora_handle);
1411 if(($contact['rel'] == CONTACT_IS_FOLLOWER) || ($contact['blocked']) || ($contact['readonly'])) {
1412 logger('diaspora_message: Ignoring this author.');
1416 $conversation = null;
1418 $c = q("select * from conv where uid = %d and guid = '%s' limit 1",
1419 intval($importer['uid']),
1420 dbesc($msg_conversation_guid)
1423 $conversation = $c[0];
1425 logger('diaspora_message: conversation not available.');
1431 $body = diaspora2bb($msg_text);
1432 $message_id = $msg_diaspora_handle . ':' . $msg_guid;
1434 $author_signed_data = $msg_guid . ';' . $msg_parent_guid . ';' . $msg_text . ';' . unxmlify($xml->created_at) . ';' . $msg_diaspora_handle . ';' . $msg_conversation_guid;
1437 $author_signature = base64_decode($msg_author_signature);
1439 $person = find_diaspora_person_by_handle($msg_diaspora_handle);
1440 if(is_array($person) && x($person,'pubkey'))
1441 $key = $person['pubkey'];
1443 logger('diaspora_message: unable to find author details');
1447 if(! rsa_verify($author_signed_data,$author_signature,$key,'sha256')) {
1448 logger('diaspora_message: verification failed.');
1452 $r = q("select id from mail where `uri` = '%s' and uid = %d limit 1",
1454 intval($importer['uid'])
1457 logger('diaspora_message: duplicate message already delivered.', LOGGER_DEBUG);
1461 q("insert into mail ( `uid`, `guid`, `convid`, `from-name`,`from-photo`,`from-url`,`contact-id`,`title`,`body`,`seen`,`reply`,`uri`,`parent-uri`,`created`) values ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, '%s','%s','%s')",
1462 intval($importer['uid']),
1464 intval($conversation['id']),
1465 dbesc($person['name']),
1466 dbesc($person['photo']),
1467 dbesc($person['url']),
1468 intval($contact['id']),
1469 dbesc($conversation['subject']),
1475 dbesc($msg_created_at)
1478 q("update conv set updated = '%s' where id = %d limit 1",
1479 dbesc(datetime_convert()),
1480 intval($conversation['id'])
1487 function diaspora_photo($importer,$xml,$msg) {
1491 logger('diaspora_photo: init',LOGGER_DEBUG);
1493 $remote_photo_path = notags(unxmlify($xml->remote_photo_path));
1495 $remote_photo_name = notags(unxmlify($xml->remote_photo_name));
1497 $status_message_guid = notags(unxmlify($xml->status_message_guid));
1499 $guid = notags(unxmlify($xml->guid));
1501 $diaspora_handle = notags(unxmlify($xml->diaspora_handle));
1503 $public = notags(unxmlify($xml->public));
1505 $created_at = notags(unxmlify($xml_created_at));
1507 logger('diaspora_photo: status_message_guid: ' . $status_message_guid, LOGGER_DEBUG);
1509 $contact = diaspora_get_contact_by_handle($importer['uid'],$msg['author']);
1511 logger('diaspora_photo: contact record not found: ' . $msg['author'] . ' handle: ' . $diaspora_handle);
1515 if(! diaspora_post_allow($importer,$contact)) {
1516 logger('diaspora_photo: Ignoring this author.');
1520 $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
1521 intval($importer['uid']),
1522 dbesc($status_message_guid)
1525 logger('diaspora_photo: parent item not found: parent: ' . $parent_guid . ' item: ' . $guid);
1529 $parent_item = $r[0];
1531 $link_text = '[img]' . $remote_photo_path . $remote_photo_name . '[/img]' . "\n";
1533 $link_text = scale_external_images($link_text);
1535 if(strpos($parent_item['body'],$link_text) === false) {
1536 $r = q("update item set `body` = '%s', `visible` = 1 where `id` = %d and `uid` = %d limit 1",
1537 dbesc($link_text . $parent_item['body']),
1538 intval($parent_item['id']),
1539 intval($parent_item['uid'])
1549 function diaspora_like($importer,$xml,$msg) {
1552 $guid = notags(unxmlify($xml->guid));
1553 $parent_guid = notags(unxmlify($xml->parent_guid));
1554 $diaspora_handle = notags(unxmlify($xml->diaspora_handle));
1555 $target_type = notags(unxmlify($xml->target_type));
1556 $positive = notags(unxmlify($xml->positive));
1557 $author_signature = notags(unxmlify($xml->author_signature));
1559 $parent_author_signature = (($xml->parent_author_signature) ? notags(unxmlify($xml->parent_author_signature)) : '');
1561 // likes on comments not supported here and likes on photos not supported by Diaspora
1563 if($target_type !== 'Post')
1566 $contact = diaspora_get_contact_by_handle($importer['uid'],$msg['author']);
1568 logger('diaspora_like: cannot find contact: ' . $msg['author']);
1572 if(! diaspora_post_allow($importer,$contact)) {
1573 logger('diaspora_like: Ignoring this author.');
1577 $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
1578 intval($importer['uid']),
1582 logger('diaspora_like: parent item not found: ' . $guid);
1586 $parent_item = $r[0];
1588 $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
1589 intval($importer['uid']),
1593 if($positive === 'true') {
1594 logger('diaspora_like: duplicate like: ' . $guid);
1597 if($positive === 'false') {
1598 q("UPDATE `item` SET `deleted` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1",
1599 intval($r[0]['id']),
1600 intval($importer['uid'])
1603 // send notification via proc_run()
1607 if($positive === 'false') {
1608 logger('diaspora_like: unlike received with no corresponding like');
1612 $author_signed_data = $guid . ';' . $target_type . ';' . $parent_guid . ';' . $positive . ';' . $diaspora_handle;
1614 $author_signature = base64_decode($author_signature);
1616 if(strcasecmp($diaspora_handle,$msg['author']) == 0) {
1621 $person = find_diaspora_person_by_handle($diaspora_handle);
1622 if(is_array($person) && x($person,'pubkey'))
1623 $key = $person['pubkey'];
1625 logger('diaspora_like: unable to find author details');
1630 if(! rsa_verify($author_signed_data,$author_signature,$key,'sha256')) {
1631 logger('diaspora_like: verification failed.');
1635 if($parent_author_signature) {
1637 $owner_signed_data = $guid . ';' . $target_type . ';' . $parent_guid . ';' . $positive . ';' . $diaspora_handle;
1639 $parent_author_signature = base64_decode($parent_author_signature);
1643 if(! rsa_verify($owner_signed_data,$parent_author_signature,$key,'sha256')) {
1644 logger('diaspora_like: owner verification failed.');
1649 // Phew! Everything checks out. Now create an item.
1651 $uri = $diaspora_handle . ':' . $guid;
1653 $activity = ACTIVITY_LIKE;
1654 $post_type = (($parent_item['resource-id']) ? t('photo') : t('status'));
1655 $objtype = (($parent_item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE );
1656 $link = xmlify('<link rel="alternate" type="text/html" href="' . $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $parent_item['id'] . '" />' . "\n") ;
1657 $body = $parent_item['body'];
1662 <type>$objtype</type>
1664 <id>{$parent_item['uri']}</id>
1667 <content>$body</content>
1670 $bodyverb = t('%1$s likes %2$s\'s %3$s');
1675 $arr['uid'] = $importer['uid'];
1676 $arr['guid'] = $guid;
1677 $arr['contact-id'] = $contact['id'];
1678 $arr['type'] = 'activity';
1679 $arr['wall'] = $parent_item['wall'];
1680 $arr['gravity'] = GRAVITY_LIKE;
1681 $arr['parent'] = $parent_item['id'];
1682 $arr['parent-uri'] = $parent_item['uri'];
1684 $arr['owner-name'] = $parent_item['name'];
1685 $arr['owner-link'] = $parent_item['url'];
1686 $arr['owner-avatar'] = $parent_item['thumb'];
1688 $arr['author-name'] = $person['name'];
1689 $arr['author-link'] = $person['url'];
1690 $arr['author-avatar'] = ((x($person,'thumb')) ? $person['thumb'] : $person['photo']);
1692 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
1693 $alink = '[url=' . $parent_item['author-link'] . ']' . $parent_item['author-name'] . '[/url]';
1694 $plink = '[url=' . $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $parent_item['id'] . ']' . $post_type . '[/url]';
1695 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink );
1697 $arr['app'] = 'Diaspora';
1699 $arr['private'] = $parent_item['private'];
1700 $arr['verb'] = $activity;
1701 $arr['object-type'] = $objtype;
1702 $arr['object'] = $obj;
1703 $arr['visible'] = 1;
1705 $arr['last-child'] = 0;
1707 $message_id = item_store($arr);
1711 q("update item set plink = '%s' where id = %d limit 1",
1712 dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id),
1717 if(! $parent_author_signature) {
1718 q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
1719 intval($message_id),
1720 dbesc($author_signed_data),
1721 dbesc(base64_encode($author_signature)),
1722 dbesc($diaspora_handle)
1726 // if the message isn't already being relayed, notify others
1727 // the existence of parent_author_signature means the parent_author or owner
1728 // is already relaying. The parent_item['origin'] indicates the message was created on our system
1730 if(($parent_item['origin']) && (! $parent_author_signature))
1731 proc_run('php','include/notifier.php','comment',$message_id);
1736 function diaspora_retraction($importer,$xml) {
1739 $guid = notags(unxmlify($xml->guid));
1740 $diaspora_handle = notags(unxmlify($xml->diaspora_handle));
1741 $type = notags(unxmlify($xml->type));
1743 $contact = diaspora_get_contact_by_handle($importer['uid'],$diaspora_handle);
1747 if($type === 'Person') {
1748 require_once('include/Contact.php');
1749 contact_remove($contact['id']);
1751 elseif($type === 'Post') {
1752 $r = q("select * from item where guid = '%s' and uid = %d and not file like '%%[%%' limit 1",
1754 intval($importer['uid'])
1757 if(link_compare($r[0]['author-link'],$contact['url'])) {
1758 q("update item set `deleted` = 1, `changed` = '%s' where `id` = %d limit 1",
1759 dbesc(datetime_convert()),
1770 function diaspora_signed_retraction($importer,$xml,$msg) {
1773 $guid = notags(unxmlify($xml->target_guid));
1774 $diaspora_handle = notags(unxmlify($xml->sender_handle));
1775 $type = notags(unxmlify($xml->target_type));
1776 $sig = notags(unxmlify($xml->target_author_signature));
1778 $contact = diaspora_get_contact_by_handle($importer['uid'],$diaspora_handle);
1780 logger('diaspora_signed_retraction: no contact');
1784 // this may not yet work for comments. Need to see how the relaying works
1785 // and figure out who signs it.
1788 $signed_data = $guid . ';' . $type ;
1790 $sig = base64_decode($sig);
1794 if(! rsa_verify($signed_data,$sig,$key,'sha256')) {
1795 logger('diaspora_signed_retraction: owner verification failed.' . print_r($msg,true));
1799 if($type === 'StatusMessage') {
1800 $r = q("select * from item where guid = '%s' and uid = %d and not file like '%%[%%' limit 1",
1802 intval($importer['uid'])
1805 if(link_compare($r[0]['author-link'],$contact['url'])) {
1806 q("update item set `deleted` = 1, `changed` = '%s' where `id` = %d limit 1",
1807 dbesc(datetime_convert()),
1814 logger('diaspora_signed_retraction: unknown type: ' . $type);
1820 function diaspora_profile($importer,$xml) {
1823 $diaspora_handle = notags(unxmlify($xml->diaspora_handle));
1825 $contact = diaspora_get_contact_by_handle($importer['uid'],$diaspora_handle);
1829 if($contact['blocked']) {
1830 logger('diaspora_post: Ignoring this author.');
1834 $name = unxmlify($xml->first_name) . ((strlen($xml->last_name)) ? ' ' . unxmlify($xml->last_name) : '');
1835 $image_url = unxmlify($xml->image_url);
1836 $birthday = unxmlify($xml->birthday);
1838 $r = q("SELECT DISTINCT ( `resource-id` ) FROM `photo` WHERE `uid` = %d AND `contact-id` = %d AND `album` = 'Contact Photos' ",
1839 intval($importer['uid']),
1840 intval($contact['id'])
1842 $oldphotos = ((count($r)) ? $r : null);
1844 require_once('include/Photo.php');
1846 $images = import_profile_photo($image_url,$importer['uid'],$contact['id']);
1848 // Generic birthday. We don't know the timezone. The year is irrelevant.
1850 $birthday = str_replace('1000','1901',$birthday);
1852 $birthday = datetime_convert('UTC','UTC',$birthday,'Y-m-d');
1854 // this is to prevent multiple birthday notifications in a single year
1855 // if we already have a stored birthday and the 'm-d' part hasn't changed, preserve the entry, which will preserve the notify year
1857 if(substr($birthday,5) === substr($contact['bd'],5))
1858 $birthday = $contact['bd'];
1860 // TODO: update name on item['author-name'] if the name changed. See consume_feed()
1861 // Not doing this currently because D* protocol is scheduled for revision soon.
1863 $r = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
1865 dbesc(datetime_convert()),
1869 dbesc(datetime_convert()),
1871 intval($contact['id']),
1872 intval($importer['uid'])
1877 foreach($oldphotos as $ph) {
1878 q("DELETE FROM `photo` WHERE `uid` = %d AND `contact-id` = %d AND `album` = 'Contact Photos' AND `resource-id` = '%s' ",
1879 intval($importer['uid']),
1880 intval($contact['id']),
1881 dbesc($ph['resource-id'])
1891 function diaspora_share($me,$contact) {
1893 $myaddr = $me['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
1894 $theiraddr = $contact['addr'];
1896 $tpl = get_markup_template('diaspora_share.tpl');
1897 $msg = replace_macros($tpl, array(
1898 '$sender' => $myaddr,
1899 '$recipient' => $theiraddr
1902 $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$me,$contact,$me['prvkey'],$contact['pubkey'])));
1904 return(diaspora_transmit($owner,$contact,$slap, false));
1907 function diaspora_unshare($me,$contact) {
1910 $myaddr = $me['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
1912 $tpl = get_markup_template('diaspora_retract.tpl');
1913 $msg = replace_macros($tpl, array(
1914 '$guid' => $me['guid'],
1915 '$type' => 'Person',
1916 '$handle' => $myaddr
1919 $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$me,$contact,$me['prvkey'],$contact['pubkey'])));
1921 return(diaspora_transmit($owner,$contact,$slap, false));
1927 function diaspora_send_status($item,$owner,$contact,$public_batch = false) {
1930 $myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
1931 $theiraddr = $contact['addr'];
1935 $title = $item['title'];
1936 $body = $item['body'];
1939 // We're trying to match Diaspora's split message/photo protocol but
1940 // all the photos are displayed on D* as links and not img's - even
1941 // though we're sending pretty much precisely what they send us when
1942 // doing the same operation.
1943 // Commented out for now, we'll use bb2diaspora to convert photos to markdown
1944 // which seems to get through intact.
1946 $cnt = preg_match_all('|\[img\](.*?)\[\/img\]|',$body,$matches,PREG_SET_ORDER);
1948 foreach($matches as $mtch) {
1950 $detail['str'] = $mtch[0];
1951 $detail['path'] = dirname($mtch[1]) . '/';
1952 $detail['file'] = basename($mtch[1]);
1953 $detail['guid'] = $item['guid'];
1954 $detail['handle'] = $myaddr;
1955 $images[] = $detail;
1956 $body = str_replace($detail['str'],$mtch[1],$body);
1960 $body = xmlify(html_entity_decode(bb2diaspora($body)));
1963 $body = xmlify('**' . html_entity_decode($title) . '**' . "\n") . $body;
1966 if($item['attach']) {
1967 $cnt = preg_match_all('/href=\"(.*?)\"(.*?)title=\"(.*?)\"/ism',$item['attach'],$matches,PREG_SET_ORDER);
1969 $body .= "\n" . t('Attachments:') . "\n";
1970 foreach($matches as $mtch) {
1971 $body .= '[' . $mtch[3] . '](' . $mtch[1] . ')' . "\n";
1977 $public = (($item['private']) ? 'false' : 'true');
1979 require_once('include/datetime.php');
1980 $created = datetime_convert('UTC','UTC',$item['created'],'Y-m-d H:i:s \U\T\C');
1982 $tpl = get_markup_template('diaspora_post.tpl');
1983 $msg = replace_macros($tpl, array(
1985 '$guid' => $item['guid'],
1986 '$handle' => xmlify($myaddr),
1987 '$public' => $public,
1988 '$created' => $created
1991 logger('diaspora_send_status: ' . $owner['username'] . ' -> ' . $contact['name'] . ' base message: ' . $msg, LOGGER_DATA);
1993 $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
1995 $return_code = diaspora_transmit($owner,$contact,$slap,$public_batch);
1997 if(count($images)) {
1998 diaspora_send_images($item,$owner,$contact,$images,$public_batch);
2001 return $return_code;
2005 function diaspora_send_images($item,$owner,$contact,$images,$public_batch = false) {
2007 if(! count($images))
2009 $mysite = substr($a->get_baseurl(),strpos($a->get_baseurl(),'://') + 3) . '/photo';
2011 $tpl = get_markup_template('diaspora_photo.tpl');
2012 foreach($images as $image) {
2013 if(! stristr($image['path'],$mysite))
2015 $resource = str_replace('.jpg','',$image['file']);
2016 $resource = substr($resource,0,strpos($resource,'-'));
2018 $r = q("select * from photo where `resource-id` = '%s' and `uid` = %d limit 1",
2020 intval($owner['uid'])
2024 $public = (($r[0]['allow_cid'] || $r[0]['allow_gid'] || $r[0]['deny_cid'] || $r[0]['deny_gid']) ? 'false' : 'true' );
2025 $msg = replace_macros($tpl,array(
2026 '$path' => xmlify($image['path']),
2027 '$filename' => xmlify($image['file']),
2028 '$msg_guid' => xmlify($image['guid']),
2029 '$guid' => xmlify($r[0]['guid']),
2030 '$handle' => xmlify($image['handle']),
2031 '$public' => xmlify($public),
2032 '$created_at' => xmlify(datetime_convert('UTC','UTC',$r[0]['created'],'Y-m-d H:i:s \U\T\C'))
2036 logger('diaspora_send_photo: base message: ' . $msg, LOGGER_DATA);
2037 $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
2039 diaspora_transmit($owner,$contact,$slap,$public_batch);
2044 function diaspora_send_followup($item,$owner,$contact,$public_batch = false) {
2047 $myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
2048 $theiraddr = $contact['addr'];
2050 $p = q("select guid from item where parent = %d limit 1",
2054 $parent_guid = $p[0]['guid'];
2058 if($item['verb'] === ACTIVITY_LIKE) {
2059 $tpl = get_markup_template('diaspora_like.tpl');
2061 $target_type = 'Post';
2062 $positive = (($item['deleted']) ? 'false' : 'true');
2065 $tpl = get_markup_template('diaspora_comment.tpl');
2069 $text = html_entity_decode(bb2diaspora($item['body']));
2074 $signed_text = $item['guid'] . ';' . $target_type . ';' . $parent_guid . ';' . $positive . ';' . $myaddr;
2076 $signed_text = $item['guid'] . ';' . $parent_guid . ';' . $text . ';' . $myaddr;
2078 $authorsig = base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256'));
2080 $msg = replace_macros($tpl,array(
2081 '$guid' => xmlify($item['guid']),
2082 '$parent_guid' => xmlify($parent_guid),
2083 '$target_type' =>xmlify($target_type),
2084 '$authorsig' => xmlify($authorsig),
2085 '$body' => xmlify($text),
2086 '$positive' => xmlify($positive),
2087 '$handle' => xmlify($myaddr)
2090 logger('diaspora_followup: base message: ' . $msg, LOGGER_DATA);
2092 $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
2094 return(diaspora_transmit($owner,$contact,$slap,$public_batch));
2098 function diaspora_send_relay($item,$owner,$contact,$public_batch = false) {
2102 $myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
2103 $theiraddr = $contact['addr'];
2106 $p = q("select guid from item where parent = %d limit 1",
2110 $parent_guid = $p[0]['guid'];
2114 if($item['verb'] === ACTIVITY_LIKE) {
2115 $tpl = get_markup_template('diaspora_like_relay.tpl');
2117 $target_type = 'Post';
2118 $positive = (($item['deleted']) ? 'false' : 'true');
2121 $tpl = get_markup_template('diaspora_comment_relay.tpl');
2125 $body = $item['body'];
2127 $text = html_entity_decode(bb2diaspora($body));
2129 // fetch the original signature if somebody sent the post to us to relay
2130 // If we are relaying for a reply originating on our own account, there wasn't a 'send to relay'
2131 // action. It wasn't needed. In that case create the original signature and the
2132 // owner (parent author) signature
2133 // comments from other networks will be relayed under our name, with a brief
2134 // preamble to describe what's happening and noting the real author
2136 $r = q("select * from sign where iid = %d limit 1",
2141 $signed_text = $orig_sign['signed_text'];
2142 $authorsig = $orig_sign['signature'];
2143 $handle = $orig_sign['signer'];
2147 $itemcontact = q("select * from contact where `id` = %d limit 1",
2148 intval($item['contact-id'])
2150 if(count($itemcontact)) {
2151 if(! $itemcontact[0]['self']) {
2152 $prefix = sprintf( t('[Relayed] Comment authored by %s from network %s'),
2153 '['. $item['author-name'] . ']' . '(' . $item['author-link'] . ')',
2154 network_to_name($itemcontact['network'])) . "\n";
2155 $body = $prefix . $body;
2161 $signed_text = $item['guid'] . ';' . $target_type . ';' . $parent_guid . ';' . $positive . ';' . $myaddr;
2163 $signed_text = $item['guid'] . ';' . $parent_guid . ';' . $text . ';' . $myaddr;
2165 $authorsig = base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256'));
2167 q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
2168 intval($item['id']),
2169 dbesc($signed_text),
2170 dbesc(base64_encode($authorsig)),
2179 $parentauthorsig = base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256'));
2181 $msg = replace_macros($tpl,array(
2182 '$guid' => xmlify($item['guid']),
2183 '$parent_guid' => xmlify($parent_guid),
2184 '$target_type' =>xmlify($target_type),
2185 '$authorsig' => xmlify($orig_sign['signature']),
2186 '$parentsig' => xmlify($parentauthorsig),
2187 '$body' => xmlify($text),
2188 '$positive' => xmlify($positive),
2189 '$handle' => xmlify($handle)
2192 logger('diaspora_relay_comment: base message: ' . $msg, LOGGER_DATA);
2194 $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
2196 return(diaspora_transmit($owner,$contact,$slap,$public_batch));
2202 function diaspora_send_retraction($item,$owner,$contact,$public_batch = false) {
2205 $myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
2207 $signed_text = $item['guid'] . ';' . 'StatusMessage';
2209 $tpl = get_markup_template('diaspora_signed_retract.tpl');
2210 $msg = replace_macros($tpl, array(
2211 '$guid' => $item['guid'],
2212 '$type' => 'StatusMessage',
2213 '$handle' => $myaddr,
2214 '$signature' => base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256'))
2217 $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
2219 return(diaspora_transmit($owner,$contact,$slap,$public_batch));
2222 function diaspora_send_mail($item,$owner,$contact) {
2225 $myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
2227 $r = q("select * from conv where id = %d and uid = %d limit 1",
2228 intval($item['convid']),
2229 intval($item['uid'])
2233 logger('diaspora_send_mail: conversation not found.');
2239 'guid' => xmlify($cnv['guid']),
2240 'subject' => xmlify($cnv['subject']),
2241 'created_at' => xmlify(datetime_convert('UTC','UTC',$cnv['created'],'Y-m-d H:i:s \U\T\C')),
2242 'diaspora_handle' => xmlify($cnv['creator']),
2243 'participant_handles' => xmlify($cnv['recips'])
2246 $body = bb2diaspora($item['body']);
2247 $created = datetime_convert('UTC','UTC',$item['created'],'Y-m-d H:i:s \U\T\C');
2249 $signed_text = $item['guid'] . ';' . $cnv['guid'] . ';' . $body . ';'
2250 . $created . ';' . $myaddr . ';' . $cnv['guid'];
2252 $sig = base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256'));
2255 'guid' => xmlify($item['guid']),
2256 'parent_guid' => xmlify($cnv['guid']),
2257 'parent_author_signature' => (($item['reply']) ? null : xmlify($sig)),
2258 'author_signature' => xmlify($sig),
2259 'text' => xmlify($body),
2260 'created_at' => xmlify($created),
2261 'diaspora_handle' => xmlify($myaddr),
2262 'conversation_guid' => xmlify($cnv['guid'])
2265 if($item['reply']) {
2266 $tpl = get_markup_template('diaspora_message.tpl');
2267 $xmsg = replace_macros($tpl, array('$msg' => $msg));
2270 $conv['messages'] = array($msg);
2271 $tpl = get_markup_template('diaspora_conversation.tpl');
2272 $xmsg = replace_macros($tpl, array('$conv' => $conv));
2275 logger('diaspora_conversation: ' . print_r($xmsg,true), LOGGER_DATA);
2277 $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($xmsg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],false)));
2279 return(diaspora_transmit($owner,$contact,$slap,false));
2284 function diaspora_transmit($owner,$contact,$slap,$public_batch) {
2286 $enabled = intval(get_config('system','diaspora_enabled'));
2292 $logid = random_string(4);
2293 $dest_url = (($public_batch) ? $contact['batch'] : $contact['notify']);
2295 logger('diaspora_transmit: no url for contact: ' . $contact['id'] . ' batch mode =' . $public_batch);
2299 logger('diaspora_transmit: ' . $logid . ' ' . $dest_url);
2301 if(! intval(get_config('system','diaspora_test')))
2302 post_url($dest_url . '/', $slap);
2304 logger('diaspora_transmit: test_mode');
2308 $return_code = $a->get_curl_code();
2309 logger('diaspora_transmit: ' . $logid . ' returns: ' . $return_code);
2311 if((! $return_code) || (($return_code == 503) && (stristr($a->get_curl_headers(),'retry-after')))) {
2312 logger('diaspora_transmit: queue message');
2314 $r = q("SELECT id from queue where cid = %d and network = '%s' and content = '%s' and batch = %d limit 1",
2315 intval($contact['id']),
2316 dbesc(NETWORK_DIASPORA),
2318 intval($public_batch)
2321 logger('diaspora_transmit: add_to_queue ignored - identical item already in queue');
2324 // queue message for redelivery
2325 add_to_queue($contact['id'],NETWORK_DIASPORA,$slap,$public_batch);
2330 return(($return_code) ? $return_code : (-1));