X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=mkdru.module;h=e7541ab664746e6118fde799cf1e3e8daafd9b36;hb=89996d58c6ef47fdba1944a4d4c6fde026f07d63;hp=b5718cc91a8c596268b2d48254f51aa7b4762957;hpb=2706489442d1d5182dc9d3ef30522bbae1ae7a28;p=mkdru-moved-to-drupal.org.git diff --git a/mkdru.module b/mkdru.module index b5718cc..e7541ab 100644 --- a/mkdru.module +++ b/mkdru.module @@ -10,7 +10,7 @@ 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"), ) @@ -18,7 +18,18 @@ function mkdru_node_info() { } function mkdru_ting_search_show($params) { - return array("content" => "You have searched for '".$params['keys']."'."); + $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 . '/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' => '1', 'query' => $params['keys'] + )), 'setting'); + return array("content" => $html); } /** @@ -69,7 +80,7 @@ function mkdru_menu() { /** * Implementation of hook_init() */ -function mkdru_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. @@ -106,6 +117,22 @@ function mkdru_form(&$node, $form_state) { '#required' => TRUE, '#default_value' => isset($node->mkdru->pz2_path) ? $node->mkdru->pz2_path : '/pazpar2/search.pz2', ); + $form['search_settings']['sp_user'] = array( + '#type' => 'textfield', + '#title' => t('Service Proxy username (optional)'), + '#description' => t('Service-Proxy username'), + '#required' => FALSE, + '#default_value' => isset($node->mkdru->sp_user) ? + $node->mkdru->sp_user : '', + ); + $form['search_settings']['sp_pass'] = array( + '#type' => 'textfield', + '#title' => t('Service Proxy password (optional)'), + '#description' => t('Service-Proxy password'), + '#required' => FALSE, + '#default_value' => isset($node->mkdru->sp_pass) ? + $node->mkdru->sp_pass : '', + ); $form['search_settings']['use_sessions'] = array( '#type' => 'checkbox', '#title' => t('Session handling'), @@ -166,8 +193,9 @@ function mkdru_validate($node) { * Implementation of hook_insert(). */ function mkdru_insert($node) { - db_query("INSERT INTO {mkdru} (nid, vid, pz2_path, use_sessions, source_max, author_max, subject_max) VALUES (%d, %d, '%s', %d, %d, %d, %d)", - $node->nid, $node->vid, $node->pz2_path, $node->use_sessions, $node->source_max, $node->author_max, $node->subject_max); + db_query("INSERT INTO {mkdru} (nid, vid, pz2_path, use_sessions, source_max, author_max, subject_max, sp_user, sp_pass) ". + "VALUES (%d, %d, '%s', %d, %d, %d, %d, '%s', '%s')", + $node->nid, $node->vid, $node->pz2_path, $node->use_sessions, $node->source_max, $node->author_max, $node->subject_max, $node->sp_user, $node->sp_pass); } /** @@ -179,7 +207,7 @@ function mkdru_update($node) { mkdru_insert($node); } else { - db_query("UPDATE {mkdru} SET pz2_path = '%s', use_sessions = %d, source_max = %d, author_max = %d, subject_max = %d WHERE vid = %d", $node->pz2_path, $node->use_sessions, $node->source_max, $node->author_max, $node->subject_max, $node->vid); + db_query("UPDATE {mkdru} SET pz2_path = '%s', use_sessions = %d, source_max = %d, author_max = %d, subject_max = %d, sp_user = '%s', sp_pass = '%s' WHERE vid = %d", $node->pz2_path, $node->use_sessions, $node->source_max, $node->author_max, $node->subject_max, $node->vid); } } @@ -233,10 +261,14 @@ function mkdru_theme() { 'mkdru_js' => array( 'arguments' => array('node' => NULL), ), -// 'mkdru_block_facet' => array( -// 'template' => 'mkdru-block-facet', -// 'arguments' => array('divId' => 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) + ) ); } @@ -245,10 +277,12 @@ function mkdru_theme() { */ function theme_mkdru_js($node) { $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 . '/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'); } @@ -277,41 +311,57 @@ function mkdru_view($node, $teaser = FALSE, $page = FALSE) { 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 = ' 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'] = '
'; + $block['content'] = theme('mkdru_block_facet', 'mkdru-facet-source'); return $block; case 'mkdru_subjects': $block['subject'] = t('Subject'); - $block['content'] = '
'; + $block['content'] = theme('mkdru_block_facet', 'mkdru-facet-subject'); return $block; case 'mkdru_authors': $block['subject'] = t('Author'); - $block['content'] = '
'; + $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; + } } }