- if (preg_match_all("(\[url\]([$URLSearchString]*)\[\/url\])ism", $body, $links, PREG_SET_ORDER)) {
- if (count($links) == 1) {
- $post["type"] = "text";
- $post["url"] = $links[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;