more code refactoring to put external protocol dependencies in plugins.
This commit is contained in:
parent
7acb068590
commit
b2d2dcc7fe
@ -801,37 +801,6 @@ function import_author_xchan($x) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Imports an author from Diaspora.
|
||||
*
|
||||
* @param array $x an associative array with
|
||||
* * \e string \b address
|
||||
* @return boolean|string false on error, otherwise xchan_hash of the new entry
|
||||
*/
|
||||
function import_author_diaspora($x) {
|
||||
if(! $x['address'])
|
||||
return false;
|
||||
|
||||
$r = q("select * from xchan where xchan_addr = '%s' limit 1",
|
||||
dbesc($x['address'])
|
||||
);
|
||||
if($r) {
|
||||
logger('in_cache: ' . $x['address'], LOGGER_DATA);
|
||||
return $r[0]['xchan_hash'];
|
||||
}
|
||||
|
||||
if(discover_by_webbie($x['address'])) {
|
||||
$r = q("select xchan_hash from xchan where xchan_addr = '%s' limit 1",
|
||||
dbesc($x['address'])
|
||||
);
|
||||
if($r)
|
||||
return $r[0]['xchan_hash'];
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Imports an author from a RSS feed.
|
||||
*
|
||||
@ -889,6 +858,11 @@ function import_author_rss($x) {
|
||||
|
||||
function import_author_unknown($x) {
|
||||
|
||||
$arr = [ 'author' => $x, 'result' => false ];
|
||||
call_hooks('import_author', $arr);
|
||||
if($arr['result'])
|
||||
return $arr['result'];
|
||||
|
||||
if(! $x['url'])
|
||||
return false;
|
||||
|
||||
|
@ -1900,3 +1900,83 @@ function probe_api_path($host) {
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
function scrape_vcard($url) {
|
||||
|
||||
require_once('library/HTML5/Parser.php');
|
||||
|
||||
$ret = array();
|
||||
|
||||
logger('url=' . $url);
|
||||
|
||||
$x = z_fetch_url($url);
|
||||
if(! $x['success'])
|
||||
return $ret;
|
||||
|
||||
$s = $x['body'];
|
||||
|
||||
if(! $s)
|
||||
return $ret;
|
||||
|
||||
$headers = $x['header'];
|
||||
$lines = explode("\n",$headers);
|
||||
if(count($lines)) {
|
||||
foreach($lines as $line) {
|
||||
// don't try and run feeds through the html5 parser
|
||||
if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$dom = HTML5_Parser::parse($s);
|
||||
} catch (DOMException $e) {
|
||||
logger('Parse error: ' . $e);
|
||||
}
|
||||
|
||||
if(! $dom)
|
||||
return $ret;
|
||||
|
||||
// Pull out hCard profile elements
|
||||
|
||||
$largest_photo = 0;
|
||||
|
||||
$items = $dom->getElementsByTagName('*');
|
||||
foreach($items as $item) {
|
||||
if(attribute_contains($item->getAttribute('class'), 'vcard')) {
|
||||
$level2 = $item->getElementsByTagName('*');
|
||||
foreach($level2 as $x) {
|
||||
if(attribute_contains($x->getAttribute('id'),'pod_location'))
|
||||
$ret['pod_location'] = $x->textContent;
|
||||
if(attribute_contains($x->getAttribute('class'),'fn'))
|
||||
$ret['fn'] = $x->textContent;
|
||||
if(attribute_contains($x->getAttribute('class'),'uid'))
|
||||
$ret['uid'] = $x->textContent;
|
||||
if(attribute_contains($x->getAttribute('class'),'nickname'))
|
||||
$ret['nick'] = $x->textContent;
|
||||
if(attribute_contains($x->getAttribute('class'),'searchable'))
|
||||
$ret['searchable'] = $x->textContent;
|
||||
if(attribute_contains($x->getAttribute('class'),'key'))
|
||||
$ret['public_key'] = $x->textContent;
|
||||
if(attribute_contains($x->getAttribute('class'),'given_name'))
|
||||
$ret['given_name'] = $x->textContent;
|
||||
if(attribute_contains($x->getAttribute('class'),'family_name'))
|
||||
$ret['family_name'] = $x->textContent;
|
||||
if(attribute_contains($x->getAttribute('class'),'url'))
|
||||
$ret['url'] = $x->textContent;
|
||||
|
||||
if((attribute_contains($x->getAttribute('class'),'photo'))
|
||||
|| (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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
Reference in New Issue
Block a user