[twitter] Add custom handling for mentions

This commit is contained in:
Hypolite Petovan 2018-10-17 01:14:57 -04:00
parent fd3eb35c33
commit 2f91ce87b7

View 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;
}