You are here

function _tweet_make_url in Tweet 5.2

Same name and namespace in other branches
  1. 5 tweet.module \_tweet_make_url()
  2. 6 tweet.module \_tweet_make_url()

Retrieves and beautifies the abbreviated URL.

Parameters

$q: The URL of the page for which to create the abbreviated URL. If not passed uses the current page.

Return value

An abbreviated URL.

See also

_tweet_to_twitter()

_tweet_get_url()

1 call to _tweet_make_url()
_tweet_to_twitter in ./tweet.module
Creates a link to post a URL and optionally title to twitter. Uses the current page by default.

File

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

Code

function _tweet_make_url($q = '') {
  if (!$q) {
    $q = url($_GET['q'], array(
      'absolute' => TRUE,
    ));
  }
  $cached = cache_get($q);
  if ($cached->data) {
    return $cached->data;
  }
  $url = _tweet_get_url($q);

  //If the primary service fails, try the secondary service.
  if (!$url) {
    $url = _tweet_get_url($q, variable_get('tweet_service_backup', 'TinyURL'));

    //If the secondary service fails, use the original URL.
    if (!$url) {
      $url = $q;
    }
  }

  //Replace "http://" with "www." if the URL is abbreviated because it's shorter.
  if ($url != $q) {
    $url = drupal_substr($url, 7);
    $url = 'www.' . $url;
  }
  $expire = time() + 60 * 60 * 24 * 7 * 3;
  cache_set($q, 'cache', $url, $expire);
  return $url;
}