mirror of
https://github.com/friendica/friendica
synced 2025-05-11 05:04:10 +02:00
Fetch Diaspora posts by url
This commit is contained in:
parent
c6131c057b
commit
53ffe5a2e1
3 changed files with 48 additions and 9 deletions
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue