function api_convert_item($item) { $body = $item['body']; $attachments = api_get_attachments($body); // Workaround for ostatus messages where the title is identically to the body $html = bbcode(api_clean_plain_items($body), false, false, 2, true); $statusbody = trim(html2plain($html, 0)); // handle data: images $statusbody = api_format_items_embeded_images($item, $statusbody); $statustitle = trim($item['title']); if ($statustitle != '' and strpos($statusbody, $statustitle) !== false) { $statustext = trim($statusbody); } else { $statustext = trim($statustitle . "\n\n" . $statusbody); } if ($item["network"] == NETWORK_FEED and strlen($statustext) > 1000) { $statustext = substr($statustext, 0, 1000) . "... \n" . $item["plink"]; } $statushtml = trim(bbcode($body, false, false)); if ($item['title'] != "") { $statushtml = "<h4>" . bbcode($item['title']) . "</h4>\n" . $statushtml; } $entities = api_get_entitities($statustext, $body); return array("text" => $statustext, "html" => $statushtml, "attachments" => $attachments, "entities" => $entities); }
function api_format_items($r, $user_info, $filter_user = false) { $a = get_app(); $ret = array(); foreach ($r as $item) { api_share_as_retweet($a, api_user(), $item); localize_item($item); $status_user = api_item_get_user($a, $item); // Look if the posts are matching if they should be filtered by user id if ($filter_user and $status_user["id"] != $user_info["id"]) { continue; } if ($item['thr-parent'] != $item['uri']) { $r = q("SELECT id FROM item WHERE uid=%d AND uri='%s' LIMIT 1", intval(api_user()), dbesc($item['thr-parent'])); if ($r) { $in_reply_to_status_id = intval($r[0]['id']); } else { $in_reply_to_status_id = intval($item['parent']); } $in_reply_to_status_id_str = (string) intval($item['parent']); $in_reply_to_screen_name = NULL; $in_reply_to_user_id = NULL; $in_reply_to_user_id_str = NULL; $r = q("SELECT `author-link` FROM item WHERE uid=%d AND id=%d LIMIT 1", intval(api_user()), intval($in_reply_to_status_id)); if ($r) { $r = q("SELECT * FROM unique_contacts WHERE `url` = '%s'", dbesc(normalise_link($r[0]['author-link']))); if ($r) { if ($r[0]['nick'] == "") { $r[0]['nick'] = api_get_nick($r[0]["url"]); } $in_reply_to_screen_name = $r[0]['nick'] ? $r[0]['nick'] : $r[0]['name']; $in_reply_to_user_id = intval($r[0]['id']); $in_reply_to_user_id_str = (string) intval($r[0]['id']); } } } else { $in_reply_to_screen_name = NULL; $in_reply_to_user_id = NULL; $in_reply_to_status_id = NULL; $in_reply_to_user_id_str = NULL; $in_reply_to_status_id_str = NULL; } // Workaround for ostatus messages where the title is identically to the body //$statusbody = trim(html2plain(bbcode(api_clean_plain_items($item['body']), false, false, 5, true), 0)); $html = bbcode(api_clean_plain_items($item['body']), false, false, 2, true); $statusbody = trim(html2plain($html, 0)); $statustitle = trim($item['title']); if ($statustitle != '' and strpos($statusbody, $statustitle) !== false) { $statustext = trim($statusbody); } else { $statustext = trim($statustitle . "\n\n" . $statusbody); } if ($item["network"] == NETWORK_FEED and strlen($statustext) > 1000) { $statustext = substr($statustext, 0, 1000) . "... \n" . $item["plink"]; } $status = array('text' => $statustext, '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, 'statusnet_html' => trim(bbcode($item['body'], false, false)), 'statusnet_conversation_id' => $item['parent']); if ($item['title'] != "") { $status['statusnet_html'] = "<h4>" . bbcode($item['title']) . "</h4>\n" . $status['statusnet_html']; } $entities = api_get_entitities($status['text'], $item['body']); if (count($entities) > 0) { $status['entities'] = $entities; } if ($item['item_network'] != "" and $status["source"] == 'web') { $status["source"] = network_to_name($item['item_network']); } else { if ($item['item_network'] != "" and network_to_name($item['item_network']) != $status["source"]) { $status["source"] = trim($status["source"] . ' (' . network_to_name($item['item_network']) . ')'); } } // Retweets are only valid for top postings // It doesn't work reliable with the link if its a feed $IsRetweet = $item['owner-link'] != $item['author-link']; if ($IsRetweet) { $IsRetweet = ($item['owner-name'] != $item['author-name'] or $item['owner-avatar'] != $item['author-avatar']); } if ($IsRetweet and $item["id"] == $item["parent"]) { $retweeted_status = $status; $retweeted_status["user"] = api_get_user($a, $item["author-link"]); $status["retweeted_status"] = $retweeted_status; } // "uid" and "self" are only needed for some internal stuff, so remove it from here unset($status["user"]["uid"]); unset($status["user"]["self"]); // 'geo' => array('type' => 'Point', // 'coordinates' => array((float) $notice->lat, // (float) $notice->lon)); $ret[] = $status; } return $ret; }