+ /**
+ * @brief collects the lost of followers of the given owner
+ *
+ * @param array $owner Owner array
+ * @param integer $page Page number
+ *
+ * @return array of owners
+ */
+ public static function getFollowers($owner, $page = null)
+ {
+ $condition = ['rel' => [Contact::FOLLOWER, Contact::FRIEND], 'network' => Protocol::NATIVE_SUPPORT, 'uid' => $owner['uid'],
+ 'self' => false, 'hidden' => false, 'archive' => false, 'pending' => false];
+ $count = DBA::count('contact', $condition);
+
+ $data = ['@context' => self::CONTEXT];
+ $data['id'] = System::baseUrl() . '/followers/' . $owner['nickname'];
+ $data['type'] = 'OrderedCollection';
+ $data['totalItems'] = $count;
+
+ // When we hide our friends we will only show the pure number but don't allow more.
+ $profile = Profile::getByUID($owner['uid']);
+ if (!empty($profile['hide-friends'])) {
+ return $data;
+ }
+
+ if (empty($page)) {
+ $data['first'] = System::baseUrl() . '/followers/' . $owner['nickname'] . '?page=1';
+ } else {
+ $list = [];
+
+ $contacts = DBA::select('contact', ['url'], $condition, ['limit' => [($page - 1) * 100, 100]]);
+ while ($contact = DBA::fetch($contacts)) {
+ $list[] = $contact['url'];
+ }
+
+ if (!empty($list)) {
+ $data['next'] = System::baseUrl() . '/followers/' . $owner['nickname'] . '?page=' . ($page + 1);
+ }
+
+ $data['partOf'] = System::baseUrl() . '/followers/' . $owner['nickname'];
+
+ $data['orderedItems'] = $list;
+ }
+
+ return $data;
+ }
+
+ /**
+ * @brief Create list of following contacts
+ *
+ * @param array $owner Owner array
+ * @param integer $page Page numbe
+ *
+ * @return array of following contacts
+ */
+ public static function getFollowing($owner, $page = null)
+ {
+ $condition = ['rel' => [Contact::SHARING, Contact::FRIEND], 'network' => Protocol::NATIVE_SUPPORT, 'uid' => $owner['uid'],
+ 'self' => false, 'hidden' => false, 'archive' => false, 'pending' => false];
+ $count = DBA::count('contact', $condition);
+
+ $data = ['@context' => self::CONTEXT];
+ $data['id'] = System::baseUrl() . '/following/' . $owner['nickname'];
+ $data['type'] = 'OrderedCollection';
+ $data['totalItems'] = $count;
+
+ // When we hide our friends we will only show the pure number but don't allow more.
+ $profile = Profile::getByUID($owner['uid']);
+ if (!empty($profile['hide-friends'])) {
+ return $data;
+ }
+
+ if (empty($page)) {
+ $data['first'] = System::baseUrl() . '/following/' . $owner['nickname'] . '?page=1';
+ } else {
+ $list = [];
+
+ $contacts = DBA::select('contact', ['url'], $condition, ['limit' => [($page - 1) * 100, 100]]);
+ while ($contact = DBA::fetch($contacts)) {
+ $list[] = $contact['url'];
+ }
+
+ if (!empty($list)) {
+ $data['next'] = System::baseUrl() . '/following/' . $owner['nickname'] . '?page=' . ($page + 1);
+ }
+
+ $data['partOf'] = System::baseUrl() . '/following/' . $owner['nickname'];
+
+ $data['orderedItems'] = $list;
+ }
+
+ return $data;
+ }
+
+ /**
+ * @brief Public posts for the given owner
+ *
+ * @param array $owner Owner array
+ * @param integer $page Page numbe
+ *
+ * @return array of posts
+ */
+ public static function getOutbox($owner, $page = null)
+ {
+ $public_contact = Contact::getIdForURL($owner['url'], 0, true);
+
+ $condition = ['uid' => $owner['uid'], 'contact-id' => $owner['id'], 'author-id' => $public_contact,
+ 'wall' => true, 'private' => false, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT],
+ 'deleted' => false, 'visible' => true];
+ $count = DBA::count('item', $condition);
+
+ $data = ['@context' => self::CONTEXT];
+ $data['id'] = System::baseUrl() . '/outbox/' . $owner['nickname'];
+ $data['type'] = 'OrderedCollection';
+ $data['totalItems'] = $count;
+
+ if (empty($page)) {
+ $data['first'] = System::baseUrl() . '/outbox/' . $owner['nickname'] . '?page=1';
+ } else {
+ $list = [];
+
+ $condition['parent-network'] = Protocol::NATIVE_SUPPORT;
+
+ $items = Item::select(['id'], $condition, ['limit' => [($page - 1) * 20, 20], 'order' => ['created' => true]]);
+ while ($item = Item::fetch($items)) {
+ $object = self::createObjectFromItemID($item['id']);
+ unset($object['@context']);
+ $list[] = $object;
+ }
+
+ if (!empty($list)) {
+ $data['next'] = System::baseUrl() . '/outbox/' . $owner['nickname'] . '?page=' . ($page + 1);
+ }
+
+ $data['partOf'] = System::baseUrl() . '/outbox/' . $owner['nickname'];
+
+ $data['orderedItems'] = $list;
+ }
+
+ return $data;
+ }
+