- if ($data["type"] == "photo") {
- $post["type"] = "photo";
- if (isset($data["images"][0])) {
- $post["image"] = $data["images"][0]["src"];
- $post["url"] = $data["url"];
- } else {
- $post["image"] = $data["url"];
- }
-
- $post["preview"] = $pictures[0][2];
- $post["text"] = str_replace($pictures[0][0], "", $body);
- } else {
- $imgdata = Image::getInfoFromURL($pictures[0][1]);
- if (substr($imgdata["mime"], 0, 6) == "image/") {
- $post["type"] = "photo";
- $post["image"] = $pictures[0][1];
- $post["preview"] = $pictures[0][2];
- $post["text"] = str_replace($pictures[0][0], "", $body);
- }
- }
- } elseif (count($pictures) > 0) {
- $post["type"] = "link";
- $post["url"] = $plink;
- $post["image"] = $pictures[0][2];
- $post["text"] = $body;
- }
- } elseif (preg_match_all("(\[img\]([$URLSearchString]*)\[\/img\])ism", $body, $pictures, PREG_SET_ORDER)) {
- if ((count($pictures) == 1) && !$has_title) {
- $post["type"] = "photo";
- $post["image"] = $pictures[0][1];
- $post["text"] = str_replace($pictures[0][0], "", $body);
- } elseif (count($pictures) > 0) {
- $post["type"] = "link";
- $post["url"] = $plink;
- $post["image"] = $pictures[0][1];
- $post["text"] = $body;
- }
- }
-
- // Test for the external links
- preg_match_all("(\[url\]([$URLSearchString]*)\[\/url\])ism", $body, $links1, PREG_SET_ORDER);
- preg_match_all("(\[url\=([$URLSearchString]*)\].*?\[\/url\])ism", $body, $links2, PREG_SET_ORDER);
-
- $links = array_merge($links1, $links2);
-
- // If there is only a single one, then use it.
- // This should cover link posts via API.
- if ((count($links) == 1) && !isset($post["preview"]) && !$has_title) {
- $post["type"] = "link";
- $post["text"] = trim($body);
- $post["url"] = $links[0][1];
- }
-
- // Now count the number of external media links
- preg_match_all("(\[vimeo\](.*?)\[\/vimeo\])ism", $body, $links1, PREG_SET_ORDER);
- preg_match_all("(\[youtube\\](.*?)\[\/youtube\\])ism", $body, $links2, PREG_SET_ORDER);
- preg_match_all("(\[video\\](.*?)\[\/video\\])ism", $body, $links3, PREG_SET_ORDER);
- preg_match_all("(\[audio\\](.*?)\[\/audio\\])ism", $body, $links4, PREG_SET_ORDER);
-
- // Add them to the other external links
- $links = array_merge($links, $links1, $links2, $links3, $links4);
-
- // Are there more than one?
- if (count($links) > 1) {
- // The post will be the type "text", which means a blog post
- unset($post["type"]);
- $post["url"] = $plink;
- }
-
- if (!isset($post["type"])) {
- $post["type"] = "text";
- $post["text"] = trim($body);
- }
- } elseif (isset($post["url"]) && ($post["type"] == "video")) {
- $data = ParseUrl::getSiteinfoCached($post["url"], true);
-
- if (isset($data["images"][0])) {
- $post["image"] = $data["images"][0]["src"];
- }
- }
-
- return $post;