You are here

function _twitter_profile_widget_parse_twitter_links in Twitter Profile Widget 8

Helper function.

Parses tweet text and replaces links, at-mentions, and hashtags.

Parameters

string $text: String with the tweet.

Return value

string Converted tweet that has anchor links to Twitter entity types.

1 call to _twitter_profile_widget_parse_twitter_links()
_twitter_profile_widget_prepare_tweets in ./twitter_profile_widget.module
Helper to parse Twitter's JSON and return a normalized array of tweets.

File

./twitter_profile_widget.module, line 260
Contains twitter_profile_widget.module.

Code

function _twitter_profile_widget_parse_twitter_links($text) {

  // Links.
  $text = preg_replace('@(https?://([-\\w\\.]+)+(/([\\w/_\\.]*(\\?\\S+)?(#\\S+)?)?)?)@', '<a href="$1">$1</a>', $text);

  // @ mentions.
  $text = preg_replace('/@(\\w+)/', '<a href="//twitter.com/$1">@$1</a>', $text);

  // Hashtags.
  $text = preg_replace('/\\s#(\\w+)/', ' <a href="//twitter.com/search?q=%23$1">#$1</a>', $text);
  return $text;
}