You are here

function shurly_expand in ShURLy 8

Same name and namespace in other branches
  1. 6 shurly.module \shurly_expand()
  2. 7 shurly.module \shurly_expand()

Function to get the long url.

2 calls to shurly_expand()
DefaultController::shurly_service_expand in shurly_service/src/Controller/DefaultController.php
shurly_service_expand in shurly_service/shurly_service.inc
Callback for shurly/api/shorten.

File

./shurly.module, line 195
Description http://www.youtube.com/watch?v=Qo7qoonzTCE.

Code

function shurly_expand($short, $account = NULL) {
  global $base_url;
  $error = '';
  $success = FALSE;
  $rate_limit = shurly_rate_limit_allowed($account);
  if (!$rate_limit['allowed']) {
    $error = t('Rate limit exceeded. You are limited to @rate requests per @time minute period.', [
      '@rate' => $rate_limit['rate'],
      '@time' => $rate_limit['time'],
    ]);
  }
  elseif ($redirect = shurly_get_redirect($short, TRUE)) {
    $success = TRUE;
    $long_url = $redirect->destination;
  }
  else {
    $error = t('Not found');
  }
  return [
    'success' => $success,
    'error' => $error,
    'longUrl' => $long_url,
    'shortUrl' => _surl($short, [
      'absolute' => TRUE,
    ]),
  ];
}