Merge pull request '[various] Ensure probe_detect hook functions don't set the result key with an empty array' (#1382) from MrPetovan/friendica-addons:bug/13080-probe_detect-result into develop
Reviewed-on: https://git.friendi.ca/friendica/friendica-addons/pulls/1382
This commit is contained in:
commit
e91962b0b6
2 changed files with 24 additions and 13 deletions
|
@ -99,6 +99,11 @@ function tumblr_probe_detect(array &$hookData)
|
||||||
}
|
}
|
||||||
|
|
||||||
$hookData['result'] = tumblr_get_contact_by_url($hookData['uri']);
|
$hookData['result'] = tumblr_get_contact_by_url($hookData['uri']);
|
||||||
|
|
||||||
|
// Authoritative probe should set the result even if the probe was unsuccessful
|
||||||
|
if ($hookData['network'] == Protocol::TUMBLR && empty($hookData['result'])) {
|
||||||
|
$hookData['result'] = [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function tumblr_item_by_link(array &$hookData)
|
function tumblr_item_by_link(array &$hookData)
|
||||||
|
@ -1213,24 +1218,25 @@ function tumblr_enabled_for_user(int $uid)
|
||||||
* Get a contact array from a Tumblr url
|
* Get a contact array from a Tumblr url
|
||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @return array
|
* @return array|null
|
||||||
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
function tumblr_get_contact_by_url(string $url): array
|
function tumblr_get_contact_by_url(string $url): ?array
|
||||||
{
|
{
|
||||||
$consumer_key = DI::config()->get('tumblr', 'consumer_key');
|
$consumer_key = DI::config()->get('tumblr', 'consumer_key');
|
||||||
if (empty($consumer_key)) {
|
if (empty($consumer_key)) {
|
||||||
return [];
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!preg_match('#^https?://tumblr.com/(.+)#', $url, $matches) && !preg_match('#^https?://www\.tumblr.com/(.+)#', $url, $matches) && !preg_match('#^https?://(.+)\.tumblr.com#', $url, $matches)) {
|
if (!preg_match('#^https?://tumblr.com/(.+)#', $url, $matches) && !preg_match('#^https?://www\.tumblr.com/(.+)#', $url, $matches) && !preg_match('#^https?://(.+)\.tumblr.com#', $url, $matches)) {
|
||||||
try {
|
try {
|
||||||
$curlResult = DI::httpClient()->get($url);
|
$curlResult = DI::httpClient()->get($url);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return [];
|
return null;
|
||||||
}
|
}
|
||||||
$html = $curlResult->getBody();
|
$html = $curlResult->getBody();
|
||||||
if (empty($html)) {
|
if (empty($html)) {
|
||||||
return [];
|
return null;
|
||||||
}
|
}
|
||||||
$doc = new DOMDocument();
|
$doc = new DOMDocument();
|
||||||
@$doc->loadHTML($html);
|
@$doc->loadHTML($html);
|
||||||
|
@ -1244,7 +1250,7 @@ function tumblr_get_contact_by_url(string $url): array
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($blog)) {
|
if (empty($blog)) {
|
||||||
return [];
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::debug('Update Tumblr blog data', ['url' => $url]);
|
Logger::debug('Update Tumblr blog data', ['url' => $url]);
|
||||||
|
@ -1253,7 +1259,7 @@ function tumblr_get_contact_by_url(string $url): array
|
||||||
$body = $curlResult->getBody();
|
$body = $curlResult->getBody();
|
||||||
$data = json_decode($body);
|
$data = json_decode($body);
|
||||||
if (empty($data)) {
|
if (empty($data)) {
|
||||||
return [];
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$baseurl = 'https://tumblr.com';
|
$baseurl = 'https://tumblr.com';
|
||||||
|
|
|
@ -526,7 +526,12 @@ function twitter_probe_detect(array &$hookData)
|
||||||
$user = twitter_fetchuser($nick);
|
$user = twitter_fetchuser($nick);
|
||||||
|
|
||||||
if ($user) {
|
if ($user) {
|
||||||
$hookData['result'] = twitter_user_to_contact($user);
|
$hookData['result'] = twitter_user_to_contact($user) ?: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Authoritative probe should set the result even if the probe was unsuccessful
|
||||||
|
if ($hookData['network'] == Protocol::TWITTER && empty($hookData['result'])) {
|
||||||
|
$hookData['result'] = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue