X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FActivityPub%2FTransmitter.php;h=7da110f6716dfd5fb6a2e284e727e19d85e551b8;hb=7f4d399fc8ca0abd4ab99f1ee9dfecd5fa175fde;hp=0338ca72f1df737e4e1a21f649125633647a3303;hpb=5fdeed8ed89d06cadb9e30446b8776c9b34bb18e;p=friendica.git diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 0338ca72f1..7da110f671 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -238,134 +238,6 @@ class Transmitter return $data; } - /** - * Public posts for the given owner - * - * @param array $owner Owner array - * @param integer $uid User id - * @param integer $page Page number - * @param integer $max_id Maximum ID - * @param string $requester URL of requesting account - * @param boolean $nocache Wether to bypass caching - * @return array of posts - * @throws \Friendica\Network\HTTPException\InternalServerErrorException - * @throws \ImagickException - */ - public static function getOutbox(array $owner, int $uid, int $page = null, int $max_id = null, string $requester = ''): array - { - $condition = ['gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT], 'private' => [Item::PUBLIC, Item::UNLISTED]]; - - if (!empty($requester)) { - $requester_id = Contact::getIdForURL($requester, $owner['uid']); - if (!empty($requester_id)) { - $permissionSets = DI::permissionSet()->selectByContactId($requester_id, $owner['uid']); - if (!empty($permissionSets)) { - $condition = ['psid' => array_merge($permissionSets->column('id'), - [DI::permissionSet()->selectPublicForUser($owner['uid'])])]; - } - } - } - - $condition = array_merge($condition, [ - 'uid' => $owner['uid'], - 'author-id' => Contact::getIdForURL($owner['url'], 0, false), - 'gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT], - 'network' => Protocol::FEDERATED, - 'parent-network' => Protocol::FEDERATED, - 'origin' => true, - 'deleted' => false, - 'visible' => true - ]); - - $apcontact = APContact::getByURL($owner['url']); - - return self::getCollection($condition, DI::baseUrl() . '/outbox/' . $owner['nickname'], $page, $max_id, $uid, $apcontact['statuses_count']); - } - - public static function getInbox(int $uid, int $page = null, int $max_id = null) - { - $owner = User::getOwnerDataById($uid); - - $condition = ['gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT], 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN], 'uid' => $uid]; - - return self::getCollection($condition, DI::baseUrl() . '/inbox/' . $owner['nickname'], $page, $max_id, $uid, null); - } - - public static function getPublicInbox(int $uid, int $page = null, int $max_id = null) - { - $condition = ['gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT], 'private' => Item::PUBLIC, - 'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN], 'author-blocked' => false, 'author-hidden' => false]; - - return self::getCollection($condition, DI::baseUrl() . '/inbox', $page, $max_id, $uid, null); - } - - private static function getCollection(array $condition, string $path, int $page = null, int $max_id = null, int $uid = null, int $total_items = null) - { - $data = ['@context' => ActivityPub::CONTEXT]; - $data['id'] = $path; - $data['type'] = 'OrderedCollection'; - - if (!is_null($total_items)) { - $data['totalItems'] = $total_items; - } - - if (!empty($page)) { - $data['id'] .= '?' . http_build_query(['page' => $page]); - } - - if (empty($page) && empty($max_id)) { - $data['first'] = $path . '?page=1'; - } else { - $data['type'] = 'OrderedCollectionPage'; - $list = []; - - if (!empty($max_id)) { - $condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $max_id]); - } - - if (!empty($page)) { - $params = ['limit' => [($page - 1) * 20, 20], 'order' => ['uri-id' => true]]; - } else { - $params = ['limit' => 20, 'order' => ['uri-id' => true]]; - } - - if (!is_null($uid)) { - $items = Post::selectForUser($uid, ['id', 'uri-id'], $condition, $params); - } else { - $items = Post::select(['id', 'uri-id'], $condition, $params); - } - - $last_id = 0; - while ($item = Post::fetch($items)) { - $activity = self::createActivityFromItem($item['id'], false, !is_null($uid)); - if (!empty($activity)) { - $list[] = $activity; - $last_id = $item['uri-id']; - continue; - } - } - DBA::close($items); - - if (count($list) == 20) { - $data['next'] = $path . '?max_id=' . $last_id; - } - - // Fix the cached total item count when it is lower than the real count - if (!is_null($total_items)) { - $total = (($page - 1) * 20) + $data['totalItems']; - if ($total > $data['totalItems']) { - $data['totalItems'] = $total; - } - } - - $data['partOf'] = $path; - - $data['orderedItems'] = $list; - } - - return $data; - } - /** * Public posts for the given owner * @@ -458,7 +330,7 @@ class Transmitter return [ 'type' => 'Service', 'name' => App::PLATFORM . " '" . App::CODENAME . "' " . App::VERSION . '-' . DB_UPDATE_VERSION, - 'url' => DI::baseUrl()->get() + 'url' => DI::baseUrl() ]; } @@ -1767,6 +1639,8 @@ class Transmitter $real_quote = false; + $item = Post\Media::addHTMLAttachmentToItem($item); + $body = $item['body']; if ($type == 'Note') { @@ -1803,7 +1677,7 @@ class Transmitter if ($type == 'Page') { // When we transmit "Page" posts we have to remove the attachment. // The attachment contains the link that we already transmit in the "url" field. - $body = preg_replace("/\s*\[attachment .*?\].*?\[\/attachment\]\s*/ism", '', $body); + $body = BBCode::removeAttachment($body); } $body = BBCode::setMentionsToNicknames($body); @@ -1835,7 +1709,7 @@ class Transmitter $richbody = DI::contentItem()->addSharedPost($item, $richbody); } } - $richbody = BBCode::removeAttachment($richbody); + $richbody = BBCode::replaceAttachment($richbody); $data['contentMap'][$language] = BBCode::convertForUriId($item['uri-id'], $richbody, BBCode::EXTERNAL); }