-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
terms tool integrated to lisencing, ebsco service added
- Loading branch information
Showing
46 changed files
with
780 additions
and
2,930 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
|
||
if (!function_exists('safe_file_rewrite')) { | ||
/** | ||
* Safely rewrites a file | ||
* | ||
* @param string $fileName A path to a file | ||
* | ||
* @param string $dataToSave the string to rewrite the file | ||
*/ | ||
function safe_file_rewrite($fileName, $dataToSave) | ||
{ | ||
if (!is_writable($fileName)) { | ||
throw new Exception("$fileName is not writeable."); | ||
} | ||
|
||
if ($fp = fopen($fileName, 'w')) { | ||
$startTime = microtime(TRUE); | ||
|
||
do { | ||
$canWrite = flock($fp, LOCK_EX); | ||
// If lock not obtained sleep for 0 - 100 milliseconds, to avoid collision and CPU load | ||
if (!$canWrite) { | ||
usleep(round(rand(0, 100) * 1000)); | ||
} | ||
} while ((!$canWrite) and ((microtime(TRUE) - $startTime) < 5)); | ||
|
||
//file was locked so now we can store information | ||
if ($canWrite) { | ||
fwrite($fp, $dataToSave); | ||
flock($fp, LOCK_UN); | ||
} | ||
fclose($fp); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
require_once 'safe_file_rewrite.php'; | ||
|
||
if (!function_exists('write_php_ini')) { | ||
/** | ||
* Safely writes to a .ini file from an array | ||
* | ||
* @param string $file A path to a .ini file | ||
* | ||
* @param array $array The array to write as a .ini file | ||
* integer key of the column you wish to retrieve, or it | ||
* may be the string key name for an associative array. | ||
*/ | ||
function write_php_ini($file, $array) | ||
{ | ||
$res = array(); | ||
foreach($array as $key => $val) | ||
{ | ||
if(is_array($val)) | ||
{ | ||
$res[] = "[$key]"; | ||
foreach($val as $skey => $sval) $res[] = "$skey = ".(is_numeric($sval) ? $sval : '"'.addcslashes($sval, '"').'"'); | ||
} | ||
else $res[] = "$key = ".(is_numeric($val) ? $val : '"'.addcslashes($val, '"').'"'); | ||
} | ||
safe_file_rewrite($file, implode("\r\n", $res)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
/* | ||
************************************************************************************************************************** | ||
** CORAL Licensing Module Terms Tool Add-On v. 1.0 | ||
** | ||
** Copyright (c) 2010 University of Notre Dame | ||
** | ||
** This file is part of CORAL. | ||
** | ||
** CORAL is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. | ||
** | ||
** CORAL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
** | ||
** You should have received a copy of the GNU General Public License along with CORAL. If not, see <http://www.gnu.org/licenses/>. | ||
** | ||
************************************************************************************************************************** | ||
*/ | ||
|
||
|
||
|
||
class EBSCOService extends Object { | ||
|
||
protected $issn; | ||
protected $isbn; | ||
protected $config; | ||
protected $error; | ||
protected $open_url; | ||
protected $object_title; | ||
|
||
protected function init(NamedArguments $arguments) { | ||
parent::init($arguments); | ||
$this->issn = $arguments->issn; | ||
$this->isbn = $arguments->isbn; | ||
$this->config = new Configuration; | ||
|
||
//determine the full open URL | ||
//get the ISBN or ISSN passed in | ||
if ($this->isbn){ | ||
$stringAppend = $this->isbn; | ||
}else{ | ||
$stringAppend = $this->issn; | ||
} | ||
|
||
//get the client identifier out of the config terms | ||
$client_identifier = $this->config->terms->client_identifier; | ||
|
||
$this->open_url = "https://api.ebsco.io/rm/rmaccounts/" . $client_identifier . "/titles?search=" . $stringAppend . "&searchfield=isxn&selection=selected&orderby=relevance&count=5&offset=1"; | ||
} | ||
|
||
|
||
public function getTargets() { | ||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_URL,$this->open_url); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, [ | ||
'Accept: application/json', | ||
'x-api-key: '.$this->config->terms->sid, | ||
]); | ||
|
||
//Make the call to EBSCO KB and load results | ||
$response = curl_exec($ch); | ||
curl_close ($ch); | ||
|
||
$responseArray = json_decode($response, true); | ||
|
||
//get the title of the resource to use in getTitle() | ||
$this->object_title = $responseArray['titles'][0]['titleName']; | ||
|
||
$targetArray = array(); | ||
|
||
//get the package name and URL for all packages and put into target array | ||
foreach($responseArray['titles'] as $title) { | ||
foreach($title['customerResourcesList'] as $package) | ||
if ($package['url']) { | ||
$targetArray[] = array( | ||
'public_name' => $package['packageName'], | ||
'target_url' => $package['url'] | ||
); | ||
} | ||
} | ||
|
||
return $targetArray; | ||
} | ||
|
||
|
||
public function getTitle() { | ||
|
||
//get title for object from variable | ||
$title = $this->object_title; | ||
|
||
//alternatively like SFX and SerialsSolutions: make a new call to EBSCO KB and load results | ||
/* | ||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_URL,$this->open_url); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, [ | ||
'Accept: application/json', | ||
'x-api-key: '.$this->config->terms->sid, | ||
]); | ||
$response = curl_exec($ch); | ||
curl_close ($ch); | ||
$responseArray = json_decode($response, true); | ||
$title = $responseArray['titles'][0]['titleName']; | ||
*/ | ||
|
||
return $title; | ||
} | ||
|
||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,9 @@ host = "" | |
name = "" | ||
username = "" | ||
password = "" | ||
|
||
[terms] | ||
resolver= | ||
open_url= | ||
sid= | ||
client_identifier= |
Oops, something went wrong.