Merge pull request #7414 from annando/fetch-diaspora
Fetch Diaspora posts by url
This commit is contained in:
commit
1d8b809227
|
@ -20,6 +20,7 @@ use Friendica\Core\Renderer;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
|
use Friendica\Protocol\ActivityPub;
|
||||||
use Friendica\Protocol\Diaspora;
|
use Friendica\Protocol\Diaspora;
|
||||||
use Friendica\Protocol\OStatus;
|
use Friendica\Protocol\OStatus;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
|
@ -29,7 +30,6 @@ use Friendica\Util\Security;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
use Friendica\Util\XML;
|
use Friendica\Util\XML;
|
||||||
use Friendica\Worker\Delivery;
|
use Friendica\Worker\Delivery;
|
||||||
use Friendica\Protocol\ActivityPub;
|
|
||||||
use Text_LanguageDetect;
|
use Text_LanguageDetect;
|
||||||
|
|
||||||
class Item extends BaseObject
|
class Item extends BaseObject
|
||||||
|
@ -3628,11 +3628,12 @@ class Item extends BaseObject
|
||||||
return $item_id;
|
return $item_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
ActivityPub\Processor::fetchMissingActivity($uri);
|
if (ActivityPub\Processor::fetchMissingActivity($uri)) {
|
||||||
|
|
||||||
/// @todo add Diaspora as well
|
|
||||||
|
|
||||||
$item_id = self::searchByLink($uri, $uid);
|
$item_id = self::searchByLink($uri, $uid);
|
||||||
|
} else {
|
||||||
|
$item_id = Diaspora::fetchByURL($uri);
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($item_id)) {
|
if (!empty($item_id)) {
|
||||||
return $item_id;
|
return $item_id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -534,8 +534,9 @@ class Processor
|
||||||
/**
|
/**
|
||||||
* Fetches missing posts
|
* Fetches missing posts
|
||||||
*
|
*
|
||||||
* @param $url
|
* @param string $url message URL
|
||||||
* @param $child
|
* @param array $child activity array with the child of this message
|
||||||
|
* @return boolean success
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public static function fetchMissingActivity($url, $child = [])
|
public static function fetchMissingActivity($url, $child = [])
|
||||||
|
@ -549,12 +550,12 @@ class Processor
|
||||||
$object = ActivityPub::fetchContent($url, $uid);
|
$object = ActivityPub::fetchContent($url, $uid);
|
||||||
if (empty($object)) {
|
if (empty($object)) {
|
||||||
Logger::log('Activity ' . $url . ' was not fetchable, aborting.');
|
Logger::log('Activity ' . $url . ' was not fetchable, aborting.');
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($object['id'])) {
|
if (empty($object['id'])) {
|
||||||
Logger::log('Activity ' . $url . ' has got not id, aborting. ' . json_encode($object));
|
Logger::log('Activity ' . $url . ' has got not id, aborting. ' . json_encode($object));
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($child['author'])) {
|
if (!empty($child['author'])) {
|
||||||
|
@ -593,6 +594,8 @@ class Processor
|
||||||
|
|
||||||
ActivityPub\Receiver::processActivity($ldactivity);
|
ActivityPub\Receiver::processActivity($ldactivity);
|
||||||
Logger::log('Activity ' . $url . ' had been fetched and processed.');
|
Logger::log('Activity ' . $url . ' had been fetched and processed.');
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1414,6 +1414,39 @@ class Diaspora
|
||||||
return $msg;
|
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)
|
||||||
|
{
|
||||||
|
// Check for Diaspora (and Friendica) typical paths
|
||||||
|
if (!preg_match("=(https?://.+)/(?:posts|display)/([a-zA-Z0-9-_@.:%]+[a-zA-Z0-9])=i", $url, $matches)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$guid = urldecode($matches[2]);
|
||||||
|
|
||||||
|
$item = Item::selectFirst(['id'], ['guid' => $guid, 'uid' => $uid]);
|
||||||
|
if (DBA::isResult($item)) {
|
||||||
|
return $item['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
self::storeByGuid($guid, $matches[1], $uid);
|
||||||
|
|
||||||
|
$item = Item::selectFirst(['id'], ['guid' => $guid, 'uid' => $uid]);
|
||||||
|
if (DBA::isResult($item)) {
|
||||||
|
return $item['id'];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Fetches the item record of a given guid
|
* @brief Fetches the item record of a given guid
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue