'Passthru ajax', 'page callback' => 'roblib_search_passthru_islandscholar_ajax', 'page arguments' => [4], 'type' => MENU_CALLBACK, 'access arguments' => ['search roblib'], ]; $items['roblib_search/passthru/evergreen/ajax/%'] = [ 'title' => 'evergreen ajax', 'page callback' => 'roblib_search_passthru_evergreen_ajax', 'page arguments' => [4], 'type' => MENU_CALLBACK, 'access arguments' => ['search roblib'], ]; $items['roblib_search/passthru/eds/ajax/%'] = [ 'title' => 'eds ajax', 'page callback' => 'roblib_search_passthru_eds_ajax', 'page arguments' => [4], 'type' => MENU_CALLBACK, 'access arguments' => ['search roblib'], ]; return $items; } function roblib_search_passthru_evergreen_ajax($query) { $output = roblib_search_passthru_evergreen_get_results($query); print $output; exit(); } function roblib_search_passthru_eds_ajax($query) { $output = roblib_search_eds_get_results($query); print $output; exit(); } /** * * @param string $query * * @return string * json */ function roblib_search_passthru_evergreen_get_results($query) { $url = variable_get('roblib_search_evergreen_url', 'http://islandpines.roblib.upei.ca'); $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'); $query = trim($query); $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'; $search_url = $url . $url_suffix . $query . '&maximumRecords=' . $number_of_records; $results = drupal_http_request($search_url); if ($results->code == '200') { $output = roblib_search_passthru_evergreen_parse_results($results, $query); } else { watchdog('roblib_search_evergreen', 'Error retrieving results: %error', ['%error' => $results->status_message], WATCHDOG_ERROR); $output = ''; } return json_encode($output); } /** * * @param string $results * results in marcxml * * @return array $output * information we want from the xml stored in an array */ function roblib_search_passthru_evergreen_parse_results($results, $query) { $xml = $results->data; if (!isset($xml)) { return 'no results found'; } $sxml = simplexml_load_string(trim($results->data)); $output = []; if ($sxml) { $sxml->registerXPathNamespace('marcxml', 'http://www.loc.gov/MARC21/slim'); $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 = 'http://islandpines.roblib.upei.ca/eg/opac/results?qtype=keyword&l=4&d=2&ol=4&tp=&query='; $catalog_base_search_url .= $query; $output['catalogBaseSearchUrl'] = $catalog_base_search_url; } return $output; } /** * Implements hook_theme(). */ function roblib_search_passthru_theme() { // set path $path = drupal_get_path('module', 'roblib_search_passthru'); $file = 'theme.inc'; return [ // results page 'roblib_search_passthru' => [ 'path' => $path . '/theme', 'file' => $file, 'template' => 'roblib-search-passthru', 'variables' => ['results' => NULL], ], ]; } function roblib_search_passthru_block_info() { $blocks['roblib_passthru_results'] = [ // info: The name of the block. 'info' => t('Misc Results'), // Block caching options (per role, per user, etc.) 'cache' => DRUPAL_CACHE_PER_ROLE, ]; return $blocks; } function roblib_search_passthru_preprocess_panels_pane(&$variables, $hook) { if ($variables['pane']->subtype == 'roblib_search_passthru-roblib_passthru_results') { $variables['title_prefix'] = '
provides a Passthru target for the Roblib search module
' ); } }