From 2f91ce87b7017078a44169cd7d51afdad8e25d4b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 17 Oct 2018 01:14:57 -0400 Subject: [PATCH] [twitter] Add custom handling for mentions --- twitter/twitter.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/twitter/twitter.php b/twitter/twitter.php index 9f07fa52..b17d9ad1 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -553,6 +553,9 @@ function twitter_post_hook(App $a, array &$b) $connection->setTimeouts(10, 30); $max_char = 280; + + $b['body'] = twitter_update_mentions($b['body']); + $msgarr = ItemContent::getPlaintextPost($b, $max_char, true, 8); $msg = $msgarr["text"]; @@ -1859,3 +1862,23 @@ function twitter_is_retweet(App $a, $uid, $body) return !isset($result->errors); } + +function twitter_update_mentions($body) +{ + $URLSearchString = "^\[\]"; + $return = preg_replace_callback( + "/@\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", + function ($matches) { + if (strpos($matches[1], 'twitter.com')) { + $return = '@' . substr($matches[1], strrpos($matches[1], '/') + 1); + } else { + $return = $matches[2] . ' (' . $matches[1] . ')'; + } + + return $return; + }, + $body + ); + + return $return; +}