|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Implementation of Roblib search for searching several targets.
|
|
|
|
*/
|
|
|
|
require_once dirname(__FILE__) . '/includes/rest/EBSCOConnector.php';
|
|
|
|
require_once dirname(__FILE__) . '/includes/rest/EBSCOResponse.php';
|
|
|
|
require_once dirname(__FILE__) . '/includes/rest/EBSCOConnector.php';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_menu().
|
|
|
|
*/
|
|
|
|
function roblib_search_eds_menu() {
|
|
|
|
$items = array();
|
|
|
|
|
|
|
|
$items['admin/roblib_search/eds_search'] = array(
|
|
|
|
'title' => 'EDS search Target configuration',
|
|
|
|
'description' => 'Configuration for the Roblib eds search target',
|
|
|
|
'page callback' => 'drupal_get_form',
|
|
|
|
'page arguments' => array('roblib_search_eds_config_form'),
|
|
|
|
'access arguments' => array('access administration pages'),
|
|
|
|
'type' => MENU_NORMAL_ITEM,
|
|
|
|
);
|
|
|
|
|
|
|
|
$items['roblib_search/eds/ajax/%'] = array(
|
|
|
|
'title' => 'eds ajax',
|
|
|
|
'page callback' => 'roblib_search_eds_ajax',
|
|
|
|
'page arguments' => array(3),
|
|
|
|
'type' => MENU_CALLBACK,
|
|
|
|
'access arguments' => array('search roblib eds'),
|
|
|
|
);
|
|
|
|
$items['roblib_search/eds/articles/%'] = array(
|
|
|
|
'title' => 'eds ajax',
|
|
|
|
'page callback' => 'roblib_search_eds_articles',
|
|
|
|
'page arguments' => array(3),
|
|
|
|
'type' => MENU_CALLBACK,
|
|
|
|
'access arguments' => array('search roblib eds'),
|
|
|
|
);
|
|
|
|
|
|
|
|
$items['roblib_search/eds/info'] = array(
|
|
|
|
'title' => 'eds info',
|
|
|
|
'page callback' => 'roblib_search_eds_info',
|
|
|
|
'type' => MENU_CALLBACK,
|
|
|
|
'access arguments' => array('search roblib eds'),
|
|
|
|
);
|
|
|
|
|
|
|
|
return $items;
|
|
|
|
}
|
|
|
|
|
|
|
|
function roblib_search_eds_info() {
|
|
|
|
$config = roblib_search_eds_build_config_arr();
|
|
|
|
$eds_api = new EBSCOAPI($config);
|
|
|
|
$output = $eds_api->getInfo();
|
|
|
|
print json_encode($output);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
function roblib_search_eds_config_form($form, &$form_state) {
|
|
|
|
|
|
|
|
$form['roblib_search_eds_rest_url'] = array(
|
|
|
|
'#type' => 'textfield',
|
|
|
|
'#title' => t('EDS Rest endpoint'),
|
|
|
|
'#default_value' => variable_get('roblib_search_eds_rest_url', 'http://eds-api.ebscohost.com/edsapi/rest'),
|
|
|
|
'#description' => t('The base EDS URL, for example http://eds-api.ebscohost.com/edsapi/rest'),
|
|
|
|
'#required' => TRUE,
|
|
|
|
);
|
|
|
|
$form['roblib_search_eds_auth_url'] = array(
|
|
|
|
'#type' => 'textfield',
|
|
|
|
'#title' => t('EDS Auth endpoint'),
|
|
|
|
'#default_value' => variable_get('roblib_search_eds_auth_url', 'https://eds-api.ebscohost.com/Authservice/rest'),
|
|
|
|
'#description' => t('The EDS Auth endpoint, for example https://eds-api.ebscohost.com/Authservice/rest'),
|
|
|
|
'#required' => TRUE,
|
|
|
|
);
|
|
|
|
|
|
|
|
$form['roblib_search_eds_user'] = array(
|
|
|
|
'#type' => 'textfield',
|
|
|
|
'#title' => t('EDS user'),
|
|
|
|
'#default_value' => variable_get('roblib_search_eds_user', 'edsusername'),
|
|
|
|
'#description' => t('EDS user, for example username'),
|
|
|
|
'#required' => TRUE,
|
|
|
|
);
|
|
|
|
|
|
|
|
$form['roblib_search_eds_pass'] = array(
|
|
|
|
'#type' => 'textfield',
|
|
|
|
'#title' => t('EDS password'),
|
|
|
|
'#default_value' => variable_get('roblib_search_eds_pass', 'edspassword'),
|
|
|
|
'#description' => t('EDS password, for example password'),
|
|
|
|
'#required' => TRUE,
|
|
|
|
);
|
|
|
|
|
|
|
|
$form['roblib_search_eds_guest'] = array(
|
|
|
|
'#type' => 'textfield',
|
|
|
|
'#title' => t('EDS Guest access'),
|
|
|
|
'#default_value' => variable_get('roblib_search_eds_guest', 'y'),
|
|
|
|
'#description' => t('EDS Guest access, y = guest access, n = not a guest'),
|
|
|
|
'#required' => TRUE,
|
|
|
|
);
|
|
|
|
|
|
|
|
$form['roblib_search_eds_profile'] = array(
|
|
|
|
'#type' => 'textfield',
|
|
|
|
'#title' => t('EDS profile'),
|
|
|
|
'#default_value' => variable_get('roblib_search_eds_profile', 'edsapi'),
|
|
|
|
'#description' => t('EDS profile, for example edsapi'),
|
|
|
|
'#required' => TRUE,
|
|
|
|
);
|
|
|
|
|
|
|
|
$form['roblib_search_eds_num_results'] = array(
|
|
|
|
'#type' => 'textfield',
|
|
|
|
'#title' => t('Number of results to return'),
|
|
|
|
'#default_value' => variable_get('roblib_search_eds_num_results', '5'),
|
|
|
|
'#description' => t('The number of results to display in the Bento box'),
|
|
|
|
'#required' => TRUE,
|
|
|
|
);
|
|
|
|
$form['roblib_search_eds_article_limiters'] = array(
|
|
|
|
'#type' => 'textarea',
|
|
|
|
'#title' => t('The limiters for Article searches'),
|
|
|
|
'#default_value' => variable_get('roblib_search_eds_article_limiters',
|
|
|
|
'AND (PT Article OR PT Magazines OR PT News OR PT Academic Journals OR PT Conference Materials)'),
|
|
|
|
'#description' => t('Specify the Publication Types to use as limiters for Article searches. Formatted similar to
|
|
|
|
AND (PT Article OR PT Magazines OR PT News OR PT Academic Journals OR PT Conference Materials)'),
|
|
|
|
'#required' => TRUE,
|
|
|
|
);
|
|
|
|
$form['roblib_search_eds_book_limiters'] = array(
|
|
|
|
'#type' => 'textarea',
|
|
|
|
'#title' => t('The limiters for Books and Media searches'),
|
|
|
|
'#default_value' => variable_get('roblib_search_eds_book_limiters',
|
|
|
|
'AND (PT Book OR PT Video OR PT Audio)'),
|
|
|
|
'#description' => t('Specify the Publication Types to use as limiters for Article searches. Formatted similar to
|
|
|
|
AND (PT Book OR PT Video OR PT Audio'),
|
|
|
|
'#required' => TRUE,
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
return system_settings_form($form);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_permission().
|
|
|
|
*/
|
|
|
|
function roblib_search_eds_permission() {
|
|
|
|
return array(
|
|
|
|
'search roblib eds' => array(
|
|
|
|
'title' => t('Search the eds target'),
|
|
|
|
'description' => t('Search oblib eds target. This permission exposes the search blocks and allows you to see search results.'),
|
|
|
|
),
|
|
|
|
'administer roblib search eds' => array(
|
|
|
|
'title' => t('Administer Roblib Search EDS'),
|
|
|
|
'description' => t('Administer settings for the Roblib eds search client.'),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_theme().
|
|
|
|
*/
|
|
|
|
function roblib_search_eds_theme() {
|
|
|
|
// set path
|
|
|
|
$path = drupal_get_path('module', 'roblib_search_eds');
|
|
|
|
$file = 'theme.inc';
|
|
|
|
|
|
|
|
return array(
|
|
|
|
// results page
|
|
|
|
'roblib_search_eds' => array(
|
|
|
|
'path' => $path . '/theme',
|
|
|
|
'file' => $file,
|
|
|
|
'template' => 'roblib-search-eds',
|
|
|
|
'variables' => array('results' => NULL),
|
|
|
|
),
|
|
|
|
'roblib_search_eds_articles' => array(
|
|
|
|
'path' => $path . '/theme',
|
|
|
|
'file' => $file,
|
|
|
|
'template' => 'roblib-search-eds-articles',
|
|
|
|
'variables' => array('results' => NULL),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function roblib_search_eds_preprocess_panels_pane(&$variables, $hook){
|
|
|
|
if($variables['pane']->subtype == 'roblib_search_eds-roblib_search_eds_articles'){
|
|
|
|
$variables['title_prefix'] = '<div class="roblib-search-header roblib-search-eds-articles-header">';
|
|
|
|
$variables['title_suffix'] ='</div>';
|
|
|
|
}
|
|
|
|
if($variables['pane']->subtype == 'roblib_search_eds-roblib_search_eds_results'){
|
|
|
|
$variables['title_prefix'] = '<div class="roblib-search-header roblib-search-eds-media-header">';
|
|
|
|
$variables['title_suffix'] ='</div>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function roblib_search_eds_block_info() {
|
|
|
|
|
|
|
|
$blocks['roblib_search_eds_results'] = array(
|
|
|
|
// info: The name of the block.
|
|
|
|
'info' => t('EDS Search Results block'),
|
|
|
|
// Block caching options (per role, per user, etc.)
|
|
|
|
'cache' => DRUPAL_CACHE_PER_ROLE,
|
|
|
|
);
|
|
|
|
$blocks['roblib_search_eds_articles'] = array(
|
|
|
|
'info' => t('EDS Search Results Articles'),
|
|
|
|
'cache' => DRUPAL_CACHE_PER_ROLE,
|
|
|
|
);
|
|
|
|
return $blocks;
|
|
|
|
}
|
|
|
|
|
|
|
|
function roblib_search_eds_block_view($delta = '') {
|
|
|
|
switch ($delta) {
|
|
|
|
case 'roblib_search_eds_results':
|
|
|
|
$block['subject'] = t('Books & Media');
|
|
|
|
$block['content'] = theme('roblib_search_eds', array('results' => NULL));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'roblib_search_eds_articles':
|
|
|
|
$block['subject'] = t('Articles');
|
|
|
|
$block['content'] = theme('roblib_search_eds_articles', array('results' => NULL));
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
return $block;
|
|
|
|
}
|
|
|
|
|
|
|
|
function roblib_search_eds_ajax($query) {
|
|
|
|
print roblib_search_eds_get_results($query, 'Books');
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
function roblib_search_eds_articles($query) {
|
|
|
|
print roblib_search_eds_get_results($query, 'Articles');
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param string $query
|
|
|
|
* @return string
|
|
|
|
* json string
|
|
|
|
*/
|
|
|
|
function roblib_search_eds_get_results($query = NULL, $type = NULL) {
|
|
|
|
drupal_add_css(drupal_get_path('module', 'roblib_search_eds') . '/css/roblib_search_eds.theme.css');
|
|
|
|
|
|
|
|
// Url parameters.
|
|
|
|
if (!isset($query)) {
|
|
|
|
if (isset($_GET['roblib_query'])) {
|
|
|
|
$query = $_GET['roblib_query'];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$limiters = '';
|
|
|
|
if ($type != NULL) {
|
|
|
|
$limiters = roblib_search_eds_get_query_limiters($type);
|
|
|
|
}
|
|
|
|
$config = roblib_search_eds_build_config_arr();
|
|
|
|
$eds_api = new EBSCOAPI($config);
|
|
|
|
$number_per_page = variable_get('roblib_search_eds_num_results', '5');
|
|
|
|
$query = urlencode($query);
|
|
|
|
$query .= $limiters;
|
|
|
|
//$params = "query=AND,$query&view=detailed&includefacets=n&$limiters&resultsperpage=$number_per_page";
|
|
|
|
$params = "query=AND,$query&view=detailed&includefacets=n&resultsperpage=$number_per_page";
|
|
|
|
$output = $eds_api->apiSearch($params);
|
|
|
|
//roblib_search_eds_get_detailed_result($output, $query, $eds_api);
|
|
|
|
return json_encode($output);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For each result query ebsco again to get the detailed record.
|
|
|
|
*
|
|
|
|
* and insert a new DetailedRecord element in each record.
|
|
|
|
*
|
|
|
|
* @param array $output
|
|
|
|
* The orginal search results array
|
|
|
|
* @param string $query
|
|
|
|
* The orginal query
|
|
|
|
* @param object $eds_api
|
|
|
|
* an ebco API PHP object
|
|
|
|
*/
|
|
|
|
function roblib_search_eds_get_detailed_result(&$output, $query, &$eds_api) {
|
|
|
|
foreach ($output['records'] as &$record) {
|
|
|
|
$db = $record['DbId'];
|
|
|
|
$an = $record['An'];
|
|
|
|
$arr = $eds_api->apiRetrieve($an, $db, $query);
|
|
|
|
$record['DetailedRecord'] = $arr['Items'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the limiter string to append to the end of a query.
|
|
|
|
*
|
|
|
|
* @param string $type
|
|
|
|
* The type of search we want (Articles or Books)
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* The limiters to append to the query.
|
|
|
|
*/
|
|
|
|
function roblib_search_eds_get_query_limiters($type) {
|
|
|
|
$limiters = 'n';
|
|
|
|
switch ($type) {
|
|
|
|
case 'Articles':
|
|
|
|
//$limiters = 'facetfilter=1,SourceType:Magazines,SourceType:News,SourceType:Academic+Journals,SourceType:Conference+Materials';
|
|
|
|
$limiters = ' ' . variable_get('roblib_search_eds_article_limiters',
|
|
|
|
'AND (PT Article OR PT Magazines OR PT News OR PT Academic Journals OR PT Conference Materials)');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Books':
|
|
|
|
// $limiters = '+AND+(PT+book)';
|
|
|
|
//$limiters = 'facetfilter=1,PublicationType:Books,PublicationType:Audio,PublicationType:Videos';
|
|
|
|
$limiters = ' ' . variable_get('roblib_search_eds_book_limiters',
|
|
|
|
'AND (PT Book OR PT Video OR PT Audio)');
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
return urlencode($limiters);
|
|
|
|
}
|
|
|
|
|
|
|
|
function roblib_search_eds_build_config_arr() {
|
|
|
|
$config = array();
|
|
|
|
$config['user'] = variable_get('roblib_search_eds_user', 'edsusername');
|
|
|
|
$config['pass'] = variable_get('roblib_search_eds_pass', 'edspassword');
|
|
|
|
$config['profile'] = variable_get('roblib_search_eds_profile', 'edsapi');
|
|
|
|
$config['auth_url'] = variable_get('roblib_search_eds_auth_url', 'https://eds-api.ebscohost.com/Authservice/rest');
|
|
|
|
$config['rest_url'] = variable_get('roblib_search_eds_rest_url', 'http://eds-api.ebscohost.com/edsapi/rest');
|
|
|
|
return $config;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_help().
|
|
|
|
*
|
|
|
|
* @param type $path
|
|
|
|
* @param type $arg
|
|
|
|
* @return type
|
|
|
|
*/
|
|
|
|
function roblib_search_eds_help($path, $arg) {
|
|
|
|
switch ($path) {
|
|
|
|
case 'admin/help#roblib_search_eds':
|
|
|
|
return t(
|
|
|
|
'<p>
|
|
|
|
provides a target for the Roblib search module. This target uses javascript
|
|
|
|
to render the results.
|
|
|
|
</p>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|