improved diaspora discovery
This commit is contained in:
parent
fda593caed
commit
aefc6209a3
3 changed files with 70 additions and 6 deletions
|
@ -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')))
|
||||
|| (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;
|
||||
|
@ -290,6 +298,9 @@ function probe_url($url) {
|
|||
return $result;
|
||||
|
||||
$diaspora = false;
|
||||
$diaspora_base = '';
|
||||
$diaspora_guid = '';
|
||||
$diaspora_key = '';
|
||||
$email_conversant = false;
|
||||
|
||||
$twitter = ((strpos($url,'twitter.com') !== false) ? true : false);
|
||||
|
@ -320,9 +331,20 @@ 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
|
||||
// to a contact on incoming messages to prevent spam, and we won't know which one
|
||||
|
@ -419,7 +441,16 @@ 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) {
|
||||
if($diaspora)
|
||||
$network = NETWORK_DIASPORA;
|
||||
else
|
||||
$network = NETWORK_OSTATUS;
|
||||
$priority = 0;
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue