+/**
+ * @param array $item Item record
+ * @param string $type Return format (atom, rss, xml, json)
+ * @param array $status_user User record of the item author, can be provided by api_item_get_user()
+ * @param array $author_user User record of the item author, can be provided by api_item_get_user()
+ * @param array $owner_user User record of the item owner, can be provided by api_item_get_user()
+ * @return array API-formatted status
+ * @throws BadRequestException
+ * @throws ImagickException
+ * @throws InternalServerErrorException
+ * @throws UnauthorizedException
+ */
+function api_format_item($item, $type = "json", $status_user = null, $author_user = null, $owner_user = null)
+{
+ $a = \Friendica\BaseObject::getApp();
+
+ if (empty($status_user) || empty($author_user) || empty($owner_user)) {
+ list($status_user, $author_user, $owner_user) = api_item_get_user($a, $item);
+ }
+
+ localize_item($item);
+
+ $in_reply_to = api_in_reply_to($item);
+
+ $converted = api_convert_item($item);
+
+ if ($type == "xml") {
+ $geo = "georss:point";
+ } else {
+ $geo = "geo";
+ }
+
+ $status = [
+ 'text' => $converted["text"],
+ 'truncated' => false,
+ 'created_at'=> api_date($item['created']),
+ 'in_reply_to_status_id' => $in_reply_to['status_id'],
+ 'in_reply_to_status_id_str' => $in_reply_to['status_id_str'],
+ 'source' => (($item['app']) ? $item['app'] : 'web'),
+ 'id' => intval($item['id']),
+ 'id_str' => (string) intval($item['id']),
+ 'in_reply_to_user_id' => $in_reply_to['user_id'],
+ 'in_reply_to_user_id_str' => $in_reply_to['user_id_str'],
+ 'in_reply_to_screen_name' => $in_reply_to['screen_name'],
+ $geo => null,
+ 'favorited' => $item['starred'] ? true : false,
+ 'user' => $status_user,
+ 'friendica_author' => $author_user,
+ 'friendica_owner' => $owner_user,
+ 'friendica_private' => $item['private'] == 1,
+ //'entities' => NULL,
+ 'statusnet_html' => $converted["html"],
+ 'statusnet_conversation_id' => $item['parent'],
+ 'external_url' => System::baseUrl() . "/display/" . $item['guid'],
+ 'friendica_activities' => api_format_items_activities($item, $type),
+ ];
+
+ if (count($converted["attachments"]) > 0) {
+ $status["attachments"] = $converted["attachments"];
+ }
+
+ if (count($converted["entities"]) > 0) {
+ $status["entities"] = $converted["entities"];
+ }
+
+ if ($status["source"] == 'web') {
+ $status["source"] = ContactSelector::networkToName($item['network'], $item['author-link']);
+ } elseif (ContactSelector::networkToName($item['network'], $item['author-link']) != $status["source"]) {
+ $status["source"] = trim($status["source"].' ('.ContactSelector::networkToName($item['network'], $item['author-link']).')');
+ }
+
+ $retweeted_item = [];
+ $quoted_item = [];
+
+ if ($item["id"] == $item["parent"]) {
+ $body = $item['body'];
+ $retweeted_item = api_share_as_retweet($item);
+ if ($body != $item['body']) {
+ $quoted_item = $retweeted_item;
+ $retweeted_item = [];
+ }
+ }
+
+ if (empty($retweeted_item) && ($item['owner-id'] == $item['author-id'])) {
+ $announce = api_get_announce($item);
+ if (!empty($announce)) {
+ $retweeted_item = $item;
+ $item = $announce;
+ $status['friendica_owner'] = api_get_user($a, $announce['author-id']);