Browse Source

[twitter] Add custom handling for mentions

pull/754/head
Hypolite Petovan 4 years ago
parent
commit
2f91ce87b7
  1. 23
      twitter/twitter.php

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

Loading…
Cancel
Save