You are here

function _twitter_filter_text in Twitter 7.6

Same name and namespace in other branches
  1. 6.5 twitter.module \_twitter_filter_text()
  2. 7.3 twitter.module \_twitter_filter_text()
  3. 7.4 twitter.module \_twitter_filter_text()
  4. 7.5 twitter.module \_twitter_filter_text()

This helper function converts Twitter-style @usernames and #hashtags into actual links.

Parameters

string $text: The text to be filtered.

string $prefix: The string to search for.

string $destination: The URL that the links will point to.

string $class: An optional class to insert into the link.

Return value

string The processed string.

2 calls to _twitter_filter_text()
_twitter_filter_hashtag in ./twitter.module
Callback for twitter #hashtag converter.
_twitter_filter_username in ./twitter.module
Callback for twitter @username converter.

File

./twitter.module, line 437
Provides API integration with the Twitter microblogging service.

Code

function _twitter_filter_text($text, $prefix, $destination, $class = '') {
  $match = '/(?<!\\w)' . preg_quote($prefix, '/') . '(\\w+)/ui';
  if (!empty($class)) {
    $class = " class=\"{$class}\"";
  }
  $replacement = '<a href="' . $destination . '$1"' . $class . '>' . $prefix . '$1</a>';
  return preg_replace($match, $replacement, $text);
}