Fetch Diaspora posts by url

This commit is contained in:
Michael 2019-07-21 07:37:50 +00:00
parent c6131c057b
commit 53ffe5a2e1
3 changed files with 48 additions and 9 deletions

View file

@ -1414,6 +1414,41 @@ class Diaspora
return $msg;
}
/**
* @brief Fetches an item with a given URL
*
* @param string $url the message url
*
* @return int the message id of the stored message or false
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public static function fetchByURL($url, $uid = 0)
{
if (!preg_match("=([http|https].*)/(.*)/(.*)=ism", $url, $matches)) {
return false;
}
// Check for Diaspora (and Friendica) typical path components
if (!in_array($matches[2], ['posts', 'display'])) {
return false;
}
$item = Item::selectFirst(['id'], ['guid' => $matches[3], 'uid' => $uid]);
if (DBA::isResult($item)) {
return $item['id'];
}
self::storeByGuid($matches[3], $matches[1], $uid);
$item = Item::selectFirst(['id'], ['guid' => $matches[3], 'uid' => $uid]);
if (DBA::isResult($item)) {
return $item['id'];
} else {
return false;
}
}
/**
* @brief Fetches the item record of a given guid
*