array( 'name' => t("Pazpar2 metasearch interface"), 'base' => 'mkdru', 'description' => t("Metasearch interface for Z39.50/SRU and other targets via a Pazpar2/Service Proxy backend"), ) ); } /** * Implements hook_search_info() */ function mkdru_search_info() { return array( 'title' => 'Meta search', 'path' => 'meta', 'conditions_callback' => 'mkdru_search_conditions_callback', ); } /** * Implements hook_search_page() */ function mkdru_search_page($results) { $output['prefix']['#markup'] = theme('mkdru_results'); $output['suffix']['#markup'] = ''; return $output; } /** * Implements hook_ding_facetbrowser() */ function mkdru_ding_facetbrowser() { $results = new stdClass(); $results->facets = array(); $results->show_empty = TRUE; # Show an empty facetbrowser block, even if search didn't return any results return $results; } /** * Search callback function that is invoked by search_view() */ function mkdru_search_conditions_callback($keys) {} /** * Implement hook_search_execute() */ function mkdru_search_execute($keys = NULL, $conditions = NULL) { $path = drupal_get_path('module', 'mkdru'); // Include client library. drupal_add_js(variable_get('pz2_js_path', 'pazpar2/js') . '/pz2.js', array('type' => 'file', 'scope' => 'footer')); drupal_add_library('overlay', 'jquery-bbq'); drupal_add_js($path . '/mkdru.theme.js', array('type' => 'file', 'scope' => 'footer')); drupal_add_js($path . '/mkdru.client.js', array('type' => 'file', 'scope' => 'footer')); drupal_add_js(array('mkdru' => array( 'use_sessions' => variable_get('use_sessions', '1'), 'pz2_path' => variable_get('pz2_path', '/pazpar2/search.pz2'), 'sp_user' => variable_get('sp_user', ''), 'sp_pass' => variable_get('sp_pass', ''), 'query' => $keys, ) ), 'setting'); return array(); } /** * Implements hook_permission() */ function mkdru_permission() { return array( 'administer metasearch interfaces' => array( 'title' => t('Administer Pazpar2 metasearch integration'), ), 'create metasearch interface' => array( 'title' => t('Create metasearch interface'), ), 'edit any metasearch interface' => array( 'title' => t('Edit any metasearch interface'), ), 'edit own metasearch interface' => array( 'title' => t('Edit own metasearch interface'), ), ); } /** * Implements hook_node_access() */ function mkdru_node_access($node, $op, $account) { if ($op == 'create') { // Only users with permission to do so may create this node type. return user_access('create metasearch interface', $account); } // Users who create a node may edit or delete it later, assuming they have the // necessary permissions. if ($op == 'update' || $op == 'delete') { if (user_access('edit own metasearch interface', $account) && ($account->uid == $node->uid)) { return TRUE; } elseif (user_access('edit any metasearch interface', $account)) { return TRUE; } } } /** * Implements hook_menu() */ function mkdru_menu() { $items['admin/settings/mkdru'] = array( 'title' => 'mkdru Settings', 'description' => 'Settings for mkdru.', 'page callback' => 'drupal_get_form', 'page arguments' => array('mkdru_admin_settings'), 'access arguments' => array('administer site configuration'), 'type' => MENU_NORMAL_ITEM, 'file' => 'mkdru.admin.inc', ); return $items; } /** * Implementation of hook_init() */ function mkdru_init() { // Applies our module specific CSS to all pages. This works best because // all CSS is aggregated and cached so we reduce the number of HTTP // requests and the size is negligible. drupal_add_css(drupal_get_path('module', 'mkdru') .'/mkdru.css'); } // Node config /** * Implements hook_form() */ function mkdru_form(&$node, $form_state) { $type = node_type_get_type($node); $form['title'] = array( '#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => FALSE, '#default_value' => $node->title, '#weight' => -5 ); $form['search_settings'] = array( '#type' => 'fieldset', '#title' => t('Pazpar2/Service Proxy search settings'), '#collapsible' => TRUE, '#collapsed' => FALSE ); $form['search_settings']['pz2_path'] = array( '#type' => 'textfield', '#title' => t('Pazpar2/Service Proxy path'), '#description' => t('Path that takes Pazpar2 commands via HTTP'), '#required' => TRUE, '#default_value' => isset($node->mkdru->pz2_path) ? $node->mkdru->pz2_path : '/pazpar2/search.pz2', ); $form['search_settings']['use_sessions'] = array( '#type' => 'checkbox', '#title' => t('Session handling'), '#description' => t('Disable for use with Service Proxy'), '#default_value' => isset($node->mkdru->use_sessions) ? $node->mkdru->use_sessions : 1, ); $form['sp_settings'] = array( '#type' => 'fieldset', '#title' => t('Service Proxy specific settings'), '#collapsible' => TRUE, '#collapsed' => TRUE ); $form['sp_settings']['sp_user'] = array( '#type' => 'textfield', '#title' => t('Service Proxy username'), '#description' => t('Service Proxy username'), '#required' => FALSE, '#default_value' => isset($node->mkdru->sp_user) ? $node->mkdru->sp_user : '', ); $form['sp_settings']['sp_pass'] = array( '#type' => 'textfield', '#title' => t('Service Proxy password'), '#description' => t('Service Proxy password'), '#required' => FALSE, '#default_value' => isset($node->mkdru->sp_pass) ? $node->mkdru->sp_pass : '', ); $form['display_settings'] = array( '#type' => 'fieldset', '#title' => t('Display settings'), '#collapsible' => TRUE, '#collapsed' => FALSE ); $form['display_settings']['source_max'] = array( '#type' => 'textfield', '#title' => t('Number of sources to display'), '#required' => TRUE, '#default_value' => isset($node->mkdru->source_max) ? $node->mkdru->source_max : 10, '#size' => 3, '#maxlength' => 3, ); $form['display_settings']['author_max'] = array( '#type' => 'textfield', '#title' => t('Number of authors to display'), '#required' => TRUE, '#default_value' => isset($node->mkdru->author_max) ? $node->mkdru->author_max : 10, '#size' => 3, '#maxlength' => 3, ); $form['display_settings']['subject_max'] = array( '#type' => 'textfield', '#title' => t('Number of subjects to display'), '#required' => TRUE, '#default_value' => isset($node->mkdru->subject_max) ? $node->mkdru->subject_max : 10, '#size' => 3, '#maxlength' => 3, ); return $form; } /** * Implements hook_validate() */ function mkdru_validate($node) { if (!is_numeric($node->source_max)) { form_set_error('source_max', t('Please enter a number.')); } if (!is_numeric($node->author_max)) { form_set_error('author_max', t('Please enter a number.')); } if (!is_numeric($node->subject_max)) { form_set_error('subject_max', t('Please enter a number.')); } } /** * Implements hook_insert(). */ function mkdru_insert($node) { drupal_write_record('mkdru', $node); } /** * Implements hook_update(). */ function mkdru_update($node) { if ($node->revision) { // New revision; treat it as a new record. mkdru_insert($node); } else { drupal_write_record('mkdru', $node, 'vid'); } } /** * Implements hook_node_revision_delete() */ function mkdru_node_revision_delete($node) { db_delete('mkdru') ->condition('vid', $node->vid) ->execute(); } /** * Implements hook_delete() */ function mkdru_delete($node) { // Deleting by nid covers all revisions. db_delete('mkdru') ->condition('nid', $node->nid) ->execute(); } // Node rendering /** * Implements hook_load() */ function mkdru_load($nodes) { $result = db_query('SELECT * FROM {mkdru} WHERE nid IN (:nids)', array(':nids' => array_keys($nodes))); foreach ($result as $record) { $nodes[$record->nid]->mkdru = $record; } } /** * Implements hook_theme(). */ function mkdru_theme() { return array( 'mkdru_form' => array( 'template' => 'mkdru-form', 'variables' => array(), ), 'mkdru_results' => array( 'template' => 'mkdru-results', 'variables' => array(), ), 'mkdru_js' => array( 'variables' => array('node' => NULL), ), 'mkdru_block_search' => array( 'template' => 'mkdru-block-search', 'variables' => array('nid' => NULL, 'path' => NULL), ), 'mkdru_block_facet' => array( 'template' => 'mkdru-block-facet', 'variables' => array('class' => NULL) ) ); } /** * Theme function to include Javascript search client and deps */ function theme_mkdru_js(&$variables) { $path = drupal_get_path('module', 'mkdru'); // Pazpar2 client library drupal_add_js(variable_get('pz2_js_path', 'pazpar2/js') . '/pz2.js', array( 'type' => 'file', 'scope' => 'footer', 'defer' => TRUE, 'preprocess' => FALSE)); // jQuery plugin for query string/history manipulation. drupal_add_library('system', 'jquery.bbq'); drupal_add_js($path . '/mkdru.theme.js', array( 'type' => 'file', 'scope' => 'footer', 'defer' => TRUE, 'preprocess' => FALSE)); drupal_add_js($path . '/mkdru.client.js', array( 'type' => 'file', 'scope' => 'footer', 'defer' => TRUE, 'preprocess' => FALSE)); drupal_add_js(array('mkdru' => $variables['node']->mkdru), 'setting'); } /** * Implements hook_view() */ function mkdru_view($node, $view_mode) { if ($view_mode == 'full') { $node->content['mkdru_js'] = array( '#markup' => theme('mkdru_js', array('node' => $node)), '#weight' => 0, ); $node->content['mkdru_form'] = array( '#markup' => theme('mkdru_form'), '#weight' => 1, ); $node->content['mkdru_results'] = array( '#markup' => theme('mkdru_results'), '#weight' => 2, ); } return $node; } // Blocks /** * Implements hook_block_info() */ function mkdru_block_info() { // facet blocks $facets = variable_get('mkdru_facets'); foreach ($facets as $facet) { // NB: block caching is redundant for static content $blocks['mkdru_facet_' . $facet]['info'] = "mkdru - $facet " . t('facet'); $blocks['mkdru_facet_' . $facet]['cache'] = DRUPAL_NO_CACHE; } // search blocks $result = db_query("SELECT title, nid FROM {node} WHERE type = 'mkdru';"); foreach($result as $node) { $blocks['mkdru_search_' . $node->nid]['info'] = t('mkdru - search box for "' . $node->title . '"'); $blocks['mkdru_sources']['cache'] = DRUPAL_NO_CACHE; }; return $blocks; } /** * Implements hook_block_view() */ function mkdru_block_view($delta) { if (substr($delta, 0, 12) == 'mkdru_facet_') { $facet = substr($delta, 12); $block['subject'] = t(ucwords($facet)); $block['content'] = theme('mkdru_block_facet', array('class' => 'mkdru-facet-' . $facet)); return $block; } elseif (substr($delta, 0, 13) == 'mkdru_search_') { $nid = substr($delta, 13); $block['content'] = theme('mkdru_block_search', array('nid' => $nid, 'path' => '/node/' . $nid)); return $block; } }