-/**
- * Return the item shared, if the item contains only the [share] tag
- *
- * @param array $item Sharer item
- * @return array|false Shared item or false if not a reshare
- * @throws ImagickException
- * @throws InternalServerErrorException
- */
-function api_share_as_retweet(&$item)
-{
- $body = trim($item["body"]);
-
- if (Diaspora::isReshare($body, false) === false) {
- if ($item['author-id'] == $item['owner-id']) {
- return false;
- } else {
- // Reshares from OStatus, ActivityPub and Twitter
- $reshared_item = $item;
- $reshared_item['owner-id'] = $reshared_item['author-id'];
- $reshared_item['owner-link'] = $reshared_item['author-link'];
- $reshared_item['owner-name'] = $reshared_item['author-name'];
- $reshared_item['owner-avatar'] = $reshared_item['author-avatar'];
- return $reshared_item;
- }
- }
-
- $reshared = Item::getShareArray($item);
- if (empty($reshared)) {
- return false;
- }
-
- $reshared_item = $item;
-
- if (empty($reshared['shared']) || empty($reshared['profile']) || empty($reshared['author']) || empty($reshared['avatar']) || empty($reshared['posted'])) {
- return false;
- }
-
- if (!empty($reshared['comment'])) {
- $item['body'] = $reshared['comment'];
- }
-
- $reshared_item["share-pre-body"] = $reshared['comment'];
- $reshared_item["body"] = $reshared['shared'];
- $reshared_item["author-id"] = Contact::getIdForURL($reshared['profile'], 0, false);
- $reshared_item["author-name"] = $reshared['author'];
- $reshared_item["author-link"] = $reshared['profile'];
- $reshared_item["author-avatar"] = $reshared['avatar'];
- $reshared_item["plink"] = $reshared['link'] ?? '';
- $reshared_item["created"] = $reshared['posted'];
- $reshared_item["edited"] = $reshared['posted'];
-
- // Try to fetch the original item
- if (!empty($reshared['guid'])) {
- $condition = ['guid' => $reshared['guid'], 'uid' => [0, $item['uid']]];
- } elseif (!empty($reshared_item['plink']) && ($original_id = Item::searchByLink($reshared_item['plink']))) {
- $condition = ['id' => $original_id];
- } else {
- $condition = [];
- }
-
- if (!empty($condition)) {
- $original_item = Post::selectFirst([], $condition);
- if (DBA::isResult($original_item)) {
- $reshared_item = array_merge($reshared_item, $original_item);
- }
- }
-
- return $reshared_item;
-}
-