View source
<?php
function twitter_profile_widget_help($path, $arg) {
switch ($path) {
case 'admin/settings/twitter_profile_widget':
return t("Twitter profile widget provides configurable block with user's latest twits.");
case 'admin/help#twitter_profile_widget':
return '<p>' . t("Twitter profile widget provides configurable block with user's latest twits.") . '</p>';
}
}
function twitter_profile_widget_menu() {
$items = array();
$items['admin/settings/twitter_profile_widget'] = array(
'title' => 'Twitter profile widget',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'twitter_profile_widget_admin',
),
'access arguments' => array(
'administer twitter profile widget',
),
'type' => MENU_NORMAL_ITEM,
'file' => 'twitter_profile_widget.admin.inc',
);
return $items;
}
function twitter_profile_widget_perm() {
return array(
'administer twitter profile widget',
);
}
function twitter_profile_widget_block($op = 'list', $delta = 0, $edit = array()) {
if ($op == 'list') {
$block[] = array(
'info' => t('Twitter Profile Widget block'),
'weight' => 0,
);
return $block;
}
elseif ($op == 'view') {
$block = array(
'subject' => '<ins class = "tpw_title">' . t('Twitter Updates') . '</ins>',
'content' => twitter_profile_widget_block_content(),
);
return $block;
}
}
function twitter_profile_widget_init() {
$module_path = drupal_get_path('module', 'twitter_profile_widget');
drupal_add_css($module_path . '/twitter_profile_widget.css');
if (variable_get('twitter_profile_widget_js', 'external') == 'internal') {
drupal_add_js($module_path . '/js/widget.js');
}
}
function twitter_profile_widget_theme() {
return array(
'twitter_profile_block' => array(
'arguments' => array(
'twitter_script' => NULL,
'follow_us_enabled' => NULL,
'follow_us_link' => NULL,
'external_js' => NULL,
),
'template' => 'twitter-profile-widget',
),
);
}
function twitter_profile_widget_block_content() {
$username = trim(variable_get('twitter_profile_widget_username', 'Twitter'));
$external_js = variable_get('twitter_profile_widget_js', 'external') == 'external' ? TRUE : FALSE;
$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';
$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'));
$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_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 = 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}')";
}
$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);
}