Left Menu Right Menu
March 7, 2016

Create a Permalink for Primo Search Results

This customization allows users to generate a permalink to a search query in Primo.  
This feature has three main components:
  • The JavaScript that adds the “generate permalink” button to the Primo interface, and the associated code that takes the current search and facet parameters and sends them to the create.php script.
  • The create.php script takes those values and stores them in a local database, and returns the permalink and injects that into the Primo interface.  This permalink (http://library.wwu.edu/goto/?eeDAJHRZNV) consists of a ‘goto’ address that contains the key (or ID) that points to that record in the database.  In the example above, the key returned by this script (from the database) was eeDAJHRZNV.   The key in our system is randomly generated, rather than using the sequential record_id value.
  • When the end-user visits the permalink (http://library.wwu.edu/goto/?eeDAJHRZNV), the index.php file in the /goto/ folder takes the querystring value (eeDAJHRZNV) and passes it to the lookup.php script, which does a database lookup based on that key, and reconstructs the target URL, and redirects the browser to that location.
This feature uses a locally-hosted database to store the permalinks.

Once this customization is implemented, A “Generate Permalink” button is displayed above every result set in Primo.  Clicking this button presents the user with a short URL that can be distributed via email.  Clicking the permalink from email or other application re-executes the original search and presents the user with the result set in Primo.

Button before clicking:

After clicking:

Link to examples: 
http://library.wwu.edu/onesearch - Perform any search and click on the “Generate Permalink” button at the top of the search results.
Example permalink for Advanced search of maps with “Mount Baker” in the subject: http://library.wwu.edu/goto/?eeDAJHRZNV

Created by: David Bass & Lesley Lowery, Western Washington University

System components: CSS, JS, locally or remotely-hosted database to keep the permalinks in - this is what makes the permalinks “permanent”, PHP scripts.

Skill set requirements: JavaScript, PHP, and some CSS for styling the “Generate Permalink” button.

Accessibility: The permalink button has been made keyboard-accessible, and screen reader cues have been added.

Browser compatibility: IE10+, current versions of Safari, Firefox, and Chrome.

Mobile compatibility: Displays as expected on iOS and Android mobile devices.

Implementation steps:

Getting the files
Download the source files js/common.js, and js/permalink.js and place them in the file storage location of your choice (either on a local server or loaded to the PBO).  
Enter the following lines in your Primo view’s footer.html file (configured in the PBO Static HTML tile for that view):

var WWU_PRIMO = {
institution : "01ALLIANCE_INST", /*what is your institution code?*/
file_host : "/path/to/primo",   /* where are your Primo files hosted? This could be the address of your PBO-uploaded files, or the local web server where you store your Primo customization files. */
GOTO_PERMALINK_URL : "http://my.library.any.edu/goto/?",       /* What URL stem do your permalinks use? For example, "http://dev1.library.wwu.edu/goto/?" (Depending on your redirector script, you may not need the question mark.)*/
error_email : "help.email@any.edu",         /* what email address should we show the end-user to ask for help?  */
DEV_MODE : false,
<script type="text/javascript"  src="/path/to/common.js"></script>
<script type="text/javascript"  src="/path/to/permalink.js"></script>

Finishing up
  • Download permalinks/readme.txt, permalinks/create.php and permalinks/lookup.php-redirect.php from the repository.  
  • Create a “permalinks” subdirectory in the /primo folder of your local file hosting location. 
  • Place the PHP and readme files in that new subdirectory.
  • Working with your local web server administrator, follow the instructions in readme.txt to set up your permalinks database on your local web server and create the db-connection.php file with the database access credentials.
  • Place the db-connection.php file in the /primo/permalinks directory, alongside create.php and lookup.php.

  • In your web server’s directory for the permalink database (for example, WWU uses library.wwu.edu/goto), create a new PHP file named index.php that contains the following:
    include( $_SERVER['DOCUMENT_ROOT'] . "/primo/permalinks/lookup.php");
  • Paste the contents of permalink.css into your existing Primo customized CSS file (which you can download from the PBO if you don’t have it stored on a local server).  
  • If your CSS files are stored locally, save the file.  
  • If you upload your CSS to the PBO, save and re-upload the file.  
Deploy your view and clear the browser cache to view the customization.

Related customizations
Back to Blog
Comments (0)
Reply To Article