You are here

function tweet_feed_format_output in Tweet Feed 8.3

Same name and namespace in other branches
  1. 6 tweet_feed.module \tweet_feed_format_output()
  2. 7.3 tweet_feed.module \tweet_feed_format_output()
  3. 7 tweet_feed.module \tweet_feed_format_output()
  4. 7.2 tweet_feed.module \tweet_feed_format_output()
  5. 4.x tweet_feed.module \tweet_feed_format_output()

Format Tweet Output to HTML

Makes links, hash tags, and usernames clickable.

1 call to tweet_feed_format_output()
TweetFeed::saveTweet in src/Controller/TweetFeed.php
Save the tweet to our tweet entity.

File

./tweet_feed.module, line 140
Contains tweet_feed.module.

Code

function tweet_feed_format_output($tweet, $new_window = FALSE, $hash_taxonomy = FALSE, $hashtags = array()) {

  /* based on our preference, assign all links to new windows or to the same window */
  $target = $new_window == 1 ? '_blank' : '_self';

  // Look for links and make them clickable
  $tweet = preg_replace('/(((f|ht){1}tp:\\/\\/)[-a-zA-Z0-9@:%_\\+.~#?&\\/\\/=]+)/i', '<a target="' . $target . '" href="\\1">\\1</a>', $tweet);
  $tweet = preg_replace('/(((f|ht){1}tps:\\/\\/)[-a-zA-Z0-9@:%_\\+.~#?&\\/\\/=]+)/i', '<a target="' . $target . '" href="\\1">\\1</a>', $tweet);
  $tweet = preg_replace('/([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\\+.~#?&\\/\\/=]+)/i', '\\1<a target="' . $target . '" href="http:\\/\\/\\2">\\2</a>', $tweet);
  $tweet = preg_replace('/([_\\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\\.)+[a-z]{2,3})/i', '<a href="mailto:\\1">\\1</a>', $tweet);

  // Look for twitter handles and make them clickable
  // Modified so that slashes in the twitter handle are counted
  $pattern = '/@([A-Za-z0-9_]{1,15})(?![.A-Za-z])/';
  $replace = '<a target="' . $target . '" href="http://twitter.com/' . strtolower('\\1') . '">@\\1</a>';
  $tweet = preg_replace($pattern, $replace, $tweet);

  // Look for twitter hash tags and make them clickable
  // Modified so that slashes in the twitter handle are counted
  // Modified to link to taxonomy term if that checkbox is selected for this feed.
  $tweet = preg_replace('/(^|\\s)#(\\w*+)/u', '\\1<a target="' . $target . '" href="http://twitter.com/search?q=%23\\2">#\\2</a>', $tweet);
  return $tweet;
}