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.
290 lines
12 KiB
290 lines
12 KiB
12 years ago
|
<?php
|
||
|
|
||
|
/**
|
||
|
* @file
|
||
|
* Implementation of Roblib search for searching several targets.
|
||
|
*/
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Implements hook_menu().
|
||
|
*/
|
||
|
function roblib_search_evergreen_menu() {
|
||
|
$items = array();
|
||
|
|
||
|
$items['admin/roblib_search/evergreen_search'] = array(
|
||
|
'title' => 'Evergreen Search Target configuration',
|
||
|
'description' => 'Configuration for the Roblib evergreen search target',
|
||
|
'page callback' => 'drupal_get_form',
|
||
|
'page arguments' => array('roblib_search_evergreen_config_form'),
|
||
|
'access arguments' => array('access administration pages'),
|
||
|
'type' => MENU_NORMAL_ITEM,
|
||
|
);
|
||
|
|
||
12 years ago
|
$items['roblib_search/evergreen/ajax/%'] = array(
|
||
|
'title' => 'evergreen ajax',
|
||
|
'page callback' => 'roblib_search_evergreen_ajax',
|
||
|
'page arguments' => array(3),
|
||
|
'type' => MENU_CALLBACK,
|
||
|
'access arguments' => array('search roblib evergreen'),
|
||
|
);
|
||
|
|
||
12 years ago
|
return $items;
|
||
|
}
|
||
|
|
||
|
function roblib_search_evergreen_config_form($form, &$form_state) {
|
||
|
/*
|
||
|
* $url = variable_get('roblib_search_evergreen_url', 'http://137.149.200.52');
|
||
12 years ago
|
$url_suffix = variable_get('roblib_search_evergreen_suffix', '/opac/extras/sru?version=1.1&operation=searchRetrieve&query=');
|
||
|
$number_of_records = variable_get('roblib_search_evergreen_num_results', '5');
|
||
12 years ago
|
*/
|
||
|
$form['roblib_search_evergreen_url'] = array(
|
||
|
'#type' => 'textfield',
|
||
|
'#title' => t('Evergreen url'),
|
||
|
'#default_value' => variable_get('roblib_search_evergreen_url', 'http://islandpines.roblib.upei.ca/'),
|
||
|
'#description' => t('The base Evergreen URL, for example http://islandpines.roblib.upei.ca/'),
|
||
|
'#required' => TRUE,
|
||
|
);
|
||
|
$form['roblib_search_evergreen_search_suffix'] = array(
|
||
|
'#type' => 'textfield',
|
||
|
'#title' => t('Evergreen search suffix'),
|
||
|
'#default_value' => variable_get('roblib_search_evergreen_search_suffix', '/opac/extras/sru?version=1.1&operation=searchRetrieve&query='),
|
||
|
'#description' => t('The suffix will be appended to the base url for searches, for example /opac/extras/sru?version=1.1&operation=searchRetrieve&query='),
|
||
|
'#required' => TRUE,
|
||
|
);
|
||
|
$form['roblib_search_evergreen_detail_suffix'] = array(
|
||
|
'#type' => 'textfield',
|
||
|
'#title' => t('Evergreen detail suffix'),
|
||
|
'#default_value' => variable_get('roblib_search_evergreen_detail_suffix', '/opac/en-CA/skin/default/xml/rdetail.xml?r='),
|
||
12 years ago
|
'#description' => t('The suffix will be appended to the base url when creating links to the Evergreen detail page, for example, /opac/en-CA/skin/default/xml/rdetail.xml?r='),
|
||
|
'#required' => TRUE,
|
||
|
);
|
||
|
//http://islandpines.roblib.upei.ca/opac/en-CA/skin/roblib/xml/rresult.xml?rt=keyword&tp=keyword&t=
|
||
|
$form['roblib_search_evergreen_catalog_base_search_url'] = array(
|
||
11 years ago
|
'#type' => 'textfield',
|
||
12 years ago
|
'#title' => t('Evergreen catalog base search url'),
|
||
|
'#default_value' => variable_get('roblib_search_evergreen_catalog_base_search_url', 'http://islandpines.roblib.upei.ca/opac/en-CA/skin/roblib/xml/rresult.xml?rt=keyword&tp=keyword&t='),
|
||
|
'#description' => t('The Catalog base url so we can repeat the search in the catalog, for example, http://islandpines.roblib.upei.ca/opac/en-CA/skin/roblib/xml/rresult.xml?rt=keyword&tp=keyword&t='),
|
||
12 years ago
|
'#required' => TRUE,
|
||
|
);
|
||
|
$form['roblib_search_evergreen_num_results'] = array(
|
||
|
'#type' => 'textfield',
|
||
|
'#title' => t('Number of results to return'),
|
||
|
'#default_value' => variable_get('roblib_search_evergreen_num_results', '5'),
|
||
|
'#description' => t('The number of results to display in the Bento box'),
|
||
|
'#required' => TRUE,
|
||
|
);
|
||
12 years ago
|
|
||
12 years ago
|
|
||
|
return system_settings_form($form);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Implements hook_permission().
|
||
|
*/
|
||
|
function roblib_search_evergreen_permission() {
|
||
|
return array(
|
||
|
'search roblib evergreen' => array(
|
||
|
'title' => t('Search the evergreen target'),
|
||
|
'description' => t('Search all Roblib evergreen target. This permission exposes the search blocks and allows you to see search results.'),
|
||
|
),
|
||
|
'administer roblib search_evergreen' => array(
|
||
|
'title' => t('Administer Roblib Search Evergreen'),
|
||
|
'description' => t('Administer settings for the Roblib evergreen search client.'),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
|
||
11 years ago
|
function roblib_search_evergreen_preprocess_panels_pane(&$variables, $hook){
|
||
|
if($variables['pane']->subtype == 'roblib_search_evergreen-roblib_search_evergreen_results'){
|
||
11 years ago
|
$variables['title_prefix'] = '<div class="roblib-search-header roblib-search-evergreen-header">';
|
||
11 years ago
|
$variables['title_suffix'] ='</div>';
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Implements hook_theme().
|
||
|
*/
|
||
|
function roblib_search_evergreen_theme() {
|
||
|
// set path
|
||
|
$path = drupal_get_path('module', 'roblib_search_evergreen');
|
||
|
$file = 'theme.inc';
|
||
|
|
||
|
return array(
|
||
|
// results page
|
||
|
'roblib_search_evergreen' => array(
|
||
|
'path' => $path . '/theme',
|
||
|
'file' => $file,
|
||
|
'template' => 'roblib-search-evergreen',
|
||
|
'variables' => array('results' => NULL),
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
function roblib_search_evergreen_block_info() {
|
||
|
|
||
|
$blocks['roblib_search_evergreen_results'] = array(
|
||
|
// info: The name of the block.
|
||
|
'info' => t('Evergreen Search Results block'),
|
||
|
// Block caching options (per role, per user, etc.)
|
||
|
'cache' => DRUPAL_CACHE_PER_ROLE, // default
|
||
|
);
|
||
|
|
||
|
return $blocks;
|
||
|
}
|
||
|
|
||
|
function roblib_search_evergreen_block_view($delta = '') {
|
||
|
//The $delta parameter tells us which block is being requested.
|
||
|
switch ($delta) {
|
||
|
case 'roblib_search_evergreen_results':
|
||
|
// The subject is displayed at the top of the block. Note that it
|
||
|
// should be passed through t() for translation. The title configured
|
||
|
// for the block using Drupal UI supercedes this one.
|
||
11 years ago
|
$block['subject'] = t('PEI Collection');
|
||
12 years ago
|
// The content of the block is typically generated by calling a custom
|
||
|
// function.
|
||
12 years ago
|
$block['content'] = theme('roblib_search_evergreen', array('results' => NULL));
|
||
12 years ago
|
break;
|
||
|
}
|
||
|
return $block;
|
||
|
}
|
||
|
|
||
12 years ago
|
function roblib_search_evergreen_ajax($query) {
|
||
7 years ago
|
$output = roblib_search_passthru_evergreen_get_results($query);
|
||
12 years ago
|
print $output;
|
||
|
exit();
|
||
|
}
|
||
12 years ago
|
|
||
12 years ago
|
/**
|
||
7 years ago
|
*
|
||
12 years ago
|
* @param string $query
|
||
|
* @return string
|
||
7 years ago
|
* json
|
||
12 years ago
|
*/
|
||
|
function roblib_search_evergreen_get_results($query) {
|
||
|
drupal_add_css(drupal_get_path('module', 'roblib_search_evergreen') . '/css/roblib_search_evergreen.theme.css');
|
||
12 years ago
|
|
||
|
$url = variable_get('roblib_search_evergreen_url', 'http://137.149.200.52');
|
||
|
$url_suffix = variable_get('roblib_search_evergreen_search_suffix', '/opac/extras/sru?version=1.1&operation=searchRetrieve&query=');
|
||
|
$number_of_records = variable_get('roblib_search_evergreen_num_results', '5');
|
||
8 years ago
|
$query = trim($query);
|
||
10 years ago
|
$query = str_replace(' ', '%20AND%20',$query); //hack until the library decides if we want phrase or individual words
|
||
|
$query .= '%20AND%20%22prince%20edward%20island%22';
|
||
12 years ago
|
$search_url = $url . $url_suffix . $query . '&maximumRecords=' . $number_of_records;
|
||
11 years ago
|
$catalog_base_search_url = variable_get('roblib_search_evergreen_catalog_base_search_url', 'http://islandpines.roblib.upei.ca/opac/en-CA/skin/roblib/xml/rresult.xml?rt=keyword&tp=keyword&t=');
|
||
12 years ago
|
drupal_add_js(array('roblib_search_evergreen' => array('catalog_url' => $catalog_base_search_url)), array('type' => 'setting'));
|
||
12 years ago
|
$results = drupal_http_request($search_url);
|
||
|
if ($results->code == '200') {
|
||
12 years ago
|
$output = roblib_search_evergreen_parse_results($results, $query);
|
||
12 years ago
|
}
|
||
|
else {
|
||
11 years ago
|
watchdog('roblib_search_evergreen', 'Error retrieving results: %error', array('%error' => $results->status_message), WATCHDOG_ERROR);
|
||
|
$output = '';
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
return json_encode($output);
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
7 years ago
|
*
|
||
12 years ago
|
* @param string $results
|
||
|
* results in marcxml
|
||
|
* @return array $output
|
||
|
* information we want from the xml stored in an array
|
||
|
*/
|
||
12 years ago
|
function roblib_search_evergreen_parse_results($results, $query) {
|
||
12 years ago
|
$xml = $results->data;
|
||
|
if (!isset($xml)) {
|
||
|
return 'no results found';
|
||
|
}
|
||
|
$sxml = simplexml_load_string(trim($results->data));
|
||
|
$output = array();
|
||
|
if ($sxml) {
|
||
|
$sxml->registerXPathNamespace('marcxml', 'http://www.loc.gov/MARC21/slim');
|
||
12 years ago
|
$sxml->registerXPathNamespace('srw', 'http://www.loc.gov/zing/srw/');
|
||
|
$number_of_records = $sxml->xpath('//srw:numberOfRecords');
|
||
|
$output['numberOfRecords'] = (string)$number_of_records[0];
|
||
|
$catalog_base_search_url = variable_get('roblib_search_evergreen_catalog_base_search_url', 'http://islandpines.roblib.upei.ca/opac/en-CA/skin/roblib/xml/rresult.xml?rt=keyword&tp=keyword&t=');
|
||
|
$catalog_base_search_url .= $query;
|
||
7 years ago
|
$output['catalogBaseSearchUrl'] = $catalog_base_search_url;
|
||
|
|
||
12 years ago
|
$records = $sxml->xpath('//marcxml:record');
|
||
|
//$records = $sxml->xpath('//marcxml:record/marcxml:recordData/marcxml:record/marcxml:datafield[@tag="245"]/marcxml:subfield[@code="a"]');
|
||
|
$index = 0;
|
||
|
foreach ($records as $record) {
|
||
7 years ago
|
$record->registerXPathNamespace('marcxml', 'http://www.loc.gov/MARC21/slim');
|
||
12 years ago
|
roblib_search_evergreen_update_array($output, $index, 'title', $record->xpath('marcxml:datafield[@tag="245"]/marcxml:subfield[@code="a"]'));
|
||
|
roblib_search_evergreen_update_array($output, $index, 'subtitle', $record->xpath('marcxml:datafield[@tag="245"]/marcxml:subfield[@code="b"]'));
|
||
|
roblib_search_evergreen_update_array($output, $index, 'sor', $record->xpath('marcxml:datafield[@tag="245"]/marcxml:subfield[@code="c"]'));
|
||
|
roblib_search_evergreen_update_array($output, $index, 'date', $record->xpath('marcxml:datafield[@tag="260"]/marcxml:subfield[@code="c"]'));
|
||
|
roblib_search_evergreen_update_array($output, $index, 'id', $record->xpath('marcxml:datafield[@tag="901"]/marcxml:subfield[@code="c"]'));
|
||
11 years ago
|
roblib_search_evergreen_update_array($output, $index, 'publisher', $record->xpath('marcxml:datafield[@tag="260"]/marcxml:subfield[@code="a"]'));
|
||
|
roblib_search_evergreen_update_array($output, $index, 'pop', $record->xpath('marcxml:datafield[@tag="260"]/marcxml:subfield[@code="b"]'));
|
||
|
roblib_search_evergreen_update_array($output, $index, 'numofpages', $record->xpath('marcxml:datafield[@tag="300"]/marcxml:subfield[@code="a"]'));
|
||
|
roblib_search_evergreen_update_array($output, $index, 'subjectsa', $record->xpath('marcxml:datafield[@tag="650"]/marcxml:subfield[@code="a"]'));
|
||
|
roblib_search_evergreen_update_array($output, $index, 'subjectsb', $record->xpath('marcxml:datafield[@tag="650"]/marcxml:subfield[@code="b"]'));
|
||
|
roblib_search_evergreen_update_array($output, $index, 'subjectsc', $record->xpath('marcxml:datafield[@tag="650"]/marcxml:subfield[@code="c"]'));
|
||
12 years ago
|
roblib_search_evergreen_holdings($output, $index, $record->xpath('marcxml:datafield[@tag="852"]'));
|
||
12 years ago
|
roblib_search_evergreen_electronic_holdings($output, $index, $record->xpath('marcxml:datafield[@tag="856"]'));
|
||
12 years ago
|
$id = $output[$index]['id'];
|
||
12 years ago
|
$output[$index++]['url'] = variable_get('roblib_search_evergreen_url', 'http://137.149.200.52')
|
||
|
. variable_get('roblib_search_evergreen_detail_suffix', '/opac/en-CA/skin/default/xml/rdetail.xml?r=')
|
||
12 years ago
|
. (string)$id;
|
||
12 years ago
|
}
|
||
|
}
|
||
|
return $output;
|
||
|
}
|
||
|
|
||
12 years ago
|
function roblib_search_evergreen_holdings(&$arr, $index, $xpath_result){
|
||
|
$holding_index = 0;
|
||
|
foreach($xpath_result as $xml){
|
||
|
$xml->registerXPathNamespace('marcxml', 'http://www.loc.gov/MARC21/slim');
|
||
|
$call_number = $xml->xpath('marcxml:subfield[@code="c"]');
|
||
|
$arr[$index]['holdings'][$holding_index]['call_number'] = (string)$call_number[0];
|
||
|
$availability = $xml->xpath('marcxml:subfield[@code="n"]');
|
||
12 years ago
|
$arr[$index]['holdings'][$holding_index]['availability'] = (string)$availability[0];
|
||
|
$location = $xml->xpath('marcxml:subfield[@code="a"]');
|
||
|
$arr[$index]['holdings'][$holding_index++]['location'] = (string)$location[0];
|
||
7 years ago
|
}
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
function roblib_search_evergreen_electronic_holdings(&$arr, $index, $xpath_result){
|
||
|
$holding_index = 0;
|
||
|
foreach($xpath_result as $xml){
|
||
|
$xml->registerXPathNamespace('marcxml', 'http://www.loc.gov/MARC21/slim');
|
||
|
$label = $xml->xpath('marcxml:subfield[@code="y"]');
|
||
|
$label = (string)$label[0];
|
||
|
$url = $xml->xpath('marcxml:subfield[@code="u"]');
|
||
|
$url = (string)$url[0];
|
||
|
$arr[$index]['electronic_holdings'][$holding_index]['url'] = $url;
|
||
|
$arr[$index]['electronic_holdings'][$holding_index++]['label'] = $label;
|
||
7 years ago
|
|
||
12 years ago
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
function roblib_search_evergreen_update_array(&$arr, $index, $key, $xpath_result){
|
||
|
if(!empty($xpath_result)){
|
||
|
$val = (string)$xpath_result[0];
|
||
|
$arr[$index][$key] = $val;
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
/**
|
||
|
* Implements hook_help().
|
||
|
*
|
||
|
* @param type $path
|
||
|
* @param type $arg
|
||
|
* @return type
|
||
|
*/
|
||
|
function roblib_search_evergreen_help($path, $arg) {
|
||
|
switch ($path) {
|
||
|
case 'admin/help#roblib_search_evergreen':
|
||
|
return t(
|
||
|
'<p>
|
||
|
provides a target for the Roblib search module
|
||
|
</p>'
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|