]> git.mxchange.org Git - friendica-addons.git/commitdiff
[twitter] Add custom handling for mentions
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 17 Oct 2018 05:14:57 +0000 (01:14 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Wed, 17 Oct 2018 05:14:57 +0000 (01:14 -0400)
twitter/twitter.php

index 9f07fa52c2d69aa206405f414c3cc480c402a0b6..b17d9ad197284c16f8cca4658a79514ac2231051 100644 (file)
@@ -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;
+}