8 * Implements hook_node_info()
10 function mkdru_node_info() {
13 'name' => t("Pazpar2 metasearch interface"),
15 'description' => t("Metasearch interface for Z39.50/SRU and other targets via a Pazpar2/Service Proxy backend"),
20 function mkdru_ting_search_show($params) {
21 $path = drupal_get_path('module', 'mkdru');
22 // Include client library.
23 drupal_add_js(variable_get('pz2_js_path', 'pazpar2/js')
24 . '/pz2.js', 'module', 'footer');
25 drupal_add_js($path . '/jquery.ba-bbq.js', 'module', 'footer');
26 drupal_add_js($path . '/mkdru.theme.js', 'module', 'footer');
27 drupal_add_js($path . '/mkdru.client.js', 'module', 'footer');
28 $html = theme('mkdru_results');
29 drupal_add_js(array('mkdru' =>
30 array('use_sessions' => '1', 'query' => $params['keys']
32 return array("content" => $html);
36 * Implements hook_perm()
38 function mkdru_perm() {
39 return array('create metasearch interface', 'edit any metasearch interface', 'edit own metasearch interface');
43 * Implements hook_access()
45 function mkdru_access($op, $node, $account) {
47 if ($op == 'create') {
48 // Only users with permission to do so may create this node type.
49 return user_access('create metasearch interface', $account);
52 // Users who create a node may edit or delete it later, assuming they have the
53 // necessary permissions.
54 if ($op == 'update' || $op == 'delete') {
55 if (user_access('edit own metasearch interface', $account) && ($account->uid == $node->uid)) {
58 elseif (user_access('edit any metasearch interface', $account)) {
65 * Implements hook_menu()
67 function mkdru_menu() {
68 $items['admin/settings/mkdru'] = array(
69 'title' => 'mkdru Settings',
70 'description' => 'Settings for mkdru.',
71 'page callback' => 'drupal_get_form',
72 'page arguments' => array('mkdru_admin_settings'),
73 'access arguments' => array('administer site configuration'),
74 'type' => MENU_NORMAL_ITEM,
75 'file' => 'mkdru.admin.inc',
81 * Implements hook_init()
83 function mkdru_init() {
84 // Applies our module specific CSS to all pages. This works best because
85 // all CSS is aggregated and cached so we reduce the number of HTTP
86 // requests and the size is negligible.
87 drupal_add_css(drupal_get_path('module', 'mkdru') .'/mkdru.css');
94 * Implements hook_form()
96 function mkdru_form(&$node, $form_state) {
97 $type = node_get_types('type', $node);
99 $form['title'] = array(
100 '#type' => 'textfield',
101 '#title' => check_plain($type->title_label),
102 '#required' => FALSE,
103 '#default_value' => $node->title,
107 $form['search_settings'] = array(
108 '#type' => 'fieldset',
109 '#title' => t('Pazpar2/Service Proxy search settings'),
110 '#collapsible' => TRUE,
111 '#collapsed' => FALSE
113 $form['search_settings']['pz2_path'] = array(
114 '#type' => 'textfield',
115 '#title' => t('Pazpar2/Service Proxy path'),
116 '#description' => t('Path that takes Pazpar2 commands via HTTP'),
118 '#default_value' => isset($node->mkdru->pz2_path) ? $node->mkdru->pz2_path : '/pazpar2/search.pz2',
120 $form['search_settings']['use_sessions'] = array(
121 '#type' => 'checkbox',
122 '#title' => t('Session handling'),
123 '#description' => t('Disable for use with Service Proxy'),
124 '#default_value' => isset($node->mkdru->use_sessions) ? $node->mkdru->use_sessions : 1,
127 $form['sp_settings'] = array(
128 '#type' => 'fieldset',
129 '#title' => t('Service Proxy specific settings'),
130 '#collapsible' => TRUE,
133 $form['sp_settings']['sp_user'] = array(
134 '#type' => 'textfield',
135 '#title' => t('Service Proxy username'),
136 '#description' => t('Service Proxy username'),
137 '#required' => FALSE,
138 '#default_value' => isset($node->mkdru->sp_user) ?
139 $node->mkdru->sp_user : '',
141 $form['sp_settings']['sp_pass'] = array(
142 '#type' => 'textfield',
143 '#title' => t('Service Proxy password'),
144 '#description' => t('Service Proxy password'),
145 '#required' => FALSE,
146 '#default_value' => isset($node->mkdru->sp_pass) ?
147 $node->mkdru->sp_pass : '',
150 $form['display_settings'] = array(
151 '#type' => 'fieldset',
152 '#title' => t('Display settings'),
153 '#collapsible' => TRUE,
154 '#collapsed' => FALSE
156 $form['display_settings']['source_max'] = array(
157 '#type' => 'textfield',
158 '#title' => t('Number of sources to display'),
160 '#default_value' => isset($node->mkdru->source_max) ? $node->mkdru->source_max : 10,
164 $form['display_settings']['author_max'] = array(
165 '#type' => 'textfield',
166 '#title' => t('Number of authors to display'),
168 '#default_value' => isset($node->mkdru->author_max) ? $node->mkdru->author_max : 10,
172 $form['display_settings']['subject_max'] = array(
173 '#type' => 'textfield',
174 '#title' => t('Number of subjects to display'),
176 '#default_value' => isset($node->mkdru->subject_max) ? $node->mkdru->subject_max : 10,
185 * Implements hook_validate()
187 function mkdru_validate($node) {
188 if (!is_numeric($node->source_max)) {
189 form_set_error('source_max', t('Please enter a number.'));
191 if (!is_numeric($node->author_max)) {
192 form_set_error('author_max', t('Please enter a number.'));
194 if (!is_numeric($node->subject_max)) {
195 form_set_error('subject_max', t('Please enter a number.'));
200 * Implements hook_insert().
202 function mkdru_insert($node) {
203 drupal_write_record('mkdru', $node);
207 * Implements hook_update().
209 function mkdru_update($node) {
210 if ($node->revision) {
211 // New revision; treat it as a new record.
215 drupal_write_record('mkdru', $node, 'vid');
220 * Implements hook_nodeapi().
222 * When a node revision is deleted, we need to remove the corresponding record
223 * from our table. The only way to handle revision deletion is by implementing
226 function mkdru_nodeapi(&$node, $op, $teaser, $page) {
228 case 'delete revision':
229 db_query('DELETE FROM {mkdru} WHERE vid = %d', $node->vid);
235 * Implements hook_delete().
237 function mkdru_delete($node) {
238 // Deleting by nid covers all revisions.
239 db_query('DELETE FROM {mkdru} WHERE nid = %d', $node->nid);
246 * Implements hook_load()
248 function mkdru_load($node) {
249 return array('mkdru' => db_fetch_object(db_query(
250 'SELECT * FROM {mkdru} WHERE vid = %d', $node->vid)));
254 * Implements hook_theme().
256 function mkdru_theme() {
258 'mkdru_form' => array(
259 'template' => 'mkdru-form',
260 'arguments' => array(),
262 'mkdru_results' => array(
263 'template' => 'mkdru-results',
264 'arguments' => array(),
267 'arguments' => array('node' => NULL),
269 'mkdru_block_search' => array(
270 'template' => 'mkdru-block-search',
271 'arguments' => array('nid' => NULL, 'path' => NULL),
273 'mkdru_block_facet' => array(
274 'template' => 'mkdru-block-facet',
275 'arguments' => array('class' => NULL)
281 * Theme function to include Javascript search client and deps
283 function theme_mkdru_js($node) {
284 $path = drupal_get_path('module', 'mkdru');
285 // Pazpar2 client library.
286 drupal_add_js(variable_get('pz2_js_path', 'pazpar2/js') . '/pz2.js', 'module', 'footer', TRUE, TRUE, FALSE);
287 // jQuery plugin for query string/history manipulation.
288 drupal_add_js($path . '/jquery.ba-bbq.js', 'module', 'footer', TRUE, TRUE, FALSE);
289 drupal_add_js($path . '/mkdru.theme.js', 'module', 'footer', TRUE, TRUE, FALSE);
290 drupal_add_js($path . '/mkdru.client.js', 'module', 'footer', TRUE, TRUE, FALSE);
291 drupal_add_js(array('mkdru' => $node->mkdru), 'setting');
295 * Implements hook_view()
297 function mkdru_view($node, $teaser = FALSE, $page = FALSE) {
298 $node->content['mkdru_js'] = array(
299 '#value' => theme('mkdru_js', $node),
302 $node->content['mkdru_form'] = array(
303 '#value' => theme('mkdru_form'),
306 $node->content['mkdru_results'] = array(
307 '#value' => theme('mkdru_results'),
314 * Implements hook_block()
316 function mkdru_block($op='list', $delta='sources', $edit=array()) {
320 // D6 has no setting for note type visibility, set
321 // the default to limit facet display to this type
323 if (arg(0) == "node" && is_numeric(arg(1))) {
324 $node = node_load(array("nid" => arg(1)));
325 return $node->type == "mkdru";
329 // NB: block caching is redundant for static content
330 $blocks['mkdru_sources']['info'] = t('mkdru - source facets');
331 $blocks['mkdru_sources']['cache'] = BLOCK_NO_CACHE;
332 $blocks['mkdru_sources']['visibility'] = 2;
333 $blocks['mkdru_sources']['pages'] = $visPHP;
334 $blocks['mkdru_subjects']['info'] = t('mkdru - subject facets');
335 $blocks['mkdru_subjects']['cache'] = BLOCK_NO_CACHE;
336 $blocks['mkdru_subjects']['visibility'] = 2;
337 $blocks['mkdru_subjects']['pages'] = $visPHP;
338 $blocks['mkdru_authors']['info'] = t('mkdru - author facets');
339 $blocks['mkdru_authors']['cache'] = BLOCK_NO_CACHE;
340 $blocks['mkdru_authors']['visibility'] = 2;
341 $blocks['mkdru_authors']['pages'] = $visPHP;
343 $result = db_query("SELECT title, nid FROM {node} WHERE type = 'mkdru';");
344 while ($node = db_fetch_object($result)) {
345 $blocks['mkdru_search_' . $node->nid]['info'] =
346 t('mkdru - search box for "' . $node->title . '"');
347 $blocks['mkdru_sources']['cache'] = BLOCK_NO_CACHE;
353 case 'mkdru_sources':
354 $block['subject'] = t('Source');
355 $block['content'] = theme('mkdru_block_facet', 'mkdru-facet-source');
357 case 'mkdru_subjects':
358 $block['subject'] = t('Subject');
359 $block['content'] = theme('mkdru_block_facet', 'mkdru-facet-subject');
361 case 'mkdru_authors':
362 $block['subject'] = t('Author');
363 $block['content'] = theme('mkdru_block_facet', 'mkdru-facet-author');
366 if (substr($delta, 0, 13) == 'mkdru_search_') {
367 $nid = substr($delta, 13);
368 $block['content'] = theme('mkdru_block_search', $nid, '/node/' . $nid);