You are here

function shorten_shorten_service in Shorten URLs 6

Same name and namespace in other branches
  1. 8.2 shorten.module \shorten_shorten_service()
  2. 8 shorten.module \shorten_shorten_service()
  3. 7.2 shorten.module \shorten_shorten_service()
  4. 7 shorten.module \shorten_shorten_service()

Implementation of hook_shorten_service().

File

./shorten.module, line 250
Shortens URLs via external services.

Code

function shorten_shorten_service() {
  $services = array();
  if (variable_get('shorten_budurl', '')) {
    $services['budurl'] = array(
      'url' => 'http://budurl.com/api/v1/budurls/shrink?api_key=' . variable_get('shorten_budurl', '') . '&format=txt&long_url=',
    );
  }
  if (variable_get('shorten_ez', '')) {
    $services['ez'] = array(
      'url' => 'http://ez.com/api/v1/ezlinks/shrink?api_key=' . variable_get('shorten_ez', '') . '&format=txt&long_url=',
    );
  }
  if (variable_get('shorten_bitly_login', '') && variable_get('shorten_bitly_key', '')) {
    $services['bit.ly'] = 'https://api-ssl.bitly.com/v3/shorten?format=txt&login=' . variable_get('shorten_bitly_login', '') . '&apiKey=' . variable_get('shorten_bitly_key', '') . '&x_login=' . variable_get('shorten_bitly_login', '') . '&x_apiKey=' . variable_get('shorten_bitly_key', '') . '&longUrl=';
    $services['j.mp'] = 'https://api-ssl.bitly.com/v3/shorten?format=txt&domain=j.mp&login=' . variable_get('shorten_bitly_login', '') . '&apiKey=' . variable_get('shorten_bitly_key', '') . '&x_login=' . variable_get('shorten_bitly_login', '') . '&x_apiKey=' . variable_get('shorten_bitly_key', '') . '&longUrl=';
  }
  $services += array(
    'cli.gs' => 'http://cli.gs/api/v1/cligs/create?appid=drupal&url=',
    'is.gd' => 'http://is.gd/api.php?longurl=',
    'migre.me' => 'http://migre.me/api.txt?url=',
    'Metamark' => 'http://metamark.net/api/rest/simple?long_url=',
    'PeekURL' => 'http://peekurl.com/api.php?desturl=',
    'qr.cx' => 'http://qr.cx/api/?longurl=',
    'redir.ec' => 'http://redir.ec/_api/rest/redirec/create?appid=drupal&url=',
    'ri.ms' => 'http://ri.ms/api-create.php?url=',
    'TinyURL' => 'http://tinyurl.com/api-create.php?url=',
  );
  if (module_exists('shorturl')) {
    $services['Drupal ShortURL module'] = array(
      'custom' => '_shorten_shorturl',
    );
  }
  if (variable_get('shorten_cligs', '')) {
    $services['cli.gs'] = 'http://cli.gs/api/v1/cligs/create?appid=drupal&key=' . variable_get('shorten_cligs', '') . '&url=';
  }
  if (variable_get('shorten_fwd4me', '')) {
    $services['fwd4.me'] = 'http://api.fwd4.me/?key=' . variable_get('shorten_fwd4me', '') . '&url=';
  }
  if (variable_get('shorten_redirec', '')) {
    $services['redir.ec'] = 'http://redir.ec/_api/rest/redirec/create?appid=drupal&apikey=' . variable_get('shorten_redirec', '') . '&url=';
  }
  if (module_exists('shurly')) {
    $services['ShURLy'] = array(
      'custom' => '_shorten_shurly',
    );
  }

  //Alphabetize. ksort() is case-sensitive.
  uksort($services, 'strcasecmp');
  return $services;
}