You are here

function twitter_pull_add_links in Twitter Pull 7.2

Same name and namespace in other branches
  1. 6.2 twitter_pull.module \twitter_pull_add_links()
  2. 6 twitter_pull.module \twitter_pull_add_links()
  3. 7 twitter_pull.module \twitter_pull_add_links()

Automatically add links to URLs and Twitter usernames in a tweet.

1 call to twitter_pull_add_links()
twitter-pull-listing.tpl.php in ./twitter-pull-listing.tpl.php
Theme template for a list of tweets.

File

./twitter_pull.module, line 205
Twitter Pull module.

Code

function twitter_pull_add_links($text) {
  $pattern = '#(https?)://([^\\s\\(\\)\\,]+)#ims';
  $repl = '<a href="$1://$2" rel="nofollow" title="$1://$2">$2</a>';
  $text = preg_replace($pattern, $repl, $text);
  $pattern = '#@(\\w+)#ims';
  $repl = '<a href="//twitter.com/$1" rel="nofollow" title="@$1">@$1</a>';
  $text = preg_replace($pattern, $repl, $text);
  $pattern = '/[#]+([A-Za-z0-9-_]+)/';
  $repl = '<a href="//twitter.com/#!/search?q=%23$1" title="#$1" rel="nofollow">#$1</a>';
  $text = preg_replace($pattern, $repl, $text);
  return filter_xss($text);
}