You are here

function _tweet_to_twitter in Tweet 5.2

Same name and namespace in other branches
  1. 5 tweet.module \_tweet_to_twitter()
  2. 6.4 tweet.module \_tweet_to_twitter()
  3. 6 tweet.module \_tweet_to_twitter()
  4. 6.2 tweet.module \_tweet_to_twitter()
  5. 6.3 tweet.module \_tweet_to_twitter()
  6. 7.4 tweet.module \_tweet_to_twitter()

Creates a link to post a URL and optionally title to twitter. Uses the current page by default.

Parameters

$type: Specifies what will show up in the link: the twitter icon, the twitter icon and text, or just text. Pass 'icon' to show just the icon, 'icon_text' to show the icon and text, and 'text' to show just the text. Required if display options for nodes are set to 'none' on the settings page.

$format: A string representing the tweet text, optionally with the case-insensitive tokens [url] and [title]. If not passed, the format from the settings page will be used.

$nid: The NID of the node for which the twitter link should be constructed.

$q: The absolute URL of the page for which the twitter link should be constructed. If this is not the current page, the title must be set manually, or it will be incorrect.

Return value

A themed link to post the specified or current page to twitter.

See also

_tweet_make_url()

_tweet_get_title()

_tweet_process()

tweet_to_twitter()

tweet_link()

2 calls to _tweet_to_twitter()
tweet_link in ./tweet.module
Implementation of hook_link().
tweet_to_twitter in ./tweet.module
Returns a link from _tweet_to_twitter().

File

./tweet.module, line 95
Builds links to post pages to twitter.

Code

function _tweet_to_twitter($type = '', $format = '', $nid = '', $q = '') {
  if ($nid && !$q) {
    $q = url('node/' . $nid, array(
      'absolute' => TRUE,
    ));
  }
  $url = _tweet_make_url($q);
  $title = _tweet_get_title($nid);
  if (!$format) {
    $format = variable_get('tweet_format', '[url] [title]');
  }
  $tweet = _tweet_process($format, array(
    '[url]' => $url,
    '[title]' => $title,
  ));
  $path = 'http://twitter.com/home';
  $text = t('Post to Twitter');
  $image_location = drupal_get_path('module', 'tweet') . '/icon.png';
  global $base_url;
  $image = '<img src="' . $base_url . base_path() . check_plain(variable_get('tweet_image', $image_location)) . '" alt="' . $text . '" title="' . $text . '" />';
  if (!$type) {

    //Note that $type can be 'none', in which case nothing shows up.
    $type = variable_get('tweet_node', 'icon');
  }
  if ($type == 'icon') {
    $show = $image;
  }
  else {
    if ($type == 'icon_text') {
      $show = $image . ' ' . $text;
    }
    else {
      if ($type == 'text') {
        $show = $text;
      }
    }
  }
  $attributes = array(
    'class' => 'tweet',
    'rel' => 'nofollow',
  );
  if (variable_get('tweet_new_window', 'target') == 'target') {
    $attributes['target'] = '_blank';
  }
  else {
    if (variable_get('tweet_new_window', 'target') == 'js') {
      $attributes['onClick'] = "window.open('{$path}?status={$tweet}','twitter','')";
      $path = $_GET['q'];
      $tweet = 'sent';
    }
  }
  return array(
    'title' => $show,
    'href' => $path,
    'attributes' => $attributes,
    'query' => 'status=' . $tweet,
    'html' => TRUE,
  );
}