You are here

function twitter_link_filter in Twitter 6.2

Same name and namespace in other branches
  1. 6.3 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 252

Code

function twitter_link_filter($text, $prefix = '@', $destination = 'http://twitter.com/') {
  $matches = array(
    '/\\>' . $prefix . '([a-z0-9_]{1,15})/i',
    '/^' . $prefix . '([a-z0-9_]{1,15})/i',
    '/(\\s+)' . $prefix . '([a-z0-9_]{1,15})/i',
  );
  $replacements = array(
    '><a href="' . $destination . '${1}">' . $prefix . '${1}</a>',
    '<a href="' . $destination . '${1}">' . $prefix . '${1}</a>',
    '${1}<a href="' . $destination . '${2}">' . $prefix . '${2}</a>',
  );
  return preg_replace($matches, $replacements, $text);
}