public function DefaultController::shurly_service_expand in ShURLy 8
1 string reference to 'DefaultController::shurly_service_expand'
- shurly_service.routing.yml in shurly_service/
shurly_service.routing.yml - shurly_service/shurly_service.routing.yml
File
- shurly_service/
src/ Controller/ DefaultController.php, line 59
Class
- DefaultController
- Default controller for the shurly_service module.
Namespace
Drupal\shurly_service\ControllerCode
public function shurly_service_expand() {
$defaults = [
'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 ? \Drupal::entityTypeManager()
->getStorage('user')
->load($uid) : NULL;
$access = $account
->hasPermission('Expand short URLs');
if ($access) {
// Only works with clean URLs.
$path = array_pop(explode('/', parse_url($input['shortUrl'], PHP_URL_PATH)));
$data = shurly_expand($path, $account);
}
else {
$data = [
'success' => FALSE,
'error' => t('Invalid API key'),
];
}
shurly_service_output($data, $input);
}