setQuery('SELECT `value` FROM `#__openaire` WHERE `key` = \'invenioUrl\''); $this->invenioUrl = $db->loadResult(); $db -> setQuery('SELECT `value` FROM `#__openaire` WHERE `key` = \'invenioPassword\''); $this->invenioPassword = $db->loadResult(); $db -> setQuery('SELECT `value` FROM `#__openaire` WHERE `key` = \'validatorBaseUrl\''); $this->validatorBaseUrl = $db->loadResult(); $db -> setQuery('SELECT `value` FROM `#__openaire` WHERE `key` = \'validatorPassword\''); $this->validatorPassword = $db->loadResult(); if (!(substr_compare($this->validatorBaseUrl, "/", -1, 1) === 0)) $this->validatorBaseUrl .= "/"; } public function createRedirectUrl($referer) { $referer = ($referer != null)?$referer:$this->invenioUrl.'/deposit?style=portal&ln=en'; $user = array( "email" => JFactory::getUser()->email, "fullname" => JFactory::getUser()->name, "nickname" => JFactory::getUser()->username, "id" => JFactory::getUser()->id, "__timeout__" => time() + 3600, "__userip__" => $this->getUserIP()); $assertion = json_encode($user); $digest = hash_hmac('sha1', $assertion, $this->invenioPassword); $params = 'assertion='.urlencode($assertion). '&robot=OpenAIRE_Portal'. '&login_method=OpenAIRE'. '&digest='.$digest. '&referer='.$referer; $invenioUrl = $this->invenioUrl.'/youraccount/robotlogin?'.$params; JLog :: getInstance() -> addEntry(array('level' => 'info', 'comment' => 'redirect url: '.$invenioUrl)); return $invenioUrl; } public function createValidatorRedirectUrl() { $validatorUrl = $this->validatorBaseUrl; if (!JFactory::getUser()->guest) { $username = JFactory::getUser()->username; $ip = $this->getUserIP(); $valid = (time() + 3600)*1000; $signature = hash_hmac('sha1', $username . $ip . $valid, $this->validatorPassword); $request = "user=".$username."&valid=".$valid."&ip=".$ip."&signature=".base64_encode($signature); $validatorUrl .= "portalLogin.action?".$request; JLog :: getInstance() -> addEntry(array('level' => 'info', 'comment' => 'redirect url: '.$validatorUrl)); } return $validatorUrl; } private function getUserIP() { $ip = null; if (function_exists('apache_request_headers')) { $headers = apache_request_headers(); if (isset($headers['X-Forwarded-For'])) { $ip = $headers['X-Forwarded-For']; } } if (!isset($ip)) $ip = $_SERVER['REMOTE_ADDR']; return $ip; } } ?>