X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fdiaspora.php;h=05d17dd9c41f8ea858566574bd6af9fb1ab205b9;hb=1f074cb44c5deda5b480f5ff814ff3640ec843d0;hp=fdf756610ea668ef53bd32d97263fdca9bc3a142;hpb=63f66a5a93661cfc327449561a2150aa8187a228;p=friendica.git diff --git a/include/diaspora.php b/include/diaspora.php old mode 100644 new mode 100755 index fdf756610e..05d17dd9c4 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -69,7 +69,7 @@ function diaspora_dispatch($importer,$msg) { $ret = diaspora_retraction($importer,$xmlbase->retraction,$msg); } elseif($xmlbase->signed_retraction) { - $ret = diaspora_signed_retraction($importer,$xmlbase->retraction,$msg); + $ret = diaspora_signed_retraction($importer,$xmlbase->signed_retraction,$msg); } elseif($xmlbase->photo) { $ret = diaspora_photo($importer,$xmlbase->photo,$msg); @@ -464,7 +464,7 @@ function diaspora_request($importer,$xml) { intval($importer['uid']) ); - if((count($r)) && ($r[0]['hide-friends'] == 0)) { + if((count($r)) && (! $r[0]['hide-friends']) && (! $contact['hidden'])) { require_once('include/items.php'); $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", @@ -527,6 +527,8 @@ function diaspora_request($importer,$xml) { $batch = (($ret['batch']) ? $ret['batch'] : implode('/', array_slice(explode('/',$ret['url']),0,3)) . '/receive/public'); + + $r = q("INSERT INTO `contact` (`uid`, `network`,`addr`,`created`,`url`,`nurl`,`batch`,`name`,`nick`,`photo`,`pubkey`,`notify`,`poll`,`blocked`,`priority`) VALUES ( %d, '%s', '%s', '%s', '%s','%s','%s','%s','%s','%s','%s','%s','%s',%d,%d) ", intval($importer['uid']), @@ -550,9 +552,15 @@ function diaspora_request($importer,$xml) { $contact_record = diaspora_get_contact_by_handle($importer['uid'],$sender_handle); - $hash = random_string() . (string) time(); // Generate a confirm_key + if(! $contact_record) { + logger('diaspora_request: unable to locate newly created contact record.'); + return; + } + + if($importer['page-flags'] == PAGE_NORMAL) { + + $hash = random_string() . (string) time(); // Generate a confirm_key - if($contact_record) { $ret = q("INSERT INTO `intro` ( `uid`, `contact-id`, `blocked`, `knowyou`, `note`, `hash`, `datetime` ) VALUES ( %d, %d, %d, %d, '%s', '%s', '%s' )", intval($importer['uid']), @@ -564,6 +572,49 @@ function diaspora_request($importer,$xml) { dbesc(datetime_convert()) ); } + else { + + // automatic friend approval + + require_once('include/Photo.php'); + + $photos = import_profile_photo($contact_record['photo'],$importer['uid'],$contact_record['id']); + + // technically they are sharing with us (CONTACT_IS_SHARING), + // but if our page-type is PAGE_COMMUNITY or PAGE_SOAPBOX + // we are going to change the relationship and make them a follower. + + if($importer['page-flags'] == PAGE_FREELOVE) + $new_relation = CONTACT_IS_FRIEND; + else + $new_relation = CONTACT_IS_FOLLOWER; + + $r = q("UPDATE `contact` SET + `photo` = '%s', + `thumb` = '%s', + `micro` = '%s', + `rel` = %d, + `name-date` = '%s', + `uri-date` = '%s', + `avatar-date` = '%s', + `blocked` = 0, + `pending` = 0, + WHERE `id` = %d LIMIT 1 + ", + dbesc($photos[0]), + dbesc($photos[1]), + dbesc($photos[2]), + intval($new_relation), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + dbesc(datetime_convert()), + intval($contact_record['id']) + ); + + $u = q("select * from user where id = %d limit 1",intval($importer['uid'])); + if($u) + $ret = diaspora_share($u[0],$contact_record); + } return; } @@ -1223,6 +1274,21 @@ function diaspora_conversation($importer,$xml,$msg) { dbesc(datetime_convert()), intval($conversation['id']) ); + + require_once('include/enotify.php'); + notification(array( + 'type' => NOTIFY_MAIL, + 'notify_flags' => $importer['notify-flags'], + 'language' => $importer['language'], + 'to_name' => $importer['username'], + 'to_email' => $importer['email'], + 'item' => array('subject' => $subject, 'body' => $body), + 'source_name' => $person['name'], + 'source_link' => $person['url'], + 'source_photo' => $person['thumb'], + 'verb' => ACTIVITY_POST, + 'otype' => 'mail' + )); } return; @@ -1328,6 +1394,9 @@ function diaspora_message($importer,$xml,$msg) { function diaspora_photo($importer,$xml,$msg) { $a = get_app(); + + logger('diaspora_photo: init',LOGGER_DEBUG); + $remote_photo_path = notags(unxmlify($xml->remote_photo_path)); $remote_photo_name = notags(unxmlify($xml->remote_photo_name)); @@ -1342,10 +1411,13 @@ function diaspora_photo($importer,$xml,$msg) { $created_at = notags(unxmlify($xml_created_at)); + logger('diaspora_photo: status_message_guid: ' . $status_message_guid, LOGGER_DEBUG); $contact = diaspora_get_contact_by_handle($importer['uid'],$msg['author']); - if(! $contact) + if(! $contact) { + logger('diaspora_photo: contact record not found: ' . $msg['author'] . ' handle: ' . $diaspora_handle); return; + } if(($contact['rel'] == CONTACT_IS_FOLLOWER) || ($contact['blocked']) || ($contact['readonly'])) { logger('diaspora_photo: Ignoring this author.'); @@ -1360,6 +1432,7 @@ function diaspora_photo($importer,$xml,$msg) { logger('diaspora_photo: parent item not found: parent: ' . $parent_guid . ' item: ' . $guid); return; } + $parent_item = $r[0]; $link_text = '[img]' . $remote_photo_path . $remote_photo_name . '[/img]' . "\n"; @@ -1569,6 +1642,7 @@ EOT; function diaspora_retraction($importer,$xml) { + $guid = notags(unxmlify($xml->guid)); $diaspora_handle = notags(unxmlify($xml->diaspora_handle)); $type = notags(unxmlify($xml->type)); @@ -1600,7 +1674,8 @@ function diaspora_retraction($importer,$xml) { // NOTREACHED } -function diaspora_signed_retraction($importer,$xml) { +function diaspora_signed_retraction($importer,$xml,$msg) { + $guid = notags(unxmlify($xml->target_guid)); $diaspora_handle = notags(unxmlify($xml->sender_handle)); @@ -1608,8 +1683,10 @@ function diaspora_signed_retraction($importer,$xml) { $sig = notags(unxmlify($xml->target_author_signature)); $contact = diaspora_get_contact_by_handle($importer['uid'],$diaspora_handle); - if(! $contact) + if(! $contact) { + logger('diaspora_signed_retraction: no contact'); return; + } // this may not yet work for comments. Need to see how the relaying works // and figure out who signs it. @@ -1628,7 +1705,7 @@ function diaspora_signed_retraction($importer,$xml) { if($type === 'StatusMessage') { $r = q("select * from item where guid = '%s' and uid = %d limit 1", - dbesc('guid'), + dbesc($guid), intval($importer['uid']) ); if(count($r)) { @@ -1640,6 +1717,8 @@ function diaspora_signed_retraction($importer,$xml) { } } } + else + logger('diaspora_signed_retraction: unknown type: ' . $type); return 202; // NOTREACHED @@ -1713,27 +1792,6 @@ function diaspora_profile($importer,$xml) { } - - - - - - - - - - - - - - - - - - - - - function diaspora_share($me,$contact) { $a = get_app(); $myaddr = $me['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);