From aeb6e53d02fdbc3208851a9a4dc8323db29c62c5 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 23 Sep 2017 20:13:09 +0000 Subject: [PATCH] Better content detection for posts to Twitter --- include/plaintext.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/include/plaintext.php b/include/plaintext.php index 1d16aa2e8d..f3318012a0 100644 --- a/include/plaintext.php +++ b/include/plaintext.php @@ -245,13 +245,19 @@ function get_attached_data($body) { } } - 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; - } + 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 (count($links) == 1) { + $post["url"] = $links[0][1]; } + + if (count($links) > 0) { + unset($post["type"]); + } + if (!isset($post["type"])) { $post["type"] = "text"; $post["text"] = trim($body);