You are here

function twitter_profile_widget_block_content in Twitter Profile Widget 6

Return content for twitter profile block

1 call to twitter_profile_widget_block_content()
twitter_profile_widget_block in ./twitter_profile_widget.module
Implementation of hook_block().

File

./twitter_profile_widget.module, line 86

Code

function twitter_profile_widget_block_content() {

  // Main settings
  $username = trim(variable_get('twitter_profile_widget_username', 'Twitter'));
  $external_js = variable_get('twitter_profile_widget_js', 'external') == 'external' ? TRUE : FALSE;

  // Preferences
  $post_amount = variable_get('twitter_profile_widget_post_amount', '5');
  $widget_behavior = variable_get('twitter_profile_widget_behavior', 'load_all_tweets') == 'load_all_tweets' ? 'all' : 'default';
  $loop_results = $widget_behavior == 'all' ? 'false' : variable_get('twitter_profile_widget_loop_results', FALSE);
  $loop_results = $loop_results == 'false' ? 'false' : 'true';
  $tweet_intervals = trim(variable_get('twitter_profile_widget_tweet_intervals', 5)) * 1000;
  $poll_for_new_results = variable_get('twitter_profile_widget_poll_for_new_results', FALSE) ? 'true' : 'false';
  $include_scrollbar = variable_get('twitter_profile_widget_include_scrollbar', FALSE) ? 'true' : 'false';
  $show_avatars = variable_get('twitter_profile_widget_show_avatars', FALSE) ? 'true' : 'false';
  $show_timastamp = variable_get('twitter_profile_widget_show_timestamp', TRUE) ? 'true' : 'false';
  $show_hashtags = variable_get('twitter_profile_widget_show_hashtags', TRUE) ? 'true' : 'false';

  // Apprearance
  $shell_bg_color_type = variable_get('twitter_profile_widget_shell_bg_color_type', 'color');
  $shell_bg_color = $shell_bg_color_type == 'transparent' ? 'none' : '#' . trim(variable_get('twitter_profile_widget_shell_bg_color', 'FFFFFF'));
  $shell_text_color = '#' . trim(variable_get('twitter_profile_widget_shell_text_color', '425367'));
  $tweet_bg_color_type = variable_get('twitter_profile_widget_tweet_bg_color_type', 'color');
  $tweet_bg_color = $tweet_bg_color_type == 'transparent' ? 'none' : '#' . trim(variable_get('twitter_profile_widget_tweet_bg_color', 'FFFFFF'));
  $tweet_text_color = '#' . trim(variable_get('twitter_profile_widget_tweet_text_color', '3E465B'));
  $tweet_links_color = '#' . trim(variable_get('twitter_profile_widget_tweet_links_color', '0178B4'));

  // Dimensions
  $width = variable_get('twitter_profile_widget_autowidth', FALSE) ? "'auto'" : trim(variable_get('twitter_profile_widget_width', '180'));
  $height = trim(variable_get('twitter_profile_widget_height', '300'));

  // Follow us button
  $follow_us_enabled = variable_get('twitter_profile_widget_follow_us_enable', TRUE);
  $follow_us_text = trim(variable_get('twitter_profile_widget_follow_us_text', 'Follow us on twitter'));
  $follow_us_url = trim(variable_get('twitter_profile_widget_follow_us_link', 'http://twitter.com/twitter'));
  $follow_us_link = l($follow_us_text, $follow_us_url, array(
    'absolute' => TRUE,
  ));

  // Widget type
  $widget_type = variable_get('twitter_profile_widget_type', 'profile');
  $twitter_list = trim(variable_get('twitter_profile_widget_twitterlist', ''));
  $captions = '';
  if ($widget_type == 'list') {
    $set = "setList('{$username}', '{$twitter_list}')";
    $title = variable_get('twitter_profile_widget_twitterlist_title', t('Everything we do at'));
    $subject = variable_get('twitter_profile_widget_twitterlist_subject', t('the twoffice'));
    $captions = "\n      title: '{$title}',\n      subject: '{$subject}',\n    ";
  }
  elseif ($widget_type == 'faves') {
    $set = "setUser('{$username}')";
    $title = variable_get('twitter_profile_widget_faves_title', t('Best twitts according to'));
    $subject = variable_get('twitter_profile_widget_faves_subject', t('Me'));
    $captions = "\n      title: '{$title}',\n      subject: '{$subject}',\n    ";
  }
  elseif ($widget_type == 'profile') {
    $set = "setUser('{$username}')";
  }

  // Load twitter widget with custom settings
  $twitter_script = "\n    new TWTR.Widget({\n      version: 2,\n      type: '{$widget_type}',\n      rpp:  {$post_amount},\n      interval: {$tweet_intervals},\n      {$captions}\n      width: {$width},\n      height: {$height},\n      theme: {\n        shell: {\n          background: '{$shell_bg_color}',\n          color: '{$shell_text_color}'\n        },\n        tweets: {\n          background: '{$tweet_bg_color}',\n          color: '{$tweet_text_color}',\n          links: '{$tweet_links_color}'\n        }\n      },\n      features: {\n        scrollbar: {$include_scrollbar},\n        loop: {$loop_results},\n        live: {$poll_for_new_results},\n        hashtags: {$show_hashtags},\n        timestamp: {$show_timastamp},\n        avatars: {$show_avatars},\n        behavior: '{$widget_behavior}'\n      }\n    }).render().{$set}.start();";
  return theme('twitter_profile_block', $twitter_script, $follow_us_enabled, $follow_us_link, $external_js);
}