View source
<?php
namespace Drupal\lingotek\Controller;
use Drupal\Core\Routing\TrustedRedirectResponse;
use Drupal\lingotek\Controller\LingotekControllerBase;
use Drupal\Core\Url;
class LingotekWorkbenchController extends LingotekControllerBase {
public function loadDocument($doc_id, $locale) {
return $this
->workbenchPageRedirect($doc_id, $locale);
}
protected function workbenchPageRedirect($doc_id, $locale) {
$account = $this->lingotek
->get('account');
$link = self::generateWorkbenchLink($doc_id, $locale, $account['default_client_id'], $account['access_token'], $account['login_id'], $account['login_id'], $account['use_production'] ? $account['host'] : $account['sandbox_host']);
return new TrustedRedirectResponse(Url::fromUri($link)
->toString());
}
public static function generateWorkbenchLink($document_id, $locale_code, $client_id, $access_token, $login_id, $acting_login_id = "anonymous", $base_url = "https://myaccount.lingotek.com", $expiration = NULL) {
$expiration_default = time() + 60 * 30;
$expiration = is_null($expiration) ? $expiration_default : $expiration;
$data = array(
'document_id' => $document_id,
'locale_code' => $locale_code,
'client_id' => $client_id,
'login_id' => $login_id,
'acting_login_id' => $acting_login_id,
'expiration' => $expiration,
);
$query_data = utf8_encode(http_build_query($data));
$hmac = urlencode(base64_encode(hash_hmac('sha1', $query_data, $access_token, TRUE)));
$workbench_url = $base_url . '/lingopoint/portal/wb.action?' . $query_data . "&hmac=" . $hmac;
return $workbench_url;
}
}