You are here

function shorten_shorten_service in Shorten URLs 8

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

Implements hook_shorten_service().

File

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

Code

function shorten_shorten_service() {
  $services = array();
  if (\Drupal::config('shorten.settings')
    ->get('shorten_budurl')) {
    $services['budurl'] = array(
      'url' => 'http://budurl.com/api/v1/budurls/shrink?api_key=' . \Drupal::config('shorten.settings')
        ->get('shorten_budurl') . '&format=txt&long_url=',
    );
  }
  if (\Drupal::config('shorten.settings')
    ->get('shorten_ez')) {
    $services['ez'] = array(
      'url' => 'http://ez.com/api/v1/ezlinks/shrink?api_key=' . \Drupal::config('shorten.settings')
        ->get('shorten_ez') . '&format=txt&long_url=',
    );
  }
  if (\Drupal::config('shorten.settings')
    ->get('shorten_bitly_login') && \Drupal::config('shorten.settings')
    ->get('shorten_bitly_key')) {
    $services['bit.ly'] = 'https://api-ssl.bitly.com/v3/shorten?format=txt&login=' . \Drupal::config('shorten.settings')
      ->get('shorten_bitly_login') . '&apiKey=' . \Drupal::config('shorten.settings')
      ->get('shorten_bitly_key') . '&x_login=' . \Drupal::config('shorten.settings')
      ->get('shorten_bitly_login') . '&x_apiKey=' . \Drupal::config('shorten.settings')
      ->get('shorten_bitly_key') . '&longUrl=';
    $services['j.mp'] = 'https://api-ssl.bitly.com/v3/shorten?format=txt&domain=j.mp&login=' . \Drupal::config('shorten.settings')
      ->get('shorten_bitly_login') . '&apiKey=' . \Drupal::config('shorten.settings')
      ->get('shorten_bitly_key') . '&x_login=' . \Drupal::config('shorten.settings')
      ->get('shorten_bitly_login') . '&x_apiKey=' . \Drupal::config('shorten.settings')
      ->get('shorten_bitly_key') . '&longUrl=';
  }
  if (\Drupal::config('shorten.settings')
    ->get('shorten_googl')) {
    $services['goo.gl'] = array(
      'custom' => '_shorten_googl',
    );
  }
  $services += array(
    '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=',
    'ri.ms' => 'http://ri.ms/api-create.php?url=',
    'TinyURL' => 'http://tinyurl.com/api-create.php?url=',
  );
  if (\Drupal::config('shorten.settings')
    ->get('shorten_fwd4me')) {
    $services['fwd4.me'] = 'http://api.fwd4.me/?key=' . \Drupal::config('shorten.settings')
      ->get('shorten_fwd4me') . '&url=';
  }
  if (\Drupal::moduleHandler()
    ->moduleExists('shurly')) {
    $services['ShURLy'] = array(
      'custom' => '_shorten_shurly',
    );
  }

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