Browse Source

fixed session issues on for eds and minor changes

2.x-ebsco
Paul Pound 12 years ago
parent
commit
86ef54b274
  1. 2
      targets/cufts/theme/roblib-search-cufts.tpl.php
  2. 92
      targets/eds/includes/rest/EBSCOAPI.php
  3. 7
      targets/eds/roblib_search_eds.module
  4. 2
      targets/eds/theme/roblib-search-eds.tpl.php
  5. 14
      targets/evergreen/js/evergreen_results.js
  6. 19
      targets/evergreen/roblib_search_evergreen.module
  7. 2
      targets/evergreen/theme/roblib-search-evergreen.tpl.php

2
targets/cufts/theme/roblib-search-cufts.tpl.php

@ -18,7 +18,7 @@
?> ?>
<div class ="roblib-search-content cufts" id="roblib-search-content-cufts"> <div class ="roblib-search-content cufts" id="roblib-search-content-cufts">
<img src="<?php print $spinner_path; ?>"/> <img src="<?php print (empty($spinner_path) ? ' ' : $spinner_path); ?>"/>
</div> </div>
<div class ="roblib-search-more">Search all Journals</div> <div class ="roblib-search-more">Search all Journals</div>

92
targets/eds/includes/rest/EBSCOAPI.php

@ -1,6 +1,5 @@
<?php <?php
/** /**
* EBSCO API class * EBSCO API class
* *
@ -8,19 +7,17 @@
* *
*/ */
/** /**
* EBSCO API class * EBSCO API class
*/ */
class EBSCOAPI class EBSCOAPI {
{
/** /**
* The authentication token used for API transactions * The authentication token used for API transactions
* @global string * @global string
*/ */
private $authenticationToken; private $authenticationToken;
/** /**
* The session token for API transactions * The session token for API transactions
* @global string * @global string
@ -32,7 +29,6 @@ class EBSCOAPI
* @global object EBSCOConnector * @global object EBSCOConnector
*/ */
private $connector; private $connector;
private $config; private $config;
public function __construct($config) { public function __construct($config) {
@ -48,8 +44,7 @@ class EBSCOAPI
* @return EBSCOConnector object * @return EBSCOConnector object
* @access public * @access public
*/ */
public function connector($config) public function connector($config) {
{
if (empty($this->connector)) { if (empty($this->connector)) {
$this->connector = new EBSCOConnector($config); $this->connector = new EBSCOConnector($config);
} }
@ -57,7 +52,6 @@ class EBSCOAPI
return $this->connector; return $this->connector;
} }
/** /**
* Create a new EBSCOResponse object * Create a new EBSCOResponse object
* *
@ -66,13 +60,11 @@ class EBSCOAPI
* @return EBSCOResponse object * @return EBSCOResponse object
* @access public * @access public
*/ */
public function response($response) public function response($response) {
{
$responseObj = new EBSCOResponse($response); $responseObj = new EBSCOResponse($response);
return $responseObj; return $responseObj;
} }
/** /**
* Request authentication and session tokens, then send the API request. * Request authentication and session tokens, then send the API request.
* Retry the request if authentication errors occur * Retry the request if authentication errors occur
@ -85,8 +77,7 @@ class EBSCOAPI
* @return array An associative array with results. * @return array An associative array with results.
* @access protected * @access protected
*/ */
protected function request($action, $params = null, $attempts = 3) protected function request($action, $params = null, $attempts = 3) {
{
try { try {
$authenticationToken = $this->getAuthToken(); $authenticationToken = $this->getAuthToken();
@ -156,7 +147,7 @@ class EBSCOAPI
} }
} }
private function writeLockFile(){ private function writeTokenFile() {
$tokenFile = fopen("edstoken.txt", "w+"); $tokenFile = fopen("edstoken.txt", "w+");
$result = $this->apiAuthenticationToken(); $result = $this->apiAuthenticationToken();
fwrite($tokenFile, $result['authenticationToken'] . "\n"); fwrite($tokenFile, $result['authenticationToken'] . "\n");
@ -166,6 +157,12 @@ class EBSCOAPI
return $result['authenticationToken']; return $result['authenticationToken'];
} }
private function writeLockFile() {
$lockFile = fopen("edslock.txt", "w+");
fwrite($lockFile, 'lock');
fclose($lockFile);
}
/* /*
* Get authentication token from appication scop * Get authentication token from appication scop
* Check authToen's expiration * Check authToen's expiration
@ -175,11 +172,17 @@ class EBSCOAPI
* *
* @access public * @access public
*/ */
public function getAuthToken() { public function getAuthToken() {
$lockFile = fopen("edslock.txt", "r"); $lockFile = fopen("edslock.txt", "r");
if (empty($lockFile)) {
$this->writeLockFile();
$lockFile = fopen("edslock.txt", "r");
}
$tokenFile = fopen("edstoken.txt", "r");
if (empty($tokenFile)) {
$this->writetokenFile();
$tokenFile = fopen("edstoken.txt", "r"); $tokenFile = fopen("edstoken.txt", "r");
if(empty($lockFile) || empty($tokenFile)){
return $this->writeLockFile();
} }
while (!feof($tokenFile)) { while (!feof($tokenFile)) {
$authToken = rtrim(fgets($tokenFile), "\n"); $authToken = rtrim(fgets($tokenFile), "\n");
@ -197,10 +200,12 @@ class EBSCOAPI
fwrite($tokenFile, $result['authenticationTimeStamp']); fwrite($tokenFile, $result['authenticationTimeStamp']);
fclose($tokenFile); fclose($tokenFile);
return $result['authenticationToken']; return $result['authenticationToken'];
}else{ }
else {
return $authToken; return $authToken;
} }
}else{ }
else {
return $authToken; return $authToken;
} }
fclose($lockFile); fclose($lockFile);
@ -213,8 +218,7 @@ class EBSCOAPI
* *
* @access public * @access public
*/ */
public function apiAuthenticationToken() public function apiAuthenticationToken() {
{
$response = $this->connector->requestAuthenticationToken(); $response = $this->connector->requestAuthenticationToken();
$result = $this->response($response)->result(); $result = $this->response($response)->result();
return $result; return $result;
@ -232,35 +236,30 @@ class EBSCOAPI
$token = ''; $token = '';
// Check user's login status // Check user's login status
if(isset($_COOKIE['login'])){ /* if(isset($_COOKIE['login'])){
if($invalid=='y'){ if($invalid=='y'){
$profile = $_SESSION['sessionToken']['profile']; $profile = $_SESSION['sessionToken']['profile'];
$sessionToken = $this->apiSessionToken($authenToken, $profile,'n'); $sessionToken = $this->apiSessionToken($authenToken, $profile,'n');
$_SESSION['sessionToken']=$sessionToken; $_SESSION['sessionToken']=$sessionToken;
} }
$token = $_SESSION['sessionToken']['sessionToken']; $token = $_SESSION['sessionToken']['sessionToken'];
} } */
else if(isset($_COOKIE['Guest'])){ //else
if (isset($_COOKIE['Guest'])) {
if ($invalid == 'y') { if ($invalid == 'y') {
$profile = $_SESSION['sessionToken']['profile']; $profile = $_SESSION['sessionToken']['profile'];
if (empty($profile)) {
$profile = $_COOKIE['Guest'];
}
$sessionToken = $this->apiSessionToken($authenToken, $profile, 'y'); $sessionToken = $this->apiSessionToken($authenToken, $profile, 'y');
$_SESSION['sessionToken'] = $sessionToken; $_SESSION['sessionToken'] = $sessionToken;
} }
$token = $_SESSION['sessionToken']['sessionToken']; $token = $_SESSION['sessionToken']['sessionToken'];
}else{ }
//$xml ="Config.xml"; else {
//$dom = new DOMDocument();
//$dom->load($xml);
//$EDSCredentials = $dom ->getElementsByTagName('EDSCredentials')->item(0);
//$users = $EDSCredentials -> getElementsByTagName('User');
$profileId = $this->config['profile']; $profileId = $this->config['profile'];
//foreach($users as $user){
// $userType = $user->getElementsByTagName('ClientUser')->item(0)->nodeValue;
// if($userType == 'guest'){
// $profileId = $user -> getElementsByTagName('EDSProfile')->item(0)->nodeValue;
// break;
// }
//}
$sessionToken = $this->apiSessionToken($authenToken, $profileId, 'y'); $sessionToken = $this->apiSessionToken($authenToken, $profileId, 'y');
$_SESSION['profile'] = $profileId; $_SESSION['profile'] = $profileId;
$_SESSION['sessionToken'] = $sessionToken; $_SESSION['sessionToken'] = $sessionToken;
@ -277,8 +276,7 @@ class EBSCOAPI
* *
* @access public * @access public
*/ */
public function apiSessionToken($authenToken, $profile, $guest) public function apiSessionToken($authenToken, $profile, $guest) {
{
// Add authentication tokens to headers // Add authentication tokens to headers
$headers = array( $headers = array(
'x-authenticationToken: ' . $authenToken 'x-authenticationToken: ' . $authenToken
@ -325,7 +323,6 @@ class EBSCOAPI
return $results; return $results;
} }
/** /**
* Wrapper for retrieve API call * Wrapper for retrieve API call
* *
@ -336,8 +333,7 @@ class EBSCOAPI
* @return array An associative array of data * @return array An associative array of data
* @access public * @access public
*/ */
public function apiRetrieve($an, $db, $term) public function apiRetrieve($an, $db, $term) {
{
// Add the HTTP query params // Add the HTTP query params
$params = array( $params = array(
'an' => $an, 'an' => $an,
@ -349,15 +345,13 @@ class EBSCOAPI
return $result; return $result;
} }
/** /**
* Wrapper for info API call * Wrapper for info API call
* *
* @return array An associative array of data * @return array An associative array of data
* @access public * @access public
*/ */
public function getInfo() public function getInfo() {
{
if (isset($_SESSION['info'])) { if (isset($_SESSION['info'])) {
$InfoArray = $_SESSION['info']; $InfoArray = $_SESSION['info'];
$timestamp = $InfoArray['timestamp']; $timestamp = $InfoArray['timestamp'];
@ -366,10 +360,12 @@ class EBSCOAPI
$InfoArray = $this->apiInfo(); $InfoArray = $this->apiInfo();
$_SESSION['info'] = $InfoArray; $_SESSION['info'] = $InfoArray;
$info = $InfoArray['Info']; $info = $InfoArray['Info'];
}else{ }
else {
$info = $InfoArray['Info']; $info = $InfoArray['Info'];
} }
}else{ }
else {
// Get new Info for the profile // Get new Info for the profile
$InfoArray = $this->apiInfo(); $InfoArray = $this->apiInfo();
$_SESSION['info'] = $InfoArray; $_SESSION['info'] = $InfoArray;
@ -387,5 +383,7 @@ class EBSCOAPI
); );
return $Info; return $Info;
} }
} }
?> ?>

7
targets/eds/roblib_search_eds.module

@ -41,7 +41,7 @@ function roblib_search_eds_menu() {
$items['admin/roblib_search/eds_search'] = array( $items['admin/roblib_search/eds_search'] = array(
'title' => 'EDS search Target configuration', 'title' => 'EDS search Target configuration',
'description' => 'Configuration for the Roblib evergreen search target', 'description' => 'Configuration for the Roblib eds search target',
'page callback' => 'drupal_get_form', 'page callback' => 'drupal_get_form',
'page arguments' => array('roblib_search_eds_config_form'), 'page arguments' => array('roblib_search_eds_config_form'),
'access arguments' => array('access administration pages'), 'access arguments' => array('access administration pages'),
@ -216,11 +216,6 @@ function roblib_search_eds_get_results($query = NULL) {
} }
$config = roblib_search_eds_build_config_arr(); $config = roblib_search_eds_build_config_arr();
/*$config['user'] = variable_get('roblib_search_eds_user', 'edsusername');
$config['pass'] = variable_get('roblib_search_eds_pass', 'edspassword');
$config['profile'] = variable_get('roblib_search_eds_profile', 'edsapi');
$config['auth_url'] = variable_get('roblib_search_eds_auth_url', 'https://eds-api.ebscohost.com/Authservice/rest');
$config['rest_url'] = variable_get('roblib_search_eds_rest_url', 'http://eds-api.ebscohost.com/edsapi/rest');*/
$eds_api = new EBSCOAPI($config); $eds_api = new EBSCOAPI($config);
$number_per_page = variable_get('roblib_search_eds_num_results', '5'); $number_per_page = variable_get('roblib_search_eds_num_results', '5');
$query = urlencode($query); $query = urlencode($query);

2
targets/eds/theme/roblib-search-eds.tpl.php

@ -18,7 +18,7 @@
?> ?>
<div class ="roblib-search-content eds" id="roblib-search-content-eds"> <div class ="roblib-search-content eds" id="roblib-search-content-eds">
<img src="<?php print $spinner_path; ?>"/> <img src="<?php print (empty($spinner_path) ? ' ' : $spinner_path); ?>"/>
</div> </div>
<div class ="roblib-search-more" id="roblib-search-eds-more"></div> <div class ="roblib-search-more" id="roblib-search-eds-more"></div>

14
targets/evergreen/js/evergreen_results.js

@ -30,6 +30,13 @@ Drupal.behaviors.roblib_search_evergreen = {
}) })
items.push('</div>') items.push('</div>')
} }
if(typeof val.electronic_holdings !== 'undefined'){
items.push('<div class="evergreen-holdings">');
jQuery.each(val.electronic_holdings, function(key2, val2){
roblibEvergreenAddElectronicHoldings(val2, items);
})
items.push('</div>')
}
items.push('</div>'); items.push('</div>');
}); });
} }
@ -41,9 +48,10 @@ Drupal.behaviors.roblib_search_evergreen = {
} }
function roblibEvergreenAddHoldings(holdings, items){ function roblibEvergreenAddHoldings(holdings, items){
items.push('<div class="evergreen-holdings-item">' + holdings.call_number + ' ' + holdings.availability + '</div>'); items.push('<div class="evergreen-holdings-item">' + holdings.call_number + ' - ' + holdings.location +' (' + holdings.availability + ')</div>');
}
function roblibEvergreenAddElectronicHoldings(holdings, items){
items.push('<div class="evergreen-holdings-item"><a href="' + holdings.url + '">' + holdings.label + '</div>');
} }

19
targets/evergreen/roblib_search_evergreen.module

@ -233,6 +233,7 @@ function roblib_search_evergreen_parse_results($results, $query) {
roblib_search_evergreen_update_array($output, $index, 'date', $record->xpath('marcxml:datafield[@tag="260"]/marcxml:subfield[@code="c"]')); roblib_search_evergreen_update_array($output, $index, 'date', $record->xpath('marcxml:datafield[@tag="260"]/marcxml:subfield[@code="c"]'));
roblib_search_evergreen_update_array($output, $index, 'id', $record->xpath('marcxml:datafield[@tag="901"]/marcxml:subfield[@code="c"]')); roblib_search_evergreen_update_array($output, $index, 'id', $record->xpath('marcxml:datafield[@tag="901"]/marcxml:subfield[@code="c"]'));
roblib_search_evergreen_holdings($output, $index, $record->xpath('marcxml:datafield[@tag="852"]')); roblib_search_evergreen_holdings($output, $index, $record->xpath('marcxml:datafield[@tag="852"]'));
roblib_search_evergreen_electronic_holdings($output, $index, $record->xpath('marcxml:datafield[@tag="856"]'));
$id = $output[$index]['id']; $id = $output[$index]['id'];
$output[$index++]['url'] = variable_get('roblib_search_evergreen_url', 'http://137.149.200.52') $output[$index++]['url'] = variable_get('roblib_search_evergreen_url', 'http://137.149.200.52')
. variable_get('roblib_search_evergreen_detail_suffix', '/opac/en-CA/skin/default/xml/rdetail.xml?r=') . variable_get('roblib_search_evergreen_detail_suffix', '/opac/en-CA/skin/default/xml/rdetail.xml?r=')
@ -249,7 +250,23 @@ function roblib_search_evergreen_holdings(&$arr, $index, $xpath_result){
$call_number = $xml->xpath('marcxml:subfield[@code="c"]'); $call_number = $xml->xpath('marcxml:subfield[@code="c"]');
$arr[$index]['holdings'][$holding_index]['call_number'] = (string)$call_number[0]; $arr[$index]['holdings'][$holding_index]['call_number'] = (string)$call_number[0];
$availability = $xml->xpath('marcxml:subfield[@code="n"]'); $availability = $xml->xpath('marcxml:subfield[@code="n"]');
$arr[$index]['holdings'][$holding_index++]['availability'] = (string)$availability[0]; $arr[$index]['holdings'][$holding_index]['availability'] = (string)$availability[0];
$location = $xml->xpath('marcxml:subfield[@code="a"]');
$arr[$index]['holdings'][$holding_index++]['location'] = (string)$location[0];
}
}
function roblib_search_evergreen_electronic_holdings(&$arr, $index, $xpath_result){
$holding_index = 0;
foreach($xpath_result as $xml){
$xml->registerXPathNamespace('marcxml', 'http://www.loc.gov/MARC21/slim');
$label = $xml->xpath('marcxml:subfield[@code="y"]');
$label = (string)$label[0];
$url = $xml->xpath('marcxml:subfield[@code="u"]');
$url = (string)$url[0];
$arr[$index]['electronic_holdings'][$holding_index]['url'] = $url;
$arr[$index]['electronic_holdings'][$holding_index++]['label'] = $label;
} }
} }

2
targets/evergreen/theme/roblib-search-evergreen.tpl.php

@ -18,7 +18,7 @@
?> ?>
<div class ="roblib-search-content evergreen" id="roblib-search-content-evergreen"> <div class ="roblib-search-content evergreen" id="roblib-search-content-evergreen">
<img src="<?php print $spinner_path; ?>"/> <img src="<?php print (empty($spinner_path) ? ' ' : $spinner_path); ?>"/>
</div> </div>
<div class ="roblib-search-more" id="roblib-search-evergreen-more">Search all Results</div> <div class ="roblib-search-more" id="roblib-search-evergreen-more">Search all Results</div>
Loading…
Cancel
Save