Small URL Service (tiny url) for SFX
Tags: elympics
, sfx
, tinyurl
, smallurl
, url-truncation
, sfx-menu
Last Updated: Feb 19, 2010 17:27
- Description
The Small URL Service for SFX uses a combination of AJAX and a locally installed cgi script to dynamically grab a small URL from a URL truncation service. While this example uses TRUNC -http://www.exlibrisgroup.org/display/CrossProductCC/TRUNC+-+URL+Truncator+%28tinyurl%29 - a locally developed small url link server, you could easily modify the cgi script to get a small url from a service like tinyurl.com, using their api.
- Author: Mark Dehmlow
- Additional author(s):
- Institution: University of Notre Dame
- Year: 2010
- License: GNU GPL version 3, Copyright 2010 University of Notre Dame/Hesburgh Libraries
- Link to terms: http://www.gnu.org/licenses/gpl-3.0.html
- Skill required for using this code:
basic
State
Stable
Programming language
Javascript and PERL
Software requirements
SFX
Screen captures
![]()
SFX Menu Before Selecting Service
![]()
SFX Menu After Selecting Service
Download
ajax javascript http://www.exlibrisgroup.org/download/attachments/26739465/ajax.js
cgi script http://www.exlibrisgroup.org/download/attachments/26739465/smallUrl.cgi
Working example
http://link.library.nd.edu/dlx5c http://link.library.nd.edu/0qibb
Using the following Ex Libris open interfaces
Templates
Release notes
Version 1
Initial Release
Installation instructions
| The basic process that this uses can be ported to virtually any product with a little modification to the javascript, html, and the location of the cgi script. |
There are three items needed to have this work in you SFX menu.
1. You need to install a cgi script (http://www.exlibrisgroup.org/download/attachments/26739465/smallUrl.cgi)
on your server in the instance/cgi directory. Usually, I create a local directory to house local
scripts which makes it easy to find them again and make sure they don't get overwritten.
- You may need to alter the first line to point to your PERL path.

To get your PERL path, type 'which perl' at the command line. 
Because browsers implement ajax in a secure way, you must install this cgi script on your SFX server - ajax will not allow cross-domain querying. This is why the cgi script handles the call to the service api and hands the result back to the ajax instead of the ajax handling everything.
2. Next, install the generic ajax.js script (http://www.exlibrisgroup.org/download/attachments/26739465/ajax.js).
Install this in the instance/templates/js directory. Usually, I create a local directory to house local
scripts which makes it easy to find them again and make sure they don't get overwritten.
This is a generic javascript file that takes a couple of inputs - first, the URL for the cgi script you want
to invoke, the id of the html element that you want to insert the cgi's output into, and an insert type - right now
there is only one insert type - form_input, but can be expanded later.
3. Add HTML to two templates:
- the call to the javascript must go in the <header> tag, templates/sfxmenu/sfxmenu.tmpl
- whichever template section you would like the user to get the small URL from
Comments
Text...

