diff options
-rw-r--r-- | boot.php | 2 | ||||
-rw-r--r-- | include/Scrape.php | 41 | ||||
-rw-r--r-- | include/diaspora.php | 33 | ||||
-rw-r--r-- | mod/dfrn_confirm.php | 20 | ||||
-rw-r--r-- | mod/probe.php | 23 | ||||
-rw-r--r-- | mod/receive.php | 2 | ||||
-rw-r--r-- | mod/webfinger.php | 2 |
7 files changed, 110 insertions, 13 deletions
@@ -7,7 +7,7 @@ require_once('include/text.php'); require_once("include/pgettext.php"); -define ( 'FRIENDIKA_VERSION', '2.2.1068' ); +define ( 'FRIENDIKA_VERSION', '2.2.1069' ); define ( 'DFRN_PROTOCOL_VERSION', '2.21' ); define ( 'DB_UPDATE_VERSION', 1079 ); diff --git a/include/Scrape.php b/include/Scrape.php index ef5d7dcae..c4882243d 100644 --- a/include/Scrape.php +++ b/include/Scrape.php @@ -1,6 +1,7 @@ <?php require_once('library/HTML5/Parser.php'); +require_once('include/crypto.php'); if(! function_exists('scrape_dfrn')) { function scrape_dfrn($url) { @@ -171,6 +172,8 @@ function scrape_vcard($url) { // Pull out hCard profile elements + $largest_photo = 0; + $items = $dom->getElementsByTagName('*'); foreach($items as $item) { if(attribute_contains($item->getAttribute('class'), 'vcard')) { @@ -179,8 +182,13 @@ function scrape_vcard($url) { if(attribute_contains($x->getAttribute('class'),'fn')) $ret['fn'] = $x->textContent; if((attribute_contains($x->getAttribute('class'),'photo')) - || (attribute_contains($x->getAttribute('class'),'avatar'))) - $ret['photo'] = $x->getAttribute('src'); + || (attribute_contains($x->getAttribute('class'),'avatar'))) { + $size = intval($x->getAttribute('width')); + if(($size > $largest_photo) || (! $largest_photo)) { + $ret['photo'] = $x->getAttribute('src'); + $largest_photo = $size; + } + } if((attribute_contains($x->getAttribute('class'),'nickname')) || (attribute_contains($x->getAttribute('class'),'uid'))) $ret['nick'] = $x->textContent; @@ -289,7 +297,10 @@ function probe_url($url) { if(! $url) return $result; - $diaspora = false; + $diaspora = false; + $diaspora_base = ''; + $diaspora_guid = ''; + $diaspora_key = ''; $email_conversant = false; $twitter = ((strpos($url,'twitter.com') !== false) ? true : false); @@ -320,8 +331,19 @@ function probe_url($url) { $hcard = unamp($link['@attributes']['href']); if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') $profile = unamp($link['@attributes']['href']); - if($link['@attributes']['rel'] === 'http://joindiaspora.com/seed_location') + if($link['@attributes']['rel'] === 'http://joindiaspora.com/seed_location') { + $diaspora_base = unamp($link['@attributes']['href']); + $diaspora = true; + } + if($link['@attributes']['rel'] === 'http://joindiaspora.com/guid') { + $diaspora_guid = unamp($link['@attributes']['href']); $diaspora = true; + } + if($link['@attributes']['rel'] === 'diaspora-public-key') { + $diaspora_key = base64_decode(unamp($link['@attributes']['href'])); + $pubkey = rsatopem($diaspora_key); + $diaspora = true; + } } // Status.Net can have more than one profile URL. We need to match the profile URL @@ -419,8 +441,17 @@ function probe_url($url) { } } + if($diaspora && $diaspora_base && $diaspora_guid) { + $notify = $diaspora_base . 'receive/post/' . $diaspora_guid; + if(strpos($url,'@')) + $addr = str_replace('acct:', '', $url); + } + if($network !== NETWORK_ZOT && $network !== NETWORK_DFRN && $network !== NETWORK_MAIL) { - $network = NETWORK_OSTATUS; + if($diaspora) + $network = NETWORK_DIASPORA; + else + $network = NETWORK_OSTATUS; $priority = 0; if($hcard) { diff --git a/include/diaspora.php b/include/diaspora.php index f799b6a49..d4e9c530c 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -244,6 +244,39 @@ function diaspora_decode($importer,$xml) { function diaspora_request($importer,$contact,$xml) { + $sender_handle = $xml->sender_handle; + $recipient_handle = $xml->recipient_handle; + + if(! $sender_handle || ! $recipient_handle) + return; + + if($contact) { + q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1", + intval(CONTACT_IS_FRIEND), + intval($contact['id']), + intval($importer['uid']) + ); + // send notification + return; + } + + 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; + + + + + + } function diaspora_post($importer,$contact,$xml) { diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index 869bde3bf..bcc4e3438 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -528,12 +528,22 @@ function dfrn_confirm_post(&$a,$handsfree = null) { dbesc($decrypted_source_url), intval($local_uid) ); - if(! count($ret)) { - // this is either a bogus confirmation (?) or we deleted the original introduction. - $message = t('Contact record was not found for you on our site.'); - xml_status(3,$message); - return; // NOTREACHED + if(strstr($decrypted_source_url,'http:')) + $newurl = str_replace('http:','https:',$decrypted_source_url); + else + $newurl = str_replace('https:','http:',$decrypted_source_url); + + $ret = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1", + dbesc($newurl), + intval($local_uid) + ); + if(! count($r)) { + // this is either a bogus confirmation (?) or we deleted the original introduction. + $message = t('Contact record was not found for you on our site.'); + xml_status(3,$message); + return; // NOTREACHED + } } $relation = $ret[0]['rel']; diff --git a/mod/probe.php b/mod/probe.php new file mode 100644 index 000000000..221d18650 --- /dev/null +++ b/mod/probe.php @@ -0,0 +1,23 @@ +<?php + +require_once('include/Scrape.php'); + +function probe_content(&$a) { + + $o .= '<h3>Probe Diagnostic</h3>'; + + $o .= '<form action="probe" method="get">'; + $o .= 'Lookup address: <input type="text" style="width: 250px;" name="addr" value="' . $_GET['addr'] .'" />'; + $o .= '<input type="submit" name="submit" value="Submit" /></form>'; + + $o .= '<br /><br />'; + + if(x($_GET,'addr')) { + $addr = trim($_GET['addr']); + $res = probe_url($addr); + $o .= '<pre>'; + $o .= str_replace("\n",'<br />',print_r($res,true)); + $o .= '</pre>'; + } + return $o; +} diff --git a/mod/receive.php b/mod/receive.php index 1dfbe59bd..72d528093 100644 --- a/mod/receive.php +++ b/mod/receive.php @@ -71,7 +71,7 @@ function receive_post(&$a) { $contact = ((count($r)) ? $r[0] : null); - + logger('diaspora msg: ' . $msg, LOGGER_DATA); if($xmlbase->request) { diaspora_request($importer,$contact,$xmlbase->request); diff --git a/mod/webfinger.php b/mod/webfinger.php index f6d6026b4..74bd2c954 100644 --- a/mod/webfinger.php +++ b/mod/webfinger.php @@ -23,4 +23,4 @@ function webfinger_content(&$a) { $o .= '</pre>'; } return $o; -}
\ No newline at end of file +} |