You are here

function shurly_service_expand in ShURLy 7

Same name and namespace in other branches
  1. 8 shurly_service/shurly_service.inc \shurly_service_expand()
  2. 6 shurly_service/shurly_service.inc \shurly_service_expand()

Callback for shurly/api/shorten

1 string reference to 'shurly_service_expand'
shurly_service_menu in shurly_service/shurly_service.module
Implements hook_menu().

File

shurly_service/shurly_service.inc, line 47
Link general search functionalities to services module.

Code

function shurly_service_expand() {
  $defaults = array(
    'format' => 'json',
    // 'domain' => NULL,

    //'longUrl' => '',
    'shortUrl' => '',
    // 'login' => NULL,
    'apiKey' => NULL,
    'func' => 'urlData',
  );
  $input = $_GET + $defaults;
  module_load_include('inc', 'shurly_service', 'shurly_api_keys');
  $uid = isset($input['apiKey']) ? shurly_get_uid($input['apiKey']) : NULL;
  $account = $uid ? user_load($uid) : NULL;
  $access = user_access('Expand short URLs', $account);
  if ($access) {
    $path = array_pop(explode('/', parse_url($input['shortUrl'], PHP_URL_PATH)));

    // only works with clean URLs
    $data = shurly_expand($path, $account);
  }
  else {
    $data = array(
      'success' => FALSE,
      'error' => t('Invalid API key'),
    );
  }
  shurly_service_output($data, $input);
}