You are here

function twitter_views_handler_field_formatted_tweet::render in Twitter 7.5

Same name and namespace in other branches
  1. 7.6 twitter_views_field_handlers.inc \twitter_views_handler_field_formatted_tweet::render()

Render the field.

Parameters

array $values: The values retrieved from the database.

Overrides views_handler_field::render

File

./twitter_views_field_handlers.inc, line 165
Views handlers for Twitter module.

Class

twitter_views_handler_field_formatted_tweet
Renders a tweet as it is presented at Twitter.com.

Code

function render($values) {
  drupal_add_js('//platform.twitter.com/widgets.js', 'external');
  drupal_add_css(drupal_get_path('module', 'twitter') . '/twitter.css');
  module_load_include('inc', 'twitter');

  // Load tweet and author.
  $status = twitter_status_load($values->twitter_id);
  $author = twitter_account_load($status->screen_name, FALSE);

  // Replace retweet data
  if (preg_match('/^RT\\s@(\\w+)\\:\\s/', $status->text, $matches)) {
    module_load_include('inc', 'twitter');

    // Use a Forced connection because RTs will probably be from accounts not
    // defined at our Twitter config.
    $twitter = twitter_connect(NULL, FALSE, TRUE);
    $status->text = str_replace($matches[0], '', $status->text);
    $author = $twitter
      ->users_show($matches[1]);
  }

  // Render the tweet.
  $output = theme('twitter_status', array(
    'status' => $status,
    'author' => $author,
    'reply' => t('Reply'),
    'retweet' => t('Retweet'),
    'favorite' => t('Favorite'),
  ));
  return str_replace('http:', '', $output);
}