You are here

function tweetbutton_tweet_get_attributes in Tweet Button 7.2

Same name and namespace in other branches
  1. 8 tweetbutton.module \tweetbutton_tweet_get_attributes()

Helper function to build the required tweet attributes.

Parameters

$options: Context specific options

Return value

List of attributes to be rendered for twitter tweetbutton

1 call to tweetbutton_tweet_get_attributes()
theme_tweetbutton_tweet_display in ./tweetbutton.module

File

./tweetbutton.module, line 337

Code

function tweetbutton_tweet_get_attributes($options = array()) {
  global $language;
  $default_option = array(
    'type' => variable_get('tweetbutton_button', 'vertical'),
    'tweet_text' => variable_get('tweetbutton_tweet_text'),
    'language' => variable_get('tweetbutton_language'),
    'account' => variable_get('tweetbutton_account'),
    'rel_account' => variable_get('tweetbutton_rel_account_name'),
    'rel_desc' => variable_get('tweetbutton_rel_account_description'),
    'size' => variable_get('tweetbutton_size', 'medium'),
  );
  if (empty($options['url'])) {
    $options['url'] = url($_GET['q'], array(
      'absolute' => TRUE,
    ));
  }
  if (empty($options['count_url'])) {
    $options['count_url'] = $options['url'];
  }
  if (module_exists('shorten') && ($service = variable_get('tweetbutton_shorten_service'))) {
    $url = shorten_url($options['url'], $service);

    // if www => http://  replacement if enabled
    if (variable_get('shorten_www', TRUE)) {
      if (strpos($url, 'www.') === 0) {
        $url = drupal_substr($url, 4);
        $url = 'http://' . $url;
      }
    }
    $options['url'] = $url;
  }
  $options += $default_option;
  $attributes = array(
    'data-size' => $options['size'],
    'data-count' => $options['type'],
    'data-via' => $options['account'],
    'data-related' => $options['rel_account'] . ':' . $options['rel_desc'],
    'data-text' => $options['tweet_text'],
    'data-counturl' => $options['count_url'],
    'data-url' => $options['url'],
    'data-lang' => $options['language'] == 'auto' ? $language->language : $options['language'],
    'class' => 'twitter-share-button',
  );
  return $attributes;
}