From 7ab335c9d620779c929d80cac3d083f183dba391 Mon Sep 17 00:00:00 2001 From: "Michael - piratica.eu" Date: Sun, 20 Jan 2013 14:08:28 +0100 Subject: [PATCH] Diaspora: Auto-adding users as friend who already sharing with us --- include/Scrape.php | 12 ++++++------ include/diaspora.php | 18 ++++++++++++++++-- include/follow.php | 6 +++--- include/network.php | 1 + include/poller.php | 12 ++++++------ view/theme/vier/profile_vcard.tpl | 2 +- 6 files changed, 33 insertions(+), 18 deletions(-) diff --git a/include/Scrape.php b/include/Scrape.php index 611cbda886..7b72a199df 100644 --- a/include/Scrape.php +++ b/include/Scrape.php @@ -346,7 +346,7 @@ function probe_url($url, $mode = PROBE_NORMAL) { $network = null; $diaspora = false; $diaspora_base = ''; - $diaspora_guid = ''; + $diaspora_guid = ''; $diaspora_key = ''; $has_lrdd = false; $email_conversant = false; @@ -485,7 +485,7 @@ function probe_url($url, $mode = PROBE_NORMAL) { } } } - } + } if($mode == PROBE_NORMAL) { if(strlen($zot)) { @@ -531,7 +531,7 @@ function probe_url($url, $mode = PROBE_NORMAL) { } if(strpos($url,'@')) $addr = str_replace('acct:', '', $url); - } + } if($network !== NETWORK_ZOT && $network !== NETWORK_DFRN && $network !== NETWORK_MAIL) { if($diaspora) @@ -544,13 +544,13 @@ function probe_url($url, $mode = PROBE_NORMAL) { $vcard = scrape_vcard($hcard); // Google doesn't use absolute url in profile photos - + if((x($vcard,'photo')) && substr($vcard['photo'],0,1) == '/') { $h = @parse_url($hcard); if($h) $vcard['photo'] = $h['scheme'] . '://' . $h['host'] . $vcard['photo']; } - + logger('probe_url: scrape_vcard: ' . print_r($vcard,true), LOGGER_DATA); } @@ -561,7 +561,7 @@ function probe_url($url, $mode = PROBE_NORMAL) { $vcard['nick'] = $addr_parts[0]; } - if($twitter) { + if($twitter) { logger('twitter: setup'); $tid = basename($url); $tapi = 'https://api.twitter.com/1/statuses/user_timeline.rss'; diff --git a/include/diaspora.php b/include/diaspora.php index 3b681e9918..8e77f03336 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -557,7 +557,7 @@ function diaspora_decode($importer,$xml) { } - + function diaspora_request($importer,$xml) { $a = get_app(); @@ -567,7 +567,7 @@ function diaspora_request($importer,$xml) { if(! $sender_handle || ! $recipient_handle) return; - + $contact = diaspora_get_contact_by_handle($importer['uid'],$sender_handle); if($contact) { @@ -752,6 +752,20 @@ function diaspora_request($importer,$xml) { } function diaspora_post_allow($importer,$contact) { + + // perhaps we were already sharing with this person. Now they're sharing with us. + // That makes us friends. + // Normally this should have handled by getting a request - but this could get lost + if($contact['rel'] == CONTACT_IS_FOLLOWER && $importer['page-flags'] != PAGE_COMMUNITY) { + q("UPDATE `contact` SET `rel` = %d, `writable` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1", + intval(CONTACT_IS_FRIEND), + intval($contact['id']), + intval($importer['uid']) + ); + $contact['rel'] = CONTACT_IS_FRIEND; + logger('diaspora_post_allow: defining user '.$contact["nick"].' as friend'); + } + if(($contact['blocked']) || ($contact['readonly']) || ($contact['archive'])) return false; if($contact['rel'] == CONTACT_IS_SHARING || $contact['rel'] == CONTACT_IS_FRIEND) diff --git a/include/follow.php b/include/follow.php index 59f3b1a5fc..fc167bb82b 100644 --- a/include/follow.php +++ b/include/follow.php @@ -48,9 +48,9 @@ function new_contact($uid,$url,$interactive = false) { $myaddr = bin2hex($a->get_baseurl() . '/profile/' . $a->user['nickname']); else $myaddr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname()); - + goaway($ret['request'] . "&addr=$myaddr"); - + // NOTREACHED } } @@ -61,7 +61,7 @@ function new_contact($uid,$url,$interactive = false) { return $result; } } - + diff --git a/include/network.php b/include/network.php index df23c2549c..1de65c42cb 100644 --- a/include/network.php +++ b/include/network.php @@ -367,6 +367,7 @@ function lrdd($uri, $debug = false) { logger('lrdd: constructed url: ' . $url); $xml = fetch_url($url); + $headers = $a->get_curl_headers(); if (! $xml) diff --git a/include/poller.php b/include/poller.php index 7df59f727a..cc5f2a9834 100644 --- a/include/poller.php +++ b/include/poller.php @@ -9,7 +9,7 @@ function poller_run(&$argv, &$argc){ if(is_null($a)) { $a = new App; } - + if(is_null($db)) { @include(".htconfig.php"); require_once("include/dba.php"); @@ -57,17 +57,17 @@ function poller_run(&$argv, &$argc){ load_hooks(); logger('poller: start'); - + // run queue delivery process in the background proc_run('php',"include/queue.php"); - + // expire any expired accounts q("UPDATE user SET `account_expired` = 1 where `account_expired` = 0 AND `account_expires_on` != '0000-00-00 00:00:00' AND `account_expires_on` < UTC_TIMESTAMP() "); - + // delete user and contact records for recently removed accounts $r = q("SELECT * FROM `user` WHERE `account_removed` = 1 AND `account_expires_on` < UTC_TIMESTAMP() - INTERVAL 3 DAY"); @@ -77,12 +77,12 @@ function poller_run(&$argv, &$argc){ q("DELETE FROM `user` WHERE `uid` = %d", intval($user['uid'])); } } - + $abandon_days = intval(get_config('system','account_abandon_days')); if($abandon_days < 1) $abandon_days = 0; - + // once daily run birthday_updates and then expire in background diff --git a/view/theme/vier/profile_vcard.tpl b/view/theme/vier/profile_vcard.tpl index 4537fd0720..aa716f100b 100644 --- a/view/theme/vier/profile_vcard.tpl +++ b/view/theme/vier/profile_vcard.tpl @@ -18,7 +18,7 @@ {{ else }} - +
{{ endif }} -- 2.39.5