Browse Source

Auto-cleanup to Drupal coding standards

This commit leverages PHPCBF, an automated cleanup technique from PHP_CodeSniffer
installed via the Drupal contrib Coder module version 8.2.12
roblib
James Wilson 8 years ago
parent
commit
520a49147d
  1. 45
      ebsco/css/ebsco.css
  2. 344
      ebsco/ebsco.module
  3. 357
      ebsco/lib/EBSCOAPI.php
  4. 249
      ebsco/lib/EBSCOConnector.php
  5. 408
      ebsco/lib/EBSCODocument.php
  6. 163
      ebsco/lib/EBSCORecord.php
  7. 186
      ebsco/lib/EBSCOResponse.php
  8. 334
      ebsco/lib/sanitizer.class.php
  9. 1
      ebsco/templates/ebsco-advanced-search.tpl.php
  10. 21
      ebsco/templates/ebsco-results.tpl.php
  11. 2
      ebsco/templates/ebsco-side-facets.tpl.php

45
ebsco/css/ebsco.css

@ -97,7 +97,7 @@
padding-left: 0; padding-left: 0;
padding-right: 10px; padding-right: 10px;
margin-left: 10px; margin-left: 10px;
border-right: 1px solid #CCCCCC; border-right: 1px solid #cccccc;
} }
.ebsco ul.custom-links li:first-child { .ebsco ul.custom-links li:first-child {
@ -178,7 +178,7 @@
/** Detailed view ***/ /** Detailed view ***/
.ebsco-record .toolbar { .ebsco-record .toolbar {
border-bottom: 1px solid #EEEEEE; border-bottom: 1px solid #eeeeee;
margin-bottom: 1em; margin-bottom: 1em;
min-height: 2em; min-height: 2em;
padding-left: 1em; padding-left: 1em;
@ -224,7 +224,7 @@
padding-left: 0; padding-left: 0;
padding-right: 10px; padding-right: 10px;
margin-left: 10px; margin-left: 10px;
border-right: 1px solid #CCCCCC; border-right: 1px solid #cccccc;
line-height: 32px; line-height: 32px;
margin: 5px; margin: 5px;
} }
@ -288,7 +288,7 @@
} }
#ebsco-sort-form > div { #ebsco-sort-form > div {
border-bottom: 1px solid #CCCCCC; border-bottom: 1px solid #cccccc;
} }
#ebsco-sort-form label, #ebsco-sort-form label,
@ -384,8 +384,8 @@
.ebsco-advanced #edit-limiters hr { .ebsco-advanced #edit-limiters hr {
margin: 15px 0; margin: 15px 0;
height: 1px; height: 1px;
background-color: #CCCCCC; background-color: #cccccc;
color: #CCCCCC; color: #cccccc;
border: 0 none; border: 0 none;
} }
@ -447,15 +447,13 @@
/* RS, EMP carousel */ /* RS, EMP carousel */
#quote-carousel #quote-carousel {
{
padding: 0 10px 30px 10px; padding: 0 10px 30px 10px;
margin-top: 30px; margin-top: 30px;
} }
/* Control buttons */ /* Control buttons */
#quote-carousel .carousel-control #quote-carousel .carousel-control {
{
background: none; background: none;
color: #222; color: #222;
font-size: 2.3em; font-size: 2.3em;
@ -463,34 +461,28 @@
margin-top: 30px; margin-top: 30px;
} }
/* Previous button */ /* Previous button */
#quote-carousel .carousel-control.left #quote-carousel .carousel-control.left {
{
left: -12px; left: -12px;
} }
/* Next button */ /* Next button */
#quote-carousel .carousel-control.right #quote-carousel .carousel-control.right {
{
right: -12px !important; right: -12px !important;
} }
/* Changes the position of the indicators */ /* Changes the position of the indicators */
#quote-carousel .carousel-indicators #quote-carousel .carousel-indicators {
{
right: 50%; right: 50%;
top: auto; top: auto;
bottom: 0px; bottom: 0px;
margin-right: -19px; margin-right: -19px;
} }
/* Changes the color of the indicators */ /* Changes the color of the indicators */
#quote-carousel .carousel-indicators li #quote-carousel .carousel-indicators li {
{
background: #c0c0c0; background: #c0c0c0;
} }
#quote-carousel .carousel-indicators .active #quote-carousel .carousel-indicators .active {
{
background: #333333; background: #333333;
} }
#quote-carousel img #quote-carousel img {
{
width: 250px; width: 250px;
height: 100px height: 100px
} }
@ -512,8 +504,9 @@
margin-right: 10px; margin-right: 10px;
} }
#relatedInformation img { padding-right :10px;} #relatedInformation img {
padding-right: 10px;
}
.glyphicon { .glyphicon {
position: relative; position: relative;
top: 1px; top: 1px;
@ -531,7 +524,8 @@
z-index: 5; z-index: 5;
display: inline-block; display: inline-block;
} }
.carousel-control.left span, .carousel-control.right span { .carousel-control.left span,
.carousel-control.right span {
background-color: #000; background-color: #000;
} }
@ -540,5 +534,4 @@
font-size: 24px; font-size: 24px;
} }
/* */ /* */

344
ebsco/ebsco.module

@ -1,12 +1,12 @@
<?php <?php
/*
* /**
* * @file
* Copyright [2017] [EBSCO Information Services] * Copyright [2017] [EBSCO Information Services].
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at.
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
@ -16,22 +16,21 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
require_once 'lib/EBSCODocument.php'; require_once 'lib/EBSCODocument.php';
# global variable // Global variable.
$Document = null; $Document = NULL;
/****************************************** /******************************************
* Hooks * Hooks
******************************************/ ******************************************/
/** /**
* Implements hook_user_login. * Implements hook_user_login.
* *
* Redirects after login * Redirects after login.
*
*/ */
function ebsco_user_login(&$edit, $account) { function ebsco_user_login(&$edit, $account) {
if (isset($_SESSION['EBSCO']['redirect'])) { if (isset($_SESSION['EBSCO']['redirect'])) {
@ -69,32 +68,30 @@ function ebsco_help($path, $arg) {
return $output; return $output;
} }
/** /**
* Implements hook_theme(). * Implements hook_theme().
*/ */
function ebsco_theme() { function ebsco_theme() {
$themes = array( $themes = array(
'ebsco_result' => array( 'ebsco_result' => array(
'template' => 'templates/ebsco-result' 'template' => 'templates/ebsco-result',
), ),
'ebsco_results' => array( 'ebsco_results' => array(
'template' => 'templates/ebsco-results' 'template' => 'templates/ebsco-results',
), ),
'ebsco_side_facets' => array( 'ebsco_side_facets' => array(
'template' => 'templates/ebsco-side-facets' 'template' => 'templates/ebsco-side-facets',
), ),
'ebsco_basic_search' => array( 'ebsco_basic_search' => array(
'template' => 'templates/ebsco-basic-search' 'template' => 'templates/ebsco-basic-search',
), ),
'ebsco_advanced_search' => array( 'ebsco_advanced_search' => array(
'template' => 'templates/ebsco-advanced-search' 'template' => 'templates/ebsco-advanced-search',
) ),
); );
return $themes; return $themes;
} }
/** /**
* Implements hook_permission(). * Implements hook_permission().
* *
@ -106,25 +103,23 @@ function ebsco_theme() {
function ebsco_permission() { function ebsco_permission() {
return array( return array(
'administer ebsco' => array( 'administer ebsco' => array(
'title' => t('Administer EBSCO') 'title' => t('Administer EBSCO'),
), ),
'use ebsco' => array( 'use ebsco' => array(
'title' => t('Use EBSCO') 'title' => t('Use EBSCO'),
) ),
); );
} }
/** /**
* Implements hook_admin(). * Implements hook_admin().
*
*/ */
function ebsco_admin() { function ebsco_admin() {
$form = array(); $form = array();
$form['ebsco_credentials'] = array( $form['ebsco_credentials'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('EDS API credentials') '#title' => t('EDS API credentials'),
); );
$form['ebsco_credentials']['ebsco_profile'] = array( $form['ebsco_credentials']['ebsco_profile'] = array(
@ -133,7 +128,7 @@ function ebsco_admin() {
'#default_value' => variable_get('ebsco_profile'), '#default_value' => variable_get('ebsco_profile'),
'#size' => 50, '#size' => 50,
'#description' => t("The API Profile Id."), '#description' => t("The API Profile Id."),
'#required' => TRUE '#required' => TRUE,
); );
$form['ebsco_credentials']['ebsco_user'] = array( $form['ebsco_credentials']['ebsco_user'] = array(
@ -142,7 +137,7 @@ function ebsco_admin() {
'#default_value' => variable_get('ebsco_user'), '#default_value' => variable_get('ebsco_user'),
'#size' => 50, '#size' => 50,
'#description' => t("The API User Id."), '#description' => t("The API User Id."),
'#required' => TRUE '#required' => TRUE,
); );
$form['ebsco_credentials']['ebsco_password'] = array( $form['ebsco_credentials']['ebsco_password'] = array(
@ -151,7 +146,7 @@ function ebsco_admin() {
'#default_value' => variable_get('ebsco_password'), '#default_value' => variable_get('ebsco_password'),
'#size' => 50, '#size' => 50,
'#description' => t("The API password."), '#description' => t("The API password."),
'#required' => TRUE '#required' => TRUE,
); );
$form['ebsco_credentials']['ebsco_interface'] = array( $form['ebsco_credentials']['ebsco_interface'] = array(
@ -160,7 +155,7 @@ function ebsco_admin() {
'#default_value' => variable_get('ebsco_interface'), '#default_value' => variable_get('ebsco_interface'),
'#size' => 50, '#size' => 50,
'#description' => t("The API Interface Id."), '#description' => t("The API Interface Id."),
'#required' => FALSE '#required' => FALSE,
); );
$form['ebsco_credentials']['ebsco_organization'] = array( $form['ebsco_credentials']['ebsco_organization'] = array(
@ -169,7 +164,7 @@ function ebsco_admin() {
'#default_value' => variable_get('ebsco_organization'), '#default_value' => variable_get('ebsco_organization'),
'#size' => 50, '#size' => 50,
'#description' => t("The API Organization Id."), '#description' => t("The API Organization Id."),
'#required' => FALSE '#required' => FALSE,
); );
$form['ebsco_credentials']['ebsco_local_ips'] = array( $form['ebsco_credentials']['ebsco_local_ips'] = array(
@ -178,7 +173,7 @@ function ebsco_admin() {
'#default_value' => variable_get('ebsco_local_ips'), '#default_value' => variable_get('ebsco_local_ips'),
'#size' => 100, '#size' => 100,
'#description' => t("Local IP address list for guest detection (ex: 127.0.0.1, 192.168.10.1, 172.18.12)"), '#description' => t("Local IP address list for guest detection (ex: 127.0.0.1, 192.168.10.1, 172.18.12)"),
'#required' => FALSE '#required' => FALSE,
); );
$form['ebsco_credentials']['ebsco_guest'] = array( $form['ebsco_credentials']['ebsco_guest'] = array(
@ -187,12 +182,12 @@ function ebsco_admin() {
'#default_value' => variable_get('ebsco_guest', 0), '#default_value' => variable_get('ebsco_guest', 0),
'#description' => t("The Guest session."), '#description' => t("The Guest session."),
'#options' => array(t('No'), t('Yes')), '#options' => array(t('No'), t('Yes')),
'#required' => TRUE '#required' => TRUE,
); );
$form['ebsco_general'] = array( $form['ebsco_general'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('General Settings') '#title' => t('General Settings'),
); );
$form['ebsco_general']['ebsco_default_limit'] = array( $form['ebsco_general']['ebsco_default_limit'] = array(
@ -201,7 +196,7 @@ function ebsco_admin() {
'#default_value' => variable_get('ebsco_default_limit', 10), '#default_value' => variable_get('ebsco_default_limit', 10),
'#description' => t("Default number of results per page."), '#description' => t("Default number of results per page."),
'#options' => EBSCODocument::limit_options(), '#options' => EBSCODocument::limit_options(),
'#required' => TRUE '#required' => TRUE,
); );
$form['ebsco_general']['ebsco_default_sort'] = array( $form['ebsco_general']['ebsco_default_sort'] = array(
@ -210,7 +205,7 @@ function ebsco_admin() {
'#default_value' => variable_get('ebsco_default_sort', 'relevance'), '#default_value' => variable_get('ebsco_default_sort', 'relevance'),
'#description' => t("Default sorting option."), '#description' => t("Default sorting option."),
'#options' => EBSCODocument::sort_options(), '#options' => EBSCODocument::sort_options(),
'#required' => TRUE '#required' => TRUE,
); );
$form['ebsco_general']['ebsco_default_amount'] = array( $form['ebsco_general']['ebsco_default_amount'] = array(
@ -219,7 +214,7 @@ function ebsco_admin() {
'#default_value' => variable_get('ebsco_default_amount', 'brief'), '#default_value' => variable_get('ebsco_default_amount', 'brief'),
'#description' => t("Default level of data detail."), '#description' => t("Default level of data detail."),
'#options' => EBSCODocument::amount_options(), '#options' => EBSCODocument::amount_options(),
'#required' => TRUE '#required' => TRUE,
); );
$form['ebsco_general']['ebsco_default_mode'] = array( $form['ebsco_general']['ebsco_default_mode'] = array(
@ -228,51 +223,50 @@ function ebsco_admin() {
'#default_value' => variable_get('ebsco_default_mode', 'all'), '#default_value' => variable_get('ebsco_default_mode', 'all'),
'#description' => t("Default search mode."), '#description' => t("Default search mode."),
'#options' => EBSCODocument::mode_options(), '#options' => EBSCODocument::mode_options(),
'#required' => TRUE '#required' => TRUE,
); );
return system_settings_form($form); return system_settings_form($form);
} }
/** /**
* Implements hook_menu(). * Implements hook_menu().
*/ */
function ebsco_menu() { function ebsco_menu() {
// Ths is a route // Ths is a route.
$items['ebsco/results'] = array( $items['ebsco/results'] = array(
'title' => 'EBSCO Results', 'title' => 'EBSCO Results',
'page callback' => 'ebsco_results_page', 'page callback' => 'ebsco_results_page',
'access callback' => true, 'access callback' => TRUE,
'type' => MENU_CALLBACK 'type' => MENU_CALLBACK,
); );
$items['ebsco/result'] = array( $items['ebsco/result'] = array(
'title' => 'EBSCO Record', 'title' => 'EBSCO Record',
'page callback' => 'ebsco_result_page', 'page callback' => 'ebsco_result_page',
'access callback' => true, 'access callback' => TRUE,
'type' => MENU_CALLBACK 'type' => MENU_CALLBACK,
); );
$items['ebsco/pdf'] = array( $items['ebsco/pdf'] = array(
'title' => 'EBSCO Record', 'title' => 'EBSCO Record',
'page callback' => 'ebsco_pdf_page', 'page callback' => 'ebsco_pdf_page',
'access callback' => true, 'access callback' => TRUE,
'type' => MENU_CALLBACK 'type' => MENU_CALLBACK,
); );
$items['ebsco/fulltext'] = array( $items['ebsco/fulltext'] = array(
'title' => 'EBSCO Record', 'title' => 'EBSCO Record',
'page callback' => 'ebsco_fulltext_page', 'page callback' => 'ebsco_fulltext_page',
'access callback' => true, 'access callback' => TRUE,
'type' => MENU_CALLBACK 'type' => MENU_CALLBACK,
); );
$items['ebsco/advanced'] = array( $items['ebsco/advanced'] = array(
'title' => 'EBSCO advanced search', 'title' => 'EBSCO advanced search',
'page callback' => 'ebsco_advanced_search_page', 'page callback' => 'ebsco_advanced_search_page',
'access callback' => true, 'access callback' => TRUE,
'type' => MENU_CALLBACK 'type' => MENU_CALLBACK,
); );
$items['admin/config/search/ebsco'] = array( $items['admin/config/search/ebsco'] = array(
@ -281,31 +275,29 @@ function ebsco_menu() {
'page callback' => 'drupal_get_form', 'page callback' => 'drupal_get_form',
'page arguments' => array('ebsco_admin'), 'page arguments' => array('ebsco_admin'),
'access arguments' => array('administer ebsco'), 'access arguments' => array('administer ebsco'),
'type' => MENU_NORMAL_ITEM 'type' => MENU_NORMAL_ITEM,
); );
return $items; return $items;
} }
/** /**
* Implements hook_block_info(). * Implements hook_block_info().
*/ */
function ebsco_block_info() { function ebsco_block_info() {
$blocks['ebsco_main'] = array( $blocks['ebsco_main'] = array(
'info' => t('EBSCO Search Form'), 'info' => t('EBSCO Search Form'),
'cache' => DRUPAL_CACHE_PER_PAGE 'cache' => DRUPAL_CACHE_PER_PAGE,
); );
$blocks['ebsco_facets'] = array( $blocks['ebsco_facets'] = array(
'info' => t('EBSCO Narrow Search'), 'info' => t('EBSCO Narrow Search'),
'cache' => DRUPAL_CACHE_PER_PAGE 'cache' => DRUPAL_CACHE_PER_PAGE,
); );
return $blocks; return $blocks;
} }
/** /**
* Implements hook_block_view(). * Implements hook_block_view().
* *
@ -315,66 +307,75 @@ function ebsco_block_view($delta = '') {
$params = $_GET; $params = $_GET;
switch ($delta) { switch ($delta) {
case 'ebsco_main': case 'ebsco_main':
$reject = isset($params['q']) && strpos('ebsco/advanced', $params['q']) !== false; $reject = isset($params['q']) && strpos('ebsco/advanced', $params['q']) !== FALSE;
return array( return array(
'content' => $reject ? '' : ebsco_basic_search_block() 'content' => $reject ? '' : ebsco_basic_search_block(),
); );
break; break;
case 'ebsco_facets': case 'ebsco_facets':
$reject = isset($params['q']) && strpos('ebsco/advanced', $params['q']) !== false; $reject = isset($params['q']) && strpos('ebsco/advanced', $params['q']) !== FALSE;
$reject = $reject || (isset($params['edit']) && strpos('ebsco/results', $params['q']) !== false); $reject = $reject || (isset($params['edit']) && strpos('ebsco/results', $params['q']) !== FALSE);
$reject = $reject || (isset($params['q']) && strpos('ebsco/result', $params['q']) !== false); $reject = $reject || (isset($params['q']) && strpos('ebsco/result', $params['q']) !== FALSE);
return array( return array(
'content' => $reject ? '' : ebsco_side_facets_block() 'content' => $reject ? '' : ebsco_side_facets_block(),
); );
break; break;
} }
} }
/**
/****************************************************** * Page callbacks.
* Page callbacks */
******************************************************/
function ebsco_results_page() { function ebsco_results_page() {
return theme('ebsco_results'); return theme('ebsco_results');
} }
/**
*
*/
function ebsco_result_page() { function ebsco_result_page() {
$is_xhr = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'; $is_xhr = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
if ($is_xhr) { if ($is_xhr) {
print theme('ebsco_result'); print theme('ebsco_result');
return true; return TRUE;
} else { }
else {
return theme('ebsco_result'); return theme('ebsco_result');
} }
} }
/**
*
*/
function ebsco_fulltext_page() { function ebsco_fulltext_page() {
$is_xhr = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'; $is_xhr = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
if (user_is_logged_in()) { if (user_is_logged_in()) {
if ($is_xhr) { if ($is_xhr) {
print theme('ebsco_result'); print theme('ebsco_result');
return true; return TRUE;
} else { }
else {
return theme('ebsco_result'); return theme('ebsco_result');
} }
} else { }
else {
$_SESSION['EBSCO']['redirect'] = drupal_get_destination(); $_SESSION['EBSCO']['redirect'] = drupal_get_destination();
if ($is_xhr) { if ($is_xhr) {
echo "<script type=\"text/javascript\">window.location.href = '" . url('user') . "';</script>"; echo "<script type=\"text/javascript\">window.location.href = '" . url('user') . "';</script>";
return; return;
} else { }
else {
drupal_goto('user'); drupal_goto('user');
} }
} }
} }
/**
*
*/
function ebsco_pdf_page() { function ebsco_pdf_page() {
global $Document; global $Document;
$params = $_REQUEST; $params = $_REQUEST;
@ -386,34 +387,38 @@ function ebsco_pdf_page() {
$Document->retrieve(); $Document->retrieve();
$record = $Document->record(); $record = $Document->record();
drupal_goto($record->pdf_link); drupal_goto($record->pdf_link);
} else { }
else {
$_SESSION['EBSCO']['redirect'] = drupal_get_destination(); $_SESSION['EBSCO']['redirect'] = drupal_get_destination();
drupal_goto('user'); drupal_goto('user');
} }
} }
/**
*
*/
function ebsco_advanced_search_page() { function ebsco_advanced_search_page() {
return theme('ebsco_advanced_search'); return theme('ebsco_advanced_search');
} }
/**
*
*/
function ebsco_basic_search_block() { function ebsco_basic_search_block() {
return theme('ebsco_basic_search'); return theme('ebsco_basic_search');
} }
/**
*
*/
function ebsco_side_facets_block() { function ebsco_side_facets_block() {
return theme('ebsco_side_facets'); return theme('ebsco_side_facets');
} }
/****************************************************** /******************************************************
* Form builders, form handlers and templates handlers * Form builders, form handlers and templates handlers
******************************************************/ ******************************************************/
/** /**
* Form builder; Output a sort form for the search results. * Form builder; Output a sort form for the search results.
* *
@ -424,7 +429,7 @@ function ebsco_sort_form() {
$form = array( $form = array(
'#attributes' => array('class' => 'sort-form'), '#attributes' => array('class' => 'sort-form'),
'#method' => 'get' '#method' => 'get',
); );
$options = EBSCODocument::amount_options(); $options = EBSCODocument::amount_options();
@ -436,7 +441,7 @@ function ebsco_sort_form() {
'#title' => t('Page options'), '#title' => t('Page options'),
'#default_value' => $default_value, '#default_value' => $default_value,
'#options' => $options, '#options' => $options,
'#attributes' => array('class' => array('form-select', '_jump_menu')) '#attributes' => array('class' => array('form-select', '_jump_menu')),
); );
$options = EBSCODocument::sort_options(); $options = EBSCODocument::sort_options();
@ -448,13 +453,12 @@ function ebsco_sort_form() {
'#title' => t('Sort'), '#title' => t('Sort'),
'#default_value' => $default_value, '#default_value' => $default_value,
'#options' => $options, '#options' => $options,
'#attributes' => array('class' => array('form-select', '_jump_menu')) '#attributes' => array('class' => array('form-select', '_jump_menu')),
); );
return $form; return $form;
} }
/** /**
* Form builder; Output a search form for the search block's search box. * Form builder; Output a search form for the search block's search box.
* *
@ -466,12 +470,12 @@ function ebsco_basic_search_form() {
$form = array( $form = array(
'#attributes' => array('class' => 'search-form'), '#attributes' => array('class' => 'search-form'),
'#action' => url('ebsco/results'), '#action' => url('ebsco/results'),
'#method' => 'get' '#method' => 'get',
); );
$form['basic']['q'] = array( $form['basic']['q'] = array(
'#type' => 'hidden', '#type' => 'hidden',
'#default_value' => 'ebsco/results' '#default_value' => 'ebsco/results',
); );
$default_value = isset($params['lookfor']) ? $params['lookfor'] : ''; $default_value = isset($params['lookfor']) ? $params['lookfor'] : '';
@ -488,23 +492,23 @@ function ebsco_basic_search_form() {
'#id' => 'ebsco-basic-search-type', '#id' => 'ebsco-basic-search-type',
'#type' => 'select', '#type' => 'select',
'#options' => EBSCODocument::basic_search_type_options(), '#options' => EBSCODocument::basic_search_type_options(),
'#default_value' => $default_value '#default_value' => $default_value,
); );
$form['basic']['submit'] = array( $form['basic']['submit'] = array(
'#id' => 'ebsco-basic-search-submit', '#id' => 'ebsco-basic-search-submit',
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Search') '#value' => t('Search'),
); );
$link = url('ebsco/advanced'); $link = url('ebsco/advanced');
$form['basic']['links'] = array( $form['basic']['links'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#value' => "<a href=\"$link\">" . t('Advanced search') . "</a>" '#value' => "<a href=\"$link\">" . t('Advanced search') . "</a>",
); );
$form['basic']['offscreen'] = array( $form['basic']['offscreen'] = array(
'#type' => 'container' '#type' => 'container',
); );
if (isset($params['filter'])) { if (isset($params['filter'])) {
@ -512,8 +516,9 @@ function ebsco_basic_search_form() {
$form['basic']['offscreen']['group' . $key]['filter[]'] = array( $form['basic']['offscreen']['group' . $key]['filter[]'] = array(
'#id' => 'ebsco-basic-search-filter' . $key, '#id' => 'ebsco-basic-search-filter' . $key,
'#type' => 'checkbox', '#type' => 'checkbox',
'#default_value' => $value, // doesn't work // doesn't work.
'#attributes' => array('checked' => 'checked', 'value' => $value) '#default_value' => $value,
'#attributes' => array('checked' => 'checked', 'value' => $value),
); );
} }
@ -522,7 +527,7 @@ function ebsco_basic_search_form() {
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Retain my current filters'), '#title' => t('Retain my current filters'),
'#prefix' => '<br />', '#prefix' => '<br />',
'#default_value' => true '#default_value' => TRUE,
); );
} }
@ -547,26 +552,26 @@ function ebsco_advanced_search_form() {
$form = array( $form = array(
'#attributes' => array('class' => 'search-form'), '#attributes' => array('class' => 'search-form'),
'#action' => url('ebsco/advanced') '#action' => url('ebsco/advanced'),
); );
$form['advanced'] = array( $form['advanced'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Advanced Search'), '#title' => t('Advanced Search'),
'#collapsible' => false, '#collapsible' => FALSE,
'#collapsed' => false '#collapsed' => FALSE,
); );
$form['advanced']['rows'] = array( $form['advanced']['rows'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => '' '#title' => '',
); );
for ($i = 0; $i < $counter; $i++) { for ($i = 0; $i < $counter; $i++) {
$form['advanced']['rows']['group' . $i] = array( $form['advanced']['rows']['group' . $i] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#tree' => true, '#tree' => TRUE,
'#attributes' => array('class' => array('_advanced-row')) '#attributes' => array('class' => array('_advanced-row')),
); );
$default_value = isset($params['group'][$i]['bool']) ? $params['group'][$i]['bool'] : ''; $default_value = isset($params['group'][$i]['bool']) ? $params['group'][$i]['bool'] : '';
@ -575,13 +580,14 @@ function ebsco_advanced_search_form() {
'#id' => 'ebsco-advanced-search-bool' . $i, '#id' => 'ebsco-advanced-search-bool' . $i,
'#type' => 'select', '#type' => 'select',
'#default_value' => $default_value, '#default_value' => $default_value,
'#options' => EBSCODocument::bool_options() '#options' => EBSCODocument::bool_options(),
); );
} else { }
else {
$form['advanced']['rows']['group' . $i]['bool'] = array( $form['advanced']['rows']['group' . $i]['bool'] = array(
'#id' => 'ebsco-advanced-search-bool' . $i, '#id' => 'ebsco-advanced-search-bool' . $i,
'#type' => 'hidden', '#type' => 'hidden',
'#default_value' => 'AND' '#default_value' => 'AND',
); );
} }
@ -593,7 +599,7 @@ function ebsco_advanced_search_form() {
'#size' => 30, '#size' => 30,
'#default_value' => $default_value, '#default_value' => $default_value,
'#title' => $title, '#title' => $title,
'#attributes' => array('title' => t('Enter the terms you wish to search for.')) '#attributes' => array('title' => t('Enter the terms you wish to search for.')),
); );
$default_value = isset($params['group'][$i]['type']) ? $params['group'][$i]['type'] : ''; $default_value = isset($params['group'][$i]['type']) ? $params['group'][$i]['type'] : '';
@ -602,30 +608,30 @@ function ebsco_advanced_search_form() {
'#type' => 'select', '#type' => 'select',
'#default_value' => $default_value, '#default_value' => $default_value,
'#title' => t('in'), '#title' => t('in'),
'#options' => EBSCODocument::advanced_search_type_options() '#options' => EBSCODocument::advanced_search_type_options(),
); );
if ($i > 2) { if ($i > 2) {
$form['advanced']['rows']['group' . $i]['remove'] = array( $form['advanced']['rows']['group' . $i]['remove'] = array(
'#markup' => '<div class="delete-search"><a href="#" class="delete _delete_row" id="delete_search_link_' . $i . '">' . t('Remove Search Field') . '</a></div>' '#markup' => '<div class="delete-search"><a href="#" class="delete _delete_row" id="delete_search_link_' . $i . '">' . t('Remove Search Field') . '</a></div>',
); );
} }
} }
$form['advanced']['rows']['add_row'] = array( $form['advanced']['rows']['add_row'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#value' => "<a class=\"add _add_row\" href=\"#\">". t('Add Search Field') . "</a>" '#value' => "<a class=\"add _add_row\" href=\"#\">" . t('Add Search Field') . "</a>",
); );
$items = array( $items = array(
array( array(
'url' => url('ebsco/results'), 'url' => url('ebsco/results'),
'title' => t('Basic search') 'title' => t('Basic search'),
), ),
array( array(
'url' => url('ebsco/advanced'), 'url' => url('ebsco/advanced'),
'title' => t('Advanced search') 'title' => t('Advanced search'),
) ),
); );
$links = array(); $links = array();
foreach ($items as $item) { foreach ($items as $item) {
@ -633,45 +639,46 @@ function ebsco_advanced_search_form() {
} }
$form['advanced']['links'] = array( $form['advanced']['links'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#value' => implode(' | ', $links) '#value' => implode(' | ', $links),
); );
$form['advanced']['modes'] = array( $form['advanced']['modes'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Search modes') '#title' => t('Search modes'),
); );
$form['advanced']['modes']['mode'] = array( $form['advanced']['modes']['mode'] = array(
'#type' => 'radios', '#type' => 'radios',
'#default_value' => 'all', '#default_value' => 'all',
'#options' => EBSCODocument::mode_options() '#options' => EBSCODocument::mode_options(),
); );
$expanders = $Document->expanders(); $expanders = $Document->expanders();
$limiters = $Document->limiters(); $limiters = $Document->limiters();
$options = array('' => true); $options = array('' => TRUE);
foreach ($expanders as $key => $expander) { foreach ($expanders as $key => $expander) {
$options[$expander['Action']] = true; $options[$expander['Action']] = TRUE;
} }
foreach ($limiters as $key => $limiter) { foreach ($limiters as $key => $limiter) {
if (!empty($limiter['Values'])) { if (!empty($limiter['Values'])) {
$options[$limiter['Id']] = true; $options[$limiter['Id']] = TRUE;
foreach ($limiter['Values'] as $value) { foreach ($limiter['Values'] as $value) {
$options[str_replace('value', $value['Value'], $value['Action'])] = true; $options[str_replace('value', $value['Value'], $value['Action'])] = TRUE;
}
} }
} else { else {
$options[str_replace('value', 'y', $limiter['Action'])] = true; $options[str_replace('value', 'y', $limiter['Action'])] = TRUE;
} }
} }
$form['advanced']['expanders'] = array( $form['advanced']['expanders'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Expand results') '#title' => t('Expand results'),
); );
$form['advanced']['limiters'] = array( $form['advanced']['limiters'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => t('Limit results') '#title' => t('Limit results'),
); );
$children = array(); $children = array();
@ -683,7 +690,7 @@ function ebsco_advanced_search_form() {
'#title_display' => 'after', '#title_display' => 'after',
'#name' => 'filter[]', '#name' => 'filter[]',
'#attributes' => array('value' => $expander['Action']), '#attributes' => array('value' => $expander['Action']),
'#checked' => $expander['selected'] '#checked' => $expander['selected'],
); );
$element['#children'] = ($key != 0) ? '<br />' : ''; $element['#children'] = ($key != 0) ? '<br />' : '';
$element['#children'] .= theme('checkbox', array('element' => $element)); $element['#children'] .= theme('checkbox', array('element' => $element));
@ -694,9 +701,9 @@ function ebsco_advanced_search_form() {
$form['advanced']['expanders']['filter'] = array( $form['advanced']['expanders']['filter'] = array(
'#type' => 'checkboxes', '#type' => 'checkboxes',
'#validated' => true, '#validated' => TRUE,
'#options' => $options, '#options' => $options,
'#children' => implode('', $children) '#children' => implode('', $children),
); );
$checkboxes = $selects = $dates = array(); $checkboxes = $selects = $dates = array();
@ -709,34 +716,38 @@ function ebsco_advanced_search_form() {
'#title_display' => 'after', '#title_display' => 'after',
'#name' => 'filter[]', '#name' => 'filter[]',
'#attributes' => array('value' => str_replace('value', 'y', $limiter['Action'])), '#attributes' => array('value' => str_replace('value', 'y', $limiter['Action'])),
'#checked' => $limiter['selected'] '#checked' => $limiter['selected'],
); );
$element['#children'] = ($key != 0) ? '<br />' : ''; $element['#children'] = ($key != 0) ? '<br />' : '';
if (!isset($element['#children'])) if (!isset($element['#children'])) {
{$element['#children']="";} $element['#children'] = "";
}
$element['#children'] .= theme('checkbox', array('element' => $element)); $element['#children'] .= theme('checkbox', array('element' => $element));
$checkboxes[] = theme('form_element', array('element' => $element)); $checkboxes[] = theme('form_element', array('element' => $element));
} else if ($limiter['Type'] == 'multiselectvalue') { }
elseif ($limiter['Type'] == 'multiselectvalue') {
$opts = array('' => t('All')); $opts = array('' => t('All'));
foreach ($limiter['Values'] as $value) { foreach ($limiter['Values'] as $value) {
$opts[$value['Action']] = $value['Value']; $opts[$value['Action']] = $value['Value'];
} }
$element = array( $element = array(
'#type' => 'select', '#type' => 'select',
'#multiple' => true, '#multiple' => TRUE,
'#size' => 4, '#size' => 4,
'#id' => 'ebsco-advanced-search-limiter' . $limiter['Id'], '#id' => 'ebsco-advanced-search-limiter' . $limiter['Id'],
'#title' => $limiter['Label'], '#title' => $limiter['Label'],
'#name' => 'filter[]', '#name' => 'filter[]',
'#options' => $opts, '#options' => $opts,
'#default_value' => $limiter['selected'], // empty value means "All" // Empty value means "All".
'#default_value' => $limiter['selected'],
'#value' => $limiter['selected'], '#value' => $limiter['selected'],
'#attributes' => array('class' => array('multiselectvalue'), 'multiple' => 'multiple') '#attributes' => array('class' => array('multiselectvalue'), 'multiple' => 'multiple'),
); );
$element['#children'] = theme('select', array('element' => $element)); $element['#children'] = theme('select', array('element' => $element));
$selects[] = theme('form_element', array('element' => $element)); $selects[] = theme('form_element', array('element' => $element));
} else if ($limiter['Type'] == 'ymrange') { }
elseif ($limiter['Type'] == 'ymrange') {
$value = $limiter['selected'] ? $limiter['selected'] : ''; $value = $limiter['selected'] ? $limiter['selected'] : '';
$displayValue = str_replace(array('addlimiter(DT1:', '-1/2013-1)'), array('', ''), $value); $displayValue = str_replace(array('addlimiter(DT1:', '-1/2013-1)'), array('', ''), $value);
$element = array( $element = array(
@ -745,8 +756,8 @@ function ebsco_advanced_search_form() {
'#title' => $limiter['Label'], '#title' => $limiter['Label'],
'#value' => $displayValue, '#value' => $displayValue,
'#name' => $limiter['Id'], '#name' => $limiter['Id'],
'#autocomplete_path' => null, '#autocomplete_path' => NULL,
'#attributes' => array('size' => 4, 'maxlength' => 4, 'class' => array('yearbox')) '#attributes' => array('size' => 4, 'maxlength' => 4, 'class' => array('yearbox')),
); );
$element['#children'] = theme('textfield', array('element' => $element)); $element['#children'] = theme('textfield', array('element' => $element));
$element['#children'] .= '<input id="ebsco-advanced-search-limiter' . $limiter['Id'] . '" type="hidden" name="filter[]" value="' . $value . '"/>'; $element['#children'] .= '<input id="ebsco-advanced-search-limiter' . $limiter['Id'] . '" type="hidden" name="filter[]" value="' . $value . '"/>';
@ -757,39 +768,38 @@ function ebsco_advanced_search_form() {
$form['advanced']['limiters']['checkboxes'] = array( $form['advanced']['limiters']['checkboxes'] = array(
'#type' => 'checkboxes', '#type' => 'checkboxes',
'#validated' => true, '#validated' => TRUE,
'#options' => $options, '#options' => $options,
'#children' => implode('', $checkboxes), '#children' => implode('', $checkboxes),
); );
$form['advanced']['limiters']['dates'] = array( $form['advanced']['limiters']['dates'] = array(
'#type' => 'container', '#type' => 'container',
'#validated' => true, '#validated' => TRUE,
'#prefix' => '<hr />', '#prefix' => '<hr />',
'#children' => implode('', $dates) '#children' => implode('', $dates),
); );
$form['advanced']['limiters']['selects'] = array( $form['advanced']['limiters']['selects'] = array(
'#type' => 'container', '#type' => 'container',
'#prefix' => '<hr />', '#prefix' => '<hr />',
'#validated' => true, '#validated' => TRUE,
'#children' => implode('', $selects) '#children' => implode('', $selects),
); );
$form['advanced']['submit'] = array( $form['advanced']['submit'] = array(
'#id' => 'ebsco-advanced-search-submit', '#id' => 'ebsco-advanced-search-submit',
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Search') '#value' => t('Search'),
); );
$form['advanced']['clear'] = array( $form['advanced']['clear'] = array(
'#markup' => '<input id="ebsco-advanced-search-clear" class="form-submit" type="reset" value="' . t('Clear') . '" name="reset">' '#markup' => '<input id="ebsco-advanced-search-clear" class="form-submit" type="reset" value="' . t('Clear') . '" name="reset">',
); );
return $form; return $form;
} }
/** /**
* Form validation handler for ebsco_basic_search_form(). * Form validation handler for ebsco_basic_search_form().
* *
@ -802,7 +812,6 @@ function ebsco_basic_search_form_validate($form, &$form_state) {
} }
} }
/** /**
* Form validation handler for ebsco_advanced_search_form(). * Form validation handler for ebsco_advanced_search_form().
* *
@ -817,7 +826,6 @@ function ebsco_advanced_search_form_validate($form, &$form_state) {
} }
} }
/** /**
* Form submission handler for ebsco_basic_search_form(). * Form submission handler for ebsco_basic_search_form().
* *
@ -831,11 +839,10 @@ function ebsco_basic_search_form_submit($form, &$form_state) {
unset($params[$key]); unset($params[$key]);
} }
} }
$form_state['rebuild'] = false; $form_state['rebuild'] = FALSE;
$form_state['redirect'] = array('ebsco/results', array('query' => $params)); $form_state['redirect'] = array('ebsco/results', array('query' => $params));
} }
/** /**
* Form submission handler for ebsco_advanced_search_form(). * Form submission handler for ebsco_advanced_search_form().
* *
@ -847,34 +854,35 @@ function ebsco_advanced_search_form_submit($form, &$form_state) {
$allowed_keys = array('filter', 'mode'); $allowed_keys = array('filter', 'mode');
foreach ($params as $key => $value) { foreach ($params as $key => $value) {
if (!(in_array($key, $allowed_keys) || strpos($key, 'group') !== false)) { if (!(in_array($key, $allowed_keys) || strpos($key, 'group') !== FALSE)) {
unset($params[$key]); unset($params[$key]);
} else { }
else {
if ($key == 'filter') { if ($key == 'filter') {
foreach ($value as $k => $v) { foreach ($value as $k => $v) {
if (empty($v)) { if (empty($v)) {
unset($params[$key][$k]); unset($params[$key][$k]);
} }
} }
} else if (empty($value)) { }
elseif (empty($value)) {
unset($params[$key]); unset($params[$key]);
} }
} }
} }
foreach ($params as $key => $value) { foreach ($params as $key => $value) {
if (strpos($key, 'group') !== false) { if (strpos($key, 'group') !== FALSE) {
$new_params['group'][] = $value; $new_params['group'][] = $value;
unset($params[$key]); unset($params[$key]);
} }
} }
$params = array_merge($params, $new_params); $params = array_merge($params, $new_params);
$form_state['rebuild'] = false; $form_state['rebuild'] = FALSE;
$form_state['redirect'] = array('ebsco/results', array('query' => $params)); $form_state['redirect'] = array('ebsco/results', array('query' => $params));
} }
/** /**
* Process variables for ebsco-results.tpl.php. * Process variables for ebsco-results.tpl.php.
* *
@ -905,7 +913,8 @@ function template_preprocess_ebsco_results(&$variables) {
$variables['lookfor'] = ''; $variables['lookfor'] = '';
if (isset($params['lookfor'])) { if (isset($params['lookfor'])) {
$variables['lookfor'] = $params['lookfor']; $variables['lookfor'] = $params['lookfor'];
} else if (isset($params['group'])) { }
elseif (isset($params['group'])) {
$types = EBSCODocument::basic_search_type_options(); $types = EBSCODocument::basic_search_type_options();
foreach ($params['group'] as $key => $group) { foreach ($params['group'] as $key => $group) {
if (!empty($group['lookfor'])) { if (!empty($group['lookfor'])) {
@ -923,7 +932,6 @@ function template_preprocess_ebsco_results(&$variables) {
// $Document->search_write(); // $Document->search_write();
} }
/** /**
* Process variables for ebsco-basic-search.tpl.php. * Process variables for ebsco-basic-search.tpl.php.
* *
@ -941,7 +949,8 @@ function template_preprocess_ebsco_basic_search(&$variables) {
$variables['lookfor'] = ''; $variables['lookfor'] = '';
if (isset($params['lookfor'])) { if (isset($params['lookfor'])) {
$variables['lookfor'] = $params['lookfor']; $variables['lookfor'] = $params['lookfor'];
} else if (isset($params['group'])) { }
elseif (isset($params['group'])) {
$types = EBSCODocument::basic_search_type_options(); $types = EBSCODocument::basic_search_type_options();
foreach ($params['group'] as $key => $group) { foreach ($params['group'] as $key => $group) {
if (!empty($group['lookfor'])) { if (!empty($group['lookfor'])) {
@ -954,7 +963,6 @@ function template_preprocess_ebsco_basic_search(&$variables) {
$variables['search_form'] = drupal_render($v1); $variables['search_form'] = drupal_render($v1);
} }
/** /**
* Process variables for ebsco-advanced-search.tpl.php. * Process variables for ebsco-advanced-search.tpl.php.
* *
@ -974,7 +982,6 @@ function template_preprocess_ebsco_advanced_search(&$variables) {
$variables['search_form'] = drupal_render($v1); $variables['search_form'] = drupal_render($v1);
} }
/** /**
* Process variables for ebsco-result.tpl.php. * Process variables for ebsco-result.tpl.php.
* *
@ -998,7 +1005,6 @@ function template_preprocess_ebsco_result(&$variables) {
drupal_set_title($record->title); drupal_set_title($record->title);
} }
/** /**
* Process variables for ebsco-side-facets.tpl.php. * Process variables for ebsco-side-facets.tpl.php.
* *
@ -1016,24 +1022,24 @@ function template_preprocess_ebsco_side_facets(&$variables) {
$variables['expanders'] = $Document->expanders(); $variables['expanders'] = $Document->expanders();
$variables['limiters'] = $Document->limiters(); $variables['limiters'] = $Document->limiters();
$variables['facets'] = $Document->facets(); $variables['facets'] = $Document->facets();
$variables['filters'] = $Document->filters(); // applied facets, limiters or expanders // Applied facets, limiters or expanders.
$variables['search_params'] = $Document->search_params(); // hidden parameters $variables['filters'] = $Document->filters();
$variables['link_search_params'] = $Document->link_search_params(); // hidden parameters // Hidden parameters.
$variables['search_params'] = $Document->search_params();
// Hidden parameters.
$variables['link_search_params'] = $Document->link_search_params();
} }
/****************************************** /******************************************
* View Helpers * View Helpers
******************************************/ ******************************************/
/** /**
* Returns an URL without the given filter parameter * Returns an URL without the given filter parameter.
* *
* @return string * @return string
*/ */
function remove_filter_link($filter) function remove_filter_link($filter) {
{
$params = $_REQUEST; $params = $_REQUEST;
if (isset($params['filter'])) { if (isset($params['filter'])) {
foreach ($params['filter'] as $key => $value) { foreach ($params['filter'] as $key => $value) {
@ -1045,14 +1051,12 @@ function remove_filter_link($filter)
return url('ebsco/results', array('query' => $params)); return url('ebsco/results', array('query' => $params));
} }
/** /**
* Performs a regex and replaces any url's with links containing themselves as the text * Performs a regex and replaces any url's with links containing themselves as the text.
* *
* @return string * @return string
*/ */
function auto_link($string) function auto_link($string) {
{
$linkedString = preg_replace_callback( $linkedString = preg_replace_callback(
"/\b(https?):\/\/([-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]*)\b/i", "/\b(https?):\/\/([-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]*)\b/i",
create_function( create_function(

357
ebsco/lib/EBSCOAPI.php

@ -1,7 +1,7 @@
<?php <?php
/** /**
* EBSCO EDS API class * EBSCO EDS API class.
* *
* PHP version 5 * PHP version 5
* *
@ -19,7 +19,6 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*
*/ */
require_once 'EBSCOConnector.php'; require_once 'EBSCOConnector.php';
@ -27,39 +26,42 @@ require_once 'EBSCOResponse.php';
/** /**
* 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
*/ */
private $sessionToken; private $sessionToken;
/** /**
* The EBSCOConnector object used for API transactions * The EBSCOConnector object used for API transactions.
*
* @global object EBSCOConnector * @global object EBSCOConnector
*/ */
private $connector; private $connector;
/** /**
* Configuration options * Configuration options.
*/ */
private $config; private $config;
/** /**
* VuFind search types mapped to EBSCO search types * VuFind search types mapped to EBSCO search types
* used for urls in search results / detailed result * used for urls in search results / detailed result.
*
* @global array * @global array
*/ */
private static $search_tags = array( private static $search_tags = array(
@ -71,25 +73,27 @@ class EBSCOAPI
'Subject' => 'SU', 'Subject' => 'SU',
'Title' => 'TI', 'Title' => 'TI',
'ISBN' => 'IB', 'ISBN' => 'IB',
'ISSN' => 'IS' 'ISSN' => 'IS',
); );
/** /**
* EBSCO sort options * EBSCO sort options .
*
* @global array * @global array
*/ */
private static $sort_options = array( private static $sort_options = array(
'relevance', 'relevance',
'date', 'date',
'date2', 'date2',
'source' 'source',
); );
/** /**
* VuFind sort types mapped to EBSCO sort types * VuFind sort types mapped to EBSCO sort types
* used for urls in Search results / Detailed view * used for urls in Search results / Detailed view.
*
* @global array * @global array
*/ */
private static $mapped_sort_options = array( private static $mapped_sort_options = array(
@ -101,136 +105,134 @@ class EBSCOAPI
'date_desc' => 'date', 'date_desc' => 'date',
'callnumber' => 'date', 'callnumber' => 'date',
'author' => 'author', 'author' => 'author',
'title' => 'date' 'title' => 'date',
); );
/** /**
* Constructor * Constructor.
*
* *
* @param array config * @param array config
* *
* @access public * @access public
*/ */
public function __construct($config) public function __construct($config) {
{
$this->config = $config; $this->config = $config;
} }
/** /**
* Setter / Getter for authentication token * Setter / Getter for authentication token.
* *
* @param string The authentication token * @param string The authentication token
* *
* @return string or none * @return string or none
*
* @access public * @access public
*/ */
public function authenticationToken($token = null) public function authenticationToken($token = NULL) {
{
if (empty($token)) { if (empty($token)) {
$token = $this->readSession('authenticationToken'); $token = $this->readSession('authenticationToken');
return !empty($token) ? $token : $this->authenticationToken; return !empty($token) ? $token : $this->authenticationToken;
} else { }
else {
$this->authenticationToken = $token; $this->authenticationToken = $token;
$this->writeSession('authenticationToken', $token); $this->writeSession('authenticationToken', $token);
} }
} }
/** /**
* Setter / Getter for session token * Setter / Getter for session token.
* *
* @param string The session token * @param string The session token
* *
* @return string or none * @return string or none
*
* @access public * @access public
*/ */
public function sessionToken($token = null) public function sessionToken($token = NULL) {
{
if (empty($token)) { if (empty($token)) {
$token = $this->readSession('sessionToken'); $token = $this->readSession('sessionToken');
return !empty($token) ? $token : $this->sessionToken; return !empty($token) ? $token : $this->sessionToken;
} else { }
else {
$this->sessionToken = $token; $this->sessionToken = $token;
$this->writeSession('sessionToken', $token); $this->writeSession('sessionToken', $token);
} }
} }
/** /**
* Getter for isGuest * Getter for isGuest.
* *
* @param string 'y' or 'n' * @param string 'y' or 'n'
* *
* @return string or none * @return string or none
*
* @access public * @access public
*/ */
public function isGuest($boolean = null) public function isGuest($boolean = NULL) {
{
if (empty($boolean)) { if (empty($boolean)) {
return $this->readSession('isGuest'); return $this->readSession('isGuest');
} else { }
else {
$this->writeSession('isGuest', $boolean); $this->writeSession('isGuest', $boolean);
} }
} }
/** /**
* Create a new EBSCOConnector object or reuse an existing one * Create a new EBSCOConnector object or reuse an existing one.
* *
* @param none * @param none
* *
* @return EBSCOConnector object * @return EBSCOConnector object
*
* @access public * @access public
*/ */
public function connector() public function connector() {
{
if (empty($this->connector)) { if (empty($this->connector)) {
$this->connector = new EBSCOConnector($this->config); $this->connector = new EBSCOConnector($this->config);
} }
return $this->connector; return $this->connector;
} }
/** /**
* Create a new EBSCOResponse object * Create a new EBSCOResponse object.
* *
* @param object $response * @param object $response
* *
* @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.
* *
* @param string $action The EBSCOConnector method name * @param string $action
* @param array $params The parameters of the HTTP request * The EBSCOConnector method name.
* @param integer $attempts The number of retries * @param array $params
* The parameters of the HTTP request.
* @param int $attempts
* The number of retries.
* *
* @return object SimpleXml DOM or PEAR Error * @return object SimpleXml DOM or PEAR Error
*
* @access protected * @access protected
*/ */
protected function request($action, $params = null, $attempts = 5) protected function request($action, $params = NULL, $attempts = 5) {
{
$authenticationToken = $this->authenticationToken(); $authenticationToken = $this->authenticationToken();
$sessionToken = $this->sessionToken(); $sessionToken = $this->sessionToken();
// If authentication token is missing then the session token is missing too, so get both tokens // If authentication token is missing then the session token is missing too, so get both tokens
// If session token is missing then the authentication token may be invalid, so get both tokens // If session token is missing then the authentication token may be invalid, so get both tokens.
if (empty($authenticationToken) || empty($sessionToken)) { if (empty($authenticationToken) || empty($sessionToken)) {
$result = $this->apiAuthenticationAndSessionToken(); $result = $this->apiAuthenticationAndSessionToken();
if ($this->isError($result)) { if ($this->isError($result)) {
// Any error should terminate the request immediately // Any error should terminate the request immediately
// in order to prevent infinite recursion // in order to prevent infinite recursion.
return $result; return $result;
} }
} }
@ -244,165 +246,183 @@ class EBSCOAPI
$headers = array( $headers = array(
'x-authenticationToken' => $this->authenticationToken(), 'x-authenticationToken' => $this->authenticationToken(),
'x-sessionToken' => $this->sessionToken() 'x-sessionToken' => $this->sessionToken(),
); );
$response = call_user_func_array(array($this->connector(), "request{$action}"), array($params, $headers)); $response = call_user_func_array(array($this->connector(), "request{$action}"), array($params, $headers));
if ($this->isError($response)) { if ($this->isError($response)) {
// Retry the request if there were authentication errors // Retry the request if there were authentication errors.
$code = $response->getCode(); $code = $response->getCode();
switch ($code) { switch ($code) {
// If authentication token is invalid then the session token is invalid too, so get both tokens // If authentication token is invalid then the session token is invalid too, so get both tokens
// If session token is invalid then the authentication token may be invalid too, so get both tokens // If session token is invalid then the authentication token may be invalid too, so get both tokens.
case EBSCOConnector::EDS_AUTH_TOKEN_INVALID: case EBSCOConnector::EDS_AUTH_TOKEN_INVALID:
$result = $this->apiAuthenticationToken(); $result = $this->apiAuthenticationToken();
if ($this->isError($result)) { if ($this->isError($result)) {
// Any error should terminate the request immediately // Any error should terminate the request immediately
// in order to prevent infinite recursion // in order to prevent infinite recursion.
return $result; return $result;
} }
if ($attempts > 0) { if ($attempts > 0) {
$result = $this->request($action, $params, --$attempts); $result = $this->request($action, $params, --$attempts);
} }
break; break;
case EBSCOConnector::EDS_SESSION_TOKEN_INVALID: case EBSCOConnector::EDS_SESSION_TOKEN_INVALID:
$result = $this->apiAuthenticationAndSessionToken(); $result = $this->apiAuthenticationAndSessionToken();
if ($this->isError($result)) { if ($this->isError($result)) {
// Any error should terminate the request immediately // Any error should terminate the request immediately
// in order to prevent infinite recursion // in order to prevent infinite recursion.
return $result; return $result;
} }
if ($attempts > 0) { if ($attempts > 0) {
$result = $this->request($action, $params, --$attempts); $result = $this->request($action, $params, --$attempts);
} }
break; break;
default: default:
$result = $this->handleError($response); $result = $this->handleError($response);
break; break;
} }
} else { }
else {
$result = $this->response($response)->result(); $result = $this->response($response)->result();
} }
return $result; return $result;
} }
/** /**
* Wrapper for authentication API call * Wrapper for authentication API call.
* *
* @param none * @param none
* *
* @access public * @access public
*/ */
public function apiAuthenticationToken() public function apiAuthenticationToken() {
{
$response = $this->connector()->requestAuthenticationToken(); $response = $this->connector()->requestAuthenticationToken();
if ($this->isError($response)) { if ($this->isError($response)) {
return $response; return $response;
} else { }
else {
$result = $this->response($response)->result(); $result = $this->response($response)->result();
if (isset($result['authenticationToken'])) { if (isset($result['authenticationToken'])) {
$this->authenticationToken($result['authenticationToken']); $this->authenticationToken($result['authenticationToken']);
return $result['authenticationToken']; return $result['authenticationToken'];
} else { }
else {
return new EBSCOException("No authentication token was found in the response."); return new EBSCOException("No authentication token was found in the response.");
} }
} }
} }
/** /**
* Wrapper for session API call * Wrapper for session API call.
* *
* @param none * @param none
* *
* @access public * @access public
*/ */
public function apiSessionToken() public function apiSessionToken() {
{ // Add authentication tokens to headers.
// Add authentication tokens to headers
$headers = array( $headers = array(
'x-authenticationToken' => $this->authenticationToken() 'x-authenticationToken' => $this->authenticationToken(),
); );
$response = $this->connector()->requestSessionToken($headers); $response = $this->connector()->requestSessionToken($headers);
// Raise the exception so that any code running this method should exit immediately // Raise the exception so that any code running this method should exit immediately.
if ($this->isError($response)) { if ($this->isError($response)) {
return $response; return $response;
} else { }
else {
$result = $this->response($response)->result(); $result = $this->response($response)->result();
if (is_string($result)) { if (is_string($result)) {
$this->sessionToken($result); $this->sessionToken($result);
return $result; return $result;
} else { }
else {
return new EBSCOException("No session token was found in the response."); return new EBSCOException("No session token was found in the response.");
} }
} }
} }
/** /**
* Initialize the authentication and session tokens * Initialize the authentication and session tokens.
* *
* @param none * @param none
* *
* @access public * @access public
*/ */
public function apiAuthenticationAndSessionToken() public function apiAuthenticationAndSessionToken() {
{
$authenticationToken = $this->apiAuthenticationToken(); $authenticationToken = $this->apiAuthenticationToken();
if ($this->isError($authenticationToken)) { if ($this->isError($authenticationToken)) {
// An authentication error should terminate the request immediately // An authentication error should terminate the request immediately.
return $authenticationToken; return $authenticationToken;
} }
$sessionToken = $this->apiSessionToken(); $sessionToken = $this->apiSessionToken();
if ($this->isError($sessionToken)) { if ($this->isError($sessionToken)) {
// A session error should terminate the request immediately // A session error should terminate the request immediately.
return $sessionToken; return $sessionToken;
} }
// We don't have to return anything, both tokens can be accessed using the getters // We don't have to return anything, both tokens can be accessed using the getters.
return true; return TRUE;
} }
/** /**
* Wrapper for search API call * Wrapper for search API call.
* *
* @param array $search The search terms * @param array $search
* @param array $filters The facet filters * The search terms.
* @param string $start The page to start with * @param array $filters
* @param string $limit The number of records to return * The facet filters.
* @param string $sortBy The value to be used by for sorting * @param string $start
* @param string $amount The amount of data to be returned * The page to start with.
* @param string $mode The search mode * @param string $limit
* The number of records to return.
* @param string $sortBy
* The value to be used by for sorting.
* @param string $amount
* The amount of data to be returned.
* @param string $mode
* The search mode.
* *
* @throws object PEAR Error * @throws object PEAR Error
*
* @return array An array of query results * @return array An array of query results
*
* @access public * @access public
*/ */
public function apiSearch($search, $filters, public function apiSearch($search,
$start = 1, $limit = 10, $sortBy = 'relevance', $amount = 'detailed', $mode = 'all', $rs=false, $emp=false,$autosuggest=false) { $filters,
$start = 1,
$limit = 10,
$sortBy = 'relevance',
$amount = 'detailed',
$mode = 'all',
$rs = FALSE,
$emp = FALSE,
$autosuggest = FALSE) {
$query = array(); $query = array();
// Basic search // Basic search.
if (!empty($search['lookfor'])) { if (!empty($search['lookfor'])) {
$lookfor = $search['lookfor']; $lookfor = $search['lookfor'];
$type = isset($search['index']) && !empty($search['index']) ? $search['index'] : 'AllFields'; $type = isset($search['index']) && !empty($search['index']) ? $search['index'] : 'AllFields';
// escape some characters from lookfor term // Escape some characters from lookfor term.
$term = str_replace(array(',', ':', '(', ')'), array('\,', '\:', '\(', '\)'), $lookfor); $term = str_replace(array(',', ':', '(', ')'), array('\,', '\:', '\(', '\)'), $lookfor);
// replace multiple consecutive empty spaces with one empty space // Replace multiple consecutive empty spaces with one empty space.
$term = preg_replace("/\s+/", ' ', $term); $term = preg_replace("/\s+/", ' ', $term);
// search terms // Search terms
// Complex search term // Complex search term.
if (preg_match('/(.*) (AND|OR) (.*)/i', $term)) { if (preg_match('/(.*) (AND|OR) (.*)/i', $term)) {
$query['query'] = $term; $query['query'] = $term;
} else { }
else {
$tag = self::$search_tags[$type]; $tag = self::$search_tags[$type];
$op = 'AND'; $op = 'AND';
$query_str = implode(',', array($op, $tag)); $query_str = implode(',', array($op, $tag));
@ -410,7 +430,7 @@ class EBSCOAPI
$query['query-1'] = $query_str; $query['query-1'] = $query_str;
} }
// Advanced search // Advanced search.
} }
elseif (!empty($search['group'])) { elseif (!empty($search['group'])) {
@ -422,9 +442,9 @@ class EBSCOAPI
$op = $group['bool']; $op = $group['bool'];
$tag = $type && isset(self::$search_tags[$type]) ? self::$search_tags[$type] : ''; $tag = $type && isset(self::$search_tags[$type]) ? self::$search_tags[$type] : '';
// escape some characters from lookfor term // Escape some characters from lookfor term.
$term = str_replace(array(',', ':', '(', ')'), array('\,', '\:', '\(', '\)'), $term); $term = str_replace(array(',', ':', '(', ')'), array('\,', '\:', '\(', '\)'), $term);
// replace multiple consecutive empty spaces with one empty space // Replace multiple consecutive empty spaces with one empty space.
$term = preg_replace("/\s+/", ' ', $term); $term = preg_replace("/\s+/", ' ', $term);
if (!empty($term)) { if (!empty($term)) {
$query_str = implode(',', array($op, $tag)); $query_str = implode(',', array($op, $tag));
@ -435,148 +455,156 @@ class EBSCOAPI
} }
} }
// No search term, return an empty array // No search term, return an empty array.
} else { }
else {
$results = array( $results = array(
'recordCount' => 0, 'recordCount' => 0,
'numFound' => 0, 'numFound' => 0,
'start' => 0, 'start' => 0,
'documents' => array(), 'documents' => array(),
'facets' => array() 'facets' => array(),
); );
return $results; return $results;
} }
// Add filters // Add filters.
$limiters = array(); $expanders = array(); $facets = array(); $limiters = array(); $expanders = array(); $facets = array();
foreach ($filters as $filter) { foreach ($filters as $filter) {
if (preg_match('/addlimiter/', $filter)) { if (preg_match('/addlimiter/', $filter)) {
list($action, $str) = explode('(', $filter, 2); list($action, $str) = explode('(', $filter, 2);
$field_and_value = substr($str, 0, -1); // e.g. FT:y or GZ:Student Research, Projects and Publications // e.g. FT:y or GZ:Student Research, Projects and Publications.
$field_and_value = substr($str, 0, -1);
list($field, $value) = explode(':', $field_and_value, 2); list($field, $value) = explode(':', $field_and_value, 2);
$limiters[$field][] = $value; $limiters[$field][] = $value;
} else if (preg_match('/addexpander/', $filter)) { }
elseif (preg_match('/addexpander/', $filter)) {
list($action, $str) = explode('(', $filter, 2); list($action, $str) = explode('(', $filter, 2);
$field = substr($str, 0, -1); // expanders don't have value // Expanders don't have value.
$field = substr($str, 0, -1);
$expanders[] = $field; $expanders[] = $field;
} else if (preg_match('/addfacetfilter/', $filter)) { }
elseif (preg_match('/addfacetfilter/', $filter)) {
list($action, $str) = explode('(', $filter, 2); list($action, $str) = explode('(', $filter, 2);
$field_and_value = substr($str, 0, -1); // e.g. ZG:FRANCE // e.g. ZG:FRANCE.
$field_and_value = substr($str, 0, -1);
list($field, $value) = explode(':', $field_and_value, 2); list($field, $value) = explode(':', $field_and_value, 2);
$facets[$field][] = $field_and_value; $facets[$field][] = $field_and_value;
} }
} }
if (!empty($limiters)) { if (!empty($limiters)) {
foreach ($limiters as $field => $limiter) { foreach ($limiters as $field => $limiter) {
$query['limiter'][] = $field . ':' . implode(',', $limiter); // e.g. LA99:English,French,German // e.g. LA99:English,French,German.
$query['limiter'][] = $field . ':' . implode(',', $limiter);
} }
} }
if (!empty($expanders)) { if (!empty($expanders)) {
$query['expander'] = implode(',', $expanders); // e.g. fulltext, thesaurus // e.g. fulltext, thesaurus.
$query['expander'] = implode(',', $expanders);
} }
if (!empty($facets)) { if (!empty($facets)) {
$groupId = 1; $groupId = 1;
foreach ($facets as $field => $facet) { foreach ($facets as $field => $facet) {
$query['facetfilter'][] = $groupId . ',' . implode(',', $facet); // e.g. 1,DE:Math,DE:History // e.g. 1,DE:Math,DE:History.
$query['facetfilter'][] = $groupId . ',' . implode(',', $facet);
$groupId += 1; $groupId += 1;
} }
} }
//2014-03-26 - new action to jump to page // 2014-03-26 - new action to jump to page.
if ($start > 1) { if ($start > 1) {
$query['action'] = "GoToPage(" . $start . ")"; $query['action'] = "GoToPage(" . $start . ")";
} }
// Add the sort option.
// Add the sort option
$sortBy = in_array($sortBy, self::$sort_options) ? $sortBy : self::$mapped_sort_options[$sortBy]; $sortBy = in_array($sortBy, self::$sort_options) ? $sortBy : self::$mapped_sort_options[$sortBy];
// Add the HTTP query params // Add the HTTP query params.
$params = array( $params = array(
// Specifies the sort. Valid options are: // Specifies the sort. Valid options are:
// relevance, date, date2 // relevance, date, date2
// date = Date descending // date = Date descending
// date2 = Date ascending // date2 = Date ascending.
'sort' => $sortBy, 'sort' => $sortBy,
// Specifies the search mode. Valid options are: // Specifies the search mode. Valid options are:
// bool, any, all, smart // bool, any, all, smart.
'searchmode' => $mode, 'searchmode' => $mode,
// Specifies the amount of data to return with the response // Specifies the amount of data to return with the response
// Valid options are: // Valid options are:
// title: Title only // title: Title only
// brief: Title + Source, Subjects // brief: Title + Source, Subjects
// detailed: Brief + full abstract // detailed: Brief + full abstract.
'view' => $amount, 'view' => $amount,
/// Specifies whether or not to include facets // Specifies whether or not to include facets.
'includefacets' => 'y', 'includefacets' => 'y',
'resultsperpage' => $limit, 'resultsperpage' => $limit,
//2014-03-26 RF // 2014-03-26 RF.
'pagenumber' => $start, 'pagenumber' => $start,
// 'pagenumber' => 1, // 'pagenumber' => 1,
// Specifies whether or not to include highlighting in the search results // Specifies whether or not to include highlighting in the search results.
'highlight' => 'y' 'highlight' => 'y',
); );
if($autosuggest==true) { if ($autosuggest == TRUE) {
$params["autosuggest"] = "y"; $params["autosuggest"] = "y";
} }
if ($rs==true){ if ($rs == TRUE) {
$params["relatedcontent"] = "rs"; $params["relatedcontent"] = "rs";
} }
if ($emp==true){ if ($emp == TRUE) {
if (isset($params["relatedcontent"])) { if (isset($params["relatedcontent"])) {
$params["relatedcontent"] .= ",emp"; $params["relatedcontent"] .= ",emp";
} }
else else {
{
$params["relatedcontent"] = "emp"; $params["relatedcontent"] = "emp";
} }
} }
$params = array_merge($params, $query); $params = array_merge($params, $query);
$result = $this->request('Search', $params); $result = $this->request('Search', $params);
return $result; return $result;
} }
/** /**
* Wrapper for retrieve API call * Wrapper for retrieve API call.
* *
* @param array $an The accession number * @param array $an
* @param string $start The short database name * The accession number.
* @param string $start
* The short database name.
* *
* @throws object PEAR Error * @throws object PEAR Error
*
* @return array An associative array of data * @return array An associative array of data
*
* @access public * @access public
*/ */
public function apiRetrieve($an, $db) public function apiRetrieve($an, $db) {
{ // Add the HTTP query params.
// Add the HTTP query params
$params = array( $params = array(
'an' => $an, 'an' => $an,
'dbid' => $db, 'dbid' => $db,
'highlight' => 'y' 'highlight' => 'y',
); );
$result = $this->request('Retrieve', $params); $result = $this->request('Retrieve', $params);
return $result; return $result;
} }
/** /**
* Wrapper for info API call * Wrapper for info API call.
* *
* @throws object PEAR Error * @throws object PEAR Error
*
* @return array An associative array of data * @return array An associative array of data
*
* @access public * @access public
*/ */
public function apiInfo() public function apiInfo() {
{
if ($result = $this->readSession('info')) { if ($result = $this->readSession('info')) {
return $result; return $result;
} }
@ -589,23 +617,23 @@ class EBSCOAPI
return $result; return $result;
} }
/** /**
* Handle a PEAR_Error. Return : * Handle a PEAR_Error. Return :
* - if the error is critical : an associative array with the current error message * - if the error is critical : an associative array with the current error message
* - if the error is not critical : the error message * - if the error is not critical : the error message .
* *
* @param Pear_Error $exception * @param Pear_Error $exception
* *
* @return array or the Pear_Error exception * @return array or the Pear_Error exception
*
* @access protected * @access protected
*/ */
private function handleError($error) { private function handleError($error) {
$errorCode = $error->getCode(); $errorCode = $error->getCode();
switch ($errorCode) { switch ($errorCode) {
// This kind of error was generated by user , so display it to user // This kind of error was generated by user , so display it to user.
case EBSCOConnector::EDS_INVALID_ARGUMENT_VALUE: case EBSCOConnector::EDS_INVALID_ARGUMENT_VALUE:
// Any other errors are system errors, don't display them to user // Any other errors are system errors, don't display them to user.
default: default:
$errorMessage = 'An error occurred when getting the data.'; $errorMessage = 'An error occurred when getting the data.';
break; break;
@ -616,58 +644,55 @@ class EBSCOAPI
'numFound' => 0, 'numFound' => 0,
'start' => 0, 'start' => 0,
'documents' => array(), 'documents' => array(),
'facets' => array() 'facets' => array(),
); );
return $result; return $result;
} }
/** /**
* Store the given object into session * Store the given object into session.
* *
* @param string $key The key used for reading the value * @param string $key
* @param object $value The object stored in session * The key used for reading the value.
* @param object $value
* The object stored in session.
* *
* @return none * @return none
*
* @access protected * @access protected
*/ */
protected function writeSession($key, $value) protected function writeSession($key, $value) {
{
if (!empty($key) && !empty($value)) { if (!empty($key) && !empty($value)) {
$_SESSION['EBSCO'][$key] = $value; $_SESSION['EBSCO'][$key] = $value;
} }
} }
/** /**
* Read from session the object having the given key * Read from session the object having the given key.
* *
* @param string $key The key used for reading the object * @param string $key
* The key used for reading the object.
* *
* @return object * @return object
*
* @access protected * @access protected
*/ */
protected function readSession($key) protected function readSession($key) {
{
$value = isset($_SESSION['EBSCO'][$key]) ? $_SESSION['EBSCO'][$key] : ''; $value = isset($_SESSION['EBSCO'][$key]) ? $_SESSION['EBSCO'][$key] : '';
return $value; return $value;
} }
/** /**
* Check if given object is an EBSCOException object * Check if given object is an EBSCOException object.
* *
* @param object $object * @param object $object
* *
* @return boolean * @return bool
*
* @access protected * @access protected
*/ */
protected function isError($object) protected function isError($object) {
{
return is_a($object, 'EBSCOException'); return is_a($object, 'EBSCOException');
} }
} }
?>

249
ebsco/lib/EBSCOConnector.php

@ -1,9 +1,9 @@
<?php <?php
/** /**
* @file
* EBSCOException class * EBSCOException class
* Used when EBSCO API calls return error messages * Used when EBSCO API calls return error messages.
*
* *
* Copyright [2017] [EBSCO Information Services] * Copyright [2017] [EBSCO Information Services]
* *
@ -19,23 +19,27 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
class EBSCOException extends Exception
{ /**
*
*/
class EBSCOException extends Exception {
const CRITICAL_ERROR = 1; const CRITICAL_ERROR = 1;
// Make message argument mandatory /**
public function __construct($message, $code = self::CRITICAL_ERROR, Exception $previous = null) { * Make message argument mandatory.
*/
public function __construct($message, $code = self::CRITICAL_ERROR, Exception $previous = NULL) {
parent::__construct($message, $code, $previous); parent::__construct($message, $code, $previous);
} }
}
}
class EBSCOConnector
{
/** /**
* Error codes defined by EDS API *
*/
class EBSCOConnector {
/**
* Error codes defined by EDS API.
*/ */
const EDS_UNKNOWN_PARAMETER = 100; const EDS_UNKNOWN_PARAMETER = 100;
const EDS_INCORRECT_PARAMETER_FORMAT = 101; const EDS_INCORRECT_PARAMETER_FORMAT = 101;
@ -79,7 +83,7 @@ class EBSCOConnector
/** /**
* HTTP status codes constants * HTTP status codes constants
* http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html * http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html.
* *
* @global integer HTTP_OK The request has succeeded * @global integer HTTP_OK The request has succeeded
* @global integer HTTP_NOT_FOUND The server has not found anything matching the Request-URI * @global integer HTTP_NOT_FOUND The server has not found anything matching the Request-URI
@ -91,100 +95,110 @@ class EBSCOConnector
/** /**
* The HTTP_Request object used for API transactions * The HTTP_Request object used for API transactions.
*
* @global object HTTP_Request * @global object HTTP_Request
*/ */
private $client; private $client;
/** /**
* The URL of the EBSCO API server * The URL of the EBSCO API server.
*
* @global string * @global string
*/ */
private static $end_point = 'http://eds-api.ebscohost.com/EDSAPI/rest'; private static $end_point = 'http://eds-api.ebscohost.com/EDSAPI/rest';
/** /**
* The URL of the EBSCO API server * The URL of the EBSCO API server.
*
* @global string * @global string
*/ */
private static $authentication_end_point = 'https://eds-api.ebscohost.com/AuthService/rest'; private static $authentication_end_point = 'https://eds-api.ebscohost.com/AuthService/rest';
/** /**
* The password used for API transactions * The password used for API transactions.
*
* @global string * @global string
*/ */
private $password; private $password;
/** /**
* The user id used for API transactions * The user id used for API transactions.
*
* @global string * @global string
*/ */
private $userId; private $userId;
/** /**
* The profile ID used for API transactions * The profile ID used for API transactions.
*
* @global string * @global string
*/ */
private $profileId; private $profileId;
/** /**
* The interface ID used for API transactions * The interface ID used for API transactions.
*
* @global string * @global string
*/ */
private $interfaceId; private $interfaceId;
/** /**
* The customer ID used for API transactions * The customer ID used for API transactions.
*
* @global string * @global string
*/ */
private $orgId; private $orgId;
/** /**
* The isGuest used for API transactions * The isGuest used for API transactions.
*
* @global string 'y' or 'n' * @global string 'y' or 'n'
*/ */
private $isGuest; private $isGuest;
/** /**
* Contains the list of ip addresses * Contains the list of ip addresses.
*
* @global string * @global string
*/ */
private $local_ip_address; private $local_ip_address;
/* /**
* You can log HTTP_Request requests using this option * You can log HTTP_Request requests using this option.
*
* @global bool logAPIRequests * @global bool logAPIRequests
*/ */
private $logAPIRequests; private $logAPIRequests;
/** /**
* The logger object * The logger object.
*
* @global object Logger * @global object Logger
*/ */
private $logger; private $logger;
/** /**
* Constructor * Constructor.
* *
* Sets up the EBSCO API settings * Sets up the EBSCO API settings.
* *
* @param none * @param none
* *
* @access public * @access public
*/ */
public function __construct($config) {
public function __construct($config)
{
$this->password = $config['password']; $this->password = $config['password'];
$this->userId = $config['user']; $this->userId = $config['user'];
$this->interfaceId = $config['interface']; $this->interfaceId = $config['interface'];
@ -199,58 +213,55 @@ class EBSCOConnector
} }
} }
/** /**
* Detects if the user is authorized based on the IP address * Detects if the user is authorized based on the IP address.
* *
* @return string * @return string
*/ */
public function isGuestIPAddress($ipUser) public function isGuestIPAddress($ipUser) {
{
$s = $this->local_ip_address; $s = $this->local_ip_address;
if (trim($s) == "") { if (trim($s) == "") {
return false; return FALSE;
} }
//break records // Break records.
$m = explode(",", $s); $m = explode(",", $s);
foreach ($m as $ip) { foreach ($m as $ip) {
if (strcmp(substr($ipUser, 0, strlen(trim($ip))), trim($ip)) == 0) { if (strcmp(substr($ipUser, 0, strlen(trim($ip))), trim($ip)) == 0) {
// inside of ip address range of customer // Inside of ip address range of customer.
return true; return TRUE;
} }
} }
return false; return FALSE;
} }
/** /**
* Public getter for private isGuest * Public getter for private isGuest .
* *
* @param none * @param none
* *
* @return string isGuest * @return string isGuest
*
* @access public * @access public
*/ */
public function isGuest() public function isGuest() {
{
return $this->isGuest; return $this->isGuest;
} }
/** /**
* Request the authentication token * Request the authentication token.
* *
* @param none * @param none
* *
* @return object SimpleXml or PEAR_Error * @return object SimpleXml or PEAR_Error
*
* @access public * @access public
*/ */
public function requestAuthenticationToken() public function requestAuthenticationToken() {
{
$url = self::$authentication_end_point . '/UIDAuth'; $url = self::$authentication_end_point . '/UIDAuth';
// Add the body of the request // Add the body of the request.
$params = <<<BODY $params = <<<BODY
<UIDAuthRequestMessage xmlns="http://www.ebscohost.com/services/public/AuthService/Response/2012/06/01"> <UIDAuthRequestMessage xmlns="http://www.ebscohost.com/services/public/AuthService/Response/2012/06/01">
<UserId>{$this->userId}</UserId> <UserId>{$this->userId}</UserId>
@ -263,78 +274,81 @@ BODY;
return $response; return $response;
} }
/** /**
* Request the session token * Request the session token.
* *
* @param array $headers Authentication token * @param array $headers
* Authentication token.
* *
* @return object SimpleXml or PEAR_Error * @return object SimpleXml or PEAR_Error
*
* @access public * @access public
*/ */
public function requestSessionToken($headers) public function requestSessionToken($headers) {
{
$url = self::$end_point . '/CreateSession'; $url = self::$end_point . '/CreateSession';
// Add the HTTP query params // Add the HTTP query params.
$params = array( $params = array(
'profile' => $this->profileId, 'profile' => $this->profileId,
'org' => $this->orgId, 'org' => $this->orgId,
'guest' => $this->isGuest 'guest' => $this->isGuest,
); );
$response = $this->request($url, $params, $headers); $response = $this->request($url, $params, $headers);
return $response; return $response;
} }
/** /**
* Request the search records * Request the search records.
* *
* @param array $params Search specific parameters * @param array $params
* @param array $headers Authentication and session tokens * Search specific parameters.
* @param array $headers
* Authentication and session tokens.
* *
* @return object SimpleXml or PEAR_Error * @return object SimpleXml or PEAR_Error
*
* @access public * @access public
*/ */
public function requestSearch($params, $headers) public function requestSearch($params, $headers) {
{
$url = self::$end_point . '/Search'; $url = self::$end_point . '/Search';
$response = $this->request($url, $params, $headers); $response = $this->request($url, $params, $headers);
return $response; return $response;
} }
/** /**
* Request a specific record * Request a specific record.
* *
* @param array $params Retrieve specific parameters * @param array $params
* @param array $headers Authentication and session tokens * Retrieve specific parameters.
* @param array $headers
* Authentication and session tokens.
* *
* @return object SimpleXml or PEAR_Error * @return object SimpleXml or PEAR_Error
*
* @access public * @access public
*/ */
public function requestRetrieve($params, $headers) public function requestRetrieve($params, $headers) {
{
$url = self::$end_point . '/Retrieve'; $url = self::$end_point . '/Retrieve';
$response = $this->request($url, $params, $headers); $response = $this->request($url, $params, $headers);
return $response; return $response;
} }
/** /**
* Request the info data * Request the info data.
* *
* @param null $params Not used * @param null $params
* @param array $headers Authentication and session tokens * Not used.
* @param array $headers
* Authentication and session tokens.
* *
* @return object SimpleXml or PEAR_Error * @return object SimpleXml or PEAR_Error
*
* @access public * @access public
*/ */
public function requestInfo($params, $headers) public function requestInfo($params, $headers) {
{
$url = self::$end_point . '/Info'; $url = self::$end_point . '/Info';
$response = $this->request($url, $params, $headers); $response = $this->request($url, $params, $headers);
@ -342,34 +356,38 @@ BODY;
return $response; return $response;
} }
/** /**
* Send an HTTP request and inspect the response * Send an HTTP request and inspect the response.
* *
* @param string $url The url of the HTTP request * @param string $url
* @param array $params The parameters of the HTTP request * The url of the HTTP request.
* @param array $headers The headers of the HTTP request * @param array $params
* @param array $body The body of the HTTP request * The parameters of the HTTP request.
* @param string $method The HTTP method, default is 'GET' * @param array $headers
* The headers of the HTTP request.
* @param array $body
* The body of the HTTP request.
* @param string $method
* The HTTP method, default is 'GET'.
* *
* @return object SimpleXml or PEAR_Error * @return object SimpleXml or PEAR_Error
*
* @access protected * @access protected
*/ */
protected function request($url, $params, $headers = array(), $method = 'GET') protected function request($url, $params, $headers = array(), $method = 'GET') {
{ $xml = FALSE;
$xml = false; $return = FALSE;
$return = false; $data = NULL;
$data = null;
if (!empty($params)) { if (!empty($params)) {
// Arrays of parameters are used only for GET requests // Arrays of parameters are used only for GET requests.
if (is_array($params)) { if (is_array($params)) {
$query = http_build_query($params, '', '&'); $query = http_build_query($params, '', '&');
$query = preg_replace('/\%5B\d+\%5D/', '', $query); $query = preg_replace('/\%5B\d+\%5D/', '', $query);
$url = $url . '?' . $query; $url = $url . '?' . $query;
// String parameters are used only for POST requests // String parameters are used only for POST requests.
} else { }
else {
$data = $params; $data = $params;
$headers = array_merge( $headers = array_merge(
array('content-type' => 'text/xml'), array('content-type' => 'text/xml'),
@ -378,8 +396,7 @@ BODY;
} }
} }
//add compression in case its not there // Add compression in case its not there.
$headers = array_merge( $headers = array_merge(
array('Accept-Encoding' => 'gzip,deflate'), array('Accept-Encoding' => 'gzip,deflate'),
$headers $headers
@ -388,15 +405,14 @@ BODY;
$options = array( $options = array(
'headers' => $headers, 'headers' => $headers,
'method' => $method, 'method' => $method,
'data' => $data 'data' => $data,
); );
// Send the request // Send the request.
try { try {
$response = drupal_http_request($url, $options); $response = drupal_http_request($url, $options);
// print_r($url); // print_r($url);
// print_r($response); // print_r($response);
$code = $response->code; $code = $response->code;
if (isset($response->headers['content-encoding'])) { if (isset($response->headers['content-encoding'])) {
if ($response->headers['content-encoding'] == 'gzip') { if ($response->headers['content-encoding'] == 'gzip') {
@ -412,11 +428,12 @@ BODY;
$xml_str = $response->data; $xml_str = $response->data;
try { try {
// clean EMP namespace // Clean EMP namespace.
$xml_str = str_replace(array("<a:", "</a:"), array("<", "</"), $xml_str); $xml_str = str_replace(array("<a:", "</a:"), array("<", "</"), $xml_str);
$xml = simplexml_load_string($xml_str); $xml = simplexml_load_string($xml_str);
$return = $xml; $return = $xml;
} catch(Exception $e) { }
catch (Exception $e) {
$return = new EBSCOException($xml); $return = new EBSCOException($xml);
} }
break; break;
@ -426,28 +443,33 @@ BODY;
try { try {
$xml = simplexml_load_string($xml_str); $xml = simplexml_load_string($xml_str);
// If the response is an API error // If the response is an API error.
$isError = isset($xml->ErrorNumber) || isset($xml->ErrorCode); $isError = isset($xml->ErrorNumber) || isset($xml->ErrorCode);
if ($isError) { if ($isError) {
$error = ''; $code = 0; $error = ''; $code = 0;
if (isset($xml->DetailedErrorDescription) && !empty($xml->DetailedErrorDescription)) { if (isset($xml->DetailedErrorDescription) && !empty($xml->DetailedErrorDescription)) {
$error = (string) $xml->DetailedErrorDescription; $error = (string) $xml->DetailedErrorDescription;
} else if (isset($xml->ErrorDescription)) { }
elseif (isset($xml->ErrorDescription)) {
$error = (string) $xml->ErrorDescription; $error = (string) $xml->ErrorDescription;
} else if (isset($xml->Reason)) { }
elseif (isset($xml->Reason)) {
$error = (string) $xml->Reason; $error = (string) $xml->Reason;
} }
if (isset($xml->ErrorNumber)) { if (isset($xml->ErrorNumber)) {
$code = (integer) $xml->ErrorNumber; $code = (integer) $xml->ErrorNumber;
} else if (isset($xml->ErrorCode)) { }
elseif (isset($xml->ErrorCode)) {
$code = (integer) $xml->ErrorCode; $code = (integer) $xml->ErrorCode;
} }
$return = new EBSCOException($error, $code); $return = new EBSCOException($error, $code);
} else { }
else {
$return = new EBSCOException("HTTP {$code} : The request could not be understood $return = new EBSCOException("HTTP {$code} : The request could not be understood
by the server due to malformed syntax. Modify your search before retrying."); by the server due to malformed syntax. Modify your search before retrying.");
} }
} catch (Exception $e) { }
catch (Exception $e) {
$return = new EBSCOException($xml); $return = new EBSCOException($xml);
} }
break; break;
@ -466,8 +488,10 @@ BODY;
$return = new EBSCOException("HTTP {$code} : Unexpected HTTP error."); $return = new EBSCOException("HTTP {$code} : Unexpected HTTP error.");
break; break;
} }
} catch (Exception $e) { }
$message = $this->toString($client); // or $this->toString($response) catch (Exception $e) {
// Or $this->toString($response)
$message = $this->toString($client);
$this->logger->log($message, Zend_Log::ERR); $this->logger->log($message, Zend_Log::ERR);
$return = new EBSCOException($response); $return = new EBSCOException($response);
} }
@ -483,22 +507,17 @@ BODY;
return $return; return $return;
} }
/**
/* * Capture the output of print_r into a string.
* Capture the output of print_r into a string
* *
* @param object Any object * @param object Any object
*
* @access private * @access private
*/ */
private function toString($object) private function toString($object) {
{
ob_start(); ob_start();
print_r($object); print_r($object);
return ob_get_clean(); return ob_get_clean();
} }
} }
?>

408
ebsco/lib/EBSCODocument.php

@ -1,12 +1,12 @@
<?php <?php
/** /**
* The EBSCO Document model class * The EBSCO Document model class.
* *
* It provides all the methods and properties needed for : * It provides all the methods and properties needed for :
* - setting up and performing API calls * - setting up and performing API calls
* - displaying results in UI * - displaying results in UI
* - displaying statistics about the search, etc * - displaying statistics about the search, etc.
* *
* PHP version 5 * PHP version 5
* *
@ -28,140 +28,148 @@
require_once 'EBSCOAPI.php'; require_once 'EBSCOAPI.php';
require_once 'EBSCORecord.php'; require_once 'EBSCORecord.php';
class EBSCODocument
{
/** /**
* The EBSCOAPI object that performs the API calls *
*/
class EBSCODocument {
/**
* The EBSCOAPI object that performs the API calls.
*
* @global object EBSCOAPI * @global object EBSCOAPI
*/ */
private $eds = null; private $eds = NULL;
/** /**
* The associative array of current request parameters * The associative array of current request parameters.
*
* @global array * @global array
*/ */
private $params = array(); private $params = array();
/** /**
* The associative array of EBSCO results returned by a Search API call * The associative array of EBSCO results returned by a Search API call
* #global array * #global array.
*/ */
private $results = array(); private $results = array();
/** /**
* The associative array of data returned by a Retrieve API call * The associative array of data returned by a Retrieve API call.
*
* @global array * @global array
*/ */
private $result = array(); private $result = array();
/** /**
* The array of data returned by an Info API call * The array of data returned by an Info API call.
*
* @global array * @global array
*/ */
private $info = array(); private $info = array();
/** /**
* The EBSCORecord model returned by a Retrieve API call * The EBSCORecord model returned by a Retrieve API call
* #global object EBSCORecord * #global object EBSCORecord.
*/ */
private $record = null; private $record = NULL;
/** /**
* The array of EBSCORecord models returned by a Search API call * The array of EBSCORecord models returned by a Search API call
* #global array of EBSCORecord objects * #global array of EBSCORecord objects.
*/ */
private $records = array(); private $records = array();
/** /**
* The array of EBSCORecord models returned by a Search API call * The array of EBSCORecord models returned by a Search API call
* #global array of RelatedRecords * #global array of RelatedRecords.
*/ */
private $relatedContent = array(); private $relatedContent = array();
private $autoSuggestTerms = array(); private $autoSuggestTerms = array();
/** /**
* The array of filters currently applied * The array of filters currently applied.
*
* @global array * @global array
*/ */
private $filters = array(); private $filters = array();
/** /**
* Maximum number of results returned by Search API call * Maximum number of results returned by Search API call .
*
* @global integer * @global integer
*/ */
private $limit = 10; private $limit = 10;
/** /**
* Default level of data detail * Default level of data detail.
*
* @global string * @global string
*/ */
private $amount = 'brief'; private $amount = 'brief';
/** /**
* Maximum number of links displayed by the pagination * Maximum number of links displayed by the pagination.
*
* @global integer * @global integer
*/ */
private static $page_links = 10; private static $page_links = 10;
/** /**
* Limit options * Limit options
* global array * global array.
*/ */
private static $limit_options = array( private static $limit_options = array(
10 => 10, 10 => 10,
20 => 20, 20 => 20,
30 => 30, 30 => 30,
40 => 40, 40 => 40,
50 => 50 50 => 50,
); );
/** /**
* Sort options * Sort options
* global array * global array.
*/ */
private static $sort_options = array( private static $sort_options = array(
'relevance' => 'Relevance', 'relevance' => 'Relevance',
'date_desc' => 'Date Descending', 'date_desc' => 'Date Descending',
'date_asc' => 'Date Ascending' 'date_asc' => 'Date Ascending',
); );
/** /**
* Amount options * Amount options
* global array * global array.
*/ */
private static $amount_options = array( private static $amount_options = array(
'detailed' => 'Detailed', 'detailed' => 'Detailed',
'brief' => 'Brief', 'brief' => 'Brief',
'title' => 'Title Only' 'title' => 'Title Only',
); );
/** /**
* Bool options * Bool options
* global array * global array.
*/ */
private static $bool_options = array( private static $bool_options = array(
'AND' => 'All terms', 'AND' => 'All terms',
'OR' => 'Any terms', 'OR' => 'Any terms',
'NOT' => 'No terms' 'NOT' => 'No terms',
); );
/** /**
* Search mode options * Search mode options
* global array * global array.
*/ */
private static $mode_options = array( private static $mode_options = array(
'all' => 'All search terms', 'all' => 'All search terms',
'bool' => 'Boolean / Phrase', 'bool' => 'Boolean / Phrase',
'any' => 'Any search terms', 'any' => 'Any search terms',
'smart' => 'SmartText Searching' 'smart' => 'SmartText Searching',
); );
/** /**
* Basic search type options * Basic search type options
* global array * global array.
*/ */
private static $basic_search_type_options = array( private static $basic_search_type_options = array(
'AllFields' => 'All Text', 'AllFields' => 'All Text',
@ -169,12 +177,12 @@ class EBSCODocument
'Author' => 'Author', 'Author' => 'Author',
'Subject' => 'Subject terms', 'Subject' => 'Subject terms',
'Source' => 'Source', 'Source' => 'Source',
'Abstract' => 'Abstract' 'Abstract' => 'Abstract',
); );
/** /**
* Advanced search type options * Advanced search type options
* global array * global array.
*/ */
private static $advanced_search_type_options = array( private static $advanced_search_type_options = array(
'AllFields' => 'All Text', 'AllFields' => 'All Text',
@ -184,7 +192,7 @@ class EBSCODocument
'Source' => 'Journal Title/Source', 'Source' => 'Journal Title/Source',
'Abstract' => 'Abstract', 'Abstract' => 'Abstract',
'ISBN' => 'ISBN', 'ISBN' => 'ISBN',
'ISSN' => 'ISSN' 'ISSN' => 'ISSN',
); );
private $local_ips = ""; private $local_ips = "";
@ -192,10 +200,10 @@ class EBSCODocument
/** /**
* Constructor. * Constructor.
* *
* @param array $data Raw data from the EBSCO search representing the record. * @param array $data
* Raw data from the EBSCO search representing the record.
*/ */
public function __construct($params = null) public function __construct($params = NULL) {
{
$this->eds = new EBSCOAPI(array( $this->eds = new EBSCOAPI(array(
'password' => variable_get('ebsco_password'), 'password' => variable_get('ebsco_password'),
'user' => variable_get('ebsco_user'), 'user' => variable_get('ebsco_user'),
@ -204,7 +212,7 @@ class EBSCODocument
'organization' => variable_get('ebsco_organization'), 'organization' => variable_get('ebsco_organization'),
'local_ip_address' => variable_get('ebsco_local_ips'), 'local_ip_address' => variable_get('ebsco_local_ips'),
'guest' => variable_get('ebsco_guest'), 'guest' => variable_get('ebsco_guest'),
'log' => variable_get('ebsco_log') 'log' => variable_get('ebsco_log'),
)); ));
$this->params = $params ? $params : $_REQUEST; $this->params = $params ? $params : $_REQUEST;
@ -212,50 +220,46 @@ class EBSCODocument
$this->amount = variable_get('ebsco_default_amount') ? variable_get('ebsco_default_amount') : $this->amount; $this->amount = variable_get('ebsco_default_amount') ? variable_get('ebsco_default_amount') : $this->amount;
} }
/** /**
* Perform the API Info call * Perform the API Info call.
* *
* @return array * @return array
*/ */
public function info() public function info() {
{
$this->info = $this->eds->apiInfo(); $this->info = $this->eds->apiInfo();
return $this->info; return $this->info;
} }
/** /**
* Perform the API Retrieve call * Perform the API Retrieve call.
* *
* @return array * @return array
*/ */
public function retrieve() public function retrieve() {
{ list($an, $db) = isset($this->params['id']) ? explode('|', $this->params['id'], 2) : array(NULL, NULL);
list($an, $db) = isset($this->params['id']) ? explode('|', $this->params['id'], 2) : array(null, null);
$this->result = $this->eds->apiRetrieve($an, $db); $this->result = $this->eds->apiRetrieve($an, $db);
return $this->result; return $this->result;
} }
/** /**
* Perform the API Search call * Perform the API Search call.
* *
* @return array * @return array
*/ */
public function search() public function search() {
{
$search = array(); $search = array();
if (isset($this->params['lookfor']) && isset($this->params['type'])) { if (isset($this->params['lookfor']) && isset($this->params['type'])) {
$search = array( $search = array(
'lookfor' => $this->params['lookfor'], 'lookfor' => $this->params['lookfor'],
'index' => $this->params['type'] 'index' => $this->params['type'],
); );
} else if (isset($this->params['group'])) { }
elseif (isset($this->params['group'])) {
$search = $this->params; $search = $this->params;
} else { }
else {
return array(); return array();
} }
@ -263,29 +267,27 @@ class EBSCODocument
$page = isset($this->params['page']) ? $this->params['page'] + 1 : 1; $page = isset($this->params['page']) ? $this->params['page'] + 1 : 1;
$limit = $this->limit; $limit = $this->limit;
$sort = isset($this->params['sort']) ? $this->params['sort'] : 'relevance'; $sort = isset($this->params['sort']) ? $this->params['sort'] : 'relevance';
$amount = isset($this->params['amount']) ? $this->params['amount'] : 'brief'; // $amount = isset($this->params['amount']) ? $this->params['amount'] : 'brief'; $mode = isset($this->params['mode']) ? $this->params['mode'] : 'all';
$mode = isset($this->params['mode']) ? $this->params['mode'] : 'all';
// Check if research starters , EMP are active.
//check if research starters , EMP are active
$info = $this->info(); $info = $this->info();
$rs=false; $rs = FALSE;
$emp=false; $emp = FALSE;
if ($info["relatedContent"]) { if ($info["relatedContent"]) {
foreach ($info["relatedContent"] as $related) { foreach ($info["relatedContent"] as $related) {
if (($related["Type"] == "rs") and ($related["DefaultOn"] == "y")) { if (($related["Type"] == "rs") and ($related["DefaultOn"] == "y")) {
$rs=true; $rs = TRUE;
} }
if (($related["Type"] == "emp") and ($related["DefaultOn"] == "y")) { if (($related["Type"] == "emp") and ($related["DefaultOn"] == "y")) {
$emp=true; $emp = TRUE;
} }
} }
} }
$autosug=false; $autosug = FALSE;
if ($info["didYouMean"]) { if ($info["didYouMean"]) {
if ($info["didYouMean"][0]["DefaultOn"] == "y") { if ($info["didYouMean"][0]["DefaultOn"] == "y") {
$autosug=true; $autosug = TRUE;
} }
} }
@ -294,14 +296,12 @@ class EBSCODocument
return $this->results; return $this->results;
} }
/** /**
* Get the EBSCORecord model for the result * Get the EBSCORecord model for the result.
* *
** @return array * * @return array.
*/ */
public function record() public function record() {
{
if (empty($this->record) && !(empty($this->result))) { if (empty($this->record) && !(empty($this->result))) {
$this->record = new EBSCORecord($this->result); $this->record = new EBSCORecord($this->result);
} }
@ -309,19 +309,17 @@ class EBSCODocument
return $this->record; return $this->record;
} }
/** /**
* Get the EBSCORecord models array from results array * Get the EBSCORecord models array from results array.
* *
** @return array * * @return array.
*/ */
public function records() public function records() {
{
if ($this->record instanceof EBSCOException) { if ($this->record instanceof EBSCOException) {
return null; return NULL;
} }
if ($this->results instanceof EBSCOException) { if ($this->results instanceof EBSCOException) {
return null; return NULL;
} }
if (empty($this->records) && !(empty($this->results))) { if (empty($this->records) && !(empty($this->results))) {
foreach ($this->results['documents'] as $result) { foreach ($this->results['documents'] as $result) {
@ -332,148 +330,133 @@ class EBSCODocument
return $this->records; return $this->records;
} }
/**
public function relatedContent() *
{ */
public function relatedContent() {
if ($this->results instanceof EBSCOException) { if ($this->results instanceof EBSCOException) {
return null; return NULL;
} }
$this->relatedContent = isset($this->results['relatedContent']) ? $this->results['relatedContent'] : array(); $this->relatedContent = isset($this->results['relatedContent']) ? $this->results['relatedContent'] : array();
return $this->relatedContent; return $this->relatedContent;
} }
public function autoSuggestTerms() /**
{ *
*/
public function autoSuggestTerms() {
$this->autoSuggestTerms = isset($this->results['autoSuggestTerms']) ? $this->results['autoSuggestTerms'] : null; $this->autoSuggestTerms = isset($this->results['autoSuggestTerms']) ? $this->results['autoSuggestTerms'] : NULL;
return $this->autoSuggestTerms; return $this->autoSuggestTerms;
} }
/** /**
* Get the pagination HTML string * Get the pagination HTML string.
* *
** @return HTML string * * @return HTML string.
*/ */
public function pager() public function pager() {
{ $pager = NULL;
$pager = null; try {
try
{
if ($this->has_records()) { if ($this->has_records()) {
pager_default_initialize($this->record_count() / $this->limit, 1); pager_default_initialize($this->record_count() / $this->limit, 1);
$pager = theme('pager', array('tags' => null, 'quantity' => self::$page_links)); $pager = theme('pager', array('tags' => NULL, 'quantity' => self::$page_links));
$pager = preg_replace('/<li class="pager-last last">(.*)<\/li>/', '', $pager); $pager = preg_replace('/<li class="pager-last last">(.*)<\/li>/', '', $pager);
} }
} }
catch(Exception $e) catch (Exception $e) {
{
} }
return $pager; return $pager;
} }
/******************************************************** /********************************************************
* *
* Getters (class methods) * Getters (class methods)
* *
********************************************************/ ********************************************************/
/** /**
* Getter for sort options * Getter for sort options.
*
* @return array * @return array
*/ */
public static function limit_options() public static function limit_options() {
{
return self::$limit_options; return self::$limit_options;
} }
/** /**
* Getter for sort options * Getter for sort options.
*
* @return array * @return array
*/ */
public static function sort_options() public static function sort_options() {
{
return self::$sort_options; return self::$sort_options;
} }
/** /**
* Getter for amount options * Getter for amount options.
*
* @return array * @return array
*/ */
public static function amount_options() public static function amount_options() {
{
return self::$amount_options; return self::$amount_options;
} }
/** /**
* Getter for boolean options * Getter for boolean options.
*
* @return array * @return array
*/ */
public static function bool_options() public static function bool_options() {
{
return self::$bool_options; return self::$bool_options;
} }
/** /**
* Getter for search mode options * Getter for search mode options.
*
* @return array * @return array
*/ */
public static function mode_options() public static function mode_options() {
{
return self::$mode_options; return self::$mode_options;
} }
/** /**
* Getter for Basic search type options * Getter for Basic search type options.
*
* @return array * @return array
*/ */
public static function basic_search_type_options() public static function basic_search_type_options() {
{
return self::$basic_search_type_options; return self::$basic_search_type_options;
} }
/** /**
* Getter for Advanced search type options * Getter for Advanced search type options.
*
* @return array * @return array
*/ */
public static function advanced_search_type_options() public static function advanced_search_type_options() {
{
return self::$advanced_search_type_options; return self::$advanced_search_type_options;
} }
/******************************************************** /********************************************************
* *
* Helper methods * Helper methods
* *
********************************************************/ ********************************************************/
/** /**
* Get the expanders. * Get the expanders.
* *
* @return array * @return array
*/ */
public function expanders() public function expanders() {
{
$expanders = array(); $expanders = array();
try try {
{ if ($this->info instanceof EBSCOException) {
if ($this->info instanceof EBSCOException)
{
return $expanders; return $expanders;
} }
$actions = array(); $actions = array();
@ -485,27 +468,23 @@ class EBSCODocument
$expanders = isset($this->info['expanders']) ? $this->info['expanders'] : array(); $expanders = isset($this->info['expanders']) ? $this->info['expanders'] : array();
foreach ($expanders as $key => $expander) { foreach ($expanders as $key => $expander) {
if (in_array($expander['Action'], $actions)) { if (in_array($expander['Action'], $actions)) {
$expanders[$key]['selected'] = true; $expanders[$key]['selected'] = TRUE;
} }
} }
} }
catch(Exception $e) catch (Exception $e) {
{
} }
return $expanders; return $expanders;
} }
/** /**
* Get the facets. * Get the facets.
* *
* @return array * @return array
*/ */
public function facets() public function facets() {
{
if ($this->results instanceof EBSCOException) { if ($this->results instanceof EBSCOException) {
return array(); return array();
} }
@ -518,9 +497,9 @@ class EBSCODocument
$facets = isset($this->results['facets']) ? $this->results['facets'] : array(); $facets = isset($this->results['facets']) ? $this->results['facets'] : array();
foreach ($facets as $key => $cluster) { foreach ($facets as $key => $cluster) {
foreach ($cluster['Values'] as $k => $facet) { foreach ($cluster['Values'] as $k => $facet) {
$is_applied = false; $is_applied = FALSE;
if (in_array($facet['Action'], $actions)) { if (in_array($facet['Action'], $actions)) {
$is_applied = true; $is_applied = TRUE;
} }
$facets[$key]['Values'][$k]['applied'] = $is_applied; $facets[$key]['Values'][$k]['applied'] = $is_applied;
} }
@ -529,14 +508,12 @@ class EBSCODocument
return $facets; return $facets;
} }
/** /**
* Get the filters. * Get the filters.
* *
* @return array * @return array
*/ */
public function filters() public function filters() {
{
if (!empty($_REQUEST['filter'])) { if (!empty($_REQUEST['filter'])) {
$labels = array(); $labels = array();
foreach ($this->info['limiters'] as $limiter) { foreach ($this->info['limiters'] as $limiter) {
@ -549,17 +526,19 @@ class EBSCODocument
if (substr($temp, -1, 1) == ')') { if (substr($temp, -1, 1) == ')') {
$temp = substr($temp, 0, -1); $temp = substr($temp, 0, -1);
} }
// Do not display addfacetfilter, addlimiter or addexpander strings // Do not display addfacetfilter, addlimiter or addexpander strings.
if (preg_match('/\:/', $filter)) { if (preg_match('/\:/', $filter)) {
list($field, $value) = explode(':', $temp, 2); list($field, $value) = explode(':', $temp, 2);
$displayField = isset($labels[$field]) ? $labels[$field] : $field; $displayField = isset($labels[$field]) ? $labels[$field] : $field;
$displayValue = $value == 'y' ? 'yes' : $value; $displayValue = $value == 'y' ? 'yes' : $value;
} else if (preg_match('/addexpander/', $filter)) { }
elseif (preg_match('/addexpander/', $filter)) {
$field = $temp; $field = $temp;
$value = 'y'; $value = 'y';
$displayField = isset($labels[$field]) ? $labels[$field] : $field; $displayField = isset($labels[$field]) ? $labels[$field] : $field;
$displayValue = 'yes'; $displayValue = 'yes';
} else { }
else {
$field = $value = $displayField = $displayValue = $filter; $field = $value = $displayField = $displayValue = $filter;
} }
@ -576,17 +555,14 @@ class EBSCODocument
return $this->filters; return $this->filters;
} }
/** /**
* Get the limiters. * Get the limiters.
* *
* @return array * @return array
*/ */
public function limiters() public function limiters() {
{
$actions = array(); $ids = array(); $actions = array(); $ids = array();
if ($this->info instanceof EBSCOException) if ($this->info instanceof EBSCOException) {
{
return array(); return array();
} }
$filters = $this->filters(); $filters = $this->filters();
@ -597,7 +573,7 @@ class EBSCODocument
$limiters = isset($this->info['limiters']) ? $this->info['limiters'] : array(); $limiters = isset($this->info['limiters']) ? $this->info['limiters'] : array();
foreach ($limiters as $key => $cluster) { foreach ($limiters as $key => $cluster) {
// multi select limiter // Multi select limiter.
if (!empty($cluster['Values'])) { if (!empty($cluster['Values'])) {
foreach ($cluster['Values'] as $limiter) { foreach ($cluster['Values'] as $limiter) {
$action = $limiter['Action']; $action = $limiter['Action'];
@ -605,17 +581,19 @@ class EBSCODocument
$limiters[$key]['selected'][] = $limiter['Action']; $limiters[$key]['selected'][] = $limiter['Action'];
} }
} }
// date limiter // Date limiter.
} else if ($cluster['Type'] == 'ymrange') { }
elseif ($cluster['Type'] == 'ymrange') {
$id = $cluster['Id']; $id = $cluster['Id'];
if (($k = array_search($id, $ids)) !== false) { if (($k = array_search($id, $ids)) !== FALSE) {
$limiters[$key]['selected'] = $filters[$k]['action']; $limiters[$key]['selected'] = $filters[$k]['action'];
} }
// other limiters // Other limiters.
} else { }
else {
$action = str_replace('value', 'y', $cluster['Action']); $action = str_replace('value', 'y', $cluster['Action']);
if (in_array($action, $actions)) { if (in_array($action, $actions)) {
$limiters[$key]['selected'] = true; $limiters[$key]['selected'] = TRUE;
} }
} }
} }
@ -623,28 +601,24 @@ class EBSCODocument
return $limiters; return $limiters;
} }
/** /**
* Get the total number of records. * Get the total number of records.
* *
* @return integer * @return int
*/ */
public function record_count() public function record_count() {
{
if ($this->results instanceof EBSCOException) { if ($this->results instanceof EBSCOException) {
return 0; return 0;
} }
return !empty($this->results) ? $this->results['recordCount'] : 0; return !empty($this->results) ? $this->results['recordCount'] : 0;
} }
/** /**
* Get the number of end record. * Get the number of end record.
* *
* @return integer * @return int
*/ */
public function record_end() public function record_end() {
{
if ($this->results instanceof EBSCOException) { if ($this->results instanceof EBSCOException) {
return -1; return -1;
} }
@ -653,28 +627,24 @@ class EBSCODocument
return $start + $count; return $start + $count;
} }
/** /**
* Get the number of start record. * Get the number of start record.
* *
* @return integer * @return int
*/ */
public function record_start() public function record_start() {
{
if ($this->results instanceof EBSCOException) { if ($this->results instanceof EBSCOException) {
return null; return NULL;
} }
return !empty($this->results) ? $this->results['start'] + 1 : 0; return !empty($this->results) ? $this->results['start'] + 1 : 0;
} }
/** /**
* Get the search time * Get the search time.
* *
* @return decimal number * @return decimal number
*/ */
public function search_time() public function search_time() {
{
if ($this->results instanceof EBSCOException) { if ($this->results instanceof EBSCOException) {
return 0; return 0;
} }
@ -682,37 +652,34 @@ class EBSCODocument
isset($this->results['searchTime']) ? $this->results['searchTime'] : 0; isset($this->results['searchTime']) ? $this->results['searchTime'] : 0;
} }
/** /**
* Get the search view : basic or advanced * Get the search view : basic or advanced.
* *
* @return string * @return string
*/ */
public function search_view() public function search_view() {
{
if (isset($_REQUEST['group'])) { if (isset($_REQUEST['group'])) {
return 'advanced'; return 'advanced';
} else { }
else {
return 'basic'; return 'basic';
} }
} }
/** /**
* Hidden params used by UpdateForm * Hidden params used by UpdateForm.
* *
* @return array * @return array
*/ */
public function search_params() public function search_params() {
{
$params = $this->link_search_params(); $params = $this->link_search_params();
// filter the params that have same values as sidebar checkboxes, otherwise they will produce duplicates // Filter the params that have same values as sidebar checkboxes, otherwise they will produce duplicates.
$not_allowed_values = array( $not_allowed_values = array(
'addexpander(thesaurus)', 'addexpander(thesaurus)',
'addexpander(fulltext)', 'addexpander(fulltext)',
'addlimiter(FT:y)', 'addlimiter(FT:y)',
'addlimiter(RV:y)', 'addlimiter(RV:y)',
'addlimiter(SO:y)' 'addlimiter(SO:y)',
); );
$params = $this->array_filter_recursive($params, function ($item) use ($not_allowed_values) { $params = $this->array_filter_recursive($params, function ($item) use ($not_allowed_values) {
@ -722,20 +689,19 @@ class EBSCODocument
return array_filter($params); return array_filter($params);
} }
/** /**
* Hidden params used by UpdateForm * Hidden params used by UpdateForm.
* *
* @return array * @return array
*/ */
public function link_search_params() public function link_search_params() {
{ // Filter the page parameter.
// filter the page parameter
$not_allowed_keys = array('page', 'ui', 'has_js', 'op', 'submit', 'form_id', 'form_build_id'); $not_allowed_keys = array('page', 'ui', 'has_js', 'op', 'submit', 'form_id', 'form_build_id');
$query = ""; $query = "";
if(isset($_SERVER['QUERY_STRING'])) if (isset($_SERVER['QUERY_STRING'])) {
{$query = urldecode($_SERVER['QUERY_STRING']);} $query = urldecode($_SERVER['QUERY_STRING']);
}
parse_str($query, $params); parse_str($query, $params);
$params = $this->array_unset_recursive($params, $not_allowed_keys); $params = $this->array_unset_recursive($params, $not_allowed_keys);
@ -743,28 +709,24 @@ class EBSCODocument
return $params; return $params;
} }
/** /**
* Check if there are records in results array * Check if there are records in results array.
* *
** @return boolean * * @return boolean.
*/ */
public function has_records() public function has_records() {
{
if ($this->results instanceof EBSCOException) { if ($this->results instanceof EBSCOException) {
return false; return FALSE;
} }
return !empty($this->results) && !empty($this->results['documents']); return !empty($this->results) && !empty($this->results['documents']);
} }
/** /**
* Create the last search data * Create the last search data.
* *
* @return void * @return void
*/ */
public function search_create($query = null) public function search_create($query = NULL) {
{
if ($this->results instanceof EBSCOException) { if ($this->results instanceof EBSCOException) {
return array(); return array();
} }
@ -782,25 +744,21 @@ class EBSCODocument
return $last_search; return $last_search;
} }
/** /**
* Save last search data in session * Save last search data in session.
* *
* @return void * @return void
*/ */
public function search_write($query = null) public function search_write($query = NULL) {
{
$_SESSION['EBSCO']['last-search'] = $this->search_create($query); $_SESSION['EBSCO']['last-search'] = $this->search_create($query);
} }
/** /**
* Load last search data from session * Load last search data from session.
* *
* @return array * @return array
*/ */
public function search_read($id = null, $op = null) public function search_read($id = NULL, $op = NULL) {
{
$params = array(); $params = array();
$lastSearch = $_SESSION['EBSCO']['last-search']; $lastSearch = $_SESSION['EBSCO']['last-search'];
if ($lastSearch) { if ($lastSearch) {
@ -810,9 +768,9 @@ class EBSCODocument
$params['page'] = (int) (isset($params['page']) ? $params['page'] : 0); $params['page'] = (int) (isset($params['page']) ? $params['page'] : 0);
$index = array_search($id, $lastSearch['records']); $index = array_search($id, $lastSearch['records']);
// if this is not the first scroll and if this is not a page refresh // If this is not the first scroll and if this is not a page refresh.
if (isset($lastSearch['current']) && $lastSearch['current'] != $id) { if (isset($lastSearch['current']) && $lastSearch['current'] != $id) {
// if we change page // If we change page.
if (($op == 'Next' && $index % $this->limit === 0) || if (($op == 'Next' && $index % $this->limit === 0) ||
($op == 'Previous' && $index % $this->limit === 9)) { ($op == 'Previous' && $index % $this->limit === 9)) {
$params['page'] = ($op == 'Next') ? $params['page'] + 1 : $params['page'] - 1; $params['page'] = ($op == 'Next') ? $params['page'] + 1 : $params['page'] - 1;
@ -824,7 +782,8 @@ class EBSCODocument
if (count($lastSearch['records']) > 10) { if (count($lastSearch['records']) > 10) {
$records = array_slice($lastSearch['records'], $index - $index % $this->limit, $this->limit); $records = array_slice($lastSearch['records'], $index - $index % $this->limit, $this->limit);
} else { }
else {
$records = $lastSearch['records']; $records = $lastSearch['records'];
} }
@ -841,7 +800,8 @@ class EBSCODocument
$lastSearch['previous'] = isset($records[8]) ? $records[8] : ''; $lastSearch['previous'] = isset($records[8]) ? $records[8] : '';
} }
$lastSearch['next'] = isset($newSearch['records'][0]) ? $newSearch['records'][0] : ''; $lastSearch['next'] = isset($newSearch['records'][0]) ? $newSearch['records'][0] : '';
} else { }
else {
$lastSearch['next'] = $lastSearch['records'][$index + 1]; $lastSearch['next'] = $lastSearch['records'][$index + 1];
} }
@ -859,10 +819,12 @@ class EBSCODocument
if ($op == 'Previous') { if ($op == 'Previous') {
$lastSearch['next'] = isset($records[1]) ? $records[1] : ''; $lastSearch['next'] = isset($records[1]) ? $records[1] : '';
} }
} else { }
else {
$lastSearch['previous'] = ''; $lastSearch['previous'] = '';
} }
} else { }
else {
$lastSearch['previous'] = $lastSearch['records'][$index - 1]; $lastSearch['previous'] = $lastSearch['records'][$index - 1];
} }
@ -875,14 +837,12 @@ class EBSCODocument
return $lastSearch; return $lastSearch;
} }
/** /**
* A recursive array_filter * A recursive array_filter.
* *
* @return array * @return array
*/ */
private function array_filter_recursive($input, $callback = null) private function array_filter_recursive($input, $callback = NULL) {
{
foreach ($input as &$value) { foreach ($input as &$value) {
if (is_array($value)) { if (is_array($value)) {
$value = $this->array_filter_recursive($value, $callback); $value = $this->array_filter_recursive($value, $callback);
@ -891,9 +851,8 @@ class EBSCODocument
return array_filter($input, $callback); return array_filter($input, $callback);
} }
/** /**
* Recursive filter an array using the given $keys * Recursive filter an array using the given $keys.
* *
* @return array * @return array
*/ */
@ -912,4 +871,5 @@ class EBSCODocument
return array_filter($input); return array_filter($input);
} }
} }

163
ebsco/lib/EBSCORecord.php

@ -1,6 +1,7 @@
<?php <?php
/** /**
* The EBSCO record object * The EBSCO record object.
* *
* PHP version 5 * PHP version 5
* *
@ -20,132 +21,148 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
class EBSCORecord {
class EBSCORecord
{
/** /**
* The array of data * The array of data.
*
* @global array * @global array
*/ */
private $data = array(); private $data = array();
/** /**
* The result id (the EBSCO counter) of the record * The result id (the EBSCO counter) of the record.
*
* @global integer * @global integer
*/ */
public $result_id = null; public $result_id = NULL;
/** /**
* The id of the record * The id of the record.
*
* @global integer * @global integer
*/ */
public $record_id = null; public $record_id = NULL;
/** /**
* The summary of the record. * The summary of the record.
*
* @global string * @global string
*/ */
public $summary = null; public $summary = NULL;
/** /**
* The authors of the record. * The authors of the record.
*
* @global string * @global string
*/ */
public $authors = null; public $authors = NULL;
/** /**
* The subjects of the record. * The subjects of the record.
*
* @global string * @global string
*/ */
public $subjects = null; public $subjects = NULL;
/** /**
* The custom links provided for the record. * The custom links provided for the record.
*
* @global array * @global array
*/ */
public $custom_links = array(); public $custom_links = array();
/** /**
* The database label of the record. * The database label of the record.
*
* @global string * @global string
*/ */
public $db_label = null; public $db_label = NULL;
/** /**
* The full-text availability of the record. * The full-text availability of the record.
*
* @global boolean * @global boolean
*/ */
public $full_text_availability = null; public $full_text_availability = NULL;
/** /**
* The full text of the record. * The full text of the record.
*
* @global string * @global string
*/ */
public $full_text = null; public $full_text = NULL;
/** /**
* The PDF availability of the record. * The PDF availability of the record.
*
* @global boolean * @global boolean
*/ */
public $pdf_availability = null; public $pdf_availability = NULL;
/** /**
* The items of the record. * The items of the record.
*
* @global array * @global array
*/ */
public $items = array(); public $items = array();
/** /**
* The external link of the record. * The external link of the record.
*
* @global string * @global string
*/ */
public $p_link = null; public $p_link = NULL;
/** /**
* The external link to the PDF version of the record. * The external link to the PDF version of the record.
*
* @global string * @global string
*/ */
public $pdf_link = null; public $pdf_link = NULL;
/** /**
* The publication type link of the record. * The publication type link of the record.
*
* @global string * @global string
*/ */
public $publication_type = null; public $publication_type = NULL;
/** /**
* The external thumbnails links of the record. * The external thumbnails links of the record.
*
* @global string * @global string
*/ */
public $small_thumb_link = null; public $small_thumb_link = NULL;
public $medium_thumb_link = null; public $medium_thumb_link = NULL;
/** /**
* The title of the record. * The title of the record.
*
* @global string * @global string
*/ */
public $title = null; public $title = NULL;
/** /**
* The source of the record. * The source of the record.
*
* @global string * @global string
*/ */
public $source = null; public $source = NULL;
/** /**
* The access level of the record. * The access level of the record.
*
* @global string * @global string
*/ */
public $access_level = null; public $access_level = NULL;
/** /**
* Constructor. * Constructor.
* *
* @param array $data Raw data from the EBSCO search representing the record. * @param array $data
* Raw data from the EBSCO search representing the record.
*/ */
public function __construct($data = array()) public function __construct($data = array()) {
{
$this->data = $data; $this->data = $data;
$this->record_id = $this->record_id(); $this->record_id = $this->record_id();
$this->result_id = $this->result_id(); $this->result_id = $this->result_id();
@ -168,152 +185,127 @@ class EBSCORecord
$this->access_level = $this->access_level(); $this->access_level = $this->access_level();
} }
/******************************************************** /********************************************************
* *
* Getters * Getters
* *
********************************************************/ ********************************************************/
/** /**
* Get the summary of the record. * Get the summary of the record.
* *
* @return string * @return string
*/ */
public function access_level() public function access_level() {
{
return isset($this->data['AccessLevel']) ? return isset($this->data['AccessLevel']) ?
$this->data['AccessLevel'] : ''; $this->data['AccessLevel'] : '';
} }
/** /**
* Get the summary of the record. * Get the summary of the record.
* *
* @return string * @return string
*/ */
public function summary() public function summary() {
{
return isset($this->data['Items']['Abstract']) ? return isset($this->data['Items']['Abstract']) ?
$this->data['Items']['Abstract']['Data'] : ''; $this->data['Items']['Abstract']['Data'] : '';
} }
/** /**
* Get the authors of the record. * Get the authors of the record.
* *
* @return string * @return string
*/ */
public function authors() public function authors() {
{
return isset($this->data['Items']['Author']) ? return isset($this->data['Items']['Author']) ?
$this->data['Items']['Author']['Data'] : ''; $this->data['Items']['Author']['Data'] : '';
} }
/** /**
* Get the custom links of the record. * Get the custom links of the record.
* *
* @return array * @return array
*/ */
public function custom_links() public function custom_links() {
{
return isset($this->data['CustomLinks']) ? return isset($this->data['CustomLinks']) ?
$this->data['CustomLinks'] : array(); $this->data['CustomLinks'] : array();
} }
/** /**
* Get the database label of the record. * Get the database label of the record.
* *
* @return string * @return string
*/ */
public function db_label() public function db_label() {
{
return isset($this->data['DbLabel']) ? return isset($this->data['DbLabel']) ?
$this->data['DbLabel'] : ''; $this->data['DbLabel'] : '';
} }
/** /**
* Get the full text availability of the record. * Get the full text availability of the record.
* *
* @return boolean * @return bool
*/ */
public function full_text() public function full_text() {
{
return isset($this->data['FullText']) && return isset($this->data['FullText']) &&
isset($this->data['FullText']['Value']) ? $this->data['FullText']['Value'] : ''; isset($this->data['FullText']['Value']) ? $this->data['FullText']['Value'] : '';
} }
/** /**
* Get the full text availability of the record. * Get the full text availability of the record.
* *
* @return boolean * @return bool
*/ */
public function full_text_availability() public function full_text_availability() {
{
return isset($this->data['FullText']) && return isset($this->data['FullText']) &&
$this->data['FullText']['Availability']; $this->data['FullText']['Availability'];
} }
/** /**
* Get the items of the record. * Get the items of the record.
* *
* @return array * @return array
*/ */
public function items() public function items() {
{
return isset($this->data['Items']) ? $this->data['Items'] : array(); return isset($this->data['Items']) ? $this->data['Items'] : array();
} }
/** /**
* Get the external url of the record. * Get the external url of the record.
* *
* @return string * @return string
*/ */
public function p_link() public function p_link() {
{
return isset($this->data['PLink']) ? $this->data['PLink'] : ''; return isset($this->data['PLink']) ? $this->data['PLink'] : '';
} }
/** /**
* Get the publication type of the record. * Get the publication type of the record.
* *
* @return string * @return string
*/ */
public function publication_type() public function publication_type() {
{
return isset($this->data['PubType']) ? $this->data['PubType'] : ''; return isset($this->data['PubType']) ? $this->data['PubType'] : '';
} }
/** /**
* Get the PDF availability of the record. * Get the PDF availability of the record.
* *
* @return boolean * @return bool
*/ */
public function pdf_availability() public function pdf_availability() {
{
return isset($this->data['FullText']) && return isset($this->data['FullText']) &&
isset($this->data['FullText']['Links']) && isset($this->data['FullText']['Links']) &&
isset($this->data['FullText']['Links']['pdflink']) && isset($this->data['FullText']['Links']['pdflink']) &&
$this->data['FullText']['Links']['pdflink']; $this->data['FullText']['Links']['pdflink'];
} }
/** /**
* Get the PDF url of the record. * Get the PDF url of the record.
* *
* @return string * @return string
*/ */
public function pdf_link() public function pdf_link() {
{
return isset($this->data['FullText']) && return isset($this->data['FullText']) &&
isset($this->data['FullText']['Links']) && isset($this->data['FullText']['Links']) &&
isset($this->data['FullText']['Links']['pdflink']) ? isset($this->data['FullText']['Links']['pdflink']) ?
@ -321,91 +313,82 @@ class EBSCORecord
''; '';
} }
/** /**
* Get the result id of the record. * Get the result id of the record.
* *
* @return integer * @return int
*/ */
public function result_id() public function result_id() {
{
return isset($this->data['ResultId']) ? return isset($this->data['ResultId']) ?
$this->data['ResultId'] : ''; $this->data['ResultId'] : '';
} }
/** /**
* Get the subject data of the record. * Get the subject data of the record.
* *
* @return string * @return string
*/ */
public function subjects() public function subjects() {
{
return isset($this->data['Items']['Subject']) ? return isset($this->data['Items']['Subject']) ?
$this->data['Items']['Subject']['Data'] : ''; $this->data['Items']['Subject']['Data'] : '';
} }
/** /**
* Return a URL to a thumbnail preview of the record, if available; false * Return a URL to a thumbnail preview of the record, if available; false
* otherwise. * otherwise.
* *
* @param string $size Size of thumbnail (small, medium or large -- small is * @param string $size
* Size of thumbnail (small, medium or large -- small is
* default). * default).
* *
* @return string * @return string
*/ */
public function thumb_link($size = 'small') public function thumb_link($size = 'small') {
{
$imageInfo = isset($this->data['ImageInfo']) ? $this->data['ImageInfo'] : ''; $imageInfo = isset($this->data['ImageInfo']) ? $this->data['ImageInfo'] : '';
if ($imageInfo && isset($imageInfo['thumb'])) { if ($imageInfo && isset($imageInfo['thumb'])) {
switch ($size) { switch ($size) {
case 'large': case 'large':
case 'medium': case 'medium':
return $imageInfo['medium']; return $imageInfo['medium'];
break; break;
case 'small': case 'small':
default: default:
return $imageInfo['thumb']; return $imageInfo['thumb'];
break; break;
} }
} }
return false; return FALSE;
} }
/** /**
* Get the title of the record. * Get the title of the record.
* *
* @return string * @return string
*/ */
public function title() public function title() {
{
return isset($this->data['Items']['Title']) ? return isset($this->data['Items']['Title']) ?
$this->data['Items']['Title']['Data'] : ''; $this->data['Items']['Title']['Data'] : '';
} }
/** /**
* Get the source of the record. * Get the source of the record.
* *
* @return string * @return string
*/ */
public function source() public function source() {
{
return isset($this->data['Items']['TitleSource']) ? return isset($this->data['Items']['TitleSource']) ?
$this->data['Items']['TitleSource']['Data'] : ''; $this->data['Items']['TitleSource']['Data'] : '';
} }
/** /**
* Return the identifier of this record within the EBSCO databases * Return the identifier of this record within the EBSCO databases.
* *
* @return string Unique identifier. * @return string Unique identifier.
*/ */
public function record_id() public function record_id() {
{
return isset($this->data['id']) ? return isset($this->data['id']) ?
$this->data['id'] : ''; $this->data['id'] : '';
} }

186
ebsco/lib/EBSCOResponse.php

@ -1,8 +1,7 @@
<?php <?php
/** /**
* EBSCO Response class * EBSCO Response class.
* *
* PHP version 5 * PHP version 5
* *
@ -26,43 +25,40 @@ require_once 'sanitizer.class.php';
/** /**
* EBSCOResponse class * EBSCOResponse class.
*/ */
class EBSCOResponse class EBSCOResponse {
{
/** /**
* A SimpleXml object * A SimpleXml object.
*
* @global object * @global object
*/ */
private $response; private $response;
/** /**
* Constructor * Constructor.
* *
* Sets up the EBSCO Response * Sets up the EBSCO Response.
* *
* @param none * @param none
* *
* @access public * @access public
*/ */
public function __construct($response) public function __construct($response) {
{
$this->response = $response; $this->response = $response;
} }
/** /**
* Returns the XML as an associative array of data * Returns the XML as an associative array of data.
* *
* @param none * @param none
* *
* @return array An associative array of data * @return array An associative array of data
*
* @access public * @access public
*/ */
public function result() public function result() {
{
if (!empty($this->response->AuthToken)) { if (!empty($this->response->AuthToken)) {
return $this->buildAuthenticationToken(); return $this->buildAuthenticationToken();
} }
@ -78,28 +74,28 @@ class EBSCOResponse
elseif (!empty($this->response->AvailableSearchCriteria)) { elseif (!empty($this->response->AvailableSearchCriteria)) {
return $this->buildInfo(); return $this->buildInfo();
} }
else { // Should not happen, it may be an exception // Should not happen, it may be an exception.
else {
return $this->response; return $this->response;
} }
} }
/** /**
* Parse the SimpleXml object when an AuthenticationToken API call was executed * Parse the SimpleXml object when an AuthenticationToken API call was executed.
* *
* @param none * @param none
* *
* @return array An associative array of data * @return array An associative array of data
*
* @access private * @access private
*/ */
private function buildAuthenticationToken() private function buildAuthenticationToken() {
{
$token = (string) $this->response->AuthToken; $token = (string) $this->response->AuthToken;
$timeout = (integer) $this->response->AuthTimeout; $timeout = (integer) $this->response->AuthTimeout;
$result = array( $result = array(
'authenticationToken' => $token, 'authenticationToken' => $token,
'authenticationTimeout' => $timeout 'authenticationTimeout' => $timeout,
); );
return $result; return $result;
@ -107,15 +103,15 @@ class EBSCOResponse
/** /**
* Parse a SimpleXml object and * Parse a SimpleXml object and
* return it as an associative array * return it as an associative array.
* *
* @param none * @param none
* *
* @return array An associative array of data * @return array An associative array of data
*
* @access private * @access private
*/ */
private function buildSearch() private function buildSearch() {
{
$hits = (integer) $this->response->SearchResult->Statistics->TotalHits; $hits = (integer) $this->response->SearchResult->Statistics->TotalHits;
$searchTime = (integer) $this->response->SearchResult->Statistics->TotalSearchTime / 1000; $searchTime = (integer) $this->response->SearchResult->Statistics->TotalSearchTime / 1000;
$records = array(); $records = array();
@ -125,15 +121,15 @@ class EBSCOResponse
$facets = $this->buildFacets(); $facets = $this->buildFacets();
} }
// research Starters & emp // Research Starters & emp.
$relatedC=null; $relatedC = NULL;
if ($this->response->SearchResult->RelatedContent) { if ($this->response->SearchResult->RelatedContent) {
$result = json_decode(json_encode($this->response->SearchResult->RelatedContent), TRUE);; $result = json_decode(json_encode($this->response->SearchResult->RelatedContent), TRUE);;
$relatedC = $result; $relatedC = $result;
} }
//did you mean / auto suggest // Did you mean / auto suggest.
$autoSuggestTerms=null; $autoSuggestTerms = NULL;
if ($this->response->SearchResult->AutoSuggestedTerms) { if ($this->response->SearchResult->AutoSuggestedTerms) {
$result = json_decode(json_encode($this->response->SearchResult->AutoSuggestedTerms), TRUE);; $result = json_decode(json_encode($this->response->SearchResult->AutoSuggestedTerms), TRUE);;
$autoSuggestTerms = $result; $autoSuggestTerms = $result;
@ -147,31 +143,29 @@ class EBSCOResponse
'documents' => $records, 'documents' => $records,
'relatedContent' => $relatedC, 'relatedContent' => $relatedC,
'autoSuggestTerms' => $autoSuggestTerms, 'autoSuggestTerms' => $autoSuggestTerms,
'facets' => $facets 'facets' => $facets,
); );
return $results; return $results;
} }
/** /**
* Parse a SimpleXml object and * Parse a SimpleXml object and
* return it as an associative array * return it as an associative array.
* *
* @param none * @param none
* *
* @return array An associative array of data * @return array An associative array of data
*
* @access private * @access private
*/ */
private function buildRecords() private function buildRecords() {
{
$results = array(); $results = array();
$records = $this->response->SearchResult->Data->Records->Record; $records = $this->response->SearchResult->Data->Records->Record;
foreach ($records as $record) { foreach ($records as $record) {
$result = array(); $result = array();
// var_dump($record); // var_dump($record);
$result['ResultId'] = $record->ResultId ? (integer) $record->ResultId : ''; $result['ResultId'] = $record->ResultId ? (integer) $record->ResultId : '';
$result['DbId'] = $record->Header->DbId ? (string) $record->Header->DbId : ''; $result['DbId'] = $record->Header->DbId ? (string) $record->Header->DbId : '';
$result['DbLabel'] = $record->Header->DbLabel ? (string) $record->Header->DbLabel : ''; $result['DbLabel'] = $record->Header->DbLabel ? (string) $record->Header->DbLabel : '';
@ -186,16 +180,16 @@ class EBSCOResponse
$target = (string) $image->Target; $target = (string) $image->Target;
$result['ImageInfo'][$size] = $target; $result['ImageInfo'][$size] = $target;
} }
} else { }
else {
$result['ImageInfo'] = ''; $result['ImageInfo'] = '';
} }
if ($record->FullText) { if ($record->FullText) {
$availability = (integer) $record->FullText->Text->Availability == 1; $availability = (integer) $record->FullText->Text->Availability == 1;
$links = array(); $links = array();
//RF 2012-12-18 // RF 2012-12-18.
if (isset($record->FullText->Links)) if (isset($record->FullText->Links)) {
{
foreach ($record->FullText->Links->Link as $link) { foreach ($record->FullText->Links->Link as $link) {
$type = (string) $link->Type; $type = (string) $link->Type;
$url = (string) $link->Url; $url = (string) $link->Url;
@ -207,7 +201,7 @@ class EBSCOResponse
} }
$result['FullText'] = array( $result['FullText'] = array(
'Availability' => $availability, 'Availability' => $availability,
'Links' => $links 'Links' => $links,
); );
} }
@ -226,7 +220,7 @@ class EBSCOResponse
'MouseOverText' => $mouseOverText, 'MouseOverText' => $mouseOverText,
'Name' => $name, 'Name' => $name,
'Text' => $text, 'Text' => $text,
'Url' => $url 'Url' => $url,
); );
} }
} }
@ -242,31 +236,28 @@ class EBSCOResponse
'Name' => $name, 'Name' => $name,
'Label' => $label, 'Label' => $label,
'Group' => $group, 'Group' => $group,
'Data' => $this->toHTML($data, $group) 'Data' => $this->toHTML($data, $group),
); );
} }
} }
$results[] = $result; $results[] = $result;
} }
return $results; return $results;
} }
/** /**
* Parse a SimpleXml object and * Parse a SimpleXml object and
* return it as an associative array * return it as an associative array.
* *
* @param none * @param none
* *
* @return array An associative array of data * @return array An associative array of data
*
* @access private * @access private
*/ */
private function buildFacets() private function buildFacets() {
{
$results = array(); $results = array();
$facets = $this->response->SearchResult->AvailableFacets->AvailableFacet; $facets = $this->response->SearchResult->AvailableFacets->AvailableFacet;
@ -281,7 +272,7 @@ class EBSCOResponse
$values[] = array( $values[] = array(
'Value' => $this_value, 'Value' => $this_value,
'Action' => $this_action, 'Action' => $this_action,
'Count' => (string) $value->Count 'Count' => (string) $value->Count,
); );
} }
$id = (string) $facet->Id; $id = (string) $facet->Id;
@ -291,7 +282,7 @@ class EBSCOResponse
'Id' => $id, 'Id' => $id,
'Label' => $label, 'Label' => $label,
'Values' => $values, 'Values' => $values,
'isApplied' => false 'isApplied' => FALSE,
); );
} }
} }
@ -300,40 +291,39 @@ class EBSCOResponse
return $results; return $results;
} }
/** /**
* Parse a SimpleXml object and * Parse a SimpleXml object and
* return it as an associative array * return it as an associative array.
* *
* @param none * @param none
* *
* @return array An associative array of data * @return array An associative array of data
*
* @access private * @access private
*/ */
private function buildInfo() private function buildInfo() {
{ // Sort options.
// Sort options
$elements = $this->response->AvailableSearchCriteria->AvailableSorts->AvailableSort; $elements = $this->response->AvailableSearchCriteria->AvailableSorts->AvailableSort;
$sort = array(); $sort = array();
foreach ($elements as $element) { foreach ($elements as $element) {
$sort[] = array( $sort[] = array(
'Id' => (string) $element->Id, 'Id' => (string) $element->Id,
'Label' => (string) $element->Label, 'Label' => (string) $element->Label,
'Action' => (string) $element->AddAction 'Action' => (string) $element->AddAction,
); );
} }
// Search fields // Search fields.
$elements = $this->response->AvailableSearchCriteria->AvailableSearchFields->AvailableSearchField; $elements = $this->response->AvailableSearchCriteria->AvailableSearchFields->AvailableSearchField;
$tags = array(); $tags = array();
foreach ($elements as $element) { foreach ($elements as $element) {
$tags[] = array( $tags[] = array(
'Label' => (string) $element->Label, 'Label' => (string) $element->Label,
'Code' => (string) $element->FieldCode 'Code' => (string) $element->FieldCode,
); );
} }
// Expanders // Expanders.
$elements = $this->response->AvailableSearchCriteria->AvailableExpanders->AvailableExpander; $elements = $this->response->AvailableSearchCriteria->AvailableExpanders->AvailableExpander;
$expanders = array(); $expanders = array();
foreach ($elements as $element) { foreach ($elements as $element) {
@ -341,11 +331,12 @@ class EBSCOResponse
'Id' => (string) $element->Id, 'Id' => (string) $element->Id,
'Label' => (string) $element->Label, 'Label' => (string) $element->Label,
'Action' => (string) $element->AddAction, 'Action' => (string) $element->AddAction,
'selected' => false // Added because of the checkboxes // Added because of the checkboxes.
'selected' => FALSE,
); );
} }
// RelatedContent // RelatedContent.
$elements = $this->response->AvailableSearchCriteria->AvailableRelatedContent->AvailableRelatedContent; $elements = $this->response->AvailableSearchCriteria->AvailableRelatedContent->AvailableRelatedContent;
$relatedContent = array(); $relatedContent = array();
foreach ($elements as $element) { foreach ($elements as $element) {
@ -353,22 +344,22 @@ class EBSCOResponse
'Type' => (string) $element->Type, 'Type' => (string) $element->Type,
'Label' => (string) $element->Label, 'Label' => (string) $element->Label,
'Action' => (string) $element->AddAction, 'Action' => (string) $element->AddAction,
'DefaultOn' => (string) $element->DefaultOn 'DefaultOn' => (string) $element->DefaultOn,
); );
} }
// Did you mean // Did you mean.
$elements = $this->response->AvailableSearchCriteria->AvailableDidYouMeanOptions->AvailableDidYouMeanOption; $elements = $this->response->AvailableSearchCriteria->AvailableDidYouMeanOptions->AvailableDidYouMeanOption;
$didYouMean = array(); $didYouMean = array();
foreach ($elements as $element) { foreach ($elements as $element) {
$didYouMean[] = array( $didYouMean[] = array(
'Id' => (string) $element->Id, 'Id' => (string) $element->Id,
'Label' => (string) $element->Label, 'Label' => (string) $element->Label,
'DefaultOn' => (string) $element->DefaultOn 'DefaultOn' => (string) $element->DefaultOn,
); );
} }
// Limiters // Limiters.
$elements = $this->response->AvailableSearchCriteria->AvailableLimiters->AvailableLimiter; $elements = $this->response->AvailableSearchCriteria->AvailableLimiters->AvailableLimiter;
$limiters = array(); $limiters = array();
$values = array(); $values = array();
@ -379,7 +370,8 @@ class EBSCOResponse
$values[] = array( $values[] = array(
'Value' => (string) $item->Value, 'Value' => (string) $item->Value,
'Action' => (string) $item->AddAction, 'Action' => (string) $item->AddAction,
'selected' => false // Added because of the checkboxes // Added because of the checkboxes.
'selected' => FALSE,
); );
} }
} }
@ -389,7 +381,7 @@ class EBSCOResponse
'Action' => (string) $element->AddAction, 'Action' => (string) $element->AddAction,
'Type' => (string) $element->Type, 'Type' => (string) $element->Type,
'Values' => $values, 'Values' => $values,
'selected' => false 'selected' => FALSE,
); );
} }
@ -399,27 +391,27 @@ class EBSCOResponse
'expanders' => $expanders, 'expanders' => $expanders,
'limiters' => $limiters, 'limiters' => $limiters,
'relatedContent' => $relatedContent, 'relatedContent' => $relatedContent,
'didYouMean' => $didYouMean 'didYouMean' => $didYouMean,
); );
return $result; return $result;
} }
/** /**
* Parse a SimpleXml object and * Parse a SimpleXml object and
* return it as an associative array * return it as an associative array.
* *
* @param none * @param none
* *
* @return array An associative array of data * @return array An associative array of data
*
* @access private * @access private
*/ */
private function buildRetrieve() private function buildRetrieve() {
{
$record = $this->response->Record; $record = $this->response->Record;
if ($record) { if ($record) {
$record = $record[0]; // there is only one record // There is only one record.
$record = $record[0];
} }
$result = array(); $result = array();
@ -437,8 +429,7 @@ class EBSCOResponse
$result['ImageInfo'][$size] = $target; $result['ImageInfo'][$size] = $target;
} }
} }
else else {
{
$result['ImageInfo'] = ''; $result['ImageInfo'] = '';
} }
@ -457,7 +448,7 @@ class EBSCOResponse
$result['FullText'] = array( $result['FullText'] = array(
'Availability' => $availability, 'Availability' => $availability,
'Links' => $links, 'Links' => $links,
'Value' => $value 'Value' => $value,
); );
} }
@ -476,7 +467,7 @@ class EBSCOResponse
'MouseOverText' => $mouseOverText, 'MouseOverText' => $mouseOverText,
'Name' => $name, 'Name' => $name,
'Text' => $text, 'Text' => $text,
'Url' => $url 'Url' => $url,
); );
} }
} }
@ -492,7 +483,7 @@ class EBSCOResponse
'Name' => $name, 'Name' => $name,
'Label' => $label, 'Label' => $label,
'Group' => $group, 'Group' => $group,
'Data' => $this->toHTML($data, $group) 'Data' => $this->toHTML($data, $group),
); );
} }
} }
@ -500,30 +491,32 @@ class EBSCOResponse
return $result; return $result;
} }
/** /**
* Parse a SimpleXml element and * Parse a SimpleXml element and
* return it's inner XML as an HTML string * return it's inner XML as an HTML string.
* *
* @param SimpleXml $element A SimpleXml DOM * @param SimpleXml $element
* A SimpleXml DOM.
* *
* @return string The HTML string * @return string The HTML string
*
* @access protected * @access protected
*/ */
private function toHTML($data, $group = null) private function toHTML($data, $group = NULL) {
{
// Any group can be added here, but we only use Au (Author) // Any group can be added here, but we only use Au (Author)
// Other groups, not present here, won't be transformed to HTML links // Other groups, not present here, won't be transformed to HTML links.
$allowed_searchlink_groups = array('au'); $allowed_searchlink_groups = array('au');
// Map xml tags to the HTML tags // Map xml tags to the HTML tags
// This is just a small list, the total number of xml tags is far more greater // This is just a small list, the total number of xml tags is far more greater.
$xml_to_html_tags = array( $xml_to_html_tags = array(
'<jsection' => '<section', '<jsection' => '<section',
'</jsection' => '</section', '</jsection' => '</section',
'<highlight' => '<span class="highlight"', '<highlight' => '<span class="highlight"',
'<highligh' => '<span class="highlight"', // Temporary bug fix // Temporary bug fix.
'</highlight>' => '</span>', // Temporary bug fix '<highligh' => '<span class="highlight"',
// Temporary bug fix.
'</highlight>' => '</span>',
'</highligh' => '</span>', '</highligh' => '</span>',
'<text' => '<div', '<text' => '<div',
'</text' => '</div', '</text' => '</div',
@ -554,32 +547,32 @@ class EBSCOResponse
'<superscript' => '<sup', '<superscript' => '<sup',
'</superscript' => '</sup', '</superscript' => '</sup',
'<relatesTo' => '<sup', '<relatesTo' => '<sup',
'</relatesTo' => '</sup' '</relatesTo' => '</sup',
); );
// Map xml types to Search types used by the UI // Map xml types to Search types used by the UI.
$xml_to_search_types = array( $xml_to_search_types = array(
'au' => 'Author', 'au' => 'Author',
'su' => 'Subject' 'su' => 'Subject',
); );
// The XML data is XML escaped, let's unescape html entities (e.g. &lt; => <) // The XML data is XML escaped, let's unescape html entities (e.g. &lt; => <)
$data = html_entity_decode($data); $data = html_entity_decode($data);
// Start parsing the xml data // Start parsing the xml data.
if (!empty($data)) { if (!empty($data)) {
// Replace the XML tags with HTML tags // Replace the XML tags with HTML tags.
$search = array_keys($xml_to_html_tags); $search = array_keys($xml_to_html_tags);
$replace = array_values($xml_to_html_tags); $replace = array_values($xml_to_html_tags);
$data = str_replace($search, $replace, $data); $data = str_replace($search, $replace, $data);
// Temporary : fix unclosed tags // Temporary : fix unclosed tags.
$data = preg_replace('/<\/highlight/', '</span>', $data); $data = preg_replace('/<\/highlight/', '</span>', $data);
$data = preg_replace('/<\/span>>/', '</span>', $data); $data = preg_replace('/<\/span>>/', '</span>', $data);
$data = preg_replace('/<\/searchLink/', '</searchLink>', $data); $data = preg_replace('/<\/searchLink/', '</searchLink>', $data);
$data = preg_replace('/<\/searchLink>>/', '</searchLink>', $data); $data = preg_replace('/<\/searchLink>>/', '</searchLink>', $data);
// Parse searchLinks // Parse searchLinks.
if (!empty($group)) { if (!empty($group)) {
$group = strtolower($group); $group = strtolower($group);
if (in_array($group, $allowed_searchlink_groups)) { if (in_array($group, $allowed_searchlink_groups)) {
@ -592,7 +585,7 @@ class EBSCOResponse
} }
} }
// Replace the rest of searchLinks with simple spans // Replace the rest of searchLinks with simple spans.
$link_xml = '/<searchLink fieldCode="([^\"]*)" term="%22([^\"]*)%22">/'; $link_xml = '/<searchLink fieldCode="([^\"]*)" term="%22([^\"]*)%22">/';
$link_html = '<span>'; $link_html = '<span>';
$data = preg_replace($link_xml, $link_html, $data); $data = preg_replace($link_xml, $link_html, $data);
@ -603,13 +596,10 @@ class EBSCOResponse
$data = preg_replace('/<a id="([^\"]*)" idref="([^\"]*)" type="([^\"]*)"/', '<a id="$1" href="#$2"', $data); $data = preg_replace('/<a id="([^\"]*)" idref="([^\"]*)" type="([^\"]*)"/', '<a id="$1" href="#$2"', $data);
} }
$sanitizer = new HTML_Sanitizer; $sanitizer = new HTML_Sanitizer();
$data = $sanitizer->sanitize($data); $data = $sanitizer->sanitize($data);
return $data; return $data;
} }
} }
?>

334
ebsco/lib/sanitizer.class.php

@ -1,40 +1,44 @@
<?php // $Id$ <?php
// vim: expandtab sw=4 ts=4 sts=4: /**
* @file
# ***** BEGIN LICENSE BLOCK ***** * $Id$.
# This file is part of HTML Sanitizer. */
# Copyright (c) 2005-2011 Frederic Minne <zefredz@gmail.com>.
# All rights reserved.
#
# HTML Sanitizer is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# HTML Sanitizer 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 Lesser General Public License
# along with HTML Sanitizer; if not, see <http://www.gnu.org/licenses/>.
#
# ***** END LICENSE BLOCK *****
// vim: expandtab sw=4 ts=4 sts=4:
// ***** BEGIN LICENSE BLOCK *****
// This file is part of HTML Sanitizer.
// Copyright (c) 2005-2011 Frederic Minne <zefredz@gmail.com>.
// All rights reserved.
//
// HTML Sanitizer is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// HTML Sanitizer 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 Lesser General Public License
// along with HTML Sanitizer; if not, see <http://www.gnu.org/licenses/>.
//
// ***** END LICENSE BLOCK *****.
/** /**
* Sanitize HTML contents : * Sanitize HTML contents :
* Remove dangerous tags and attributes that can lead to security issues like * Remove dangerous tags and attributes that can lead to security issues like
* XSS or HTTP response splitting * XSS or HTTP response splitting.
* *
* @author Frederic Minne <zefredz@gmail.com> * @author Frederic Minne <zefredz@gmail.com>
* @copyright Copyright &copy; 2005-2011, Frederic Minne * @copyright Copyright &copy; 2005-2011, Frederic Minne
* @license http://www.gnu.org/licenses/lgpl.txt GNU Lesser General Public License version 3 or later * @license http://www.gnu.org/licenses/lgpl.txt GNU Lesser General Public License version 3 or later
* @version 1.1 * @version 1.1
*/ */
class HTML_Sanitizer class HTML_Sanitizer {
{ /**
// Private fields * Private fields.
*/
private $_allowedTags; private $_allowedTags;
private $_allowJavascriptEvents; private $_allowJavascriptEvents;
private $_allowJavascriptInUrls; private $_allowJavascriptInUrls;
@ -44,125 +48,123 @@ class HTML_Sanitizer
private $_additionalTags; private $_additionalTags;
/** /**
* Constructor * Constructor.
*/ */
public function __construct() public function __construct() {
{
$this->resetAll(); $this->resetAll();
} }
/** /**
* (re)set all options to default value * (re)set all options to default value.
*/ */
public function resetAll() public function resetAll() {
{ $this->_allowDOMEvents = FALSE;
$this->_allowDOMEvents = false; $this->_allowJavascriptInUrls = FALSE;
$this->_allowJavascriptInUrls = false; $this->_allowStyle = FALSE;
$this->_allowStyle = false; $this->_allowScript = FALSE;
$this->_allowScript = false; $this->_allowObjects = FALSE;
$this->_allowObjects = false; $this->_allowStyle = FALSE;
$this->_allowStyle = false;
$this->_allowedTags = '<a><br><b><h1><h2><h3><h4><h5><h6>' $this->_allowedTags = '<a><br><b><h1><h2><h3><h4><h5><h6>'
. '<img><li><ol><p><strong><table><tr><td><th><u><ul><thead>' . '<img><li><ol><p><strong><table><tr><td><th><u><ul><thead>'
. '<tbody><tfoot><em><dd><dt><dl><span><div><del><add><i><hr>' . '<tbody><tfoot><em><dd><dt><dl><span><div><del><add><i><hr>'
. '<pre><br><blockquote><address><code><caption><abbr><acronym>' . '<pre><br><blockquote><address><code><caption><abbr><acronym>'
. '<cite><dfn><q><ins><sup><sub><kbd><samp><var><tt><small><big>' . '<cite><dfn><q><ins><sup><sub><kbd><samp><var><tt><small><big>';
;
$this->_additionalTags = ''; $this->_additionalTags = '';
} }
/** /**
* Add additional tags to allowed tags * Add additional tags to allowed tags.
*
* @param string * @param string
*
* @access public * @access public
*/ */
public function addAdditionalTags( $tags ) public function addAdditionalTags($tags) {
{
$this->_additionalTags .= $tags; $this->_additionalTags .= $tags;
} }
/** /**
* Allow iframes * Allow iframes.
*
* @access public * @access public
*/ */
public function allowIframes() public function allowIframes() {
{
$this->addAdditionalTags('<iframe>'); $this->addAdditionalTags('<iframe>');
} }
/** /**
* Allow HTML5 media tags * Allow HTML5 media tags.
*
* @access public * @access public
*/ */
public function allowHtml5Media() public function allowHtml5Media() {
{
$this->addAdditionalTags('<canvas><video><audio>'); $this->addAdditionalTags('<canvas><video><audio>');
} }
/** /**
* Allow object, embed, applet and param tags in html * Allow object, embed, applet and param tags in html.
*
* @access public * @access public
*/ */
public function allowObjects() public function allowObjects() {
{ $this->_allowObjects = TRUE;
$this->_allowObjects = true;
} }
/** /**
* Allow DOM event on DOM elements * Allow DOM event on DOM elements.
*
* @access public * @access public
*/ */
public function allowDOMEvents() public function allowDOMEvents() {
{ $this->_allowDOMEvents = TRUE;
$this->_allowDOMEvents = true;
} }
/** /**
* Allow script tags * Allow script tags.
*
* @access public * @access public
*/ */
public function allowScript() public function allowScript() {
{ $this->_allowScript = TRUE;
$this->_allowScript = true;
} }
/** /**
* Allow the use of javascript: in urls * Allow the use of javascript: in urls.
*
* @access public * @access public
*/ */
public function allowJavascriptInUrls() public function allowJavascriptInUrls() {
{ $this->_allowJavascriptInUrls = TRUE;
$this->_allowJavascriptInUrls = true;
} }
/** /**
* Allow style tags and attributes * Allow style tags and attributes.
*
* @access public * @access public
*/ */
public function allowStyle() public function allowStyle() {
{ $this->_allowStyle = TRUE;
$this->_allowStyle = true;
} }
/** /**
* Helper to allow all javascript related tags and attributes * Helper to allow all javascript related tags and attributes.
*
* @access public * @access public
*/ */
public function allowAllJavascript() public function allowAllJavascript() {
{
$this->allowDOMEvents(); $this->allowDOMEvents();
$this->allowScript(); $this->allowScript();
$this->allowJavascriptInUrls(); $this->allowJavascriptInUrls();
} }
/** /**
* Allow all tags and attributes * Allow all tags and attributes.
*
* @access public * @access public
*/ */
public function allowAll() public function allowAll() {
{
$this->allowAllJavascript(); $this->allowAllJavascript();
$this->allowObjects(); $this->allowObjects();
$this->allowStyle(); $this->allowStyle();
@ -171,44 +173,44 @@ class HTML_Sanitizer
} }
/** /**
* Filter URLs to avoid HTTP response splitting attacks * Filter URLs to avoid HTTP response splitting attacks.
*
* @access public * @access public
* @param string url * @param string url
*
* @return string filtered url * @return string filtered url
*/ */
public function filterHTTPResponseSplitting( $url ) public function filterHTTPResponseSplitting($url) {
{
$dangerousCharactersPattern = '~(\r\n|\r|\n|%0a|%0d|%0D|%0A)~'; $dangerousCharactersPattern = '~(\r\n|\r|\n|%0a|%0d|%0D|%0A)~';
return preg_replace($dangerousCharactersPattern, '', $url); return preg_replace($dangerousCharactersPattern, '', $url);
} }
/** /**
* Remove potential javascript in urls * Remove potential javascript in urls.
*
* @access public * @access public
* @param string url * @param string url
*
* @return string filtered url * @return string filtered url
*/ */
public function removeJavascriptURL( $str ) public function removeJavascriptURL($str) {
{
$HTML_Sanitizer_stripJavascriptURL = 'javascript:[^"]+'; $HTML_Sanitizer_stripJavascriptURL = 'javascript:[^"]+';
$str = preg_replace("/$HTML_Sanitizer_stripJavascriptURL/i" $str = preg_replace("/$HTML_Sanitizer_stripJavascriptURL/i", '__forbidden__', $str);
, '__forbidden__'
, $str );
return $str; return $str;
} }
/** /**
* Remove potential flaws in urls * Remove potential flaws in urls.
*
* @access private * @access private
* @param string url * @param string url
*
* @return string filtered url * @return string filtered url
*/ */
private function sanitizeURL( $url ) private function sanitizeURL($url) {
{ if (!$this->_allowJavascriptInUrls) {
if ( ! $this->_allowJavascriptInUrls )
{
$url = $this->removeJavascriptURL($url); $url = $this->removeJavascriptURL($url);
} }
@ -218,172 +220,167 @@ class HTML_Sanitizer
} }
/** /**
* Callback for PCRE * Callback for PCRE.
*
* @access private * @access private
* @param matches array * @param matches array
*
* @return string * @return string
*
* @see sanitizeURL * @see sanitizeURL
*/ */
private function _sanitizeURLCallback( $matches ) private function _sanitizeURLCallback($matches) {
{
return 'href="' . $this->sanitizeURL($matches[1]) . '"'; return 'href="' . $this->sanitizeURL($matches[1]) . '"';
} }
/** /**
* Remove potential flaws in href attributes * Remove potential flaws in href attributes.
*
* @access private * @access private
* @param string html tag * @param string html tag
*
* @return string filtered html tag * @return string filtered html tag
*/ */
private function sanitizeHref( $str ) private function sanitizeHref($str) {
{
$HTML_Sanitizer_URL = 'href="([^"]+)"'; $HTML_Sanitizer_URL = 'href="([^"]+)"';
return preg_replace_callback("/$HTML_Sanitizer_URL/i" return preg_replace_callback("/$HTML_Sanitizer_URL/i", array(&$this, '_sanitizeURLCallback'), $str);
, array( &$this, '_sanitizeURLCallback' )
, $str );
} }
/** /**
* Callback for PCRE * Callback for PCRE.
*
* @access private * @access private
* @param matches array * @param matches array
*
* @return string * @return string
*
* @see sanitizeURL * @see sanitizeURL
*/ */
private function _sanitizeSrcCallback( $matches ) private function _sanitizeSrcCallback($matches) {
{
return 'src="' . $this->sanitizeURL($matches[1]) . '"'; return 'src="' . $this->sanitizeURL($matches[1]) . '"';
} }
/** /**
* Remove potential flaws in href attributes * Remove potential flaws in href attributes.
*
* @access private * @access private
* @param string html tag * @param string html tag
*
* @return string filtered html tag * @return string filtered html tag
*/ */
private function sanitizeSrc( $str ) private function sanitizeSrc($str) {
{
$HTML_Sanitizer_URL = 'src="([^"]+)"'; $HTML_Sanitizer_URL = 'src="([^"]+)"';
return preg_replace_callback("/$HTML_Sanitizer_URL/i" return preg_replace_callback("/$HTML_Sanitizer_URL/i", array(&$this, '_sanitizeSrcCallback'), $str);
, array( &$this, '_sanitizeSrcCallback' )
, $str );
} }
/** /**
* Remove dangerous attributes from html tags * Remove dangerous attributes from html tags.
*
* @access private * @access private
* @param string html tag * @param string html tag
*
* @return string filtered html tag * @return string filtered html tag
*/ */
private function removeEvilAttributes( $str ) private function removeEvilAttributes($str) {
{ if (!$this->_allowDOMEvents) {
if ( ! $this->_allowDOMEvents ) $str = preg_replace_callback('/<(.*?)>/i', array(&$this, '_removeDOMEventsCallback'), $str);
{
$str = preg_replace_callback('/<(.*?)>/i'
, array( &$this, '_removeDOMEventsCallback' )
, $str );
} }
if ( ! $this->_allowStyle ) if (!$this->_allowStyle) {
{ $str = preg_replace_callback('/<(.*?)>/i', array(&$this, '_removeStyleCallback'), $str);
$str = preg_replace_callback('/<(.*?)>/i'
, array( &$this, '_removeStyleCallback' )
, $str );
} }
return $str; return $str;
} }
/** /**
* Remove DOM events attributes from html tags * Remove DOM events attributes from html tags.
*
* @access private * @access private
* @param string html tag * @param string html tag
*
* @return string filtered html tag * @return string filtered html tag
*/ */
private function removeDOMEvents( $str ) private function removeDOMEvents($str) {
{
$str = preg_replace('/\s*=\s*/', '=', $str); $str = preg_replace('/\s*=\s*/', '=', $str);
$HTML_Sanitizer_stripAttrib = '(onclick|ondblclick|onmousedown|' $HTML_Sanitizer_stripAttrib = '(onclick|ondblclick|onmousedown|'
. 'onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|' . 'onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|'
. 'onkeyup|onfocus|onblur|onabort|onerror|onload)' . 'onkeyup|onfocus|onblur|onabort|onerror|onload)';
;
$str = stripslashes( preg_replace("/$HTML_Sanitizer_stripAttrib/i" $str = stripslashes(preg_replace("/$HTML_Sanitizer_stripAttrib/i", 'forbidden', $str));
, 'forbidden'
, $str ) );
return $str; return $str;
} }
/** /**
* Callback for PCRE * Callback for PCRE.
*
* @access private * @access private
* @param matches array * @param matches array
*
* @return string * @return string
*
* @see removeDOMEvents * @see removeDOMEvents
*/ */
private function _removeDOMEventsCallback( $matches ) private function _removeDOMEventsCallback($matches) {
{
return '<' . $this->removeDOMEvents($matches[1]) . '>'; return '<' . $this->removeDOMEvents($matches[1]) . '>';
} }
/** /**
* Remove style attributes from html tags * Remove style attributes from html tags.
*
* @access private * @access private
* @param string html tag * @param string html tag
*
* @return string filtered html tag * @return string filtered html tag
*/ */
private function removeStyle( $str ) private function removeStyle($str) {
{
$str = preg_replace('/\s*=\s*/', '=', $str); $str = preg_replace('/\s*=\s*/', '=', $str);
$HTML_Sanitizer_stripAttrib = '(style)' $HTML_Sanitizer_stripAttrib = '(style)';
;
$str = stripslashes( preg_replace("/$HTML_Sanitizer_stripAttrib/i" $str = stripslashes(preg_replace("/$HTML_Sanitizer_stripAttrib/i", 'forbidden', $str));
, 'forbidden'
, $str ) );
return $str; return $str;
} }
/** /**
* Callback for PCRE * Callback for PCRE.
*
* @access private * @access private
* @param matches array * @param matches array
*
* @return string * @return string
*
* @see removeStyle * @see removeStyle
*/ */
private function _removeStyleCallback( $matches ) private function _removeStyleCallback($matches) {
{
return '<' . $this->removeStyle($matches[1]) . '>'; return '<' . $this->removeStyle($matches[1]) . '>';
} }
/** /**
* Remove dangerous HTML tags * Remove dangerous HTML tags.
*
* @access private * @access private
* @param string html code * @param string html code
*
* @return string filtered url * @return string filtered url
*/ */
private function removeEvilTags( $str ) private function removeEvilTags($str) {
{
$allowedTags = $this->_allowedTags; $allowedTags = $this->_allowedTags;
if ( $this->_allowScript ) if ($this->_allowScript) {
{
$allowedTags .= '<script>'; $allowedTags .= '<script>';
} }
if ( $this->_allowStyle ) if ($this->_allowStyle) {
{
$allowedTags .= '<style>'; $allowedTags .= '<style>';
} }
if ( $this->_allowObjects ) if ($this->_allowObjects) {
{
$allowedTags .= '<object><embed><applet><param>'; $allowedTags .= '<object><embed><applet><param>';
} }
@ -397,13 +394,14 @@ class HTML_Sanitizer
/** /**
* Sanitize HTML * Sanitize HTML
* remove dangerous tags and attributes * remove dangerous tags and attributes
* clean urls * clean urls.
*
* @access public * @access public
* @param string html code * @param string html code
*
* @return string sanitized html code * @return string sanitized html code
*/ */
public function sanitize( $html ) public function sanitize($html) {
{
$html = $this->removeEvilTags($html); $html = $this->removeEvilTags($html);
$html = $this->removeEvilAttributes($html); $html = $this->removeEvilAttributes($html);
@ -414,31 +412,33 @@ class HTML_Sanitizer
return $html; return $html;
} }
} }
function html_sanitize( $str ) /**
{ *
static $san = null; */
function html_sanitize($str) {
static $san = NULL;
if ( empty( $san ) ) if (empty($san)) {
{ $san = new HTML_Sanitizer();
$san = new HTML_Sanitizer;
} }
return $san->sanitize($str); return $san->sanitize($str);
} }
function html_loose_sanitize( $str ) /**
{ *
static $san = null; */
function html_loose_sanitize($str) {
static $san = NULL;
if ( empty( $san ) ) if (empty($san)) {
{ $san = new HTML_Sanitizer();
$san = new HTML_Sanitizer;
$san->allowAll(); $san->allowAll();
} }
return $san->sanitize($str); return $san->sanitize($str);
} }

1
ebsco/templates/ebsco-advanced-search.tpl.php

@ -51,7 +51,6 @@
<option value="Abstract">Abstract</option> <option value="Abstract">Abstract</option>
<option value="ISBN">ISBN</option> <option value="ISBN">ISBN</option>
<option value="ISSN">ISSN</option> <option value="ISSN">ISSN</option>
</select> </select>
</div> </div>
<div class="delete-search"> <div class="delete-search">

21
ebsco/templates/ebsco-results.tpl.php

@ -22,7 +22,6 @@
* limitations under the License. * limitations under the License.
*/ */
if (isset($autoSuggestTerms)) { if (isset($autoSuggestTerms)) {
if (count($autoSuggestTerms) > 0) { if (count($autoSuggestTerms) > 0) {
$suggestString = ""; $suggestString = "";
@ -60,7 +59,7 @@
$tabsContent = ""; $tabsContent = "";
$counter = 0; $counter = 0;
$rsItem=null; $rsItem = NULL;
if (isset($relatedContent)) { if (isset($relatedContent)) {
foreach ($relatedContent as $item) { foreach ($relatedContent as $item) {
@ -76,7 +75,7 @@
$rsItem = $item["Records"]["Record"]; $rsItem = $item["Records"]["Record"];
} }
} }
if ($rsItem==null) { if ($rsItem == NULL) {
continue; continue;
} }
// var_dump($rsItem); // var_dump($rsItem);
@ -97,13 +96,16 @@
case "Ti": case "Ti":
$rsTitle = $it["Data"]; $rsTitle = $it["Data"];
break; break;
case "Src": case "Src":
$rsSource = $it["Data"]; $rsSource = $it["Data"];
break; break;
case "Su": case "Su":
$rsSubjects = $it["Data"]; $rsSubjects = $it["Data"];
break; break;
case "Ab": case "Ab":
$rsAbstract = $it["Data"]; $rsAbstract = $it["Data"];
break; break;
@ -135,7 +137,7 @@
$tabsContent .= '</div></div>'; $tabsContent .= '</div></div>';
} }
// replated publications // Replated publications.
if (isset($item["RelatedPublication"])) { if (isset($item["RelatedPublication"])) {
// var_dump($item); // var_dump($item);
$tabs .= '<li data-target="#ematchplacard" data-slide-to="' . $counter . '" ' . ($counter == 0 ? ' class="active" ' : ' ') . '></li>'; $tabs .= '<li data-target="#ematchplacard" data-slide-to="' . $counter . '" ' . ($counter == 0 ? ' class="active" ' : ' ') . '></li>';
@ -165,7 +167,7 @@
$hCoverage = isset($itemHoldings["CoverageStatement"]) ? $itemHoldings["CoverageStatement"] : ""; $hCoverage = isset($itemHoldings["CoverageStatement"]) ? $itemHoldings["CoverageStatement"] : "";
$hEmbargo = ""; $hEmbargo = "";
if (isset($itemHoldings["EmbargoDescription"])) { if (isset($itemHoldings["EmbargoDescription"])) {
// if no embargo, zero size array // If no embargo, zero size array.
if (!is_array($itemHoldings["EmbargoDescription"])) { if (!is_array($itemHoldings["EmbargoDescription"])) {
$hEmbargo = $itemHoldings["EmbargoDescription"]; $hEmbargo = $itemHoldings["EmbargoDescription"];
} }
@ -178,8 +180,7 @@
$tabsContent .= '</li><li>Embargo:' . $hEmbargo; $tabsContent .= '</li><li>Embargo:' . $hEmbargo;
} }
$tabsContent .= '</li></ul></li>'; $tabsContent .= '</li></ul></li>';
// Notes // Notes.
} }
$tabsContent .= '</ul></div>'; $tabsContent .= '</ul></div>';
} }
@ -305,7 +306,8 @@
foreach ($record->custom_links as $link){ ?> foreach ($record->custom_links as $link){ ?>
<li> <li>
<a href="<?php print $link['Url']; ?>" target="_blank" title="<?php print $link['MouseOverText']; ?>" class="external-link"> <a href="<?php print $link['Url']; ?>" target="_blank" title="<?php print $link['MouseOverText']; ?>" class="external-link">
<?php if ($link['Icon']): ?><img src="<?php print $link['Icon']?>" /><?php endif; ?><?php print $link['Name']; ?> <?php if ($link['Icon']): ?><img src="<?php print $link['Icon']?>" /><?php
endif; ?><?php print $link['Name']; ?>
</a> </a>
</li> </li>
<?php } ?> <?php } ?>
@ -341,8 +343,7 @@
} }
elseif (!empty($lookfor)) { elseif (!empty($lookfor)) {
echo "<h2>" . t('Your search did not match any resources.') . "</h2>"; echo "<h2>" . t('Your search did not match any resources.') . "</h2>";
// check for autocomplete // Check for autocomplete.
/* /*
if (isset ($autoSuggestTerms) ) { if (isset ($autoSuggestTerms) ) {
if (count($autoSuggestTerms)>0) { if (count($autoSuggestTerms)>0) {

2
ebsco/templates/ebsco-side-facets.tpl.php

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Display the sidebar block with facets filters * Display the sidebar block with facets filters.
* *
* @see template_preprocess_ebsco_side_facets() * @see template_preprocess_ebsco_side_facets()
* *

Loading…
Cancel
Save