You are here

function twitter_profile_widget_start in Twitter Profile Widget 7

Function returns block content for twitter profile widget

1 call to twitter_profile_widget_start()
twitter_profile_widget_block_view in ./twitter_profile_widget.module
Implements hook_block_view().

File

./twitter_profile_widget.module, line 88

Code

function twitter_profile_widget_start() {

  // Main settings
  $username = trim(variable_get('twitter_profile_widget_username', 'Twitter'));

  // 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 = '';
  $set = '';
  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', array(
    'twitter_script' => $twitter_script,
    'follow_us_enabled' => $follow_us_enabled,
    'follow_us_link' => $follow_us_link,
  ));
}