You are here

function twitter_link_filter in Twitter 6.3

Same name and namespace in other branches
  1. 6.2 twitter.module \twitter_link_filter()
  2. 6.4 twitter.module \twitter_link_filter()

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

2 calls to twitter_link_filter()
twitter_filter in ./twitter.module
Implementation of hook_filter().
twitter_views_handler_field_xss::render in ./twitter_views_field_handlers.inc

File

./twitter.module, line 212

Code

function twitter_link_filter($text, $prefix = '@', $destination = '') {
  if ($destination == '') {
    $destination = variable_get('twitter_host', TWITTER_HOST) . '/';
  }
  $matches = array(
    '/\\>' . $prefix . '(\\w+)/ui',
    '/^' . $prefix . '(\\w+)/ui',
    '/(\\s+)' . $prefix . '(\\w+)/ui',
  );
  $replacements = array(
    '><a href="' . $destination . '${1}" target="_blank">' . $prefix . '${1}</a>',
    '<a href="' . $destination . '${1}" target="_blank">' . $prefix . '${1}</a>',
    '${1}<a href="' . $destination . '${2}" target="_blank">' . $prefix . '${2}</a>',
  );
  return preg_replace($matches, $replacements, $text);
}