getId(); // fetch the access token $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $plugin->getSetting($contextId, 'orcidProfileAPIPath').OAUTH_TOKEN_URL, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => array('Accept: application/json'), CURLOPT_POST => true, CURLOPT_POSTFIELDS => http_build_query(array( 'code' => Request::getUserVar('code'), 'grant_type' => 'authorization_code', 'client_id' => $plugin->getSetting($contextId, 'orcidClientId'), 'client_secret' => $plugin->getSetting($contextId, 'orcidClientSecret') )) )); $result = curl_exec($curl); if (!$result) error_log('CURL error: ' . curl_error($curl)); $response = json_decode($result, true); curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $url = $plugin->getSetting($contextId, 'orcidProfileAPIPath') . ORCID_API_VERSION_URL . urlencode($response['orcid']) . '/' . ORCID_PROFILE_URL, CURLOPT_POST => false, CURLOPT_HTTPHEADER => array('Accept: application/json'), )); $result = curl_exec($curl); if (!$result) error_log('CURL error: ' . curl_error($curl)); $info = curl_getinfo($curl); if ($info['http_code'] == 200) { $json = json_decode($result, true); } curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $url = $plugin->getSetting($contextId, 'orcidProfileAPIPath') . ORCID_API_VERSION_URL . urlencode($response['orcid']) . '/' . ORCID_EMAIL_URL, CURLOPT_POST => false, CURLOPT_HTTPHEADER => array('Accept: application/json'), )); $result = curl_exec($curl); if (!$result) error_log('CURL error: ' . curl_error($curl)); $info = curl_getinfo($curl); if ($info['http_code'] == 200) { $json_email = json_decode($result, true); $json['email']['value'] = $json_email['email'][0]['email']; } $orcid_uri = 'http://orcid.org/' . $response['orcid']; switch (Request::getUserVar('targetOp')) { case 'register': echo '
'; break; case 'profile': // Set the ORCiD in the user profile from the response echo ''; break; case 'submit': // Submission process: Pre-fill the first author's ORCiD from the ORCiD data echo ''; break; default: assert(false); } } /** * Verify an incoming author claim for an ORCiD association. * @param $args array * @param $request PKPRequest */ function orcidVerify($args, $request) { $context = Request::getContext(); $op = Request::getRequestedOp(); $plugin = PluginRegistry::getPlugin('generic', 'orcidprofileplugin'); $templateMgr = TemplateManager::getManager($request); $contextId = ($context == null) ? 0 : $context->getId(); // fetch the access token $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $plugin->getSetting($contextId, 'orcidProfileAPIPath').OAUTH_TOKEN_URL, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => array('Accept: application/json'), CURLOPT_POST => true, CURLOPT_POSTFIELDS => http_build_query(array( 'code' => Request::getUserVar('code'), 'grant_type' => 'authorization_code', 'client_id' => $plugin->getSetting($contextId, 'orcidClientId'), 'client_secret' => $plugin->getSetting($contextId, 'orcidClientSecret') )) )); $result = curl_exec($curl); if (!$result) error_log('CURL error: ' . curl_error($curl)); $response = json_decode($result, true); if (!isset($response['orcid'])) { $templateMgr->assign(array( 'currentUrl' => $request->url(null, 'index'), 'pageTitle' => 'plugins.generic.orcidProfile.author.submission', 'message' => 'plugins.generic.orcidProfile.authFailure', )); $templateMgr->display('common/message.tpl'); exit(); } $authorDao = DAORegistry::getDAO('AuthorDAO'); $authors = $authorDao->getAuthorsBySubmissionId($request->getUserVar('articleId')); foreach ($authors as $author) { if ($author->getData('orcidToken') == $request->getUserVar('orcidToken')) { $author->setData('orcid', 'http://orcid.org/' . $response['orcid']); $author->setData('orcidToken', null); $authorDao->updateAuthor($author); $templateMgr->assign(array( 'currentUrl' => $request->url(null, 'index'), 'pageTitle' => 'plugins.generic.orcidProfile.author.submission', 'message' => 'plugins.generic.orcidProfile.author.submission.success', )); $templateMgr->display('common/message.tpl'); exit(); } } $templateMgr->assign(array( 'currentUrl' => $request->url(null, 'index'), 'pageTitle' => 'plugins.generic.orcidProfile.author.submission', 'message' => 'plugins.generic.orcidProfile.author.submission.failure', )); $templateMgr->display('common/message.tpl'); } } ?>