- 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_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),
- ];
+ return $ret;
+}
+
+/**
+ * @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"];
+ }