@ -1,26 +1,28 @@
<?php
<?php
/**
/**
* @file
* @file
* Copyright [2017] [EBSCO Information Services].
* EBSCO Drupal integration module.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Copyright [2017] [EBSCO Information Services]
* you may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at.
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
* http://www.apache.org/licenses/LICENSE-2.0
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* http://www.apache.org/licenses/LICENSE-2.0
* distributed under the License is distributed on an "AS IS" BASIS,
*
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* Unless required by applicable law or agreed to in writing, software
* See the License for the specific language governing permissions and
* distributed under the License is distributed on an "AS IS" BASIS,
* limitations under the License.
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
* See the License for the specific language governing permissions and
* limitations under the License.
*/
require_once 'lib/EBSCODocument.php';
require_once 'lib/EBSCODocument.php';
// Global variable.
// Global variable.
$D ocument = NULL;
$_ebsco_d ocument = NULL;
/******************************************
/******************************************
@ -28,11 +30,11 @@ $Document = NULL;
******************************************/
******************************************/
/**
/**
* Implements hook_user_login.
* Implements hook_user_login().
*
* Redirects after login.
*/
*/
function ebsco_user_login(&$edit, $account) {
function ebsco_user_login(&$edit, $account) {
// Redirect after login.
if (isset($_SESSION['EBSCO']['redirect'])) {
if (isset($_SESSION['EBSCO']['redirect'])) {
$_GET['destination'] = urldecode($_SESSION['EBSCO']['redirect']['destination']);
$_GET['destination'] = urldecode($_SESSION['EBSCO']['redirect']['destination']);
unset($_SESSION['EBSCO']['redirect']);
unset($_SESSION['EBSCO']['redirect']);
@ -40,29 +42,17 @@ function ebsco_user_login(&$edit, $account) {
}
}
/**
/**
* Implements hook_help.
* Implements hook_help().
*
* Displays help and module information.
*
* @param path
* Which path of the site we're using to display help
* @param arg
* Array that holds the current path as returned from arg() function
*/
*/
function ebsco_help($path, $arg) {
function ebsco_help($path, $arg) {
$output = "";
$output = "";
switch ($path) {
switch ($path) {
case "admin/help#ebsco":
case "admin/help#ebsco":
$output .= '<h2>' . t("Full-text articles and eBooks from EBSCOhost Discovery Services") . '</h2>';
$output .= '<h2>' . t("Full-text articles and eBooks from EBSCOhost Discovery Services") . '</h2>';
$output .= '<p>' . t("EBSCO Discovery Service provides users with an easy, yet powerful means of accessing all of
$output .= '<p>' . 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.") . '</p>';
an institution's information resources through a single search.") . '</p>';
$output .= '<p>' . 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.") . '</p>';
$output .= '<p>' . t("This is achieved by harvesting metadata from both internal (library) and external (database vendors) sources,
$output .= '<p>' . 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.") . '</p>';
and creating a pre-indexed service of unprecedented size and speed.") . '</p>';
$output .= '<p>' . 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.") . '</p>';
$output .= '<p>' . 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.") . '</p>';
$output .= '<p>' . 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.") . '</p>';
break;
break;
}
}
return $output;
return $output;
@ -305,36 +295,32 @@ function ebsco_block_info() {
*/
*/
function ebsco_block_view($delta = '') {
function ebsco_block_view($delta = '') {
$params = $_GET;
$params = $_GET;
$block = array();
switch ($delta) {
switch ($delta) {
case 'ebsco_main':
case 'ebsco_main':
$reject = isset($params['q']) && strpos('ebsco/advanced', $params['q']) !== FALSE;
$reject = isset($params['q']) && strpos('ebsco/advanced', $params['q']) !== FALSE;
return array(
$block['content'] = $reject ? '' : ebsco_basic_search_block();
'content' => $reject ? '' : ebsco_basic_search_block(),
break;
);
break;
case 'ebsco_facets':
case 'ebsco_facets':
$reject = isset($params['q']) && strpos('ebsco/advanced', $params['q']) !== FALSE;
$reject = isset($params['q']) && strpos('ebsco/advanced', $params['q']) !== FALSE;
$reject = $reject || (isset($params['edit']) && strpos('ebsco/results', $params['q']) !== FALSE);
$reject = $reject || (isset($params['edit']) && strpos('ebsco/results', $params['q']) !== FALSE);
$reject = $reject || (isset($params['q']) && strpos('ebsco/result', $params['q']) !== FALSE);
$reject = $reject || (isset($params['q']) && strpos('ebsco/result', $params['q']) !== FALSE);
return array(
$block['content'] = $reject ? '' : ebsco_side_facets_block();
'content' => $reject ? '' : ebsco_side_facets_block(),
break;
);
break;
}
}
return $block;
}
}
/**
/**
* Page callbacks .
* EBSCO search results page callback .
*/
*/
function ebsco_results_page() {
function ebsco_results_page() {
return theme('ebsco_results');
return theme('ebsco_results');
}
}
/**
/**
*
* EBSCO search result page callback.
*/
*/
function ebsco_result_page() {
function ebsco_result_page() {
$is_xhr = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
$is_xhr = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
@ -348,7 +334,7 @@ function ebsco_result_page() {
}
}
/**
/**
*
* EBSCO fulltext page callback.
*/
*/
function ebsco_fulltext_page() {
function ebsco_fulltext_page() {
$is_xhr = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
$is_xhr = !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
@ -374,18 +360,18 @@ function ebsco_fulltext_page() {
}
}
/**
/**
*
* EBSCO pdf page callback.
*/
*/
function ebsco_pdf_page() {
function ebsco_pdf_page() {
global $D ocument;
global $_ebsco_d ocument;
$params = $_REQUEST;
$params = $_REQUEST;
if (user_is_logged_in()) {
if (user_is_logged_in()) {
if (empty($D ocument)) {
if (empty($_ebsco_d ocument)) {
$D ocument = new EBSCODocument();
$_ebsco_d ocument = new EBSCODocument();
}
}
$D ocument->retrieve();
$_ebsco_d ocument->retrieve();
$record = $D ocument->record();
$record = $_ebsco_d ocument->record();
drupal_goto($record->pdf_link);
drupal_goto($record->pdf_link);
}
}
else {
else {
@ -395,21 +381,21 @@ function ebsco_pdf_page() {
}
}
/**
/**
*
* EBSCO advanced search page callback.
*/
*/
function ebsco_advanced_search_page() {
function ebsco_advanced_search_page() {
return theme('ebsco_advanced_search');
return theme('ebsco_advanced_search');
}
}
/**
/**
*
* EBSCO basic search page callback.
*/
*/
function ebsco_basic_search_block() {
function ebsco_basic_search_block() {
return theme('ebsco_basic_search');
return theme('ebsco_basic_search');
}
}
/**
/**
*
* EBSCO side facets block callback.
*/
*/
function ebsco_side_facets_block() {
function ebsco_side_facets_block() {
return theme('ebsco_side_facets');
return theme('ebsco_side_facets');
@ -540,7 +526,7 @@ function ebsco_basic_search_form() {
* @ingroup forms
* @ingroup forms
*/
*/
function ebsco_advanced_search_form() {
function ebsco_advanced_search_form() {
global $D ocument;
global $_ebsco_d ocument;
$params = $_REQUEST;
$params = $_REQUEST;
if (isset($params['edit']) && !empty($params['edit'])) {
if (isset($params['edit']) && !empty($params['edit'])) {
@ -653,8 +639,8 @@ function ebsco_advanced_search_form() {
'#options' => EBSCODocument::mode_options(),
'#options' => EBSCODocument::mode_options(),
);
);
$expanders = $D ocument->expanders();
$expanders = $_ebsco_d ocument->expanders();
$limiters = $D ocument->limiters();
$limiters = $_ebsco_d ocument->limiters();
$options = array('' => TRUE);
$options = array('' => TRUE);
foreach ($expanders as $key => $expander) {
foreach ($expanders as $key => $expander) {
$options[$expander['Action']] = TRUE;
$options[$expander['Action']] = TRUE;
@ -715,7 +701,9 @@ function ebsco_advanced_search_form() {
'#title' => $limiter['Label'],
'#title' => $limiter['Label'],
'#title_display' => 'after',
'#title_display' => 'after',
'#name' => 'filter[]',
'#name' => 'filter[]',
'#attributes' => array('value' => str_replace('value', 'y', $limiter['Action'])),
'#attributes' => array(
'value' => str_replace('value', 'y', $limiter['Action']),
),
'#checked' => $limiter['selected'],
'#checked' => $limiter['selected'],
);
);
@ -757,7 +745,11 @@ function ebsco_advanced_search_form() {
'#value' => $displayValue,
'#value' => $displayValue,
'#name' => $limiter['Id'],
'#name' => $limiter['Id'],
'#autocomplete_path' => NULL,
'#autocomplete_path' => NULL,
'#attributes' => array('size' => 4, 'maxlength' => 4, 'class' => array('yearbox')),
'#attributes' => array(
'size' => 4,
'maxlength' => 4,
'class' => array('yearbox'),
),
);
);
$element['#children'] = theme('textfield', array('element' => $element));
$element['#children'] = theme('textfield', array('element' => $element));
$element['#children'] .= '<input id="ebsco-advanced-search-limiter' . $limiter['Id'] . '" type="hidden" name="filter[]" value="' . $value . '"/>';
$element['#children'] .= '<input id="ebsco-advanced-search-limiter' . $limiter['Id'] . '" type="hidden" name="filter[]" value="' . $value . '"/>';
@ -793,8 +785,9 @@ function ebsco_advanced_search_form() {
'#value' => t('Search'),
'#value' => t('Search'),
);
);
$reset_button_text = t('Clear');
$form['advanced']['clear'] = array(
$form['advanced']['clear'] = array(
'#markup' => '<input id="ebsco-advanced-search-clear" class="form-submit" type="reset" value="' . t('Clear') . '" name="reset">',
'#markup' => '<input id="ebsco-advanced-search-clear" class="form-submit" type="reset" value="' . $reset_button_text . '" name="reset">',
);
);
return $form;
return $form;
@ -889,27 +882,27 @@ function ebsco_advanced_search_form_submit($form, &$form_state) {
* @see ebsco-results.tpl.php
* @see ebsco-results.tpl.php
*/
*/
function template_preprocess_ebsco_results(&$variables) {
function template_preprocess_ebsco_results(&$variables) {
global $D ocument;
global $_ebsco_d ocument;
$params = $_REQUEST;
$params = $_REQUEST;
$_SESSION['EBSCO']['redirect'] = drupal_get_destination();
$_SESSION['EBSCO']['redirect'] = drupal_get_destination();
if (empty($D ocument)) {
if (empty($_ebsco_d ocument)) {
$D ocument = new EBSCODocument();
$_ebsco_d ocument = new EBSCODocument();
}
}
$title = !empty($params['lookfor']) ? ' - ' . $params['lookfor'] : '';
$title = !empty($params['lookfor']) ? ' - ' . $params['lookfor'] : '';
drupal_set_title('Search results' . $title);
drupal_set_title('Search results' . $title);
$D ocument->search();
$_ebsco_d ocument->search();
$variables['records'] = $D ocument->records();
$variables['records'] = $_ebsco_d ocument->records();
$variables['record_start'] = $D ocument->record_start();
$variables['record_start'] = $_ebsco_d ocument->record_start();
$variables['record_end'] = $D ocument->record_end();
$variables['record_end'] = $_ebsco_d ocument->record_end();
$variables['record_count'] = $D ocument->record_count();
$variables['record_count'] = $_ebsco_d ocument->record_count();
$variables['search_view'] = $D ocument->search_view();
$variables['search_view'] = $_ebsco_d ocument->search_view();
$variables['search_time'] = $D ocument->search_time();
$variables['search_time'] = $_ebsco_d ocument->search_time();
$variables['relatedContent'] = $D ocument->relatedContent();
$variables['relatedContent'] = $_ebsco_d ocument->relatedContent();
$variables['autoSuggestTerms'] = $D ocument->autoSuggestTerms();
$variables['autoSuggestTerms'] = $_ebsco_d ocument->autoSuggestTerms();
$variables['lookfor'] = '';
$variables['lookfor'] = '';
if (isset($params['lookfor'])) {
if (isset($params['lookfor'])) {
$variables['lookfor'] = $params['lookfor'];
$variables['lookfor'] = $params['lookfor'];
@ -923,13 +916,13 @@ function template_preprocess_ebsco_results(&$variables) {
}
}
}
}
}
}
$variables['pager'] = $D ocument->pager();
$variables['pager'] = $_ebsco_d ocument->pager();
$v1 = drupal_get_form('ebsco_sort_form');
$v1 = drupal_get_form('ebsco_sort_form');
$variables['sort_form'] = drupal_render($v1);
$variables['sort_form'] = drupal_render($v1);
// Save data needed by scroller in Detailed view page
// Save data needed by scroller in Detailed view page
// $D ocument->search_write();
// $_ebsco_d ocument->search_write();
}
}
/**
/**
@ -938,14 +931,14 @@ function template_preprocess_ebsco_results(&$variables) {
* @see ebsco-basic-search.tpl.php
* @see ebsco-basic-search.tpl.php
*/
*/
function template_preprocess_ebsco_basic_search(&$variables) {
function template_preprocess_ebsco_basic_search(&$variables) {
global $D ocument;
global $_ebsco_d ocument;
$params = $_REQUEST;
$params = $_REQUEST;
if (empty($D ocument)) {
if (empty($_ebsco_d ocument)) {
$D ocument = new EBSCODocument();
$_ebsco_d ocument = new EBSCODocument();
}
}
$variables['search_view'] = $D ocument->search_view();
$variables['search_view'] = $_ebsco_d ocument->search_view();
$variables['lookfor'] = '';
$variables['lookfor'] = '';
if (isset($params['lookfor'])) {
if (isset($params['lookfor'])) {
$variables['lookfor'] = $params['lookfor'];
$variables['lookfor'] = $params['lookfor'];
@ -970,13 +963,13 @@ function template_preprocess_ebsco_basic_search(&$variables) {
*/
*/
function template_preprocess_ebsco_advanced_search(&$variables) {
function template_preprocess_ebsco_advanced_search(&$variables) {
drupal_add_library('system', 'ui.slider');
drupal_add_library('system', 'ui.slider');
global $D ocument;
global $_ebsco_d ocument;
$params = $_REQUEST;
$params = $_REQUEST;
if (empty($D ocument)) {
if (empty($_ebsco_d ocument)) {
$D ocument = new EBSCODocument();
$_ebsco_d ocument = new EBSCODocument();
}
}
$D ocument->info();
$_ebsco_d ocument->info();
$v1 = drupal_get_form('ebsco_advanced_search_form');
$v1 = drupal_get_form('ebsco_advanced_search_form');
$variables['search_form'] = drupal_render($v1);
$variables['search_form'] = drupal_render($v1);
@ -992,14 +985,14 @@ function template_preprocess_ebsco_result(&$variables) {
$params['op'] = isset($params['op']) ? $params['op'] : 'Next';
$params['op'] = isset($params['op']) ? $params['op'] : 'Next';
$_SESSION['EBSCO']['redirect'] = drupal_get_destination();
$_SESSION['EBSCO']['redirect'] = drupal_get_destination();
if (empty($D ocument)) {
if (empty($_ebsco_d ocument)) {
$D ocument = new EBSCODocument();
$_ebsco_d ocument = new EBSCODocument();
}
}
$D ocument->retrieve();
$_ebsco_d ocument->retrieve();
$record = $D ocument->record();
$record = $_ebsco_d ocument->record();
$variables['record'] = $record;
$variables['record'] = $record;
$lastSearch = isset($params['id']) ? $D ocument->search_read($params['id'], $params['op']) : '';
$lastSearch = isset($params['id']) ? $_ebsco_d ocument->search_read($params['id'], $params['op']) : '';
$variables['last_search'] = $lastSearch;
$variables['last_search'] = $lastSearch;
drupal_set_title($record->title);
drupal_set_title($record->title);
@ -1011,23 +1004,23 @@ function template_preprocess_ebsco_result(&$variables) {
* @see ebsco-side-facets.tpl.php
* @see ebsco-side-facets.tpl.php
*/
*/
function template_preprocess_ebsco_side_facets(&$variables) {
function template_preprocess_ebsco_side_facets(&$variables) {
global $D ocument;
global $_ebsco_d ocument;
if (empty($D ocument)) {
if (empty($_ebsco_d ocument)) {
$D ocument = new EBSCODocument();
$_ebsco_d ocument = new EBSCODocument();
}
}
$D ocument->info();
$_ebsco_d ocument->info();
$variables['record_count'] = $D ocument->record_count();
$variables['record_count'] = $_ebsco_d ocument->record_count();
$variables['expanders'] = $D ocument->expanders();
$variables['expanders'] = $_ebsco_d ocument->expanders();
$variables['limiters'] = $D ocument->limiters();
$variables['limiters'] = $_ebsco_d ocument->limiters();
$variables['facets'] = $D ocument->facets();
$variables['facets'] = $_ebsco_d ocument->facets();
// Applied facets, limiters or expanders.
// Applied facets, limiters or expanders.
$variables['filters'] = $D ocument->filters();
$variables['filters'] = $_ebsco_d ocument->filters();
// Hidden parameters.
// Hidden parameters.
$variables['search_params'] = $D ocument->search_params();
$variables['search_params'] = $_ebsco_d ocument->search_params();
// Hidden parameters.
// Hidden parameters.
$variables['link_search_params'] = $D ocument->link_search_params();
$variables['link_search_params'] = $_ebsco_d ocument->link_search_params();
}
}
/******************************************
/******************************************
@ -1035,9 +1028,10 @@ function template_preprocess_ebsco_side_facets(&$variables) {
******************************************/
******************************************/
/**
/**
* Returns an URL without the given filter parameter.
* Returns the current request's URL without the specified filter parameter.
*
*
* @return string
* @return string
* the filtered request URL
*/
*/
function remove_filter_link($filter) {
function remove_filter_link($filter) {
$params = $_REQUEST;
$params = $_REQUEST;
@ -1052,18 +1046,22 @@ function remove_filter_link($filter) {
}
}
/**
/**
* Performs a regex and replaces any url's with links containing themselves as the text.
* Convert URLs in the given string into HTML link tags.
*
* Performs a regex and replaces any URLs with links containing themselves
* as the text.
*
*
* @return string
* @return string
* the filtered request URL
*/
*/
function auto_link($string) {
function auto_link($string) {
$linkedString = preg_replace_callback(
$linkedString = preg_replace_callback(
"/\b(https?):\/\/([-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]*)\b/i",
"/\b(https?):\/\/([-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]*)\b/i",
create_function(
create_function(
'$matches',
'$matches',
'return "<a href=\'".($matches[0])."\'>".($matches[0])."</a>";'
'return "<a href=\'".($matches[0])."\'>".($matches[0])."</a>";'
),
),
$string
$string
);
);
return $linkedString;
return $linkedString;
}
}