You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
260 lines
7.7 KiB
260 lines
7.7 KiB
12 years ago
|
<?php
|
||
|
|
||
|
/**
|
||
|
* @file
|
||
|
* Implementation of Roblib search for searching several targets.
|
||
|
*/
|
||
12 years ago
|
|
||
12 years ago
|
|
||
|
/**
|
||
|
* Implements hook_menu().
|
||
|
*/
|
||
|
function roblib_search_eds_menu() {
|
||
|
$items = array();
|
||
|
|
||
|
$items['admin/roblib_search/eds_search'] = array(
|
||
|
'title' => 'EDS search Target configuration',
|
||
12 years ago
|
'description' => 'Configuration for the Roblib eds search target',
|
||
12 years ago
|
'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'),
|
||
|
);
|
||
10 years ago
|
$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'),
|
||
|
);
|
||
12 years ago
|
|
||
7 years ago
|
$items['roblib_search/eds/info/%'] = array(
|
||
12 years ago
|
'title' => 'eds info',
|
||
|
'page callback' => 'roblib_search_eds_info',
|
||
7 years ago
|
'page arguments' => array(3),
|
||
12 years ago
|
'type' => MENU_CALLBACK,
|
||
|
'access arguments' => array('search roblib eds'),
|
||
|
);
|
||
|
|
||
12 years ago
|
return $items;
|
||
|
}
|
||
|
|
||
7 years ago
|
function roblib_search_eds_info($type = 'Articles') {
|
||
|
$config = roblib_search_eds_build_config_arr($type);
|
||
10 years ago
|
$eds_api = new EBSCOAPI($config);
|
||
7 years ago
|
$output['type'] = $type;
|
||
|
$output['profile'] = $eds_api->getInfo();
|
||
12 years ago
|
print json_encode($output);
|
||
7 years ago
|
|
||
12 years ago
|
exit();
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Implements hook_permission().
|
||
|
*/
|
||
3 years ago
|
/*function roblib_search_eds_permission() {
|
||
12 years ago
|
return array(
|
||
|
'search roblib eds' => array(
|
||
|
'title' => t('Search the eds target'),
|
||
7 years ago
|
'description' => t('Search Roblib eds target. This permission exposes the search blocks and allows you to see search results.'),
|
||
12 years ago
|
),
|
||
|
'administer roblib search eds' => array(
|
||
|
'title' => t('Administer Roblib Search EDS'),
|
||
|
'description' => t('Administer settings for the Roblib eds search client.'),
|
||
|
),
|
||
|
);
|
||
3 years ago
|
}*/
|
||
|
|
||
12 years ago
|
|
||
|
/**
|
||
|
* Implements hook_theme().
|
||
|
*/
|
||
3 years ago
|
function roblib_search_eds_theme($existing, $type, $theme, $path) {
|
||
|
return [
|
||
|
'roblib_search_eds_books' => [
|
||
|
'variables' => ['query' => NULL],
|
||
|
],
|
||
|
'roblib_search_eds_articles' => [
|
||
|
'variables' => ['query' => NULL],
|
||
|
],
|
||
|
];
|
||
12 years ago
|
}
|
||
|
|
||
3 years ago
|
|
||
10 years ago
|
|
||
3 years ago
|
/*function roblib_search_eds_block_info() {
|
||
12 years ago
|
|
||
|
$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.)
|
||
10 years ago
|
'cache' => DRUPAL_CACHE_PER_ROLE,
|
||
|
);
|
||
|
$blocks['roblib_search_eds_articles'] = array(
|
||
|
'info' => t('EDS Search Results Articles'),
|
||
|
'cache' => DRUPAL_CACHE_PER_ROLE,
|
||
12 years ago
|
);
|
||
|
return $blocks;
|
||
3 years ago
|
}*/
|
||
12 years ago
|
|
||
3 years ago
|
/*function roblib_search_eds_block_view($delta = '') {
|
||
12 years ago
|
switch ($delta) {
|
||
|
case 'roblib_search_eds_results':
|
||
10 years ago
|
$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));
|
||
12 years ago
|
break;
|
||
10 years ago
|
|
||
12 years ago
|
}
|
||
|
return $block;
|
||
3 years ago
|
}*/
|
||
12 years ago
|
|
||
3 years ago
|
/*function roblib_search_eds_ajax($query) {
|
||
10 years ago
|
print roblib_search_eds_get_results($query, 'Books');
|
||
|
exit();
|
||
|
}
|
||
|
|
||
10 years ago
|
function roblib_search_eds_articles($query) {
|
||
10 years ago
|
print roblib_search_eds_get_results($query, 'Articles');
|
||
12 years ago
|
exit();
|
||
3 years ago
|
}*/
|
||
12 years ago
|
|
||
12 years ago
|
/**
|
||
10 years ago
|
*
|
||
12 years ago
|
* @param string $query
|
||
|
* @return string
|
||
|
* json string
|
||
|
*/
|
||
7 years ago
|
function roblib_search_eds_get_results($query = NULL, $type = 'Articles') {
|
||
12 years ago
|
drupal_add_css(drupal_get_path('module', 'roblib_search_eds') . '/css/roblib_search_eds.theme.css');
|
||
7 years ago
|
module_load_include('php', 'ebsco', 'lib/EBSCOAPI');
|
||
|
module_load_include('php', 'ebsco', 'lib/EBSCOAPIConnector');
|
||
|
module_load_include('php', 'ebsco', 'lib/EBSCOAPIResponse');
|
||
12 years ago
|
// Url parameters.
|
||
|
if (!isset($query)) {
|
||
|
if (isset($_GET['roblib_query'])) {
|
||
|
$query = $_GET['roblib_query'];
|
||
|
}
|
||
|
else {
|
||
|
return '';
|
||
|
}
|
||
|
}
|
||
10 years ago
|
$limiters = '';
|
||
10 years ago
|
if ($type != NULL) {
|
||
7 years ago
|
$limiters = urldecode(roblib_search_eds_get_query_limiters($type));
|
||
10 years ago
|
}
|
||
7 years ago
|
// hardcoding "available in library collection" limiter as we can't pass it the
|
||
|
// same way we passed other limiters
|
||
|
$filters = ($type === 'Books') ? array("addlimiter(FT1:y)") : array();
|
||
7 years ago
|
$config = roblib_search_eds_build_config_arr($type);
|
||
7 years ago
|
|
||
12 years ago
|
$number_per_page = variable_get('roblib_search_eds_num_results', '5');
|
||
5 years ago
|
$query = '(' . $query . ') ' . $limiters;
|
||
7 years ago
|
$search = array('lookfor' => $query, 'type' => 'ALLFields', 'index' => 'AllFields', 'q' => 'ebsco/results', 'op' => 'Search');
|
||
7 years ago
|
$eds_api = new EBSCOAPI($config);
|
||
7 years ago
|
$is_local_ip = $eds_api->connector()->isGuestIPAddress($_SERVER["REMOTE_ADDR"]);
|
||
|
//$eds_api->isGuest(boolval(variable_get('roblib_search_eds_guest','y')));
|
||
|
$eds_api->isGuest(!$is_local_ip);
|
||
|
|
||
7 years ago
|
$output = $eds_api->apiSearch($search, $filters, 1, $number_per_page);
|
||
7 years ago
|
$output['is_local_ip'] = $is_local_ip;
|
||
12 years ago
|
return json_encode($output);
|
||
12 years ago
|
}
|
||
|
|
||
10 years ago
|
/**
|
||
|
* 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
|
||
|
*/
|
||
10 years ago
|
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'];
|
||
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
/**
|
||
|
* 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.
|
||
|
*/
|
||
10 years ago
|
function roblib_search_eds_get_query_limiters($type) {
|
||
10 years ago
|
$limiters = 'n';
|
||
|
switch ($type) {
|
||
|
case 'Articles':
|
||
10 years ago
|
//$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)');
|
||
10 years ago
|
break;
|
||
10 years ago
|
|
||
10 years ago
|
case 'Books':
|
||
10 years ago
|
// $limiters = '+AND+(PT+book)';
|
||
10 years ago
|
//$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)');
|
||
10 years ago
|
break;
|
||
10 years ago
|
|
||
|
|
||
|
}
|
||
10 years ago
|
return urlencode($limiters);
|
||
10 years ago
|
}
|
||
|
|
||
7 years ago
|
function roblib_search_eds_build_config_arr($type) {
|
||
12 years ago
|
$config = array();
|
||
|
$config['user'] = variable_get('roblib_search_eds_user', 'edsusername');
|
||
7 years ago
|
$config['password'] = variable_get('roblib_search_eds_pass', 'edspassword');
|
||
7 years ago
|
//get the local ips allowed from ebsco
|
||
|
$config['local_ip_address'] = variable_get('ebsco_local_ips');
|
||
7 years ago
|
$config['profile'] = ($type === 'Books') ? variable_get('roblib_search_eds_book_profile', 'apilite') :
|
||
|
variable_get('roblib_search_eds_profile', 'edsapi');
|
||
12 years ago
|
$config['auth_url'] = variable_get('roblib_search_eds_auth_url', 'https://eds-api.ebscohost.com/Authservice/rest');
|
||
3 years ago
|
$config['rest_url'] = variable_get('roblib_search_eds_rest_url', 'https://eds-api.ebscohost.com/edsapi/rest');
|
||
7 years ago
|
$config['guest'] = variable_get('roblib_search_eds_guest','y');
|
||
12 years ago
|
return $config;
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* 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(
|
||
10 years ago
|
'<p>
|
||
|
provides a target for the Roblib search module. This target uses javascript
|
||
|
to render the results.
|
||
|
</p>'
|
||
12 years ago
|
);
|
||
|
}
|
||
|
}
|
||
|
|