From 520a49147da39b60377b3e4d0b226694d507eda5 Mon Sep 17 00:00:00 2001
From: James Wilson
Date: Fri, 21 Apr 2017 16:05:48 -0400
Subject: [PATCH] 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
---
ebsco/css/ebsco.css | 509 +++--
ebsco/ebsco.info | 2 +-
ebsco/ebsco.module | 1650 ++++++++--------
ebsco/lib/EBSCOAPI.php | 1247 ++++++------
ebsco/lib/EBSCOConnector.php | 925 ++++-----
ebsco/lib/EBSCODocument.php | 1670 ++++++++---------
ebsco/lib/EBSCORecord.php | 735 ++++----
ebsco/lib/EBSCOResponse.php | 1090 ++++++-----
ebsco/lib/sanitizer.class.php | 826 ++++----
ebsco/templates/ebsco-advanced-search.tpl.php | 7 +-
ebsco/templates/ebsco-basic-search.tpl.php | 30 +-
ebsco/templates/ebsco-result.tpl.php | 226 +--
ebsco/templates/ebsco-results.tpl.php | 651 +++----
ebsco/templates/ebsco-side-facets.tpl.php | 6 +-
14 files changed, 4774 insertions(+), 4800 deletions(-)
diff --git a/ebsco/css/ebsco.css b/ebsco/css/ebsco.css
index b1176cb..500f88b 100644
--- a/ebsco/css/ebsco.css
+++ b/ebsco/css/ebsco.css
@@ -9,7 +9,7 @@
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,92 +21,92 @@
/** General ***/
.floatleft {
- float: left;
+ float: left;
}
.floatright {
- float: right;
+ float: right;
}
.clear {
- clear: both;
+ clear: both;
}
.offscreen {
- display: none;
+ display: none;
}
.spinner {
- width: 16px;
- height: 16px;
- background: url("../images/ajax_loading.gif") no-repeat left top;
- display: none;
+ width: 16px;
+ height: 16px;
+ background: url("../images/ajax_loading.gif") no-repeat left top;
+ display: none;
}
.highlight {
- font-weight: bold;
+ font-weight: bold;
}
/** Search list ***/
.ebsco .result {
- width: 650px;
+ width: 650px;
}
.ebsco .record-number {
- margin-right: 10px;
- min-width: 10px;
+ margin-right: 10px;
+ min-width: 10px;
}
.ebsco .span-2 {
- width: auto;
- max-width: 70px;
- margin-right: 10px;
- float: left;
+ width: auto;
+ max-width: 70px;
+ margin-right: 10px;
+ float: left;
}
.ebsco .span-9 {
- float: none;
- overflow: auto;
- width: auto;
- margin-right: 0;
+ float: none;
+ overflow: auto;
+ width: auto;
+ margin-right: 0;
}
.ebsco .pagination {
- margin-bottom: 0;
- padding: 0.2em
+ margin-bottom: 0;
+ padding: 0.2em
}
.ebsco p.submit {
- padding: 10px 0;
+ padding: 10px 0;
}
.ebsco .jumpMenu {
- max-width: 130px;
+ max-width: 130px;
}
.ebsco ul.custom-links {
- list-style-type: none;
- margin: 0;
- padding: 0;
+ list-style-type: none;
+ margin: 0;
+ padding: 0;
}
.ebsco ul.custom-links li {
- display: inline-block;
- padding-left: 0;
- padding-right: 10px;
- margin-left: 10px;
- border-right: 1px solid #CCCCCC;
+ display: inline-block;
+ padding-left: 0;
+ padding-right: 10px;
+ margin-left: 10px;
+ border-right: 1px solid #cccccc;
}
.ebsco ul.custom-links li:first-child {
- margin-left: 0;
+ margin-left: 0;
}
.ebsco ul.custom-links li:last-child {
- padding-right: 0;
- border-right: 0 none;
+ padding-right: 0;
+ border-right: 0 none;
}
@@ -114,63 +114,63 @@
/** Side facets **/
#block-ebsco-ebsco-facets h2 {
- font-weight: bold;
+ font-weight: bold;
}
#block-ebsco-ebsco-facets {
- padding: 5px !important;
+ padding: 5px !important;
}
#block-ebsco-ebsco-facets dl {
- margin: 5px 0;
- padding: 0;
+ margin: 5px 0;
+ padding: 0;
}
#block-ebsco-ebsco-facets dl dt {
- font-size: 115%;
- padding: 5px;
- background-color: #eeeeee;
+ font-size: 115%;
+ padding: 5px;
+ background-color: #eeeeee;
}
#block-ebsco-ebsco-facets dd {
- font-weight: normal !important;
- margin: 0;
- padding: 5px !important;
- border-bottom: 1px solid #dddddd;
+ font-weight: normal !important;
+ margin: 0;
+ padding: 5px !important;
+ border-bottom: 1px solid #dddddd;
}
#block-ebsco-ebsco-facets dd.submit input {
- margin: 0;
+ margin: 0;
}
#block-ebsco-ebsco-facets dl dd:last-child {
- border-bottom: none;
+ border-bottom: none;
}
#block-ebsco-ebsco-facets dd label {
- font-weight: normal;
- font-family: Arial;
- padding: 0 3px;
+ font-weight: normal;
+ font-family: Arial;
+ padding: 0 3px;
}
#block-ebsco-ebsco-facets dd label {
- display: inline;
+ display: inline;
}
#block-ebsco-ebsco-facets dl.expandable:hover {
- cursor: pointer;
+ cursor: pointer;
}
#block-ebsco-ebsco-facets dl.expandable:hover dt span {
- color: #444444;
+ color: #444444;
}
#block-ebsco-ebsco-facets .narrow-list.filters {
- background-color: orange;
+ background-color: orange;
}
#block-ebsco-ebsco-facets .narrow-list.filters a {
- color: white;
+ color: white;
}
@@ -178,85 +178,85 @@
/** Detailed view ***/
.ebsco-record .toolbar {
- border-bottom: 1px solid #EEEEEE;
- margin-bottom: 1em;
- min-height: 2em;
- padding-left: 1em;
+ border-bottom: 1px solid #eeeeee;
+ margin-bottom: 1em;
+ min-height: 2em;
+ padding-left: 1em;
}
.ebsco-record.push-5 {
- margin: 0;
+ margin: 0;
}
.ebsco-record .span-13 {
- min-width: 540px;
- max-width: 690px;
- width: auto;
- float: left;
+ min-width: 540px;
+ max-width: 690px;
+ width: auto;
+ float: left;
}
.ebsco-record .span-13 table {
- margin-top: 0;
+ margin-top: 0;
}
.ebsco-record .span-13 table tr td {
- word-break: break-all;
+ word-break: break-all;
}
.ebsco-record .span-4 {
- max-width: 150px;
- min-width: 80px;
- width: auto;
- margin: 0 0 0 10px;
- text-align: center;
- float: left;
+ max-width: 150px;
+ min-width: 80px;
+ width: auto;
+ margin: 0 0 0 10px;
+ text-align: center;
+ float: left;
}
.ebsco-record .external-links {
- border: 1px solid #eeeeee;
- list-style-type: none;
- margin: 10px 0;
- padding: 0;
+ border: 1px solid #eeeeee;
+ list-style-type: none;
+ margin: 10px 0;
+ padding: 0;
}
.ebsco-record .external-links li {
- display: inline-block;
- padding-left: 0;
- padding-right: 10px;
- margin-left: 10px;
- border-right: 1px solid #CCCCCC;
- line-height: 32px;
- margin: 5px;
+ display: inline-block;
+ padding-left: 0;
+ padding-right: 10px;
+ margin-left: 10px;
+ border-right: 1px solid #cccccc;
+ line-height: 32px;
+ margin: 5px;
}
.ebsco-record .external-links li:last-child {
- border-right: 0 none;
+ border-right: 0 none;
}
.external-link img {
- vertical-align: middle;
- padding-right: 5px;
+ vertical-align: middle;
+ padding-right: 5px;
}
.top-login-message {
- margin-top:10px;
- width: 100%;
- text-align: center;
+ margin-top: 10px;
+ width: 100%;
+ text-align: center;
}
.ebsco-record .record {
- width: 100%;
- padding: 0;
+ width: 100%;
+ padding: 0;
}
.ebsco-record .book-jacket {
- max-width: 150px;
+ max-width: 150px;
}
.ebsco-record .html {
- background-color: white;
- padding:10px 0;
- border: 0;
+ background-color: white;
+ padding: 10px 0;
+ border: 0;
}
@@ -264,281 +264,274 @@
#ebsco-basic-search-form .form-item-lookfor,
#ebsco-basic-search-form .form-item-type {
- display: inline !important;
+ display: inline !important;
}
#ebsco-basic-search-form #edit-links {
- display: inline;
- margin: 0;
- padding: 0;
- border: none 0;
- position: static;
+ display: inline;
+ margin: 0;
+ padding: 0;
+ border: none 0;
+ position: static;
}
#ebsco-basic-search-form #edit-offscreen {
- display: none;
+ display: none;
}
#ebsco-basic-search-form .form-item-remember label {
- font-weight: bold;
+ font-weight: bold;
}
#ebsco-sort-form {
- margin : 10px 0;
+ margin: 10px 0;
}
#ebsco-sort-form > div {
- border-bottom: 1px solid #CCCCCC;
+ border-bottom: 1px solid #cccccc;
}
#ebsco-sort-form label,
#ebsco-sort-form .form-item {
- display: inline-block !important;
+ display: inline-block !important;
}
#ebsco-sort-form .form-item:first-child {
- float: right;
+ float: right;
}
#ebsco-sort-form .form-item:last-child {
- float: left;
+ float: left;
}
/** Advanced search form ***/
.ebsco-advanced ._advanced-row {
- border: 0 none;
- padding: 0;
- margin: 10px;
- top: 5px;
+ border: 0 none;
+ padding: 0;
+ margin: 10px;
+ top: 5px;
}
.ebsco-advanced #edit-rows {
- margin-bottom: 20px;
+ margin-bottom: 20px;
}
.ebsco-advanced ._advanced-row .fieldset-wrapper {
- margin: 0 !important;
- padding: 0;
+ margin: 0 !important;
+ padding: 0;
}
.ebsco-advanced .form-item-group0-lookfor label {
- display: inline-block;
- text-align: right;
- width: 100px;
+ display: inline-block;
+ text-align: right;
+ width: 100px;
}
.ebsco-advanced .form-type-radio label {
- display: inline-block;
- text-align: left;
- width: 90%;
+ display: inline-block;
+ text-align: left;
+ width: 90%;
}
.ebsco-advanced #edit-add-row {
- border: 0 none;
- padding: 0;
- margin: 10px;
- top: 5px;
+ border: 0 none;
+ padding: 0;
+ margin: 10px;
+ top: 5px;
}
.ebsco-advanced #edit-add-row .fieldset-wrapper {
- margin-top: 5px;
+ margin-top: 5px;
}
.ebsco-advanced #edit-links {
- margin-bottom: 20px;
- text-align: center;
+ margin-bottom: 20px;
+ text-align: center;
}
.ebsco-advanced #edit-links .fieldset-wrapper {
- margin-top: 10px;
+ margin-top: 10px;
}
.ebsco-advanced #edit-limiters {
- width: 99%;
+ width: 99%;
}
.ebsco-advanced #edit-modes {
- width: 49%;
- float: left;
+ width: 49%;
+ float: left;
}
.ebsco-advanced #edit-modes {
- width: 49%;
- float: left;
+ width: 49%;
+ float: left;
}
.ebsco-advanced #edit-expanders {
- width: 49%;
- float: right;
+ width: 49%;
+ float: right;
}
.ebsco-advanced #edit-limiters label {
- font-weight: normal;
+ font-weight: normal;
}
.ebsco-advanced #edit-limiters .form-type-select label {
- display: block;
+ display: block;
}
.ebsco-advanced #edit-limiters hr {
- margin: 15px 0;
- height: 1px;
- background-color: #CCCCCC;
- color: #CCCCCC;
- border: 0 none;
+ margin: 15px 0;
+ height: 1px;
+ background-color: #cccccc;
+ color: #cccccc;
+ border: 0 none;
}
.dateSlider {
- width: 150px;
- display: inline-block !important;
- margin: 0 10px;
+ width: 150px;
+ display: inline-block !important;
+ margin: 0 10px;
}
/** Icons ***/
.icon {
- background: url("../images/sprites_32.png") no-repeat top left;
- height: 32px;
- line-height: 32px;
- display: inline-block;
- padding: 0 0 0 36px !important;
+ background: url("../images/sprites_32.png") no-repeat top left;
+ height: 32px;
+ line-height: 32px;
+ display: inline-block;
+ padding: 0 0 0 36px !important;
}
.icon.ebook {
- background-position: 0 0;
+ background-position: 0 0;
}
.icon.html {
- background-position: 0 -42px;
+ background-position: 0 -42px;
}
.icon.pdf {
- background-position: 0 -84px;
+ background-position: 0 -84px;
}
.icon13 {
- background: url("../images/sprites_32.png") no-repeat top left;
- padding-left: 18px !important;
- width: 13px;
- height: 13px;
+ background: url("../images/sprites_32.png") no-repeat top left;
+ padding-left: 18px !important;
+ width: 13px;
+ height: 13px;
}
.icon13.collapsed {
- background-position: 0 -126px;
+ background-position: 0 -126px;
}
.icon13.expanded {
- background-position: 0 -149px;
+ background-position: 0 -149px;
}
.icon16 {
- background: url("../images/sprites_32.png") no-repeat top left;
- padding-left: 21px !important;
- width: 16px;
- height: 16px;
- display: inline-block;
+ background: url("../images/sprites_32.png") no-repeat top left;
+ padding-left: 21px !important;
+ width: 16px;
+ height: 16px;
+ display: inline-block;
}
.icon16.tick {
- background-position: 0 -171px;
+ background-position: 0 -171px;
}
/* RS, EMP carousel */
- #quote-carousel
- {
- padding: 0 10px 30px 10px;
- margin-top: 30px;
- }
-
- /* Control buttons */
- #quote-carousel .carousel-control
- {
- background: none;
- color: #222;
- font-size: 2.3em;
- text-shadow: none;
- margin-top: 30px;
- }
- /* Previous button */
- #quote-carousel .carousel-control.left
- {
- left: -12px;
- }
- /* Next button */
- #quote-carousel .carousel-control.right
- {
- right: -12px !important;
- }
- /* Changes the position of the indicators */
- #quote-carousel .carousel-indicators
- {
- right: 50%;
- top: auto;
- bottom: 0px;
- margin-right: -19px;
- }
- /* Changes the color of the indicators */
- #quote-carousel .carousel-indicators li
- {
- background: #c0c0c0;
- }
- #quote-carousel .carousel-indicators .active
- {
- background: #333333;
- }
- #quote-carousel img
- {
- width: 250px;
- height: 100px
- }
- /* End carousel */
-
- .item blockquote {
- border-left: none;
- margin: 0;
- }
-
- .item blockquote img {
- margin-bottom: 10px;
- }
-
- .item blockquote p:before {
- content: "\f10d";
- font-family: 'Fontawesome';
- float: left;
- margin-right: 10px;
- }
-
- #relatedInformation img { padding-right :10px;}
-
- .glyphicon {
- position: relative;
- top: 1px;
- display: inline-block;
- font-family: 'Glyphicons Halflings';
- font-style: normal;
- font-weight: 400;
- line-height: 1;
- -webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
- }
+#quote-carousel {
+ padding: 0 10px 30px 10px;
+ margin-top: 30px;
+}
+
+/* Control buttons */
+#quote-carousel .carousel-control {
+ background: none;
+ color: #222;
+ font-size: 2.3em;
+ text-shadow: none;
+ margin-top: 30px;
+}
+/* Previous button */
+#quote-carousel .carousel-control.left {
+ left: -12px;
+}
+/* Next button */
+#quote-carousel .carousel-control.right {
+ right: -12px !important;
+}
+/* Changes the position of the indicators */
+#quote-carousel .carousel-indicators {
+ right: 50%;
+ top: auto;
+ bottom: 0px;
+ margin-right: -19px;
+}
+/* Changes the color of the indicators */
+#quote-carousel .carousel-indicators li {
+ background: #c0c0c0;
+}
+#quote-carousel .carousel-indicators .active {
+ background: #333333;
+}
+#quote-carousel img {
+ width: 250px;
+ height: 100px
+}
+/* End carousel */
+
+.item blockquote {
+ border-left: none;
+ margin: 0;
+}
+
+.item blockquote img {
+ margin-bottom: 10px;
+}
+
+.item blockquote p:before {
+ content: "\f10d";
+ font-family: 'Fontawesome';
+ float: left;
+ margin-right: 10px;
+}
+
+#relatedInformation img {
+ padding-right: 10px;
+}
+.glyphicon {
+ position: relative;
+ top: 1px;
+ display: inline-block;
+ font-family: 'Glyphicons Halflings';
+ font-style: normal;
+ font-weight: 400;
+ line-height: 1;
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
+}
.carousel-control .glyphicon-chevron-right {
- position: absolute;
- top: 50%;
- z-index: 5;
- display: inline-block;
+ position: absolute;
+ top: 50%;
+ z-index: 5;
+ display: inline-block;
+}
+.carousel-control.left span,
+.carousel-control.right span {
+ background-color: #000;
}
-.carousel-control.left span, .carousel-control.right span {
- background-color: #000;
-}
- h3.relatedTitle a{
- font-size:24px;
- }
-
+h3.relatedTitle a {
+ font-size: 24px;
+}
- /* */
\ No newline at end of file
+/* */
diff --git a/ebsco/ebsco.info b/ebsco/ebsco.info
index e5799c3..f1753e8 100644
--- a/ebsco/ebsco.info
+++ b/ebsco/ebsco.info
@@ -5,4 +5,4 @@ core = 7.x
configure = admin/config/search/ebsco
stylesheets[screen][] = css/ebsco.css
-scripts[] = js/ebsco.js
\ No newline at end of file
+scripts[] = js/ebsco.js
diff --git a/ebsco/ebsco.module b/ebsco/ebsco.module
index 0e6f907..0fe3dfa 100644
--- a/ebsco/ebsco.module
+++ b/ebsco/ebsco.module
@@ -1,100 +1,97 @@
'. t("Full-text articles and eBooks from EBSCOhost Discovery Services") .'';
- $output .= ''. t("EBSCO Discovery Service provides users with an easy, yet powerful means of accessing all of
- an institution's information resources through a single search.") .'
';
- $output .= ''. t("This is achieved by harvesting metadata from both internal (library) and external (database vendors) sources,
- and creating a pre-indexed service of unprecedented size and speed.") .'
';
- $output .= ''. t("Although the resulting collection can be massive in size and scope, the fact that it is indexed locally
- (on the EBSCOhost® servers) allows for exceptionally fast search response times.") .'
';
- $output .= ''. t("As no two institutions are the same, EBSCO Discovery Service offers a vast array of customization options with
+ $output = "";
+ switch ($path) {
+ case "admin/help#ebsco":
+ $output .= '
' . t("Full-text articles and eBooks from EBSCOhost Discovery Services") . ' ';
+ $output .= '' . t("EBSCO Discovery Service provides users with an easy, yet powerful means of accessing all of
+ an institution's information resources through a single search.") . '
';
+ $output .= '' . t("This is achieved by harvesting metadata from both internal (library) and external (database vendors) sources,
+ and creating a pre-indexed service of unprecedented size and speed.") . '
';
+ $output .= '' . t("Although the resulting collection can be massive in size and scope, the fact that it is indexed locally
+ (on the EBSCOhost® servers) allows for exceptionally fast search response times.") . '
';
+ $output .= '' . t("As no two institutions are the same, EBSCO Discovery Service offers a vast array of customization options with
regard to both the underlying collection of metadata as well as the front-end delivery of search results.
- All of this functionality is based upon the powerful EBSCOhost search experience familiar to researchers worldwide.") .'
';
- break;
- }
- return $output;
+ All of this functionality is based upon the powerful EBSCOhost search experience familiar to researchers worldwide.") . '
';
+ break;
+ }
+ return $output;
}
-
/**
* Implements hook_theme().
*/
function ebsco_theme() {
- $themes = array(
- 'ebsco_result' => array(
- 'template' => 'templates/ebsco-result'
- ),
- 'ebsco_results' => array(
- 'template' => 'templates/ebsco-results'
- ),
- 'ebsco_side_facets' => array(
- 'template' => 'templates/ebsco-side-facets'
- ),
- 'ebsco_basic_search' => array(
- 'template' => 'templates/ebsco-basic-search'
- ),
- 'ebsco_advanced_search' => array(
- 'template' => 'templates/ebsco-advanced-search'
- )
- );
- return $themes;
+ $themes = array(
+ 'ebsco_result' => array(
+ 'template' => 'templates/ebsco-result',
+ ),
+ 'ebsco_results' => array(
+ 'template' => 'templates/ebsco-results',
+ ),
+ 'ebsco_side_facets' => array(
+ 'template' => 'templates/ebsco-side-facets',
+ ),
+ 'ebsco_basic_search' => array(
+ 'template' => 'templates/ebsco-basic-search',
+ ),
+ 'ebsco_advanced_search' => array(
+ 'template' => 'templates/ebsco-advanced-search',
+ ),
+ );
+ return $themes;
}
-
/**
* Implements hook_permission().
*
@@ -104,429 +101,437 @@ function ebsco_theme() {
* administration pages.
*/
function ebsco_permission() {
- return array(
- 'administer ebsco' => array(
- 'title' => t('Administer EBSCO')
- ),
- 'use ebsco' => array(
- 'title' => t('Use EBSCO')
- )
- );
+ return array(
+ 'administer ebsco' => array(
+ 'title' => t('Administer EBSCO'),
+ ),
+ 'use ebsco' => array(
+ 'title' => t('Use EBSCO'),
+ ),
+ );
}
-
/**
* Implements hook_admin().
- *
*/
function ebsco_admin() {
- $form = array();
-
- $form['ebsco_credentials'] = array(
- '#type' => 'fieldset',
- '#title' => t('EDS API credentials')
- );
-
- $form['ebsco_credentials']['ebsco_profile'] = array(
- '#type' => 'textfield',
- '#title' => t('Profile Id'),
- '#default_value' => variable_get('ebsco_profile'),
- '#size' => 50,
- '#description' => t("The API Profile Id."),
- '#required' => TRUE
- );
-
- $form['ebsco_credentials']['ebsco_user'] = array(
- '#type' => 'textfield',
- '#title' => t('User Id'),
- '#default_value' => variable_get('ebsco_user'),
- '#size' => 50,
- '#description' => t("The API User Id."),
- '#required' => TRUE
- );
-
- $form['ebsco_credentials']['ebsco_password'] = array(
- '#type' => 'textfield',
- '#title' => t('Password'),
- '#default_value' => variable_get('ebsco_password'),
- '#size' => 50,
- '#description' => t("The API password."),
- '#required' => TRUE
- );
-
- $form['ebsco_credentials']['ebsco_interface'] = array(
- '#type' => 'textfield',
- '#title' => t('Interface Id'),
- '#default_value' => variable_get('ebsco_interface'),
- '#size' => 50,
- '#description' => t("The API Interface Id."),
- '#required' => FALSE
- );
-
- $form['ebsco_credentials']['ebsco_organization'] = array(
- '#type' => 'textfield',
- '#title' => t('Organization Id'),
- '#default_value' => variable_get('ebsco_organization'),
- '#size' => 50,
- '#description' => t("The API Organization Id."),
- '#required' => FALSE
- );
-
- $form['ebsco_credentials']['ebsco_local_ips'] = array(
- '#type' => 'textfield',
- '#title' => t('Local IP addresses'),
- '#default_value' => variable_get('ebsco_local_ips'),
- '#size' => 100,
- '#description' => t("Local IP address list for guest detection (ex: 127.0.0.1, 192.168.10.1, 172.18.12)"),
- '#required' => FALSE
- );
-
- $form['ebsco_credentials']['ebsco_guest'] = array(
- '#type' => 'radios',
- '#title' => t('Guest ?'),
- '#default_value' => variable_get('ebsco_guest', 0),
- '#description' => t("The Guest session."),
- '#options' => array(t('No'), t('Yes')),
- '#required' => TRUE
- );
-
- $form['ebsco_general'] = array(
- '#type' => 'fieldset',
- '#title' => t('General Settings')
- );
-
- $form['ebsco_general']['ebsco_default_limit'] = array(
- '#type' => 'select',
- '#title' => t('Default limit'),
- '#default_value' => variable_get('ebsco_default_limit', 10),
- '#description' => t("Default number of results per page."),
- '#options' => EBSCODocument::limit_options(),
- '#required' => TRUE
- );
-
- $form['ebsco_general']['ebsco_default_sort'] = array(
- '#type' => 'select',
- '#title' => t('Default sort'),
- '#default_value' => variable_get('ebsco_default_sort', 'relevance'),
- '#description' => t("Default sorting option."),
- '#options' => EBSCODocument::sort_options(),
- '#required' => TRUE
- );
-
- $form['ebsco_general']['ebsco_default_amount'] = array(
- '#type' => 'select',
- '#title' => t('Default detail level'),
- '#default_value' => variable_get('ebsco_default_amount', 'brief'),
- '#description' => t("Default level of data detail."),
- '#options' => EBSCODocument::amount_options(),
- '#required' => TRUE
- );
-
- $form['ebsco_general']['ebsco_default_mode'] = array(
- '#type' => 'select',
- '#title' => t('Default search mode'),
- '#default_value' => variable_get('ebsco_default_mode', 'all'),
- '#description' => t("Default search mode."),
- '#options' => EBSCODocument::mode_options(),
- '#required' => TRUE
- );
-
- return system_settings_form($form);
+ $form = array();
+
+ $form['ebsco_credentials'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('EDS API credentials'),
+ );
+
+ $form['ebsco_credentials']['ebsco_profile'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Profile Id'),
+ '#default_value' => variable_get('ebsco_profile'),
+ '#size' => 50,
+ '#description' => t("The API Profile Id."),
+ '#required' => TRUE,
+ );
+
+ $form['ebsco_credentials']['ebsco_user'] = array(
+ '#type' => 'textfield',
+ '#title' => t('User Id'),
+ '#default_value' => variable_get('ebsco_user'),
+ '#size' => 50,
+ '#description' => t("The API User Id."),
+ '#required' => TRUE,
+ );
+
+ $form['ebsco_credentials']['ebsco_password'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Password'),
+ '#default_value' => variable_get('ebsco_password'),
+ '#size' => 50,
+ '#description' => t("The API password."),
+ '#required' => TRUE,
+ );
+
+ $form['ebsco_credentials']['ebsco_interface'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Interface Id'),
+ '#default_value' => variable_get('ebsco_interface'),
+ '#size' => 50,
+ '#description' => t("The API Interface Id."),
+ '#required' => FALSE,
+ );
+
+ $form['ebsco_credentials']['ebsco_organization'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Organization Id'),
+ '#default_value' => variable_get('ebsco_organization'),
+ '#size' => 50,
+ '#description' => t("The API Organization Id."),
+ '#required' => FALSE,
+ );
+
+ $form['ebsco_credentials']['ebsco_local_ips'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Local IP addresses'),
+ '#default_value' => variable_get('ebsco_local_ips'),
+ '#size' => 100,
+ '#description' => t("Local IP address list for guest detection (ex: 127.0.0.1, 192.168.10.1, 172.18.12)"),
+ '#required' => FALSE,
+ );
+
+ $form['ebsco_credentials']['ebsco_guest'] = array(
+ '#type' => 'radios',
+ '#title' => t('Guest ?'),
+ '#default_value' => variable_get('ebsco_guest', 0),
+ '#description' => t("The Guest session."),
+ '#options' => array(t('No'), t('Yes')),
+ '#required' => TRUE,
+ );
+
+ $form['ebsco_general'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('General Settings'),
+ );
+
+ $form['ebsco_general']['ebsco_default_limit'] = array(
+ '#type' => 'select',
+ '#title' => t('Default limit'),
+ '#default_value' => variable_get('ebsco_default_limit', 10),
+ '#description' => t("Default number of results per page."),
+ '#options' => EBSCODocument::limit_options(),
+ '#required' => TRUE,
+ );
+
+ $form['ebsco_general']['ebsco_default_sort'] = array(
+ '#type' => 'select',
+ '#title' => t('Default sort'),
+ '#default_value' => variable_get('ebsco_default_sort', 'relevance'),
+ '#description' => t("Default sorting option."),
+ '#options' => EBSCODocument::sort_options(),
+ '#required' => TRUE,
+ );
+
+ $form['ebsco_general']['ebsco_default_amount'] = array(
+ '#type' => 'select',
+ '#title' => t('Default detail level'),
+ '#default_value' => variable_get('ebsco_default_amount', 'brief'),
+ '#description' => t("Default level of data detail."),
+ '#options' => EBSCODocument::amount_options(),
+ '#required' => TRUE,
+ );
+
+ $form['ebsco_general']['ebsco_default_mode'] = array(
+ '#type' => 'select',
+ '#title' => t('Default search mode'),
+ '#default_value' => variable_get('ebsco_default_mode', 'all'),
+ '#description' => t("Default search mode."),
+ '#options' => EBSCODocument::mode_options(),
+ '#required' => TRUE,
+ );
+
+ return system_settings_form($form);
}
-
/**
* Implements hook_menu().
*/
function ebsco_menu() {
- // Ths is a route
- $items['ebsco/results'] = array(
- 'title' => 'EBSCO Results',
- 'page callback' => 'ebsco_results_page',
- 'access callback' => true,
- 'type' => MENU_CALLBACK
- );
-
- $items['ebsco/result'] = array(
- 'title' => 'EBSCO Record',
- 'page callback' => 'ebsco_result_page',
- 'access callback' => true,
- 'type' => MENU_CALLBACK
- );
-
- $items['ebsco/pdf'] = array(
- 'title' => 'EBSCO Record',
- 'page callback' => 'ebsco_pdf_page',
- 'access callback' => true,
- 'type' => MENU_CALLBACK
- );
-
- $items['ebsco/fulltext'] = array(
- 'title' => 'EBSCO Record',
- 'page callback' => 'ebsco_fulltext_page',
- 'access callback' => true,
- 'type' => MENU_CALLBACK
- );
-
- $items['ebsco/advanced'] = array(
- 'title' => 'EBSCO advanced search',
- 'page callback' => 'ebsco_advanced_search_page',
- 'access callback' => true,
- 'type' => MENU_CALLBACK
- );
-
- $items['admin/config/search/ebsco'] = array(
- 'title' => 'EBSCO settings',
- 'description' => 'Configure EBSCO Service.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('ebsco_admin'),
- 'access arguments' => array('administer ebsco'),
- 'type' => MENU_NORMAL_ITEM
- );
-
- return $items;
+ // Ths is a route.
+ $items['ebsco/results'] = array(
+ 'title' => 'EBSCO Results',
+ 'page callback' => 'ebsco_results_page',
+ 'access callback' => TRUE,
+ 'type' => MENU_CALLBACK,
+ );
+
+ $items['ebsco/result'] = array(
+ 'title' => 'EBSCO Record',
+ 'page callback' => 'ebsco_result_page',
+ 'access callback' => TRUE,
+ 'type' => MENU_CALLBACK,
+ );
+
+ $items['ebsco/pdf'] = array(
+ 'title' => 'EBSCO Record',
+ 'page callback' => 'ebsco_pdf_page',
+ 'access callback' => TRUE,
+ 'type' => MENU_CALLBACK,
+ );
+
+ $items['ebsco/fulltext'] = array(
+ 'title' => 'EBSCO Record',
+ 'page callback' => 'ebsco_fulltext_page',
+ 'access callback' => TRUE,
+ 'type' => MENU_CALLBACK,
+ );
+
+ $items['ebsco/advanced'] = array(
+ 'title' => 'EBSCO advanced search',
+ 'page callback' => 'ebsco_advanced_search_page',
+ 'access callback' => TRUE,
+ 'type' => MENU_CALLBACK,
+ );
+
+ $items['admin/config/search/ebsco'] = array(
+ 'title' => 'EBSCO settings',
+ 'description' => 'Configure EBSCO Service.',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('ebsco_admin'),
+ 'access arguments' => array('administer ebsco'),
+ 'type' => MENU_NORMAL_ITEM,
+ );
+
+ return $items;
}
-
/**
-* Implements hook_block_info().
-*/
+ * Implements hook_block_info().
+ */
function ebsco_block_info() {
- $blocks['ebsco_main'] = array(
- 'info' => t('EBSCO Search Form'),
- 'cache' => DRUPAL_CACHE_PER_PAGE
- );
+ $blocks['ebsco_main'] = array(
+ 'info' => t('EBSCO Search Form'),
+ 'cache' => DRUPAL_CACHE_PER_PAGE,
+ );
- $blocks['ebsco_facets'] = array(
- 'info' => t('EBSCO Narrow Search'),
- 'cache' => DRUPAL_CACHE_PER_PAGE
- );
+ $blocks['ebsco_facets'] = array(
+ 'info' => t('EBSCO Narrow Search'),
+ 'cache' => DRUPAL_CACHE_PER_PAGE,
+ );
- return $blocks;
+ return $blocks;
}
-
/**
-* Implements hook_block_view().
-*
-* Prepares the content of the block.
-*/
+ * Implements hook_block_view().
+ *
+ * Prepares the content of the block.
+ */
function ebsco_block_view($delta = '') {
- $params = $_GET;
- switch ($delta) {
- case 'ebsco_main':
- $reject = isset($params['q']) && strpos('ebsco/advanced', $params['q']) !== false;
- return array(
- 'content' => $reject ? '' : ebsco_basic_search_block()
- );
- break;
-
- case 'ebsco_facets':
- $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['q']) && strpos('ebsco/result', $params['q']) !== false);
- return array(
- 'content' => $reject ? '' : ebsco_side_facets_block()
- );
- break;
- }
+ $params = $_GET;
+ switch ($delta) {
+ case 'ebsco_main':
+ $reject = isset($params['q']) && strpos('ebsco/advanced', $params['q']) !== FALSE;
+ return array(
+ 'content' => $reject ? '' : ebsco_basic_search_block(),
+ );
+
+ break;
+
+ case 'ebsco_facets':
+ $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['q']) && strpos('ebsco/result', $params['q']) !== FALSE);
+ return array(
+ 'content' => $reject ? '' : ebsco_side_facets_block(),
+ );
+
+ break;
+ }
}
-
-/******************************************************
- * Page callbacks
- ******************************************************/
-
-
+/**
+ * Page callbacks.
+ */
function ebsco_results_page() {
- return theme('ebsco_results');
+ return theme('ebsco_results');
}
-
+/**
+ *
+ */
function ebsco_result_page() {
- $is_xhr = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
- if ($is_xhr) {
- print theme('ebsco_result');
- return true;
- } else {
- return theme('ebsco_result');
- }
+ $is_xhr = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
+ if ($is_xhr) {
+ print theme('ebsco_result');
+ return TRUE;
+ }
+ else {
+ return theme('ebsco_result');
+ }
}
-
+/**
+ *
+ */
function ebsco_fulltext_page() {
- $is_xhr = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
- if (user_is_logged_in()) {
- if ($is_xhr) {
- print theme('ebsco_result');
- return true;
- } else {
- return theme('ebsco_result');
- }
- } else {
- $_SESSION['EBSCO']['redirect'] = drupal_get_destination();
- if ($is_xhr) {
- echo "";
- return;
- } else {
- drupal_goto('user');
- }
+ $is_xhr = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
+ if (user_is_logged_in()) {
+ if ($is_xhr) {
+ print theme('ebsco_result');
+ return TRUE;
+ }
+ else {
+ return theme('ebsco_result');
+ }
+ }
+ else {
+ $_SESSION['EBSCO']['redirect'] = drupal_get_destination();
+ if ($is_xhr) {
+ echo "";
+ return;
}
+ else {
+ drupal_goto('user');
+ }
+ }
}
-
+/**
+ *
+ */
function ebsco_pdf_page() {
- global $Document;
- $params = $_REQUEST;
+ global $Document;
+ $params = $_REQUEST;
- if (user_is_logged_in()) {
- if (empty($Document)) {
- $Document = new EBSCODocument();
- }
- $Document->retrieve();
- $record = $Document->record();
- drupal_goto($record->pdf_link);
- } else {
- $_SESSION['EBSCO']['redirect'] = drupal_get_destination();
- drupal_goto('user');
+ if (user_is_logged_in()) {
+ if (empty($Document)) {
+ $Document = new EBSCODocument();
}
+ $Document->retrieve();
+ $record = $Document->record();
+ drupal_goto($record->pdf_link);
+ }
+ else {
+ $_SESSION['EBSCO']['redirect'] = drupal_get_destination();
+ drupal_goto('user');
+ }
}
-
+/**
+ *
+ */
function ebsco_advanced_search_page() {
- return theme('ebsco_advanced_search');
+ return theme('ebsco_advanced_search');
}
-
+/**
+ *
+ */
function ebsco_basic_search_block() {
- return theme('ebsco_basic_search');
+ return theme('ebsco_basic_search');
}
-
+/**
+ *
+ */
function ebsco_side_facets_block() {
- return theme('ebsco_side_facets');
+ return theme('ebsco_side_facets');
}
-
-
/******************************************************
* Form builders, form handlers and templates handlers
******************************************************/
-
/**
* Form builder; Output a sort form for the search results.
*
* @ingroup forms
*/
function ebsco_sort_form() {
- $params = $_REQUEST;
-
- $form = array(
- '#attributes' => array('class' => 'sort-form'),
- '#method' => 'get'
- );
-
- $options = EBSCODocument::amount_options();
- $values = array_values($options);
- $default_value = isset($params['amount']) ? $params['amount'] : variable_get('ebsco_default_amount', 'brief');
- $form['mode'] = array(
- '#id' => 'ebsco-amount',
- '#type' => 'select',
- '#title' => t('Page options'),
- '#default_value' => $default_value,
- '#options' => $options,
- '#attributes' => array('class' => array('form-select', '_jump_menu'))
- );
-
- $options = EBSCODocument::sort_options();
- $values = array_values($options);
- $default_value = isset($params['sort']) ? $params['sort'] : $values[0];
- $form['sort'] = array(
- '#id' => 'ebsco-sort',
- '#type' => 'select',
- '#title' => t('Sort'),
- '#default_value' => $default_value,
- '#options' => $options,
- '#attributes' => array('class' => array('form-select', '_jump_menu'))
- );
-
- return $form;
+ $params = $_REQUEST;
+
+ $form = array(
+ '#attributes' => array('class' => 'sort-form'),
+ '#method' => 'get',
+ );
+
+ $options = EBSCODocument::amount_options();
+ $values = array_values($options);
+ $default_value = isset($params['amount']) ? $params['amount'] : variable_get('ebsco_default_amount', 'brief');
+ $form['mode'] = array(
+ '#id' => 'ebsco-amount',
+ '#type' => 'select',
+ '#title' => t('Page options'),
+ '#default_value' => $default_value,
+ '#options' => $options,
+ '#attributes' => array('class' => array('form-select', '_jump_menu')),
+ );
+
+ $options = EBSCODocument::sort_options();
+ $values = array_values($options);
+ $default_value = isset($params['sort']) ? $params['sort'] : $values[0];
+ $form['sort'] = array(
+ '#id' => 'ebsco-sort',
+ '#type' => 'select',
+ '#title' => t('Sort'),
+ '#default_value' => $default_value,
+ '#options' => $options,
+ '#attributes' => array('class' => array('form-select', '_jump_menu')),
+ );
+
+ return $form;
}
-
/**
* Form builder; Output a search form for the search block's search box.
*
* @ingroup forms
*/
function ebsco_basic_search_form() {
- $params = $_REQUEST;
-
- $form = array(
- '#attributes' => array('class' => 'search-form'),
- '#action' => url('ebsco/results'),
- '#method' => 'get'
- );
-
- $form['basic']['q'] = array(
- '#type' => 'hidden',
- '#default_value' => 'ebsco/results'
- );
-
- $default_value = isset($params['lookfor']) ? $params['lookfor'] : '';
- $form['basic']['lookfor'] = array(
- '#id' => 'ebsco-basic-search-lookfor',
- '#type' => 'textfield',
- '#size' => 40,
- '#default_value' => $default_value,
- '#attributes' => array('title' => t('Enter the terms you wish to search for.')),
- );
-
- $default_value = isset($params['type']) ? $params['type'] : '';
- $form['basic']['type'] = array(
- '#id' => 'ebsco-basic-search-type',
- '#type' => 'select',
- '#options' => EBSCODocument::basic_search_type_options(),
- '#default_value' => $default_value
- );
-
- $form['basic']['submit'] = array(
- '#id' => 'ebsco-basic-search-submit',
- '#type' => 'submit',
- '#value' => t('Search')
- );
-
- $link = url('ebsco/advanced');
- $form['basic']['links'] = array(
- '#type' => 'fieldset',
- '#value' => "" . t('Advanced search') . " "
- );
+ $params = $_REQUEST;
+
+ $form = array(
+ '#attributes' => array('class' => 'search-form'),
+ '#action' => url('ebsco/results'),
+ '#method' => 'get',
+ );
+
+ $form['basic']['q'] = array(
+ '#type' => 'hidden',
+ '#default_value' => 'ebsco/results',
+ );
+
+ $default_value = isset($params['lookfor']) ? $params['lookfor'] : '';
+ $form['basic']['lookfor'] = array(
+ '#id' => 'ebsco-basic-search-lookfor',
+ '#type' => 'textfield',
+ '#size' => 40,
+ '#default_value' => $default_value,
+ '#attributes' => array('title' => t('Enter the terms you wish to search for.')),
+ );
+
+ $default_value = isset($params['type']) ? $params['type'] : '';
+ $form['basic']['type'] = array(
+ '#id' => 'ebsco-basic-search-type',
+ '#type' => 'select',
+ '#options' => EBSCODocument::basic_search_type_options(),
+ '#default_value' => $default_value,
+ );
+
+ $form['basic']['submit'] = array(
+ '#id' => 'ebsco-basic-search-submit',
+ '#type' => 'submit',
+ '#value' => t('Search'),
+ );
+
+ $link = url('ebsco/advanced');
+ $form['basic']['links'] = array(
+ '#type' => 'fieldset',
+ '#value' => "" . t('Advanced search') . " ",
+ );
+
+ $form['basic']['offscreen'] = array(
+ '#type' => 'container',
+ );
+
+ if (isset($params['filter'])) {
+ foreach ($params['filter'] as $key => $value) {
+ $form['basic']['offscreen']['group' . $key]['filter[]'] = array(
+ '#id' => 'ebsco-basic-search-filter' . $key,
+ '#type' => 'checkbox',
+ // doesn't work.
+ '#default_value' => $value,
+ '#attributes' => array('checked' => 'checked', 'value' => $value),
+
+ );
+ }
- $form['basic']['offscreen'] = array(
- '#type' => 'container'
+ $form['basic']['remember'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Retain my current filters'),
+ '#prefix' => ' ',
+ '#default_value' => TRUE,
);
+ }
- if (isset($params['filter'])) {
- foreach($params['filter'] as $key => $value) {
- $form['basic']['offscreen']['group'.$key]['filter[]'] = array(
- '#id' => 'ebsco-basic-search-filter' . $key,
- '#type' => 'checkbox',
- '#default_value' => $value, // doesn't work
- '#attributes' => array('checked' => 'checked', 'value' => $value)
-
- );
- }
-
- $form['basic']['remember'] = array(
- '#type' => 'checkbox',
- '#title' => t('Retain my current filters'),
- '#prefix' => ' ',
- '#default_value' => true
- );
- }
-
- return $form;
+ return $form;
}
/**
@@ -535,525 +540,524 @@ function ebsco_basic_search_form() {
* @ingroup forms
*/
function ebsco_advanced_search_form() {
- global $Document;
- $params = $_REQUEST;
+ global $Document;
+ $params = $_REQUEST;
+
+ if (isset($params['edit']) && !empty($params['edit'])) {
+ $query = $_SESSION['EBSCO']['last-search']['query'];
+ parse_str($query, $new_params);
+ $params = $_REQUEST = array_merge($_REQUEST, $new_params);
+ }
+ $counter = isset($params['group']) ? count($params['group']) : 3;
+
+ $form = array(
+ '#attributes' => array('class' => 'search-form'),
+ '#action' => url('ebsco/advanced'),
+ );
+
+ $form['advanced'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Advanced Search'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE,
+ );
+
+ $form['advanced']['rows'] = array(
+ '#type' => 'fieldset',
+ '#title' => '',
+ );
+
+ for ($i = 0; $i < $counter; $i++) {
+ $form['advanced']['rows']['group' . $i] = array(
+ '#type' => 'fieldset',
+ '#tree' => TRUE,
+ '#attributes' => array('class' => array('_advanced-row')),
+ );
- if (isset($params['edit']) && !empty($params['edit'])) {
- $query = $_SESSION['EBSCO']['last-search']['query'];
- parse_str($query, $new_params);
- $params = $_REQUEST = array_merge($_REQUEST, $new_params);
+ $default_value = isset($params['group'][$i]['bool']) ? $params['group'][$i]['bool'] : '';
+ if ($i > 0) {
+ $form['advanced']['rows']['group' . $i]['bool'] = array(
+ '#id' => 'ebsco-advanced-search-bool' . $i,
+ '#type' => 'select',
+ '#default_value' => $default_value,
+ '#options' => EBSCODocument::bool_options(),
+ );
+ }
+ else {
+ $form['advanced']['rows']['group' . $i]['bool'] = array(
+ '#id' => 'ebsco-advanced-search-bool' . $i,
+ '#type' => 'hidden',
+ '#default_value' => 'AND',
+ );
}
- $counter = isset($params['group']) ? count($params['group']) : 3;
-
- $form = array(
- '#attributes' => array('class' => 'search-form'),
- '#action' => url('ebsco/advanced')
- );
- $form['advanced'] = array(
- '#type' => 'fieldset',
- '#title' => t('Advanced Search'),
- '#collapsible' => false,
- '#collapsed' => false
+ $title = $i == 0 ? t('Search for :') : '';
+ $default_value = isset($params['group'][$i]['lookfor']) ? $params['group'][$i]['lookfor'] : '';
+ $form['advanced']['rows']['group' . $i]['lookfor'] = array(
+ '#id' => 'ebsco-advanced-search-lookfor' . $i,
+ '#type' => 'textfield',
+ '#size' => 30,
+ '#default_value' => $default_value,
+ '#title' => $title,
+ '#attributes' => array('title' => t('Enter the terms you wish to search for.')),
);
- $form['advanced']['rows'] = array(
- '#type' => 'fieldset',
- '#title' => ''
+ $default_value = isset($params['group'][$i]['type']) ? $params['group'][$i]['type'] : '';
+ $form['advanced']['rows']['group' . $i]['type'] = array(
+ '#id' => 'ebsco-advanced-search-type' . $i,
+ '#type' => 'select',
+ '#default_value' => $default_value,
+ '#title' => t('in'),
+ '#options' => EBSCODocument::advanced_search_type_options(),
);
- for ($i = 0; $i < $counter; $i++) {
- $form['advanced']['rows']['group' . $i] = array(
- '#type' => 'fieldset',
- '#tree' => true,
- '#attributes' => array('class' => array('_advanced-row'))
- );
-
- $default_value = isset($params['group'][$i]['bool']) ? $params['group'][$i]['bool'] : '';
- if ($i > 0) {
- $form['advanced']['rows']['group' . $i]['bool'] = array(
- '#id' => 'ebsco-advanced-search-bool' . $i,
- '#type' => 'select',
- '#default_value' => $default_value,
- '#options' => EBSCODocument::bool_options()
- );
- } else {
- $form['advanced']['rows']['group' . $i]['bool'] = array(
- '#id' => 'ebsco-advanced-search-bool' . $i,
- '#type' => 'hidden',
- '#default_value' => 'AND'
- );
- }
-
- $title = $i == 0 ? t('Search for :') : '';
- $default_value = isset($params['group'][$i]['lookfor']) ? $params['group'][$i]['lookfor'] : '';
- $form['advanced']['rows']['group' . $i]['lookfor'] = array(
- '#id' => 'ebsco-advanced-search-lookfor' . $i,
- '#type' => 'textfield',
- '#size' => 30,
- '#default_value' => $default_value,
- '#title' => $title,
- '#attributes' => array('title' => t('Enter the terms you wish to search for.'))
- );
-
- $default_value = isset($params['group'][$i]['type']) ? $params['group'][$i]['type'] : '';
- $form['advanced']['rows']['group' . $i]['type'] = array(
- '#id' => 'ebsco-advanced-search-type' . $i,
- '#type' => 'select',
- '#default_value' => $default_value,
- '#title' => t('in'),
- '#options' => EBSCODocument::advanced_search_type_options()
- );
-
- if ($i > 2) {
- $form['advanced']['rows']['group' . $i]['remove'] = array(
- '#markup' => ''
- );
- }
+ if ($i > 2) {
+ $form['advanced']['rows']['group' . $i]['remove'] = array(
+ '#markup' => '',
+ );
}
+ }
- $form['advanced']['rows']['add_row'] = array(
- '#type' => 'fieldset',
- '#value' => "". t('Add Search Field') . " "
- );
+ $form['advanced']['rows']['add_row'] = array(
+ '#type' => 'fieldset',
+ '#value' => "" . t('Add Search Field') . " ",
+ );
- $items = array(
+ $items = array(
array(
- 'url' => url('ebsco/results'),
- 'title' => t('Basic search')
+ 'url' => url('ebsco/results'),
+ 'title' => t('Basic search'),
),
array(
- 'url' => url('ebsco/advanced'),
- 'title' => t('Advanced search')
- )
- );
- $links = array();
- foreach ($items as $item) {
- $links[] = "{$item['title']} ";
- }
- $form['advanced']['links'] = array(
- '#type' => 'fieldset',
- '#value' => implode(' | ', $links)
- );
-
- $form['advanced']['modes'] = array(
- '#type' => 'fieldset',
- '#title' => t('Search modes')
- );
-
- $form['advanced']['modes']['mode'] = array(
- '#type' => 'radios',
- '#default_value' => 'all',
- '#options' => EBSCODocument::mode_options()
- );
-
- $expanders = $Document->expanders();
- $limiters = $Document->limiters();
- $options = array('' => true);
- foreach($expanders as $key => $expander) {
- $options[$expander['Action']] = true;
+ 'url' => url('ebsco/advanced'),
+ 'title' => t('Advanced search'),
+ ),
+ );
+ $links = array();
+ foreach ($items as $item) {
+ $links[] = "{$item['title']} ";
+ }
+ $form['advanced']['links'] = array(
+ '#type' => 'fieldset',
+ '#value' => implode(' | ', $links),
+ );
+
+ $form['advanced']['modes'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Search modes'),
+ );
+
+ $form['advanced']['modes']['mode'] = array(
+ '#type' => 'radios',
+ '#default_value' => 'all',
+ '#options' => EBSCODocument::mode_options(),
+ );
+
+ $expanders = $Document->expanders();
+ $limiters = $Document->limiters();
+ $options = array('' => TRUE);
+ foreach ($expanders as $key => $expander) {
+ $options[$expander['Action']] = TRUE;
+ }
+ foreach ($limiters as $key => $limiter) {
+ if (!empty($limiter['Values'])) {
+ $options[$limiter['Id']] = TRUE;
+ foreach ($limiter['Values'] as $value) {
+ $options[str_replace('value', $value['Value'], $value['Action'])] = TRUE;
+ }
}
- foreach($limiters as $key => $limiter) {
- if (!empty($limiter['Values'])) {
- $options[$limiter['Id']] = true;
- foreach($limiter['Values'] as $value) {
- $options[str_replace('value', $value['Value'], $value['Action'])] = true;
- }
- } else {
- $options[str_replace('value', 'y', $limiter['Action'])] = true;
- }
+ else {
+ $options[str_replace('value', 'y', $limiter['Action'])] = TRUE;
}
-
- $form['advanced']['expanders'] = array(
- '#type' => 'fieldset',
- '#title' => t('Expand results')
- );
-
- $form['advanced']['limiters'] = array(
- '#type' => 'fieldset',
- '#title' => t('Limit results')
+ }
+
+ $form['advanced']['expanders'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Expand results'),
+ );
+
+ $form['advanced']['limiters'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Limit results'),
+ );
+
+ $children = array();
+ foreach ($expanders as $key => $expander) {
+ $element = array(
+ '#type' => 'checkbox',
+ '#id' => 'ebsco-advanced-search-expander' . $key,
+ '#title' => $expander['Label'],
+ '#title_display' => 'after',
+ '#name' => 'filter[]',
+ '#attributes' => array('value' => $expander['Action']),
+ '#checked' => $expander['selected'],
);
-
- $children = array();
- foreach($expanders as $key => $expander) {
- $element = array(
- '#type' => 'checkbox',
- '#id' => 'ebsco-advanced-search-expander' . $key,
- '#title' => $expander['Label'],
- '#title_display' => 'after',
- '#name' => 'filter[]',
- '#attributes' => array('value' => $expander['Action']),
- '#checked' => $expander['selected']
- );
- $element['#children'] = ($key != 0) ? ' ' : '';
- $element['#children'] .= theme('checkbox', array('element' => $element));
-
- $children[] = theme('form_element', array('element' => $element));
-
+ $element['#children'] = ($key != 0) ? ' ' : '';
+ $element['#children'] .= theme('checkbox', array('element' => $element));
+
+ $children[] = theme('form_element', array('element' => $element));
+
+ }
+
+ $form['advanced']['expanders']['filter'] = array(
+ '#type' => 'checkboxes',
+ '#validated' => TRUE,
+ '#options' => $options,
+ '#children' => implode('', $children),
+ );
+
+ $checkboxes = $selects = $dates = array();
+ foreach ($limiters as $key => $limiter) {
+ if ($limiter['Type'] == 'text' || $limiter['Type'] == 'select') {
+ $element = array(
+ '#type' => 'checkbox',
+ '#id' => 'ebsco-advanced-search-limiter' . $limiter['Id'],
+ '#title' => $limiter['Label'],
+ '#title_display' => 'after',
+ '#name' => 'filter[]',
+ '#attributes' => array('value' => str_replace('value', 'y', $limiter['Action'])),
+ '#checked' => $limiter['selected'],
+
+ );
+ $element['#children'] = ($key != 0) ? ' ' : '';
+ if (!isset($element['#children'])) {
+ $element['#children'] = "";
+ }
+ $element['#children'] .= theme('checkbox', array('element' => $element));
+ $checkboxes[] = theme('form_element', array('element' => $element));
}
-
- $form['advanced']['expanders']['filter'] = array(
- '#type' => 'checkboxes',
- '#validated' => true,
- '#options' => $options,
- '#children' => implode('', $children)
- );
-
- $checkboxes = $selects = $dates = array();
- foreach($limiters as $key => $limiter) {
- if ($limiter['Type'] == 'text' || $limiter['Type'] == 'select') {
- $element = array(
- '#type' => 'checkbox',
- '#id' => 'ebsco-advanced-search-limiter' . $limiter['Id'],
- '#title' => $limiter['Label'],
- '#title_display' => 'after',
- '#name' => 'filter[]',
- '#attributes' => array('value' => str_replace('value', 'y', $limiter['Action'])),
- '#checked' => $limiter['selected']
-
- );
- $element['#children'] = ($key != 0) ? ' ' : '';
- if (!isset($element['#children']))
- {$element['#children']="";}
- $element['#children'] .= theme('checkbox', array('element' => $element));
- $checkboxes[] = theme('form_element', array('element' => $element));
- } else if ($limiter['Type'] == 'multiselectvalue') {
- $opts = array('' => t('All'));
- foreach($limiter['Values'] as $value) {
- $opts[$value['Action']] = $value['Value'];
- }
- $element = array(
- '#type' => 'select',
- '#multiple' => true,
- '#size' => 4,
- '#id' => 'ebsco-advanced-search-limiter' . $limiter['Id'],
- '#title' => $limiter['Label'],
- '#name' => 'filter[]',
- '#options' => $opts,
- '#default_value' => $limiter['selected'], // empty value means "All"
- '#value' => $limiter['selected'],
- '#attributes' => array('class' => array('multiselectvalue'), 'multiple' => 'multiple')
- );
- $element['#children'] = theme('select', array('element' => $element));
- $selects[] = theme('form_element', array('element' => $element));
- } else if ($limiter['Type'] == 'ymrange') {
- $value = $limiter['selected'] ? $limiter['selected'] : '';
- $displayValue = str_replace(array('addlimiter(DT1:', '-1/2013-1)'), array('', ''), $value);
- $element = array(
- '#type' => 'textfield',
- '#id' => $limiter['Id'],
- '#title' => $limiter['Label'],
- '#value' => $displayValue,
- '#name' => $limiter['Id'],
- '#autocomplete_path' => null,
- '#attributes' => array('size' => 4, 'maxlength' => 4, 'class' => array('yearbox'))
- );
- $element['#children'] = theme('textfield', array('element' => $element));
- $element['#children'] .= ' ';
- $element['#children'] .= '
';
- $dates[] = theme('form_element', array('element' => $element));
- }
+ elseif ($limiter['Type'] == 'multiselectvalue') {
+ $opts = array('' => t('All'));
+ foreach ($limiter['Values'] as $value) {
+ $opts[$value['Action']] = $value['Value'];
+ }
+ $element = array(
+ '#type' => 'select',
+ '#multiple' => TRUE,
+ '#size' => 4,
+ '#id' => 'ebsco-advanced-search-limiter' . $limiter['Id'],
+ '#title' => $limiter['Label'],
+ '#name' => 'filter[]',
+ '#options' => $opts,
+ // Empty value means "All".
+ '#default_value' => $limiter['selected'],
+ '#value' => $limiter['selected'],
+ '#attributes' => array('class' => array('multiselectvalue'), 'multiple' => 'multiple'),
+ );
+ $element['#children'] = theme('select', array('element' => $element));
+ $selects[] = theme('form_element', array('element' => $element));
}
-
- $form['advanced']['limiters']['checkboxes'] = array(
- '#type' => 'checkboxes',
- '#validated' => true,
- '#options' => $options,
- '#children' => implode('', $checkboxes),
- );
-
- $form['advanced']['limiters']['dates'] = array(
- '#type' => 'container',
- '#validated' => true,
- '#prefix' => ' ',
- '#children' => implode('', $dates)
- );
-
- $form['advanced']['limiters']['selects'] = array(
- '#type' => 'container',
- '#prefix' => ' ',
- '#validated' => true,
- '#children' => implode('', $selects)
- );
-
- $form['advanced']['submit'] = array(
- '#id' => 'ebsco-advanced-search-submit',
- '#type' => 'submit',
- '#value' => t('Search')
- );
-
- $form['advanced']['clear'] = array(
- '#markup' => ' '
- );
-
- return $form;
+ elseif ($limiter['Type'] == 'ymrange') {
+ $value = $limiter['selected'] ? $limiter['selected'] : '';
+ $displayValue = str_replace(array('addlimiter(DT1:', '-1/2013-1)'), array('', ''), $value);
+ $element = array(
+ '#type' => 'textfield',
+ '#id' => $limiter['Id'],
+ '#title' => $limiter['Label'],
+ '#value' => $displayValue,
+ '#name' => $limiter['Id'],
+ '#autocomplete_path' => NULL,
+ '#attributes' => array('size' => 4, 'maxlength' => 4, 'class' => array('yearbox')),
+ );
+ $element['#children'] = theme('textfield', array('element' => $element));
+ $element['#children'] .= ' ';
+ $element['#children'] .= '
';
+ $dates[] = theme('form_element', array('element' => $element));
+ }
+ }
+
+ $form['advanced']['limiters']['checkboxes'] = array(
+ '#type' => 'checkboxes',
+ '#validated' => TRUE,
+ '#options' => $options,
+ '#children' => implode('', $checkboxes),
+ );
+
+ $form['advanced']['limiters']['dates'] = array(
+ '#type' => 'container',
+ '#validated' => TRUE,
+ '#prefix' => ' ',
+ '#children' => implode('', $dates),
+ );
+
+ $form['advanced']['limiters']['selects'] = array(
+ '#type' => 'container',
+ '#prefix' => ' ',
+ '#validated' => TRUE,
+ '#children' => implode('', $selects),
+ );
+
+ $form['advanced']['submit'] = array(
+ '#id' => 'ebsco-advanced-search-submit',
+ '#type' => 'submit',
+ '#value' => t('Search'),
+ );
+
+ $form['advanced']['clear'] = array(
+ '#markup' => ' ',
+ );
+
+ return $form;
}
-
/**
* Form validation handler for ebsco_basic_search_form().
*
* @see ebsco_basic_search_form_submit()
*/
function ebsco_basic_search_form_validate($form, &$form_state) {
- $params = $form_state['values'];
- if (empty($params['lookfor'])) {
- form_set_error('lookfor', t('Please enter some keywords.'));
- }
+ $params = $form_state['values'];
+ if (empty($params['lookfor'])) {
+ form_set_error('lookfor', t('Please enter some keywords.'));
+ }
}
-
/**
* Form validation handler for ebsco_advanced_search_form().
*
* @see ebsco_advanced_search_form_submit()
*/
function ebsco_advanced_search_form_validate($form, &$form_state) {
- $params = $form_state['values'];
- if (empty($params['group0']['lookfor']) &&
+ $params = $form_state['values'];
+ if (empty($params['group0']['lookfor']) &&
empty($params['group1']['lookfor']) &&
empty($params['group2']['lookfor'])) {
- form_set_error('group0][lookfor', t('Please enter some keywords.'));
- }
+ form_set_error('group0][lookfor', t('Please enter some keywords.'));
+ }
}
-
/**
* Form submission handler for ebsco_basic_search_form().
*
* @see ebsco_basic_search_form_validate()
*/
function ebsco_basic_search_form_submit($form, &$form_state) {
- $params = $form_state['values'];
- $allowed_keys = array('lookfor', 'type');
- foreach($params as $key => $value) {
- if (!in_array($key, $allowed_keys)) {
- unset($params[$key]);
- }
+ $params = $form_state['values'];
+ $allowed_keys = array('lookfor', 'type');
+ foreach ($params as $key => $value) {
+ if (!in_array($key, $allowed_keys)) {
+ unset($params[$key]);
}
- $form_state['rebuild'] = false;
- $form_state['redirect'] = array('ebsco/results', array('query' => $params));
+ }
+ $form_state['rebuild'] = FALSE;
+ $form_state['redirect'] = array('ebsco/results', array('query' => $params));
}
-
/**
* Form submission handler for ebsco_advanced_search_form().
*
* @see ebsco_advanced_search_form_validate()
*/
function ebsco_advanced_search_form_submit($form, &$form_state) {
- $params = $_REQUEST;
- $new_params = array();
- $allowed_keys = array('filter', 'mode');
-
- foreach($params as $key => $value) {
- if (!(in_array($key, $allowed_keys) || strpos($key, 'group') !== false)) {
- unset($params[$key]);
- } else {
- if ($key == 'filter') {
- foreach($value as $k => $v) {
- if (empty($v)) {
- unset($params[$key][$k]);
- }
- }
- } else if (empty($value)) {
- unset($params[$key]);
- }
+ $params = $_REQUEST;
+ $new_params = array();
+ $allowed_keys = array('filter', 'mode');
+
+ foreach ($params as $key => $value) {
+ if (!(in_array($key, $allowed_keys) || strpos($key, 'group') !== FALSE)) {
+ unset($params[$key]);
+ }
+ else {
+ if ($key == 'filter') {
+ foreach ($value as $k => $v) {
+ if (empty($v)) {
+ unset($params[$key][$k]);
+ }
}
+ }
+ elseif (empty($value)) {
+ unset($params[$key]);
+ }
}
+ }
- foreach($params as $key => $value) {
- if (strpos($key, 'group') !== false) {
- $new_params['group'][] = $value;
- unset($params[$key]);
- }
+ foreach ($params as $key => $value) {
+ if (strpos($key, 'group') !== FALSE) {
+ $new_params['group'][] = $value;
+ unset($params[$key]);
}
- $params = array_merge($params, $new_params);
+ }
+ $params = array_merge($params, $new_params);
- $form_state['rebuild'] = false;
- $form_state['redirect'] = array('ebsco/results', array('query' => $params));
+ $form_state['rebuild'] = FALSE;
+ $form_state['redirect'] = array('ebsco/results', array('query' => $params));
}
-
/**
* Process variables for ebsco-results.tpl.php.
*
* @see ebsco-results.tpl.php
*/
function template_preprocess_ebsco_results(&$variables) {
- global $Document;
- $params = $_REQUEST;
-
- $_SESSION['EBSCO']['redirect'] = drupal_get_destination();
- if (empty($Document)) {
- $Document = new EBSCODocument();
+ global $Document;
+ $params = $_REQUEST;
+
+ $_SESSION['EBSCO']['redirect'] = drupal_get_destination();
+ if (empty($Document)) {
+ $Document = new EBSCODocument();
+ }
+
+ $title = !empty($params['lookfor']) ? ' - ' . $params['lookfor'] : '';
+ drupal_set_title('Search results' . $title);
+
+ $Document->search();
+
+ $variables['records'] = $Document->records();
+ $variables['record_start'] = $Document->record_start();
+ $variables['record_end'] = $Document->record_end();
+ $variables['record_count'] = $Document->record_count();
+ $variables['search_view'] = $Document->search_view();
+ $variables['search_time'] = $Document->search_time();
+ $variables['relatedContent'] = $Document->relatedContent();
+ $variables['autoSuggestTerms'] = $Document->autoSuggestTerms();
+ $variables['lookfor'] = '';
+ if (isset($params['lookfor'])) {
+ $variables['lookfor'] = $params['lookfor'];
+ }
+ elseif (isset($params['group'])) {
+ $types = EBSCODocument::basic_search_type_options();
+ foreach ($params['group'] as $key => $group) {
+ if (!empty($group['lookfor'])) {
+ $pre = $key == 0 ? '' : " {$group['bool']} ";
+ $variables['lookfor'] .= $pre . $types[$group['type']] . ':' . $group['lookfor'];
+ }
}
+ }
+ $variables['pager'] = $Document->pager();
- $title = !empty($params['lookfor']) ? ' - ' . $params['lookfor'] : '';
- drupal_set_title('Search results' . $title);
-
- $Document->search();
-
- $variables['records'] = $Document->records();
- $variables['record_start'] = $Document->record_start();
- $variables['record_end'] = $Document->record_end();
- $variables['record_count'] = $Document->record_count();
- $variables['search_view'] = $Document->search_view();
- $variables['search_time'] = $Document->search_time();
- $variables['relatedContent'] = $Document->relatedContent();
- $variables['autoSuggestTerms'] = $Document->autoSuggestTerms();
- $variables['lookfor'] = '';
- if (isset($params['lookfor'])) {
- $variables['lookfor'] = $params['lookfor'];
- } else if (isset($params['group'])) {
- $types = EBSCODocument::basic_search_type_options();
- foreach ($params['group'] as $key => $group) {
- if (!empty($group['lookfor'])) {
- $pre = $key == 0 ? '' : " {$group['bool']} ";
- $variables['lookfor'] .= $pre . $types[$group['type']] . ':' . $group['lookfor'];
- }
- }
- }
- $variables['pager'] = $Document->pager();
+ $v1 = drupal_get_form('ebsco_sort_form');
+ $variables['sort_form'] = drupal_render($v1);
- $v1=drupal_get_form('ebsco_sort_form');
- $variables['sort_form'] = drupal_render($v1);
-
- // Save data needed by scroller in Detailed view page
- //$Document->search_write();
+ // Save data needed by scroller in Detailed view page
+ // $Document->search_write();
}
-
/**
* Process variables for ebsco-basic-search.tpl.php.
*
* @see ebsco-basic-search.tpl.php
*/
function template_preprocess_ebsco_basic_search(&$variables) {
- global $Document;
- $params = $_REQUEST;
-
- if (empty($Document)) {
- $Document = new EBSCODocument();
+ global $Document;
+ $params = $_REQUEST;
+
+ if (empty($Document)) {
+ $Document = new EBSCODocument();
+ }
+
+ $variables['search_view'] = $Document->search_view();
+ $variables['lookfor'] = '';
+ if (isset($params['lookfor'])) {
+ $variables['lookfor'] = $params['lookfor'];
+ }
+ elseif (isset($params['group'])) {
+ $types = EBSCODocument::basic_search_type_options();
+ foreach ($params['group'] as $key => $group) {
+ if (!empty($group['lookfor'])) {
+ $pre = $key == 0 ? '' : " {$group['bool']} ";
+ $variables['lookfor'] .= $pre . $types[$group['type']] . ':' . $group['lookfor'];
+ }
}
-
- $variables['search_view'] = $Document->search_view();
- $variables['lookfor'] = '';
- if (isset($params['lookfor'])) {
- $variables['lookfor'] = $params['lookfor'];
- } else if (isset($params['group'])) {
- $types = EBSCODocument::basic_search_type_options();
- foreach ($params['group'] as $key => $group) {
- if (!empty($group['lookfor'])) {
- $pre = $key == 0 ? '' : " {$group['bool']} ";
- $variables['lookfor'] .= $pre . $types[$group['type']] . ':' . $group['lookfor'];
- }
- }
- }
- $v1=drupal_get_form('ebsco_basic_search_form');
- $variables['search_form'] = drupal_render($v1);
+ }
+ $v1 = drupal_get_form('ebsco_basic_search_form');
+ $variables['search_form'] = drupal_render($v1);
}
-
/**
* Process variables for ebsco-advanced-search.tpl.php.
*
* @see ebsco-advanced-search.tpl.php
*/
function template_preprocess_ebsco_advanced_search(&$variables) {
- drupal_add_library('system','ui.slider');
- global $Document;
- $params = $_REQUEST;
+ drupal_add_library('system', 'ui.slider');
+ global $Document;
+ $params = $_REQUEST;
- if (empty($Document)) {
- $Document = new EBSCODocument();
- }
- $Document->info();
+ if (empty($Document)) {
+ $Document = new EBSCODocument();
+ }
+ $Document->info();
- $v1=drupal_get_form('ebsco_advanced_search_form');
- $variables['search_form'] = drupal_render($v1);
+ $v1 = drupal_get_form('ebsco_advanced_search_form');
+ $variables['search_form'] = drupal_render($v1);
}
-
/**
* Process variables for ebsco-result.tpl.php.
*
* @see ebsco-result.tpl.php
*/
function template_preprocess_ebsco_result(&$variables) {
- $params = $_REQUEST;
- $params['op'] = isset($params['op']) ? $params['op'] : 'Next';
+ $params = $_REQUEST;
+ $params['op'] = isset($params['op']) ? $params['op'] : 'Next';
- $_SESSION['EBSCO']['redirect'] = drupal_get_destination();
- if (empty($Document)) {
- $Document = new EBSCODocument();
- }
- $Document->retrieve();
- $record = $Document->record();
+ $_SESSION['EBSCO']['redirect'] = drupal_get_destination();
+ if (empty($Document)) {
+ $Document = new EBSCODocument();
+ }
+ $Document->retrieve();
+ $record = $Document->record();
- $variables['record'] = $record;
- $lastSearch = isset($params['id']) ? $Document->search_read($params['id'], $params['op']) : '';
- $variables['last_search'] = $lastSearch;
+ $variables['record'] = $record;
+ $lastSearch = isset($params['id']) ? $Document->search_read($params['id'], $params['op']) : '';
+ $variables['last_search'] = $lastSearch;
- drupal_set_title($record->title);
+ drupal_set_title($record->title);
}
-
/**
* Process variables for ebsco-side-facets.tpl.php.
*
* @see ebsco-side-facets.tpl.php
*/
function template_preprocess_ebsco_side_facets(&$variables) {
- global $Document;
-
- if (empty($Document)) {
- $Document = new EBSCODocument();
- }
- $Document->info();
-
- $variables['record_count'] = $Document->record_count();
- $variables['expanders'] = $Document->expanders();
- $variables['limiters'] = $Document->limiters();
- $variables['facets'] = $Document->facets();
- $variables['filters'] = $Document->filters(); // applied facets, limiters or expanders
- $variables['search_params'] = $Document->search_params(); // hidden parameters
- $variables['link_search_params'] = $Document->link_search_params(); // hidden parameters
+ global $Document;
+
+ if (empty($Document)) {
+ $Document = new EBSCODocument();
+ }
+ $Document->info();
+
+ $variables['record_count'] = $Document->record_count();
+ $variables['expanders'] = $Document->expanders();
+ $variables['limiters'] = $Document->limiters();
+ $variables['facets'] = $Document->facets();
+ // Applied facets, limiters or expanders.
+ $variables['filters'] = $Document->filters();
+ // Hidden parameters.
+ $variables['search_params'] = $Document->search_params();
+ // Hidden parameters.
+ $variables['link_search_params'] = $Document->link_search_params();
}
-
-
/******************************************
* View Helpers
******************************************/
/**
- * Returns an URL without the given filter parameter
+ * Returns an URL without the given filter parameter.
*
* @return string
*/
-function remove_filter_link($filter)
-{
- $params = $_REQUEST;
- if (isset($params['filter'])) {
- foreach($params['filter'] as $key => $value) {
- if ($value == $filter['action']) {
- unset($params['filter'][$key]);
- }
- }
+function remove_filter_link($filter) {
+ $params = $_REQUEST;
+ if (isset($params['filter'])) {
+ foreach ($params['filter'] as $key => $value) {
+ if ($value == $filter['action']) {
+ unset($params['filter'][$key]);
+ }
}
- 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
- *
- * @return string
- */
-function auto_link($string)
-{
- $linkedString = preg_replace_callback(
+ * Performs a regex and replaces any url's with links containing themselves as the text.
+ *
+ * @return string
+ */
+function auto_link($string) {
+ $linkedString = preg_replace_callback(
"/\b(https?):\/\/([-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]*)\b/i",
create_function(
'$matches',
@@ -1061,5 +1065,5 @@ function auto_link($string)
),
$string
);
- return $linkedString;
-}
\ No newline at end of file
+ return $linkedString;
+}
diff --git a/ebsco/lib/EBSCOAPI.php b/ebsco/lib/EBSCOAPI.php
index 9ec33f4..6bda9a6 100644
--- a/ebsco/lib/EBSCOAPI.php
+++ b/ebsco/lib/EBSCOAPI.php
@@ -1,10 +1,10 @@
'',
- 'AllFields' => '',
- 'Abstract' => 'AB',
- 'Author' => 'AU',
- 'Source' => 'SO',
- 'Subject' => 'SU',
- 'Title' => 'TI',
- 'ISBN' => 'IB',
- 'ISSN' => 'IS'
- );
-
-
- /**
- * EBSCO sort options
- * @global array
- */
- private static $sort_options = array(
- 'relevance',
- 'date',
- 'date2',
- 'source'
- );
+class EBSCOAPI {
+ /**
+ * The authentication token used for API transactions.
+ *
+ * @global string
+ */
+ private $authenticationToken;
+
+
+ /**
+ * The session token for API transactions.
+ *
+ * @global string
+ */
+ private $sessionToken;
+
+
+ /**
+ * The EBSCOConnector object used for API transactions.
+ *
+ * @global object EBSCOConnector
+ */
+ private $connector;
+
+
+ /**
+ * Configuration options.
+ */
+ private $config;
+
+ /**
+ * VuFind search types mapped to EBSCO search types
+ * used for urls in search results / detailed result.
+ *
+ * @global array
+ */
+ private static $search_tags = array(
+ '' => '',
+ 'AllFields' => '',
+ 'Abstract' => 'AB',
+ 'Author' => 'AU',
+ 'Source' => 'SO',
+ 'Subject' => 'SU',
+ 'Title' => 'TI',
+ 'ISBN' => 'IB',
+ 'ISSN' => 'IS',
+ );
+
+
+ /**
+ * EBSCO sort options .
+ *
+ * @global array
+ */
+ private static $sort_options = array(
+ 'relevance',
+ 'date',
+ 'date2',
+ 'source',
+ );
+
+
+ /**
+ * VuFind sort types mapped to EBSCO sort types
+ * used for urls in Search results / Detailed view.
+ *
+ * @global array
+ */
+ private static $mapped_sort_options = array(
+ '' => 'relevance',
+ 'relevance' => 'relevance',
+ 'subject' => 'date',
+ 'date' => 'date2',
+ 'date_asc' => 'date2',
+ 'date_desc' => 'date',
+ 'callnumber' => 'date',
+ 'author' => 'author',
+ 'title' => 'date',
+ );
+
+ /**
+ * Constructor.
+ *
+ * @param array config
+ *
+ * @access public
+ */
+ public function __construct($config) {
+ $this->config = $config;
+ }
+
+ /**
+ * Setter / Getter for authentication token.
+ *
+ * @param string The authentication token
+ *
+ * @return string or none
+ *
+ * @access public
+ */
+ public function authenticationToken($token = NULL) {
+ if (empty($token)) {
+ $token = $this->readSession('authenticationToken');
+ return !empty($token) ? $token : $this->authenticationToken;
+ }
+ else {
+ $this->authenticationToken = $token;
+ $this->writeSession('authenticationToken', $token);
+ }
+ }
+
+ /**
+ * Setter / Getter for session token.
+ *
+ * @param string The session token
+ *
+ * @return string or none
+ *
+ * @access public
+ */
+ public function sessionToken($token = NULL) {
+ if (empty($token)) {
+ $token = $this->readSession('sessionToken');
+ return !empty($token) ? $token : $this->sessionToken;
+ }
+ else {
+ $this->sessionToken = $token;
+ $this->writeSession('sessionToken', $token);
+ }
+ }
+
+ /**
+ * Getter for isGuest.
+ *
+ * @param string 'y' or 'n'
+ *
+ * @return string or none
+ *
+ * @access public
+ */
+ public function isGuest($boolean = NULL) {
+ if (empty($boolean)) {
+ return $this->readSession('isGuest');
+ }
+ else {
+ $this->writeSession('isGuest', $boolean);
+ }
+ }
+
+ /**
+ * Create a new EBSCOConnector object or reuse an existing one.
+ *
+ * @param none
+ *
+ * @return EBSCOConnector object
+ *
+ * @access public
+ */
+ public function connector() {
+ if (empty($this->connector)) {
+ $this->connector = new EBSCOConnector($this->config);
+ }
+ return $this->connector;
+ }
+
+ /**
+ * Create a new EBSCOResponse object.
+ *
+ * @param object $response
+ *
+ * @return EBSCOResponse object
+ *
+ * @access public
+ */
+ public function response($response) {
+ $responseObj = new EBSCOResponse($response);
+ return $responseObj;
+ }
+
+ /**
+ * Request authentication and session tokens, then send the API request.
+ * Retry the request if authentication errors occur.
+ *
+ * @param string $action
+ * The EBSCOConnector method name.
+ * @param array $params
+ * The parameters of the HTTP request.
+ * @param int $attempts
+ * The number of retries.
+ *
+ * @return object SimpleXml DOM or PEAR Error
+ *
+ * @access protected
+ */
+ protected function request($action, $params = NULL, $attempts = 5) {
+ $authenticationToken = $this->authenticationToken();
+ $sessionToken = $this->sessionToken();
+
+ // 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 (empty($authenticationToken) || empty($sessionToken)) {
+ $result = $this->apiAuthenticationAndSessionToken();
+ if ($this->isError($result)) {
+ // Any error should terminate the request immediately
+ // in order to prevent infinite recursion.
+ return $result;
+ }
+ }
+ // Any change of the isGuest should request a new session
+ // (and don't terminate the current request if there was an error during the session request
+ // since it's not that important)
+ if ($this->isGuest() != $this->connector()->isGuest()) {
+ $this->apiSessionToken();
+ }
- /**
- * VuFind sort types mapped to EBSCO sort types
- * used for urls in Search results / Detailed view
- * @global array
- */
- private static $mapped_sort_options = array(
- '' => 'relevance',
- 'relevance' => 'relevance',
- 'subject' => 'date',
- 'date' => 'date2',
- 'date_asc' => 'date2',
- 'date_desc' => 'date',
- 'callnumber' => 'date',
- 'author' => 'author',
- 'title' => 'date'
+ $headers = array(
+ 'x-authenticationToken' => $this->authenticationToken(),
+ 'x-sessionToken' => $this->sessionToken(),
);
-
- /**
- * Constructor
- *
- *
- * @param array config
- *
- * @access public
- */
- public function __construct($config)
- {
- $this->config = $config;
- }
-
- /**
- * Setter / Getter for authentication token
- *
- * @param string The authentication token
- *
- * @return string or none
- * @access public
- */
- public function authenticationToken($token = null)
- {
- if (empty($token)) {
- $token = $this->readSession('authenticationToken');
- return !empty($token) ? $token : $this->authenticationToken;
- } else {
- $this->authenticationToken = $token;
- $this->writeSession('authenticationToken', $token);
- }
+ $response = call_user_func_array(array($this->connector(), "request{$action}"), array($params, $headers));
+ if ($this->isError($response)) {
+ // Retry the request if there were authentication errors.
+ $code = $response->getCode();
+ switch ($code) {
+ // 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.
+ case EBSCOConnector::EDS_AUTH_TOKEN_INVALID:
+ $result = $this->apiAuthenticationToken();
+ if ($this->isError($result)) {
+ // Any error should terminate the request immediately
+ // in order to prevent infinite recursion.
+ return $result;
+ }
+ if ($attempts > 0) {
+ $result = $this->request($action, $params, --$attempts);
+ }
+ break;
+
+ case EBSCOConnector::EDS_SESSION_TOKEN_INVALID:
+ $result = $this->apiAuthenticationAndSessionToken();
+ if ($this->isError($result)) {
+ // Any error should terminate the request immediately
+ // in order to prevent infinite recursion.
+ return $result;
+ }
+ if ($attempts > 0) {
+ $result = $this->request($action, $params, --$attempts);
+ }
+ break;
+
+ default:
+ $result = $this->handleError($response);
+ break;
+ }
}
-
-
- /**
- * Setter / Getter for session token
- *
- * @param string The session token
- *
- * @return string or none
- * @access public
- */
- public function sessionToken($token = null)
- {
- if (empty($token)) {
- $token = $this->readSession('sessionToken');
- return !empty($token) ? $token : $this->sessionToken;
- } else {
- $this->sessionToken = $token;
- $this->writeSession('sessionToken', $token);
- }
+ else {
+ $result = $this->response($response)->result();
}
-
- /**
- * Getter for isGuest
- *
- * @param string 'y' or 'n'
- *
- * @return string or none
- * @access public
- */
- public function isGuest($boolean = null)
- {
- if (empty($boolean)) {
- return $this->readSession('isGuest');
- } else {
- $this->writeSession('isGuest', $boolean);
- }
+ return $result;
+ }
+
+ /**
+ * Wrapper for authentication API call.
+ *
+ * @param none
+ *
+ * @access public
+ */
+ public function apiAuthenticationToken() {
+ $response = $this->connector()->requestAuthenticationToken();
+
+ if ($this->isError($response)) {
+ return $response;
}
+ else {
+ $result = $this->response($response)->result();
+ if (isset($result['authenticationToken'])) {
+ $this->authenticationToken($result['authenticationToken']);
+ return $result['authenticationToken'];
+ }
+ else {
+ return new EBSCOException("No authentication token was found in the response.");
+ }
+ }
+ }
+
+ /**
+ * Wrapper for session API call.
+ *
+ * @param none
+ *
+ * @access public
+ */
+ public function apiSessionToken() {
+ // Add authentication tokens to headers.
+ $headers = array(
+ 'x-authenticationToken' => $this->authenticationToken(),
+ );
-
- /**
- * Create a new EBSCOConnector object or reuse an existing one
- *
- * @param none
- *
- * @return EBSCOConnector object
- * @access public
- */
- public function connector()
- {
- if (empty($this->connector)) {
- $this->connector = new EBSCOConnector($this->config);
- }
- return $this->connector;
- }
-
-
- /**
- * Create a new EBSCOResponse object
- *
- * @param object $response
- *
- * @return EBSCOResponse object
- * @access public
- */
- public function response($response)
- {
- $responseObj = new EBSCOResponse($response);
- return $responseObj;
- }
-
-
- /**
- * Request authentication and session tokens, then send the API request.
- * Retry the request if authentication errors occur
- *
- * @param string $action The EBSCOConnector method name
- * @param array $params The parameters of the HTTP request
- * @param integer $attempts The number of retries
- *
- * @return object SimpleXml DOM or PEAR Error
- * @access protected
- */
- protected function request($action, $params = null, $attempts = 5)
- {
- $authenticationToken = $this->authenticationToken();
- $sessionToken = $this->sessionToken();
-
- // 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 (empty($authenticationToken) || empty($sessionToken)) {
- $result = $this->apiAuthenticationAndSessionToken();
- if ($this->isError($result)) {
- // Any error should terminate the request immediately
- // in order to prevent infinite recursion
- return $result;
- }
- }
-
- // Any change of the isGuest should request a new session
- // (and don't terminate the current request if there was an error during the session request
- // since it's not that important)
- if ($this->isGuest() != $this->connector()->isGuest()) {
- $this->apiSessionToken();
- }
-
- $headers = array(
- 'x-authenticationToken' => $this->authenticationToken(),
- 'x-sessionToken' => $this->sessionToken()
- );
-
- $response = call_user_func_array(array($this->connector(), "request{$action}"), array($params, $headers));
- if ($this->isError($response)) {
- // Retry the request if there were authentication errors
- $code = $response->getCode();
- switch ($code) {
- // 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
- case EBSCOConnector::EDS_AUTH_TOKEN_INVALID:
- $result = $this->apiAuthenticationToken();
- if ($this->isError($result)) {
- // Any error should terminate the request immediately
- // in order to prevent infinite recursion
- return $result;
- }
- if ($attempts > 0) {
- $result = $this->request($action, $params, --$attempts);
- }
- break;
- case EBSCOConnector::EDS_SESSION_TOKEN_INVALID:
- $result = $this->apiAuthenticationAndSessionToken();
- if ($this->isError($result)) {
- // Any error should terminate the request immediately
- // in order to prevent infinite recursion
- return $result;
- }
- if ($attempts > 0) {
- $result = $this->request($action, $params, --$attempts);
- }
- break;
- default:
- $result = $this->handleError($response);
- break;
- }
- } else {
- $result = $this->response($response)->result();
- }
-
+ $response = $this->connector()->requestSessionToken($headers);
+ // Raise the exception so that any code running this method should exit immediately.
+ if ($this->isError($response)) {
+ return $response;
+ }
+ else {
+ $result = $this->response($response)->result();
+ if (is_string($result)) {
+ $this->sessionToken($result);
return $result;
+ }
+ else {
+ return new EBSCOException("No session token was found in the response.");
+ }
}
-
-
- /**
- * Wrapper for authentication API call
- *
- * @param none
- *
- * @access public
- */
- public function apiAuthenticationToken()
- {
- $response = $this->connector()->requestAuthenticationToken();
-
- if ($this->isError($response)) {
- return $response;
- } else {
- $result = $this->response($response)->result();
- if (isset($result['authenticationToken'])) {
- $this->authenticationToken($result['authenticationToken']);
- return $result['authenticationToken'];
- } else {
- return new EBSCOException("No authentication token was found in the response.");
- }
- }
+ }
+
+ /**
+ * Initialize the authentication and session tokens.
+ *
+ * @param none
+ *
+ * @access public
+ */
+ public function apiAuthenticationAndSessionToken() {
+ $authenticationToken = $this->apiAuthenticationToken();
+ if ($this->isError($authenticationToken)) {
+ // An authentication error should terminate the request immediately.
+ return $authenticationToken;
}
-
- /**
- * Wrapper for session API call
- *
- * @param none
- *
- * @access public
- */
- public function apiSessionToken()
- {
- // Add authentication tokens to headers
- $headers = array(
- 'x-authenticationToken' => $this->authenticationToken()
- );
-
- $response = $this->connector()->requestSessionToken($headers);
- // Raise the exception so that any code running this method should exit immediately
- if ($this->isError($response)) {
- return $response;
- } else {
- $result = $this->response($response)->result();
- if (is_string($result)) {
- $this->sessionToken($result);
- return $result;
- } else {
- return new EBSCOException("No session token was found in the response.");
- }
- }
+ $sessionToken = $this->apiSessionToken();
+ if ($this->isError($sessionToken)) {
+ // A session error should terminate the request immediately.
+ return $sessionToken;
}
-
- /**
- * Initialize the authentication and session tokens
- *
- * @param none
- *
- * @access public
- */
- public function apiAuthenticationAndSessionToken()
- {
- $authenticationToken = $this->apiAuthenticationToken();
- if ($this->isError($authenticationToken)) {
- // An authentication error should terminate the request immediately
- return $authenticationToken;
- }
-
- $sessionToken = $this->apiSessionToken();
- if ($this->isError($sessionToken)) {
- // A session error should terminate the request immediately
- return $sessionToken;
- }
-
- // We don't have to return anything, both tokens can be accessed using the getters
- return true;
- }
-
-
- /**
- * Wrapper for search API call
- *
- * @param array $search The search terms
- * @param array $filters The facet filters
- * @param string $start The page to start with
- * @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
- * @return array An array of query results
- * @access public
- */
- public function apiSearch($search, $filters,
- $start = 1, $limit = 10, $sortBy = 'relevance', $amount = 'detailed', $mode = 'all', $rs=false, $emp=false,$autosuggest=false) {
- $query = array();
-
- // Basic search
- if(!empty($search['lookfor'])) {
- $lookfor = $search['lookfor'];
- $type = isset($search['index']) && !empty($search['index']) ? $search['index'] : 'AllFields';
-
- // escape some characters from lookfor term
- $term = str_replace(array(',', ':', '(', ')'), array('\,', '\:', '\(', '\)'), $lookfor);
- // replace multiple consecutive empty spaces with one empty space
- $term = preg_replace("/\s+/", ' ', $term);
-
- // search terms
- // Complex search term
- if (preg_match('/(.*) (AND|OR) (.*)/i', $term)) {
- $query['query'] = $term;
- } else {
- $tag = self::$search_tags[$type];
- $op = 'AND';
- $query_str = implode(',', array($op, $tag));
- $query_str = implode(($tag ? ':' : ''), array($query_str, $term));
- $query['query-1'] = $query_str;
- }
-
- // Advanced search
- }
- else if(!empty($search['group'])) {
-
- $counter = 1;
- foreach ($search['group'] as $group) {
- $type = $group['type'];
- if (isset($group['lookfor'])) {
- $term = $group['lookfor'];
- $op = $group['bool'];
- $tag = $type && isset(self::$search_tags[$type]) ? self::$search_tags[$type] : '';
-
- // escape some characters from lookfor term
- $term = str_replace(array(',', ':', '(', ')'), array('\,', '\:', '\(', '\)'), $term);
- // replace multiple consecutive empty spaces with one empty space
- $term = preg_replace("/\s+/", ' ', $term);
- if (!empty($term)) {
- $query_str = implode(',', array($op, $tag));
- $query_str = implode(($tag ? ':' : ''), array($query_str, $term));
- $query["query-$counter"] = $query_str;
- $counter++;
- }
- }
- }
-
- // No search term, return an empty array
- } else {
- $results = array(
- 'recordCount' => 0,
- 'numFound' => 0,
- 'start' => 0,
- 'documents' => array(),
- 'facets' => array()
- );
- return $results;
+ // We don't have to return anything, both tokens can be accessed using the getters.
+ return TRUE;
+ }
+
+ /**
+ * Wrapper for search API call.
+ *
+ * @param array $search
+ * The search terms.
+ * @param array $filters
+ * The facet filters.
+ * @param string $start
+ * The page to start with.
+ * @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
+ *
+ * @return array An array of query results
+ *
+ * @access public
+ */
+ public function apiSearch($search,
+ $filters,
+ $start = 1,
+ $limit = 10,
+ $sortBy = 'relevance',
+ $amount = 'detailed',
+ $mode = 'all',
+ $rs = FALSE,
+ $emp = FALSE,
+ $autosuggest = FALSE) {
+ $query = array();
+
+ // Basic search.
+ if (!empty($search['lookfor'])) {
+ $lookfor = $search['lookfor'];
+ $type = isset($search['index']) && !empty($search['index']) ? $search['index'] : 'AllFields';
+
+ // Escape some characters from lookfor term.
+ $term = str_replace(array(',', ':', '(', ')'), array('\,', '\:', '\(', '\)'), $lookfor);
+ // Replace multiple consecutive empty spaces with one empty space.
+ $term = preg_replace("/\s+/", ' ', $term);
+
+ // Search terms
+ // Complex search term.
+ if (preg_match('/(.*) (AND|OR) (.*)/i', $term)) {
+ $query['query'] = $term;
+ }
+ else {
+ $tag = self::$search_tags[$type];
+ $op = 'AND';
+ $query_str = implode(',', array($op, $tag));
+ $query_str = implode(($tag ? ':' : ''), array($query_str, $term));
+ $query['query-1'] = $query_str;
+ }
+
+ // Advanced search.
+ }
+ elseif (!empty($search['group'])) {
+
+ $counter = 1;
+ foreach ($search['group'] as $group) {
+ $type = $group['type'];
+ if (isset($group['lookfor'])) {
+ $term = $group['lookfor'];
+ $op = $group['bool'];
+ $tag = $type && isset(self::$search_tags[$type]) ? self::$search_tags[$type] : '';
+
+ // Escape some characters from lookfor term.
+ $term = str_replace(array(',', ':', '(', ')'), array('\,', '\:', '\(', '\)'), $term);
+ // Replace multiple consecutive empty spaces with one empty space.
+ $term = preg_replace("/\s+/", ' ', $term);
+ if (!empty($term)) {
+ $query_str = implode(',', array($op, $tag));
+ $query_str = implode(($tag ? ':' : ''), array($query_str, $term));
+ $query["query-$counter"] = $query_str;
+ $counter++;
+ }
}
+ }
- // Add filters
- $limiters = array(); $expanders = array(); $facets = array();
- foreach ($filters as $filter) {
- if (preg_match('/addlimiter/', $filter)) {
- list($action, $str) = explode('(', $filter, 2);
- $field_and_value = substr($str, 0, -1); // e.g. FT:y or GZ:Student Research, Projects and Publications
- list($field, $value) = explode(':', $field_and_value, 2);
- $limiters[$field][] = $value;
- } else if (preg_match('/addexpander/', $filter)) {
- list($action, $str) = explode('(', $filter, 2);
- $field = substr($str, 0, -1); // expanders don't have value
- $expanders[] = $field;
- } else if (preg_match('/addfacetfilter/', $filter)) {
- list($action, $str) = explode('(', $filter, 2);
- $field_and_value = substr($str, 0, -1); // e.g. ZG:FRANCE
- list($field, $value) = explode(':', $field_and_value, 2);
- $facets[$field][] = $field_and_value;
- }
- }
- if (!empty($limiters)) {
- foreach($limiters as $field => $limiter) {
- $query['limiter'][] = $field . ':' . implode(',', $limiter); // e.g. LA99:English,French,German
- }
- }
- if (!empty($expanders)) {
- $query['expander'] = implode(',', $expanders); // e.g. fulltext, thesaurus
- }
- if (!empty($facets)) {
- $groupId = 1;
- foreach($facets as $field => $facet) {
- $query['facetfilter'][] = $groupId . ',' . implode(',', $facet); // e.g. 1,DE:Math,DE:History
- $groupId += 1;
- }
- }
-
- //2014-03-26 - new action to jump to page
- if ($start>1) {
- $query['action']="GoToPage(".$start.")";
- }
-
-
- // Add the sort option
- $sortBy = in_array($sortBy, self::$sort_options) ? $sortBy : self::$mapped_sort_options[$sortBy];
-
- // Add the HTTP query params
- $params = array(
- // Specifies the sort. Valid options are:
- // relevance, date, date2
- // date = Date descending
- // date2 = Date ascending
- 'sort' => $sortBy,
- // Specifies the search mode. Valid options are:
- // bool, any, all, smart
- 'searchmode' => $mode,
- // Specifies the amount of data to return with the response
- // Valid options are:
- // title: Title only
- // brief: Title + Source, Subjects
- // detailed: Brief + full abstract
- 'view' => $amount,
- /// Specifies whether or not to include facets
- 'includefacets' => 'y',
- 'resultsperpage' => $limit,
-
- //2014-03-26 RF
- 'pagenumber' => $start,
- //'pagenumber' => 1,
- // Specifies whether or not to include highlighting in the search results
- 'highlight' => 'y'
- );
-
- if($autosuggest==true) {
- $params["autosuggest"]="y";
- }
-
- if ($rs==true){
- $params["relatedcontent"]="rs";
- }
-
- if ($emp==true){
- if (isset($params["relatedcontent"])) {
- $params["relatedcontent"].=",emp";
- }
- else
- {
- $params["relatedcontent"]="emp";
- }
- }
-
-
- $params = array_merge($params, $query);
-
- $result = $this->request('Search', $params);
- return $result;
+ // No search term, return an empty array.
}
-
-
- /**
- * Wrapper for retrieve API call
- *
- * @param array $an The accession number
- * @param string $start The short database name
- *
- * @throws object PEAR Error
- * @return array An associative array of data
- * @access public
- */
- public function apiRetrieve($an, $db)
- {
- // Add the HTTP query params
- $params = array(
- 'an' => $an,
- 'dbid' => $db,
- 'highlight' => 'y'
- );
-
- $result = $this->request('Retrieve', $params);
- return $result;
+ else {
+ $results = array(
+ 'recordCount' => 0,
+ 'numFound' => 0,
+ 'start' => 0,
+ 'documents' => array(),
+ 'facets' => array(),
+ );
+ return $results;
}
+ // Add filters.
+ $limiters = array(); $expanders = array(); $facets = array();
+ foreach ($filters as $filter) {
+ if (preg_match('/addlimiter/', $filter)) {
+ list($action, $str) = explode('(', $filter, 2);
+ // 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);
+ $limiters[$field][] = $value;
+ }
+ elseif (preg_match('/addexpander/', $filter)) {
+ list($action, $str) = explode('(', $filter, 2);
+ // Expanders don't have value.
+ $field = substr($str, 0, -1);
+ $expanders[] = $field;
+ }
+ elseif (preg_match('/addfacetfilter/', $filter)) {
+ list($action, $str) = explode('(', $filter, 2);
+ // e.g. ZG:FRANCE.
+ $field_and_value = substr($str, 0, -1);
+ list($field, $value) = explode(':', $field_and_value, 2);
+ $facets[$field][] = $field_and_value;
+ }
+ }
+ if (!empty($limiters)) {
+ foreach ($limiters as $field => $limiter) {
+ // e.g. LA99:English,French,German.
+ $query['limiter'][] = $field . ':' . implode(',', $limiter);
+ }
+ }
+ if (!empty($expanders)) {
+ // e.g. fulltext, thesaurus.
+ $query['expander'] = implode(',', $expanders);
+ }
+ if (!empty($facets)) {
+ $groupId = 1;
+ foreach ($facets as $field => $facet) {
+ // e.g. 1,DE:Math,DE:History.
+ $query['facetfilter'][] = $groupId . ',' . implode(',', $facet);
+ $groupId += 1;
+ }
+ }
- /**
- * Wrapper for info API call
- *
- * @throws object PEAR Error
- * @return array An associative array of data
- * @access public
- */
- public function apiInfo()
- {
- if ($result = $this->readSession('info')) {
- return $result;
- }
- $result = $this->request('Info');
-
- if(!$this->isError($result)) {
- $this->writeSession('info', $result);
- }
-
- return $result;
+ // 2014-03-26 - new action to jump to page.
+ if ($start > 1) {
+ $query['action'] = "GoToPage(" . $start . ")";
}
+ // Add the sort option.
+ $sortBy = in_array($sortBy, self::$sort_options) ? $sortBy : self::$mapped_sort_options[$sortBy];
+
+ // Add the HTTP query params.
+ $params = array(
+ // Specifies the sort. Valid options are:
+ // relevance, date, date2
+ // date = Date descending
+ // date2 = Date ascending.
+ 'sort' => $sortBy,
+ // Specifies the search mode. Valid options are:
+ // bool, any, all, smart.
+ 'searchmode' => $mode,
+ // Specifies the amount of data to return with the response
+ // Valid options are:
+ // title: Title only
+ // brief: Title + Source, Subjects
+ // detailed: Brief + full abstract.
+ 'view' => $amount,
+ // Specifies whether or not to include facets.
+ 'includefacets' => 'y',
+ 'resultsperpage' => $limit,
+
+ // 2014-03-26 RF.
+ 'pagenumber' => $start,
+ // 'pagenumber' => 1,
+ // Specifies whether or not to include highlighting in the search results.
+ 'highlight' => 'y',
+ );
- /**
- * Handle a PEAR_Error. Return :
- * - if the error is critical : an associative array with the current error message
- * - if the error is not critical : the error message
- *
- * @param Pear_Error $exception
- *
- * @return array or the Pear_Error exception
- * @access protected
- */
- private function handleError($error) {
- $errorCode = $error->getCode();
- switch($errorCode) {
- // This kind of error was generated by user , so display it to user
- case EBSCOConnector::EDS_INVALID_ARGUMENT_VALUE:
- // Any other errors are system errors, don't display them to user
- default:
- $errorMessage = 'An error occurred when getting the data.';
- break;
- }
- $result = array(
- 'errors' => $errorMessage,
- 'recordCount' => 0,
- 'numFound' => 0,
- 'start' => 0,
- 'documents' => array(),
- 'facets' => array()
- );
- return $result;
+ if ($autosuggest == TRUE) {
+ $params["autosuggest"] = "y";
}
+ if ($rs == TRUE) {
+ $params["relatedcontent"] = "rs";
+ }
- /**
- * Store the given object into session
- *
- * @param string $key The key used for reading the value
- * @param object $value The object stored in session
- *
- * @return none
- * @access protected
- */
- protected function writeSession($key, $value)
- {
- if(!empty($key) && !empty($value)) {
- $_SESSION['EBSCO'][$key] = $value;
- }
+ if ($emp == TRUE) {
+ if (isset($params["relatedcontent"])) {
+ $params["relatedcontent"] .= ",emp";
+ }
+ else {
+ $params["relatedcontent"] = "emp";
+ }
}
+ $params = array_merge($params, $query);
+
+ $result = $this->request('Search', $params);
+ return $result;
+ }
+
+ /**
+ * Wrapper for retrieve API call.
+ *
+ * @param array $an
+ * The accession number.
+ * @param string $start
+ * The short database name.
+ *
+ * @throws object PEAR Error
+ *
+ * @return array An associative array of data
+ *
+ * @access public
+ */
+ public function apiRetrieve($an, $db) {
+ // Add the HTTP query params.
+ $params = array(
+ 'an' => $an,
+ 'dbid' => $db,
+ 'highlight' => 'y',
+ );
- /**
- * Read from session the object having the given key
- *
- * @param string $key The key used for reading the object
- *
- * @return object
- * @access protected
- */
- protected function readSession($key)
- {
- $value = isset($_SESSION['EBSCO'][$key]) ? $_SESSION['EBSCO'][$key] : '';
- return $value;
+ $result = $this->request('Retrieve', $params);
+ return $result;
+ }
+
+ /**
+ * Wrapper for info API call.
+ *
+ * @throws object PEAR Error
+ *
+ * @return array An associative array of data
+ *
+ * @access public
+ */
+ public function apiInfo() {
+ if ($result = $this->readSession('info')) {
+ return $result;
}
+ $result = $this->request('Info');
+ if (!$this->isError($result)) {
+ $this->writeSession('info', $result);
+ }
- /**
- * Check if given object is an EBSCOException object
- *
- * @param object $object
- *
- * @return boolean
- * @access protected
- */
- protected function isError($object)
- {
- return is_a($object, 'EBSCOException');
+ return $result;
+ }
+
+ /**
+ * Handle a PEAR_Error. Return :
+ * - if the error is critical : an associative array with the current error message
+ * - if the error is not critical : the error message .
+ *
+ * @param Pear_Error $exception
+ *
+ * @return array or the Pear_Error exception
+ *
+ * @access protected
+ */
+ private function handleError($error) {
+ $errorCode = $error->getCode();
+ switch ($errorCode) {
+ // This kind of error was generated by user , so display it to user.
+ case EBSCOConnector::EDS_INVALID_ARGUMENT_VALUE:
+ // Any other errors are system errors, don't display them to user.
+ default:
+ $errorMessage = 'An error occurred when getting the data.';
+ break;
}
+ $result = array(
+ 'errors' => $errorMessage,
+ 'recordCount' => 0,
+ 'numFound' => 0,
+ 'start' => 0,
+ 'documents' => array(),
+ 'facets' => array(),
+ );
+ return $result;
+ }
+
+ /**
+ * Store the given object into session.
+ *
+ * @param string $key
+ * The key used for reading the value.
+ * @param object $value
+ * The object stored in session.
+ *
+ * @return none
+ *
+ * @access protected
+ */
+ protected function writeSession($key, $value) {
+ if (!empty($key) && !empty($value)) {
+ $_SESSION['EBSCO'][$key] = $value;
+ }
+ }
+
+ /**
+ * Read from session the object having the given key.
+ *
+ * @param string $key
+ * The key used for reading the object.
+ *
+ * @return object
+ *
+ * @access protected
+ */
+ protected function readSession($key) {
+ $value = isset($_SESSION['EBSCO'][$key]) ? $_SESSION['EBSCO'][$key] : '';
+ return $value;
+ }
+
+ /**
+ * Check if given object is an EBSCOException object.
+ *
+ * @param object $object
+ *
+ * @return bool
+ *
+ * @access protected
+ */
+ protected function isError($object) {
+ return is_a($object, 'EBSCOException');
+ }
}
-
-
-?>
\ No newline at end of file
diff --git a/ebsco/lib/EBSCOConnector.php b/ebsco/lib/EBSCOConnector.php
index a683181..617cce6 100644
--- a/ebsco/lib/EBSCOConnector.php
+++ b/ebsco/lib/EBSCOConnector.php
@@ -1,9 +1,9 @@
password = $config['password'];
- $this->userId = $config['user'];
- $this->interfaceId = $config['interface'];
- $this->profileId = $config['profile'];
- $this->orgId = $config['organization'];
- $this->local_ip_address = $config['local_ip_address'];
- $this->isGuest = (user_is_logged_in() || $this->isGuestIPAddress($_SERVER["REMOTE_ADDR"]))? 'n' : 'y';
- $this->logAPIRequests = ($config['log'] == 1);
- if ($this->logAPIRequests) {
- $writer = new Zend_Log_Writer_Stream('php://output');
- $this->logger = new Zend_Log($writer);
- }
+ const HTTP_OK = 200;
+ const HTTP_BAD_REQUEST = 400;
+ const HTTP_NOT_FOUND = 404;
+ const HTTP_INTERNAL_SERVER_ERROR = 500;
+
+
+ /**
+ * The HTTP_Request object used for API transactions.
+ *
+ * @global object HTTP_Request
+ */
+ private $client;
+
+
+ /**
+ * The URL of the EBSCO API server.
+ *
+ * @global string
+ */
+ private static $end_point = 'http://eds-api.ebscohost.com/EDSAPI/rest';
+
+
+ /**
+ * The URL of the EBSCO API server.
+ *
+ * @global string
+ */
+ private static $authentication_end_point = 'https://eds-api.ebscohost.com/AuthService/rest';
+
+
+ /**
+ * The password used for API transactions.
+ *
+ * @global string
+ */
+ private $password;
+
+
+ /**
+ * The user id used for API transactions.
+ *
+ * @global string
+ */
+ private $userId;
+
+
+ /**
+ * The profile ID used for API transactions.
+ *
+ * @global string
+ */
+ private $profileId;
+
+
+ /**
+ * The interface ID used for API transactions.
+ *
+ * @global string
+ */
+ private $interfaceId;
+
+
+ /**
+ * The customer ID used for API transactions.
+ *
+ * @global string
+ */
+ private $orgId;
+
+
+ /**
+ * The isGuest used for API transactions.
+ *
+ * @global string 'y' or 'n'
+ */
+ private $isGuest;
+
+ /**
+ * Contains the list of ip addresses.
+ *
+ * @global string
+ */
+ private $local_ip_address;
+
+
+ /**
+ * You can log HTTP_Request requests using this option.
+ *
+ * @global bool logAPIRequests
+ */
+
+ private $logAPIRequests;
+
+
+ /**
+ * The logger object.
+ *
+ * @global object Logger
+ */
+ private $logger;
+
+ /**
+ * Constructor.
+ *
+ * Sets up the EBSCO API settings.
+ *
+ * @param none
+ *
+ * @access public
+ */
+ public function __construct($config) {
+ $this->password = $config['password'];
+ $this->userId = $config['user'];
+ $this->interfaceId = $config['interface'];
+ $this->profileId = $config['profile'];
+ $this->orgId = $config['organization'];
+ $this->local_ip_address = $config['local_ip_address'];
+ $this->isGuest = (user_is_logged_in() || $this->isGuestIPAddress($_SERVER["REMOTE_ADDR"])) ? 'n' : 'y';
+ $this->logAPIRequests = ($config['log'] == 1);
+ if ($this->logAPIRequests) {
+ $writer = new Zend_Log_Writer_Stream('php://output');
+ $this->logger = new Zend_Log($writer);
}
-
-
- /**
- * Detects if the user is authorized based on the IP address
- *
- * @return string
- */
- public function isGuestIPAddress($ipUser)
- {
- $s= $this->local_ip_address;
-
- if (trim($s)=="") {
- return false;
- }
- //break records
- $m=explode(",",$s);
-
- foreach($m as $ip) {
- if ( strcmp(substr($ipUser,0,strlen(trim($ip))),trim($ip))==0) {
- // inside of ip address range of customer
- return true;
- }
- }
- return false;
+ }
+
+ /**
+ * Detects if the user is authorized based on the IP address.
+ *
+ * @return string
+ */
+ public function isGuestIPAddress($ipUser) {
+ $s = $this->local_ip_address;
+
+ if (trim($s) == "") {
+ return FALSE;
}
-
- /**
- * Public getter for private isGuest
- *
- * @param none
- *
- * @return string isGuest
- * @access public
- */
- public function isGuest()
- {
- return $this->isGuest;
+ // Break records.
+ $m = explode(",", $s);
+
+ foreach ($m as $ip) {
+ if (strcmp(substr($ipUser, 0, strlen(trim($ip))), trim($ip)) == 0) {
+ // Inside of ip address range of customer.
+ return TRUE;
+ }
}
-
-
- /**
- * Request the authentication token
- *
- * @param none
- *
- * @return object SimpleXml or PEAR_Error
- * @access public
- */
- public function requestAuthenticationToken()
- {
- $url = self::$authentication_end_point . '/UIDAuth';
-
- // Add the body of the request
- $params =<<isGuest;
+ }
+
+ /**
+ * Request the authentication token.
+ *
+ * @param none
+ *
+ * @return object SimpleXml or PEAR_Error
+ *
+ * @access public
+ */
+ public function requestAuthenticationToken() {
+ $url = self::$authentication_end_point . '/UIDAuth';
+
+ // Add the body of the request.
+ $params = <<
{$this->userId}
{$this->password}
@@ -259,246 +270,254 @@ class EBSCOConnector
BODY;
- $response = $this->request($url, $params, array(), 'POST');
- return $response;
- }
-
-
- /**
- * Request the session token
- *
- * @param array $headers Authentication token
- *
- * @return object SimpleXml or PEAR_Error
- * @access public
- */
- public function requestSessionToken($headers)
- {
- $url = self::$end_point . '/CreateSession';
-
- // Add the HTTP query params
- $params = array(
- 'profile' => $this->profileId,
- 'org' => $this->orgId,
- 'guest' => $this->isGuest
- );
-
- $response = $this->request($url, $params, $headers);
- return $response;
- }
-
-
- /**
- * Request the search records
- *
- * @param array $params Search specific parameters
- * @param array $headers Authentication and session tokens
- *
- * @return object SimpleXml or PEAR_Error
- * @access public
- */
- public function requestSearch($params, $headers)
- {
- $url = self::$end_point . '/Search';
-
- $response = $this->request($url, $params, $headers);
- return $response;
- }
-
-
- /**
- * Request a specific record
- *
- * @param array $params Retrieve specific parameters
- * @param array $headers Authentication and session tokens
- *
- * @return object SimpleXml or PEAR_Error
- * @access public
- */
- public function requestRetrieve($params, $headers)
- {
- $url = self::$end_point . '/Retrieve';
-
- $response = $this->request($url, $params, $headers);
- return $response;
+ $response = $this->request($url, $params, array(), 'POST');
+ return $response;
+ }
+
+ /**
+ * Request the session token.
+ *
+ * @param array $headers
+ * Authentication token.
+ *
+ * @return object SimpleXml or PEAR_Error
+ *
+ * @access public
+ */
+ public function requestSessionToken($headers) {
+ $url = self::$end_point . '/CreateSession';
+
+ // Add the HTTP query params.
+ $params = array(
+ 'profile' => $this->profileId,
+ 'org' => $this->orgId,
+ 'guest' => $this->isGuest,
+ );
+
+ $response = $this->request($url, $params, $headers);
+ return $response;
+ }
+
+ /**
+ * Request the search records.
+ *
+ * @param array $params
+ * Search specific parameters.
+ * @param array $headers
+ * Authentication and session tokens.
+ *
+ * @return object SimpleXml or PEAR_Error
+ *
+ * @access public
+ */
+ public function requestSearch($params, $headers) {
+ $url = self::$end_point . '/Search';
+
+ $response = $this->request($url, $params, $headers);
+ return $response;
+ }
+
+ /**
+ * Request a specific record.
+ *
+ * @param array $params
+ * Retrieve specific parameters.
+ * @param array $headers
+ * Authentication and session tokens.
+ *
+ * @return object SimpleXml or PEAR_Error
+ *
+ * @access public
+ */
+ public function requestRetrieve($params, $headers) {
+ $url = self::$end_point . '/Retrieve';
+
+ $response = $this->request($url, $params, $headers);
+ return $response;
+ }
+
+ /**
+ * Request the info data.
+ *
+ * @param null $params
+ * Not used.
+ * @param array $headers
+ * Authentication and session tokens.
+ *
+ * @return object SimpleXml or PEAR_Error
+ *
+ * @access public
+ */
+ public function requestInfo($params, $headers) {
+ $url = self::$end_point . '/Info';
+
+ $response = $this->request($url, $params, $headers);
+
+ return $response;
+ }
+
+ /**
+ * Send an HTTP request and inspect the response.
+ *
+ * @param string $url
+ * The url of the HTTP request.
+ * @param array $params
+ * The parameters of the HTTP request.
+ * @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
+ *
+ * @access protected
+ */
+ protected function request($url, $params, $headers = array(), $method = 'GET') {
+ $xml = FALSE;
+ $return = FALSE;
+ $data = NULL;
+
+ if (!empty($params)) {
+ // Arrays of parameters are used only for GET requests.
+ if (is_array($params)) {
+ $query = http_build_query($params, '', '&');
+ $query = preg_replace('/\%5B\d+\%5D/', '', $query);
+ $url = $url . '?' . $query;
+ // String parameters are used only for POST requests.
+ }
+ else {
+ $data = $params;
+ $headers = array_merge(
+ array('content-type' => 'text/xml'),
+ $headers
+ );
+ }
}
-
- /**
- * Request the info data
- *
- * @param null $params Not used
- * @param array $headers Authentication and session tokens
- *
- * @return object SimpleXml or PEAR_Error
- * @access public
- */
- public function requestInfo($params, $headers)
- {
- $url = self::$end_point . '/Info';
-
- $response = $this->request($url, $params, $headers);
-
- return $response;
- }
-
-
-
- /**
- * Send an HTTP request and inspect the response
- *
- * @param string $url The url of the HTTP request
- * @param array $params The parameters of the HTTP request
- * @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
- * @access protected
- */
- protected function request($url, $params, $headers = array(), $method = 'GET')
- {
- $xml = false;
- $return = false;
- $data = null;
-
- if (!empty($params)) {
- // Arrays of parameters are used only for GET requests
- if (is_array($params)) {
- $query = http_build_query($params, '', '&');
- $query = preg_replace('/\%5B\d+\%5D/', '', $query);
- $url = $url . '?' . $query;
- // String parameters are used only for POST requests
- } else {
- $data = $params;
- $headers = array_merge(
- array('content-type' => 'text/xml'),
- $headers
- );
- }
+ // Add compression in case its not there.
+ $headers = array_merge(
+ array('Accept-Encoding' => 'gzip,deflate'),
+ $headers
+ );
+
+ $options = array(
+ 'headers' => $headers,
+ 'method' => $method,
+ 'data' => $data,
+ );
+
+ // Send the request.
+ try {
+ $response = drupal_http_request($url, $options);
+ // print_r($url);
+ // print_r($response);
+ $code = $response->code;
+ if (isset($response->headers['content-encoding'])) {
+ if ($response->headers['content-encoding'] == 'gzip') {
+ $response->data = gzinflate(substr($response->data, 10));
}
-
- //add compression in case its not there
-
- $headers = array_merge(
- array('Accept-Encoding' => 'gzip,deflate'),
- $headers
- );
-
- $options = array(
- 'headers' => $headers,
- 'method' => $method,
- 'data' => $data
- );
-
- // Send the request
- try {
- $response = drupal_http_request($url, $options);
-//print_r($url);
-//print_r($response);
-
- $code = $response->code;
- if (isset($response->headers['content-encoding'])) {
- if ($response->headers['content-encoding'] == 'gzip') {
- $response->data = gzinflate(substr($response->data, 10));
- }
- elseif ($response->headers['content-encoding'] == 'deflate') {
- $response->data = gzinflate($response->data);
- }
- }
- switch ($code) {
- case self::HTTP_OK:
-
- $xml_str = $response->data;
-
- try {
- // clean EMP namespace
- $xml_str=str_replace(array("data;
- try {
- $xml = simplexml_load_string($xml_str);
-
- // If the response is an API error
- $isError = isset($xml->ErrorNumber) || isset($xml->ErrorCode);
- if ($isError) {
- $error = ''; $code = 0;
- if (isset($xml->DetailedErrorDescription) && !empty($xml->DetailedErrorDescription)) {
- $error = (string) $xml->DetailedErrorDescription;
- } else if (isset($xml->ErrorDescription)) {
- $error = (string) $xml->ErrorDescription;
- } else if (isset($xml->Reason)) {
- $error = (string) $xml->Reason;
- }
- if (isset($xml->ErrorNumber)) {
- $code = (integer) $xml->ErrorNumber;
- } else if (isset($xml->ErrorCode)) {
- $code = (integer) $xml->ErrorCode;
- }
- $return = new EBSCOException($error, $code);
- } else {
- $return = new EBSCOException("HTTP {$code} : The request could not be understood
+ elseif ($response->headers['content-encoding'] == 'deflate') {
+ $response->data = gzinflate($response->data);
+ }
+ }
+ switch ($code) {
+ case self::HTTP_OK:
+
+ $xml_str = $response->data;
+
+ try {
+ // Clean EMP namespace.
+ $xml_str = str_replace(array("data;
+ try {
+ $xml = simplexml_load_string($xml_str);
+
+ // If the response is an API error.
+ $isError = isset($xml->ErrorNumber) || isset($xml->ErrorCode);
+ if ($isError) {
+ $error = ''; $code = 0;
+ if (isset($xml->DetailedErrorDescription) && !empty($xml->DetailedErrorDescription)) {
+ $error = (string) $xml->DetailedErrorDescription;
+ }
+ elseif (isset($xml->ErrorDescription)) {
+ $error = (string) $xml->ErrorDescription;
+ }
+ elseif (isset($xml->Reason)) {
+ $error = (string) $xml->Reason;
+ }
+ if (isset($xml->ErrorNumber)) {
+ $code = (integer) $xml->ErrorNumber;
+ }
+ elseif (isset($xml->ErrorCode)) {
+ $code = (integer) $xml->ErrorCode;
+ }
+ $return = new EBSCOException($error, $code);
+ }
+ else {
+ $return = new EBSCOException("HTTP {$code} : The request could not be understood
by the server due to malformed syntax. Modify your search before retrying.");
- }
- } catch (Exception $e) {
- $return = new EBSCOException($xml);
- }
- break;
-
- case self::HTTP_NOT_FOUND:
- $return = new EBSCOException("HTTP {$code} : The resource you are looking for might
+ }
+ }
+ catch (Exception $e) {
+ $return = new EBSCOException($xml);
+ }
+ break;
+
+ case self::HTTP_NOT_FOUND:
+ $return = new EBSCOException("HTTP {$code} : The resource you are looking for might
have been removed, had its name changed, or is temporarily unavailable.");
- break;
+ break;
- case self::HTTP_INTERNAL_SERVER_ERROR:
- $return = new EBSCOException("HTTP {$code} : The server encountered an unexpected condition
+ case self::HTTP_INTERNAL_SERVER_ERROR:
+ $return = new EBSCOException("HTTP {$code} : The server encountered an unexpected condition
which prevented it from fulfilling the request.");
- break;
-
- default:
- $return = new EBSCOException("HTTP {$code} : Unexpected HTTP error.");
- break;
- }
- } catch (Exception $e) {
- $message = $this->toString($client); // or $this->toString($response)
- $this->logger->log($message, Zend_Log::ERR);
- $return = new EBSCOException($response);
- }
+ break;
- // Log any error
- /*if ($this->logAPIRequests) {
- // $client = both the HTTP request and response
- // $response = only the HTTP response
- $message = $this->toString($client); // or $this->toString($response)
- $this->logger->log($message, Zend_Log::ERR);
- }*/
-
- return $return;
+ default:
+ $return = new EBSCOException("HTTP {$code} : Unexpected HTTP error.");
+ break;
+ }
}
-
-
- /*
- * Capture the output of print_r into a string
- *
- * @param object Any object
- * @access private
- */
- private function toString($object)
- {
- ob_start();
- print_r($object);
- return ob_get_clean();
+ catch (Exception $e) {
+ // Or $this->toString($response)
+ $message = $this->toString($client);
+ $this->logger->log($message, Zend_Log::ERR);
+ $return = new EBSCOException($response);
}
+ // Log any error
+ /*if ($this->logAPIRequests) {
+ // $client = both the HTTP request and response
+ // $response = only the HTTP response
+ $message = $this->toString($client); // or $this->toString($response)
+ $this->logger->log($message, Zend_Log::ERR);
+ }*/
+
+ return $return;
+ }
+
+ /**
+ * Capture the output of print_r into a string.
+ *
+ * @param object Any object
+ *
+ * @access private
+ */
+ private function toString($object) {
+ ob_start();
+ print_r($object);
+ return ob_get_clean();
+ }
}
-
-
-?>
\ No newline at end of file
diff --git a/ebsco/lib/EBSCODocument.php b/ebsco/lib/EBSCODocument.php
index 7f04d83..54eb3db 100644
--- a/ebsco/lib/EBSCODocument.php
+++ b/ebsco/lib/EBSCODocument.php
@@ -1,15 +1,15 @@
10,
- 20 => 20,
- 30 => 30,
- 40 => 40,
- 50 => 50
- );
-
- /**
- * Sort options
- * global array
- */
- private static $sort_options = array(
- 'relevance' => 'Relevance',
- 'date_desc' => 'Date Descending',
- 'date_asc' => 'Date Ascending'
- );
-
- /**
- * Amount options
- * global array
- */
- private static $amount_options = array(
- 'detailed' => 'Detailed',
- 'brief' => 'Brief',
- 'title' => 'Title Only'
- );
-
- /**
- * Bool options
- * global array
- */
- private static $bool_options = array(
- 'AND' => 'All terms',
- 'OR' => 'Any terms',
- 'NOT' => 'No terms'
- );
-
- /**
- * Search mode options
- * global array
- */
- private static $mode_options = array(
- 'all' => 'All search terms',
- 'bool' => 'Boolean / Phrase',
- 'any' => 'Any search terms',
- 'smart' => 'SmartText Searching'
- );
-
- /**
- * Basic search type options
- * global array
- */
- private static $basic_search_type_options = array(
- 'AllFields' => 'All Text',
- 'Title' => 'Title',
- 'Author' => 'Author',
- 'Subject' => 'Subject terms',
- 'Source' => 'Source',
- 'Abstract' => 'Abstract'
- );
-
- /**
- * Advanced search type options
- * global array
- */
- private static $advanced_search_type_options = array(
- 'AllFields' => 'All Text',
- 'Title' => 'Title',
- 'Author' => 'Author',
- 'Subject' => 'Subject terms',
- 'Source' => 'Journal Title/Source',
- 'Abstract' => 'Abstract',
- 'ISBN' => 'ISBN',
- 'ISSN' => 'ISSN'
- );
-
- private $local_ips = "";
-
- /**
- * Constructor.
- *
- * @param array $data Raw data from the EBSCO search representing the record.
- */
- public function __construct($params = null)
- {
- $this->eds = new EBSCOAPI(array(
- 'password' => variable_get('ebsco_password'),
- 'user' => variable_get('ebsco_user'),
- 'profile' => variable_get('ebsco_profile'),
- 'interface' => variable_get('ebsco_interface'),
- 'organization' => variable_get('ebsco_organization'),
- 'local_ip_address' => variable_get('ebsco_local_ips'),
- 'guest' => variable_get('ebsco_guest'),
- 'log' => variable_get('ebsco_log')
- ));
-
- $this->params = $params ? $params : $_REQUEST;
- $this->limit = variable_get('ebsco_default_limit') ? variable_get('ebsco_default_limit') : $this->limit;
- $this->amount = variable_get('ebsco_default_amount') ? variable_get('ebsco_default_amount') : $this->amount;
- }
-
-
- /**
- * Perform the API Info call
- *
- * @return array
- */
- public function info()
- {
- $this->info = $this->eds->apiInfo();
- return $this->info;
- }
-
-
- /**
- * Perform the API Retrieve call
- *
- * @return array
- */
- public function retrieve()
- {
- list($an, $db) = isset($this->params['id']) ? explode('|', $this->params['id'], 2) : array(null, null);
- $this->result = $this->eds->apiRetrieve($an, $db);
-
- return $this->result;
- }
-
-
- /**
- * Perform the API Search call
- *
- * @return array
- */
- public function search()
- {
- $search = array();
-
- if (isset($this->params['lookfor']) && isset($this->params['type'])) {
- $search = array(
- 'lookfor' => $this->params['lookfor'],
- 'index' => $this->params['type']
- );
- } else if (isset($this->params['group'])) {
- $search = $this->params;
- } else {
- return array();
+/**
+ *
+ */
+class EBSCODocument {
+ /**
+ * The EBSCOAPI object that performs the API calls.
+ *
+ * @global object EBSCOAPI
+ */
+ private $eds = NULL;
+
+ /**
+ * The associative array of current request parameters.
+ *
+ * @global array
+ */
+ private $params = array();
+
+ /**
+ * The associative array of EBSCO results returned by a Search API call
+ * #global array.
+ */
+ private $results = array();
+
+ /**
+ * The associative array of data returned by a Retrieve API call.
+ *
+ * @global array
+ */
+ private $result = array();
+
+ /**
+ * The array of data returned by an Info API call.
+ *
+ * @global array
+ */
+ private $info = array();
+
+ /**
+ * The EBSCORecord model returned by a Retrieve API call
+ * #global object EBSCORecord.
+ */
+ private $record = NULL;
+
+ /**
+ * The array of EBSCORecord models returned by a Search API call
+ * #global array of EBSCORecord objects.
+ */
+ private $records = array();
+
+ /**
+ * The array of EBSCORecord models returned by a Search API call
+ * #global array of RelatedRecords.
+ */
+ private $relatedContent = array();
+
+ private $autoSuggestTerms = array();
+
+ /**
+ * The array of filters currently applied.
+ *
+ * @global array
+ */
+ private $filters = array();
+
+ /**
+ * Maximum number of results returned by Search API call .
+ *
+ * @global integer
+ */
+ private $limit = 10;
+
+ /**
+ * Default level of data detail.
+ *
+ * @global string
+ */
+ private $amount = 'brief';
+
+ /**
+ * Maximum number of links displayed by the pagination.
+ *
+ * @global integer
+ */
+ private static $page_links = 10;
+
+ /**
+ * Limit options
+ * global array.
+ */
+ private static $limit_options = array(
+ 10 => 10,
+ 20 => 20,
+ 30 => 30,
+ 40 => 40,
+ 50 => 50,
+ );
+
+ /**
+ * Sort options
+ * global array.
+ */
+ private static $sort_options = array(
+ 'relevance' => 'Relevance',
+ 'date_desc' => 'Date Descending',
+ 'date_asc' => 'Date Ascending',
+ );
+
+ /**
+ * Amount options
+ * global array.
+ */
+ private static $amount_options = array(
+ 'detailed' => 'Detailed',
+ 'brief' => 'Brief',
+ 'title' => 'Title Only',
+ );
+
+ /**
+ * Bool options
+ * global array.
+ */
+ private static $bool_options = array(
+ 'AND' => 'All terms',
+ 'OR' => 'Any terms',
+ 'NOT' => 'No terms',
+ );
+
+ /**
+ * Search mode options
+ * global array.
+ */
+ private static $mode_options = array(
+ 'all' => 'All search terms',
+ 'bool' => 'Boolean / Phrase',
+ 'any' => 'Any search terms',
+ 'smart' => 'SmartText Searching',
+ );
+
+ /**
+ * Basic search type options
+ * global array.
+ */
+ private static $basic_search_type_options = array(
+ 'AllFields' => 'All Text',
+ 'Title' => 'Title',
+ 'Author' => 'Author',
+ 'Subject' => 'Subject terms',
+ 'Source' => 'Source',
+ 'Abstract' => 'Abstract',
+ );
+
+ /**
+ * Advanced search type options
+ * global array.
+ */
+ private static $advanced_search_type_options = array(
+ 'AllFields' => 'All Text',
+ 'Title' => 'Title',
+ 'Author' => 'Author',
+ 'Subject' => 'Subject terms',
+ 'Source' => 'Journal Title/Source',
+ 'Abstract' => 'Abstract',
+ 'ISBN' => 'ISBN',
+ 'ISSN' => 'ISSN',
+ );
+
+ private $local_ips = "";
+
+ /**
+ * Constructor.
+ *
+ * @param array $data
+ * Raw data from the EBSCO search representing the record.
+ */
+ public function __construct($params = NULL) {
+ $this->eds = new EBSCOAPI(array(
+ 'password' => variable_get('ebsco_password'),
+ 'user' => variable_get('ebsco_user'),
+ 'profile' => variable_get('ebsco_profile'),
+ 'interface' => variable_get('ebsco_interface'),
+ 'organization' => variable_get('ebsco_organization'),
+ 'local_ip_address' => variable_get('ebsco_local_ips'),
+ 'guest' => variable_get('ebsco_guest'),
+ 'log' => variable_get('ebsco_log'),
+ ));
+
+ $this->params = $params ? $params : $_REQUEST;
+ $this->limit = variable_get('ebsco_default_limit') ? variable_get('ebsco_default_limit') : $this->limit;
+ $this->amount = variable_get('ebsco_default_amount') ? variable_get('ebsco_default_amount') : $this->amount;
+ }
+
+ /**
+ * Perform the API Info call.
+ *
+ * @return array
+ */
+ public function info() {
+ $this->info = $this->eds->apiInfo();
+ return $this->info;
+ }
+
+ /**
+ * Perform the API Retrieve call.
+ *
+ * @return array
+ */
+ public function retrieve() {
+ list($an, $db) = isset($this->params['id']) ? explode('|', $this->params['id'], 2) : array(NULL, NULL);
+ $this->result = $this->eds->apiRetrieve($an, $db);
+
+ return $this->result;
+ }
+
+ /**
+ * Perform the API Search call.
+ *
+ * @return array
+ */
+ public function search() {
+ $search = array();
+
+ if (isset($this->params['lookfor']) && isset($this->params['type'])) {
+ $search = array(
+ 'lookfor' => $this->params['lookfor'],
+ 'index' => $this->params['type'],
+ );
+ }
+ elseif (isset($this->params['group'])) {
+ $search = $this->params;
+ }
+ else {
+ return array();
+ }
+
+ $filter = isset($this->params['filter']) ? $this->params['filter'] : array();
+ $page = isset($this->params['page']) ? $this->params['page'] + 1 : 1;
+ $limit = $this->limit;
+ $sort = isset($this->params['sort']) ? $this->params['sort'] : 'relevance';
+ $amount = isset($this->params['amount']) ? $this->params['amount'] : 'brief'; $mode = isset($this->params['mode']) ? $this->params['mode'] : 'all';
+
+ // Check if research starters , EMP are active.
+ $info = $this->info();
+ $rs = FALSE;
+ $emp = FALSE;
+
+ if ($info["relatedContent"]) {
+ foreach ($info["relatedContent"] as $related) {
+ if (($related["Type"] == "rs") and ($related["DefaultOn"] == "y")) {
+ $rs = TRUE;
}
-
- $filter = isset($this->params['filter']) ? $this->params['filter'] : array();
- $page = isset($this->params['page']) ? $this->params['page'] + 1 : 1;
- $limit = $this->limit;
- $sort = isset($this->params['sort']) ? $this->params['sort'] : 'relevance';
- $amount = isset($this->params['amount']) ? $this->params['amount'] : 'brief'; //
- $mode = isset($this->params['mode']) ? $this->params['mode'] : 'all';
-
-
- //check if research starters , EMP are active
- $info = $this->info();
- $rs=false;
- $emp=false;
-
- if ($info["relatedContent"]){
- foreach ($info["relatedContent"] as $related) {
- if ( ($related["Type"] == "rs") and ($related["DefaultOn"] == "y")) {
- $rs=true;
- }
- if ( ($related["Type"] == "emp") and ($related["DefaultOn"] == "y")) {
- $emp=true;
- }
- }
- }
- $autosug=false;
- if ($info["didYouMean"]){
- if ( $info["didYouMean"][0]["DefaultOn"] == "y") {
- $autosug=true;
- }
- }
-
- $this->results = $this->eds->apiSearch($search, $filter, $page, $limit, $sort, $amount, $mode,$rs,$emp,$autosug);
-
- return $this->results;
- }
-
-
- /**
- * Get the EBSCORecord model for the result
- *
- ** @return array
- */
- public function record()
- {
- if (empty($this->record) && !(empty($this->result))) {
- $this->record = new EBSCORecord($this->result);
+ if (($related["Type"] == "emp") and ($related["DefaultOn"] == "y")) {
+ $emp = TRUE;
}
-
- return $this->record;
- }
-
-
- /**
- * Get the EBSCORecord models array from results array
- *
- ** @return array
- */
- public function records()
- {
- if ($this->record instanceof EBSCOException ) {
- return null;
- }
- if ($this->results instanceof EBSCOException ) {
- return null;
- }
- if (empty($this->records) && !(empty($this->results))) {
- foreach($this->results['documents'] as $result) {
- $this->records[] = new EBSCORecord($result);
- }
+ }
+ }
+ $autosug = FALSE;
+ if ($info["didYouMean"]) {
+ if ($info["didYouMean"][0]["DefaultOn"] == "y") {
+ $autosug = TRUE;
+ }
+ }
+
+ $this->results = $this->eds->apiSearch($search, $filter, $page, $limit, $sort, $amount, $mode, $rs, $emp, $autosug);
+
+ return $this->results;
+ }
+
+ /**
+ * Get the EBSCORecord model for the result.
+ *
+ * * @return array.
+ */
+ public function record() {
+ if (empty($this->record) && !(empty($this->result))) {
+ $this->record = new EBSCORecord($this->result);
+ }
+
+ return $this->record;
+ }
+
+ /**
+ * Get the EBSCORecord models array from results array.
+ *
+ * * @return array.
+ */
+ public function records() {
+ if ($this->record instanceof EBSCOException) {
+ return NULL;
+ }
+ if ($this->results instanceof EBSCOException) {
+ return NULL;
+ }
+ if (empty($this->records) && !(empty($this->results))) {
+ foreach ($this->results['documents'] as $result) {
+ $this->records[] = new EBSCORecord($result);
+ }
+ }
+
+ return $this->records;
+ }
+
+ /**
+ *
+ */
+ public function relatedContent() {
+
+ if ($this->results instanceof EBSCOException) {
+ return NULL;
+ }
+ $this->relatedContent = isset($this->results['relatedContent']) ? $this->results['relatedContent'] : array();
+
+ return $this->relatedContent;
+ }
+
+ /**
+ *
+ */
+ public function autoSuggestTerms() {
+
+ $this->autoSuggestTerms = isset($this->results['autoSuggestTerms']) ? $this->results['autoSuggestTerms'] : NULL;
+
+ return $this->autoSuggestTerms;
+ }
+
+ /**
+ * Get the pagination HTML string.
+ *
+ * * @return HTML string.
+ */
+ public function pager() {
+ $pager = NULL;
+ try {
+ if ($this->has_records()) {
+ pager_default_initialize($this->record_count() / $this->limit, 1);
+ $pager = theme('pager', array('tags' => NULL, 'quantity' => self::$page_links));
+ $pager = preg_replace('/