<?php
+// $Id$
+
+
+
// Module metainfo
/**
-* Implementation of hook_node_info().
+* Implements hook_node_info()
*/
function mkdru_node_info() {
return array(
'mkdru' => array(
- 'name' => t("Z39.50/SRU metasearch interface"),
+ 'name' => t("Pazpar2 metasearch interface"),
'module' => 'mkdru',
'description' => t("Metasearch interface for Z39.50/SRU and other targets via a Pazpar2/Service Proxy backend"),
-
)
);
}
+function mkdru_ting_search_tab($keys) {
+ error_log("TING SEARCH TAB invoked");
+ $path = drupal_get_path('module', 'mkdru');
+ // Include client library.
+ drupal_add_js(variable_get('pz2_js_path', 'pazpar2/js')
+ . '/pz2.js', 'module', 'footer');
+ drupal_add_js($path . '/jquery.ba-bbq.js', 'module', 'footer');
+ drupal_add_js($path . '/recipe.js', 'module', 'footer');
+ drupal_add_js($path . '/mkdru.theme.js', 'module', 'footer');
+ drupal_add_js($path . '/mkdru.client.js', 'module', 'footer');
+ $html = theme('mkdru_results');
+ 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("content" => $html, "title" => "Meta Search");
+}
+
/**
-* Implementation of hook_perm().
+* Implements hook_perm()
*/
function mkdru_perm() {
return array('create metasearch interface', 'edit any metasearch interface', 'edit own metasearch interface');
}
/**
-* Implementation of hook_access().
+* Implements hook_access()
*/
function mkdru_access($op, $node, $account) {
}
}
+/**
+* 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;
+}
+
+/**
+* Implements 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
/**
-* Implementation of hook_form().
+* Implements hook_form()
*/
function mkdru_form(&$node, $form_state) {
$type = node_get_types('type', $node);
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
- '#required' => TRUE,
+ '#required' => FALSE,
'#default_value' => $node->title,
'#weight' => -5
);
- $form['pz2_path'] = array(
+
+ $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('Absolute URL path without leading slash'),
+ '#description' => t('Path that takes Pazpar2 commands via HTTP'),
'#required' => TRUE,
- '#default_value' => isset($node->pz2_path) ? $node->pz2_path : 'pazpar2',
- '#weight' => 0
+ '#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' => FALSE
+ );
+ $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.'));
+ }
+}
+
/**
-* Implementation of hook_insert().
+* Implements hook_insert().
*/
function mkdru_insert($node) {
- db_query("INSERT INTO {mkdru} (nid, vid, pz2_path) VALUES (%d, %d, '%s')",
- $node->nid, $node->vid, $node->pz2_path);
+ drupal_write_record('mkdru', $node);
}
/**
-* Implementation of hook_update().
+* Implements hook_update().
*/
function mkdru_update($node) {
if ($node->revision) {
mkdru_insert($node);
}
else {
- db_query("UPDATE {mkdru} SET pz2_path = '%s' WHERE vid = '%d'", $node->pz2_path, $node->vid);
+ drupal_write_record('mkdru', $node, 'vid');
}
}
/**
- * Implementation of hook_nodeapi().
+ * Implements hook_nodeapi().
*
* When a node revision is deleted, we need to remove the corresponding record
* from our table. The only way to handle revision deletion is by implementing
* hook_nodeapi().
*/
-function node_example_nodeapi(&$node, $op, $teaser, $page) {
+function mkdru_nodeapi(&$node, $op, $teaser, $page) {
switch ($op) {
case 'delete revision':
- // Notice that we're matching a single revision based on the node's vid.
db_query('DELETE FROM {mkdru} WHERE vid = %d', $node->vid);
break;
}
}
/**
- * Implementation of hook_delete().
- *
- * When a node is deleted, we need to remove all related records from our table.
+ * Implements hook_delete().
*/
-function node_example_delete($node) {
+function mkdru_delete($node) {
// Deleting by nid covers all revisions.
db_query('DELETE FROM {mkdru} WHERE nid = %d', $node->nid);
}
// Node rendering
/**
-* Implementation of hook_load()
+* Implements hook_load()
*/
function mkdru_load($node) {
- return db_fetch_object(db_query('SELECT pz2_path FROM {mkdru} WHERE vid = %d', $node->vid));
+ return array('mkdru' => db_fetch_object(db_query(
+ 'SELECT * FROM {mkdru} WHERE vid = %d', $node->vid)));
}
/**
-* Implementation of hook_theme().
+* Implements hook_theme().
*/
function mkdru_theme() {
return array(
- 'mkdru_page' => array(
- 'template' => 'mkdru-page',
+ 'mkdru_form' => array(
+ 'template' => 'mkdru-form',
'arguments' => array(),
),
- 'mkdru_page_js' => array(
+ 'mkdru_results' => array(
+ 'template' => 'mkdru-results',
'arguments' => array(),
),
-// 'mkdru_block_facet' => array(
-// 'template' => 'mkdru-block-facet',
-// 'arguments' => array('divId' => NULL),
-// ),
+ 'mkdru_js' => array(
+ 'arguments' => array('node' => NULL),
+ ),
+ 'mkdru_block_search' => array(
+ 'template' => 'mkdru-block-search',
+ 'arguments' => array('nid' => NULL, 'path' => NULL),
+ ),
+ 'mkdru_block_facet' => array(
+ 'template' => 'mkdru-block-facet',
+ 'arguments' => array('class' => NULL)
+ )
);
}
/**
* Theme function to include Javascript search client and deps
*/
-function theme_mkdru_page_js() {
+function theme_mkdru_js($node) {
$path = drupal_get_path('module', 'mkdru');
- drupal_add_js('pazpar2/js/pz2.js', 'module', 'footer');
- drupal_add_js($path . '/mkdru.theme.js', 'module', 'footer');
- drupal_add_js($path . '/mkdru.client.js', 'module', 'footer');
+ // Pazpar2 client library.
+ drupal_add_js(variable_get('pz2_js_path', 'pazpar2/js') . '/pz2.js', 'module', 'footer', TRUE, TRUE, FALSE);
+ // jQuery plugin for query string/history manipulation.
+ drupal_add_js($path . '/jquery.ba-bbq.js', 'module', 'footer', TRUE, TRUE, FALSE);
+ drupal_add_js($path . '/mkdru.theme.js', 'module', 'footer', TRUE, TRUE, FALSE);
+ drupal_add_js($path . '/mkdru.client.js', 'module', 'footer', TRUE, TRUE, FALSE);
+ drupal_add_js(array('mkdru' => $node->mkdru), 'setting');
}
/**
-* Implementation of hook_view()
+* Implements hook_view()
*/
function mkdru_view($node, $teaser = FALSE, $page = FALSE) {
- $node->content['mkdru_page_js'] = array(
- '#value' => theme('mkdru_page_js'),
+ $node->content['mkdru_js'] = array(
+ '#value' => theme('mkdru_js', $node),
'#weight' => 0,
);
- $node->content['mkdru_page'] = array(
- '#value' => theme('mkdru_page'),
+ $node->content['mkdru_form'] = array(
+ '#value' => theme('mkdru_form'),
'#weight' => 1,
);
+ $node->content['mkdru_results'] = array(
+ '#value' => theme('mkdru_results'),
+ '#weight' => 2,
+ );
return $node;
}
/**
-* Implementation of hook_block()
+* Implements hook_block()
*/
function mkdru_block($op='list', $delta='sources', $edit=array()) {
switch ($op) {
case 'list':
+ // facet blocks
+ // D6 has no setting for note type visibility, set
+ // the default to limit facet display to this type
+ $visPHP = '<?php
+ if (arg(0) == "node" && is_numeric(arg(1))) {
+ $node = node_load(array("nid" => arg(1)));
+ return $node->type == "mkdru";
+ }
+?>';
+
+ // NB: block caching is redundant for static content
$blocks['mkdru_sources']['info'] = t('mkdru - source facets');
$blocks['mkdru_sources']['cache'] = BLOCK_NO_CACHE;
+ $blocks['mkdru_sources']['visibility'] = 2;
+ $blocks['mkdru_sources']['pages'] = $visPHP;
$blocks['mkdru_subjects']['info'] = t('mkdru - subject facets');
$blocks['mkdru_subjects']['cache'] = BLOCK_NO_CACHE;
+ $blocks['mkdru_subjects']['visibility'] = 2;
+ $blocks['mkdru_subjects']['pages'] = $visPHP;
$blocks['mkdru_authors']['info'] = t('mkdru - author facets');
$blocks['mkdru_authors']['cache'] = BLOCK_NO_CACHE;
+ $blocks['mkdru_authors']['visibility'] = 2;
+ $blocks['mkdru_authors']['pages'] = $visPHP;
+ // search blocks
+ $result = db_query("SELECT title, nid FROM {node} WHERE type = 'mkdru';");
+ while ($node = db_fetch_object($result)) {
+ $blocks['mkdru_search_' . $node->nid]['info'] =
+ t('mkdru - search box for "' . $node->title . '"');
+ $blocks['mkdru_sources']['cache'] = BLOCK_NO_CACHE;
+ };
return $blocks;
case 'view':
switch ($delta) {
- // TODO: make the facet themable, I have no clue why this won't work
-// case 'mkdru_sources':
-// $block['subject'] = t('Source');
-// $block['content'] = theme('mkdru_block_facet', 'mkdru-sources');
-// return $block;
-// case 'mkdru_subjects':
-// $block['subject'] = t('Subject');
-// $block['content'] = theme('mkdru_block_facet', 'mkdru-subjects');
-// return $block;
-// case 'mkdru_authors':
-// $block['subject'] = t('Author');
-// $block['content'] = theme('mkdru_block_facet', 'mkdru-authors');
-// return $block;
case 'mkdru_sources':
$block['subject'] = t('Source');
- $block['content'] = '<div id="mkdru-sources"> </div>';
+ $block['content'] = theme('mkdru_block_facet', 'mkdru-facet-source');
return $block;
case 'mkdru_subjects':
$block['subject'] = t('Subject');
- $block['content'] = '<div id="mkdru-subjects"> </div>';
+ $block['content'] = theme('mkdru_block_facet', 'mkdru-facet-subject');
return $block;
case 'mkdru_authors':
$block['subject'] = t('Author');
- $block['content'] = '<div id="mkdru-authors"> </div>';
+ $block['content'] = theme('mkdru_block_facet', 'mkdru-facet-author');
return $block;
}
+ if (substr($delta, 0, 13) == 'mkdru_search_') {
+ $nid = substr($delta, 13);
+ $block['content'] = theme('mkdru_block_search', $nid, '/node/' . $nid);
+ return $block;
+ }
}
}