mirror of
https://github.com/friendica/friendica
synced 2024-11-11 07:42:54 +00:00
Merge pull request #7642 from annando/fix-twitter
Fetch avatar and name on Twitter discovery
This commit is contained in:
commit
cc617e42a3
1 changed files with 32 additions and 3 deletions
|
@ -1504,10 +1504,39 @@ class Probe
|
||||||
$data['baseurl'] = 'https://twitter.com';
|
$data['baseurl'] = 'https://twitter.com';
|
||||||
|
|
||||||
$curlResult = Network::curl($data['url'], false);
|
$curlResult = Network::curl($data['url'], false);
|
||||||
if ($curlResult->isSuccess()) {
|
if (!$curlResult->isSuccess()) {
|
||||||
return $data;
|
return [];
|
||||||
}
|
}
|
||||||
return [];
|
|
||||||
|
$body = $curlResult->getBody();
|
||||||
|
$doc = new DOMDocument();
|
||||||
|
@$doc->loadHTML($body);
|
||||||
|
$xpath = new DOMXPath($doc);
|
||||||
|
|
||||||
|
$list = $xpath->query('//img[@class]');
|
||||||
|
foreach ($list as $node) {
|
||||||
|
$img_attr = [];
|
||||||
|
if ($node->attributes->length) {
|
||||||
|
foreach ($node->attributes as $attribute) {
|
||||||
|
$img_attr[$attribute->name] = $attribute->value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($img_attr['class'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strpos($img_attr['class'], 'ProfileAvatar-image') !== false) {
|
||||||
|
if (!empty($img_attr['src'])) {
|
||||||
|
$data['photo'] = $img_attr['src'];
|
||||||
|
}
|
||||||
|
if (!empty($img_attr['alt'])) {
|
||||||
|
$data['name'] = $img_attr['alt'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue