function _tweet_make_url in Tweet 6
Same name and namespace in other branches
- 5.2 tweet.module \_tweet_make_url()
 - 5 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
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 185  - Builds links to post pages to twitter.
 
Code
function _tweet_make_url($q = '') {
  if (!$q) {
    global $base_url;
    $q = $base_url . base_path() . $_GET['q'];
  }
  $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, $url, 'cache', $expire);
  return $url;
}