diff options
author | Friendika <info@friendika.com> | 2011-08-13 06:52:33 -0700 |
---|---|---|
committer | Friendika <info@friendika.com> | 2011-08-13 06:52:33 -0700 |
commit | 88f94325a412d2ef39ac57c6419507ace6b3f8bb (patch) | |
tree | f2ad8efd3e2862e676b8f11068986eaf9f4d961c /include/diaspora.php | |
parent | e15e18e0d1499a91f6e3d20553a09af534c471f7 (diff) | |
download | volse-hubzilla-88f94325a412d2ef39ac57c6419507ace6b3f8bb.tar.gz volse-hubzilla-88f94325a412d2ef39ac57c6419507ace6b3f8bb.tar.bz2 volse-hubzilla-88f94325a412d2ef39ac57c6419507ace6b3f8bb.zip |
incoming diaspora share notification turned into Friendika friend request
Diffstat (limited to 'include/diaspora.php')
-rw-r--r-- | include/diaspora.php | 56 |
1 files changed, 47 insertions, 9 deletions
diff --git a/include/diaspora.php b/include/diaspora.php index d4e9c530c..90fa09b25 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -250,7 +250,7 @@ function diaspora_request($importer,$contact,$xml) { if(! $sender_handle || ! $recipient_handle) return; - if($contact) { + if($contact && ($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['rel'] == CONTACT_IS_FRIEND)) { q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1", intval(CONTACT_IS_FRIEND), intval($contact['id']), @@ -262,20 +262,58 @@ function diaspora_request($importer,$contact,$xml) { require_once('include/Scrape.php'); $ret = probe_url($sender_handle); - $errors = false; + if((! count($ret)) || ($ret['network'] != NETWORK_DIASPORA)) { logger('diaspora_request: Cannot resolve diaspora handle ' . $sender_handle . ' for ' . $recipient_handle); - $errors = true; - } - - - if($errors) return; + } + $r = q("INSERT INTO `contact` (`uid`, `network`,`addr`,`created`,`url`,`name`,`nick`,`photo`,`pubkey`,`notify`,`poll`,`blocked`,`priority`) + VALUES ( %d, '%s', '%s', '%s','%s','%s','%s','%s','%s','%s','%s',%d,%d) ", + intval($importer['uid']), + dbesc($ret['network']), + dbesc($ret['addr']), + datetime_convert(), + dbesc($ret['url']), + dbesc($ret['name']), + dbesc($ret['nick']), + dbesc($ret['photo']), + dbesc($ret['pubkey']), + dbesc($ret['notify']), + dbesc($ret['poll']), + 1, + 2 + ); + + // find the contact record we just created + $contact_record = null; + if($r) { + $r = q("SELECT `id` FROM `contact` + WHERE `uid` = %d AND `addr` = '%s' AND `poll` = '%s' LIMIT 1", + intval($importer['uid']), + $ret['addr'], + $ret['poll'] + ); + if(count($r)) + $contact_record = $r[0]; + } + $hash = random_string() . (string) time(); // Generate a confirm_key + + if(is_array($contact_record)) { + $ret = q("INSERT INTO `intro` ( `uid`, `contact-id`, `blocked`, `knowyou`, `note`, `hash`, `datetime`) + VALUES ( %d, %d, 1, %d, '%s', '%s', '%s' )", + intval($importer['uid']), + intval($contact_record['id']), + 0, + dbesc( t('Sharing notification from Diaspora network')), + dbesc($hash), + dbesc(datetime_convert()) + ); + } + - - + return; } |