- /**
- * Public posts for the given owner
- *
- * @param array $owner Owner array
- * @param integer $page Page number
- * @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 $page = null, string $requester = '', bool $nocache = false): array
- {
- $condition = ['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']);
-
- $data = ['@context' => ActivityPub::CONTEXT];
- $data['id'] = DI::baseUrl() . '/outbox/' . $owner['nickname'];
- $data['type'] = 'OrderedCollection';
- $data['totalItems'] = $apcontact['statuses_count'] ?? 0;
-
- if (!empty($page)) {
- $data['id'] .= '?' . http_build_query(['page' => $page]);
- }
-
- if (empty($page)) {
- $data['first'] = DI::baseUrl() . '/outbox/' . $owner['nickname'] . '?page=1';
- } else {
- $data['type'] = 'OrderedCollectionPage';
- $list = [];
-
- $items = Post::select(['id'], $condition, ['limit' => [($page - 1) * 20, 20], 'order' => ['created' => true]]);
- while ($item = Post::fetch($items)) {
- $activity = self::createActivityFromItem($item['id'], true);
- $activity['type'] = $activity['type'] == 'Update' ? 'Create' : $activity['type'];
-
- // Only list "Create" activity objects here, no reshares
- if (!empty($activity['object']) && ($activity['type'] == 'Create')) {
- $list[] = $activity['object'];
- }
- }
- DBA::close($items);
-
- if (count($list) == 20) {
- $data['next'] = DI::baseUrl() . '/outbox/' . $owner['nickname'] . '?page=' . ($page + 1);
- }
-
- // Fix the cached total item count when it is lower than the real count
- $total = (($page - 1) * 20) + $data['totalItems'];
- if ($total > $data['totalItems']) {
- $data['totalItems'] = $total;
- }
-
- $data['partOf'] = DI::baseUrl() . '/outbox/' . $owner['nickname'];
-
- $data['orderedItems'] = $list;
- }
-
- return $data;
- }
-