Skip to content

Instantly share code, notes, and snippets.

@mreidsma
Last active December 18, 2015 21:59
Show Gist options
  • Select an option

  • Save mreidsma/5851003 to your computer and use it in GitHub Desktop.

Select an option

Save mreidsma/5851003 to your computer and use it in GitHub Desktop.
Sample setup for adding license information from a text file into link resolver for Jenny at Queen's University
/* I'm assuming you are using jQuery for simplicity sake, but you can do this with straight JS too */
/* Include this file right before your closing </body> but after you include jQuery */
$(document).ready(function() {
// Get the database name.
// This script assumes there is only one, & you don't already have license link
// You'll have to account for other situations
var databaseName = encodeURIComponent($("#DatabaseCL").find("a").text());
// Do a GET request to grab the HTML for the database license info
$.get('http://path/to/get_license.php?database=' + databaseName, function(data) {
$("#DatabaseCL").append(data);
});
});
<?php
// A php script to parse the above text file to return the URL
// Make it okay to get requests from other domains (SS might not allow this on their end, though)
// May want to change the allow-origin to your 360Link installation URL
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET');
// Assuming we are given the Database name from 360Link JavaScript (see the get_license.js for details)
// The string will be URL encoded, so decode it
$database = urldecode($_GET['database']);
$row = 1;
// Start parsing through the CSV file to find the database you want
$file = new SplFileObject("licenses.csv");
$file->setFlags(SplFileObject::READ_CSV);
$file->setCsvControl(';');
foreach ($file as $data_row) {
$row++;
if(count($data_row) < 2) continue; //throw away rows that are empty or have less than the number of columns needed
// Check to see if this is the database listed
if($data_row[0] == $database) {
// Set the license link variable to the URL associated with this database
$license_link = $data[1];
break 1; // End the foreach loop
}
}
if(isset($license_link)) {
// Don't echo the link unless you have a URL
// Return the value of the URL as the HTML that will be included on the link resolver page
echo '<a href="' . $license_link . '" title="License Information">[license information]</a>';
}
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
# This is just a sample if what your text file might look like
# I formatted this one as a CSV since it's easy to work with in PHP
#Headers
"Database Name";"License URL"
# Values
"Gale Virtual Reference Library";"http://cengage.com/long-boring-license.html"
"My Favorite Database";"http://myfavoritedatabase.org/license.html"
#etc
@mreidsma
Copy link
Copy Markdown
Author

I haven't tested this, but it's a proof of concept. Should work with minor modifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment