mirror of
https://github.com/friendica/friendica
synced 2025-04-26 04:30:11 +00:00
Fetch items by given uri
This commit is contained in:
parent
dcebf53ecf
commit
41a1c1c3e6
3 changed files with 77 additions and 9 deletions
|
@ -29,6 +29,7 @@ use Friendica\Util\Security;
|
|||
use Friendica\Util\Strings;
|
||||
use Friendica\Util\XML;
|
||||
use Friendica\Worker\Delivery;
|
||||
use Friendica\Protocol\ActivityPub;
|
||||
use Text_LanguageDetect;
|
||||
|
||||
class Item extends BaseObject
|
||||
|
@ -3575,4 +3576,69 @@ class Item extends BaseObject
|
|||
|
||||
return Contact::isForum($item['contact-id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search item id for given URI or plink
|
||||
*
|
||||
* @param string $uri
|
||||
* @param integer $uid
|
||||
*
|
||||
* @return integer item id
|
||||
*/
|
||||
public static function searchByLink($uri, $uid = 0)
|
||||
{
|
||||
$ssl_uri = str_replace('http://', 'https://', $uri);
|
||||
$uris = [$uri, $ssl_uri, Strings::normaliseLink($uri)];
|
||||
|
||||
$item = DBA::selectFirst('item', ['id'], ['uri' => $uris, 'uid' => $uid]);
|
||||
if (DBA::isResult($item)) {
|
||||
return $item['id'];
|
||||
}
|
||||
|
||||
$itemcontent = DBA::selectFirst('item-content', ['uri-id'], ['plink' => $uris]);
|
||||
if (!DBA::isResult($itemcontent)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$itemuri = DBA::selectFirst('item-uri', ['uri'], ['id' => $itemcontent['uri-id']]);
|
||||
if (!DBA::isResult($itemuri)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$item = DBA::selectFirst('item', ['id'], ['uri' => $itemuri['uri'], 'uid' => $uid]);
|
||||
if (DBA::isResult($item)) {
|
||||
return $item['id'];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches item for given URI or plink
|
||||
*
|
||||
* @param string $uri
|
||||
* @param integer $uid
|
||||
*
|
||||
* @return integer item id
|
||||
*/
|
||||
public static function fetchByLink($uri, $uid = 0)
|
||||
{
|
||||
$item_id = self::searchByLink($uri, $uid);
|
||||
if (!empty($item_id)) {
|
||||
echo "a\n";
|
||||
return $item_id;
|
||||
}
|
||||
|
||||
echo "b\n";
|
||||
ActivityPub\Processor::fetchMissingActivity($uri);
|
||||
|
||||
$item_id = self::searchByLink($uri, $uid);
|
||||
if (!empty($item_id)) {
|
||||
echo "c\n";
|
||||
return $item_id;
|
||||
}
|
||||
|
||||
echo "d\n";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue