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_tab($keys) {
21 error_log("TING SEARCH TAB invoked");
22 $path = drupal_get_path('module', 'mkdru');
23 // Include client library.
24 drupal_add_js(variable_get('pz2_js_path', 'pazpar2/js')
25 . '/pz2.js', 'module', 'footer');
26 drupal_add_js($path . '/jquery.ba-bbq.js', 'module', 'footer');
27 drupal_add_js($path . '/recipe.js', 'module', 'footer');
28 drupal_add_js($path . '/mkdru.theme.js', 'module', 'footer');
29 drupal_add_js($path . '/mkdru.client.js', 'module', 'footer');
30 $html = theme('mkdru_results');
31 drupal_add_js(array('mkdru' =>
33 'use_sessions' => variable_get('use_sessions', '1'),
34 'pz2_path' => variable_get('pz2_path', '/pazpar2/search.pz2'),
35 'sp_user' => variable_get('sp_user', ''),
36 'sp_pass' => variable_get('sp_pass', ''),
40 return array("content" => $html, "title" => "Meta Search");
44 * Implements hook_perm()
46 function mkdru_perm() {
47 return array('create metasearch interface', 'edit any metasearch interface', 'edit own metasearch interface');
51 * Implements hook_access()
53 function mkdru_access($op, $node, $account) {
55 if ($op == 'create') {
56 // Only users with permission to do so may create this node type.
57 return user_access('create metasearch interface', $account);
60 // Users who create a node may edit or delete it later, assuming they have the
61 // necessary permissions.
62 if ($op == 'update' || $op == 'delete') {
63 if (user_access('edit own metasearch interface', $account) && ($account->uid == $node->uid)) {
66 elseif (user_access('edit any metasearch interface', $account)) {
73 * Implements hook_menu()
75 function mkdru_menu() {
76 $items['admin/settings/mkdru'] = array(
77 'title' => 'mkdru Settings',
78 'description' => 'Settings for mkdru.',
79 'page callback' => 'drupal_get_form',
80 'page arguments' => array('mkdru_admin_settings'),
81 'access arguments' => array('administer site configuration'),
82 'type' => MENU_NORMAL_ITEM,
83 'file' => 'mkdru.admin.inc',
89 * Implements hook_init()
91 function mkdru_init() {
92 // Applies our module specific CSS to all pages. This works best because
93 // all CSS is aggregated and cached so we reduce the number of HTTP
94 // requests and the size is negligible.
95 drupal_add_css(drupal_get_path('module', 'mkdru') .'/mkdru.css');
102 * Implements hook_form()
104 function mkdru_form(&$node, $form_state) {
105 $type = node_get_types('type', $node);
107 $form['title'] = array(
108 '#type' => 'textfield',
109 '#title' => check_plain($type->title_label),
110 '#required' => FALSE,
111 '#default_value' => $node->title,
115 $form['search_settings'] = array(
116 '#type' => 'fieldset',
117 '#title' => t('Pazpar2/Service Proxy search settings'),
118 '#collapsible' => TRUE,
119 '#collapsed' => FALSE
121 $form['search_settings']['pz2_path'] = array(
122 '#type' => 'textfield',
123 '#title' => t('Pazpar2/Service Proxy path'),
124 '#description' => t('Path that takes Pazpar2 commands via HTTP'),
126 '#default_value' => isset($node->mkdru->pz2_path) ? $node->mkdru->pz2_path : '/pazpar2/search.pz2',
128 $form['search_settings']['use_sessions'] = array(
129 '#type' => 'checkbox',
130 '#title' => t('Session handling'),
131 '#description' => t('Disable for use with Service Proxy'),
132 '#default_value' => isset($node->mkdru->use_sessions) ? $node->mkdru->use_sessions : 1,
135 $form['sp_settings'] = array(
136 '#type' => 'fieldset',
137 '#title' => t('Service Proxy specific settings'),
138 '#collapsible' => TRUE,
139 '#collapsed' => FALSE
141 $form['sp_settings']['sp_user'] = array(
142 '#type' => 'textfield',
143 '#title' => t('Service Proxy username'),
144 '#description' => t('Service Proxy username'),
145 '#required' => FALSE,
146 '#default_value' => isset($node->mkdru->sp_user) ?
147 $node->mkdru->sp_user : '',
149 $form['sp_settings']['sp_pass'] = array(
150 '#type' => 'textfield',
151 '#title' => t('Service Proxy password'),
152 '#description' => t('Service Proxy password'),
153 '#required' => FALSE,
154 '#default_value' => isset($node->mkdru->sp_pass) ?
155 $node->mkdru->sp_pass : '',
158 $form['display_settings'] = array(
159 '#type' => 'fieldset',
160 '#title' => t('Display settings'),
161 '#collapsible' => TRUE,
162 '#collapsed' => FALSE
164 $form['display_settings']['source_max'] = array(
165 '#type' => 'textfield',
166 '#title' => t('Number of sources to display'),
168 '#default_value' => isset($node->mkdru->source_max) ? $node->mkdru->source_max : 10,
172 $form['display_settings']['author_max'] = array(
173 '#type' => 'textfield',
174 '#title' => t('Number of authors to display'),
176 '#default_value' => isset($node->mkdru->author_max) ? $node->mkdru->author_max : 10,
180 $form['display_settings']['subject_max'] = array(
181 '#type' => 'textfield',
182 '#title' => t('Number of subjects to display'),
184 '#default_value' => isset($node->mkdru->subject_max) ? $node->mkdru->subject_max : 10,
193 * Implements hook_validate()
195 function mkdru_validate($node) {
196 if (!is_numeric($node->source_max)) {
197 form_set_error('source_max', t('Please enter a number.'));
199 if (!is_numeric($node->author_max)) {
200 form_set_error('author_max', t('Please enter a number.'));
202 if (!is_numeric($node->subject_max)) {
203 form_set_error('subject_max', t('Please enter a number.'));
208 * Implements hook_insert().
210 function mkdru_insert($node) {
211 drupal_write_record('mkdru', $node);
215 * Implements hook_update().
217 function mkdru_update($node) {
218 if ($node->revision) {
219 // New revision; treat it as a new record.
223 drupal_write_record('mkdru', $node, 'vid');
228 * Implements hook_nodeapi().
230 * When a node revision is deleted, we need to remove the corresponding record
231 * from our table. The only way to handle revision deletion is by implementing
234 function mkdru_nodeapi(&$node, $op, $teaser, $page) {
236 case 'delete revision':
237 db_query('DELETE FROM {mkdru} WHERE vid = %d', $node->vid);
243 * Implements hook_delete().
245 function mkdru_delete($node) {
246 // Deleting by nid covers all revisions.
247 db_query('DELETE FROM {mkdru} WHERE nid = %d', $node->nid);
254 * Implements hook_load()
256 function mkdru_load($node) {
257 return array('mkdru' => db_fetch_object(db_query(
258 'SELECT * FROM {mkdru} WHERE vid = %d', $node->vid)));
262 * Implements hook_theme().
264 function mkdru_theme() {
266 'mkdru_form' => array(
267 'template' => 'mkdru-form',
268 'arguments' => array(),
270 'mkdru_results' => array(
271 'template' => 'mkdru-results',
272 'arguments' => array(),
275 'arguments' => array('node' => NULL),
277 'mkdru_block_search' => array(
278 'template' => 'mkdru-block-search',
279 'arguments' => array('nid' => NULL, 'path' => NULL),
281 'mkdru_block_facet' => array(
282 'template' => 'mkdru-block-facet',
283 'arguments' => array('class' => NULL)
289 * Theme function to include Javascript search client and deps
291 function theme_mkdru_js($node) {
292 $path = drupal_get_path('module', 'mkdru');
293 // Pazpar2 client library.
294 drupal_add_js(variable_get('pz2_js_path', 'pazpar2/js') . '/pz2.js', 'module', 'footer', TRUE, TRUE, FALSE);
295 // jQuery plugin for query string/history manipulation.
296 drupal_add_js($path . '/jquery.ba-bbq.js', 'module', 'footer', TRUE, TRUE, FALSE);
297 drupal_add_js($path . '/mkdru.theme.js', 'module', 'footer', TRUE, TRUE, FALSE);
298 drupal_add_js($path . '/mkdru.client.js', 'module', 'footer', TRUE, TRUE, FALSE);
299 drupal_add_js(array('mkdru' => $node->mkdru), 'setting');
303 * Implements hook_view()
305 function mkdru_view($node, $teaser = FALSE, $page = FALSE) {
306 $node->content['mkdru_js'] = array(
307 '#value' => theme('mkdru_js', $node),
310 $node->content['mkdru_form'] = array(
311 '#value' => theme('mkdru_form'),
314 $node->content['mkdru_results'] = array(
315 '#value' => theme('mkdru_results'),
322 * Implements hook_block()
324 function mkdru_block($op='list', $delta='sources', $edit=array()) {
328 // D6 has no setting for note type visibility, set
329 // the default to limit facet display to this type
331 if (arg(0) == "node" && is_numeric(arg(1))) {
332 $node = node_load(array("nid" => arg(1)));
333 return $node->type == "mkdru";
337 // NB: block caching is redundant for static content
338 $blocks['mkdru_sources']['info'] = t('mkdru - source facets');
339 $blocks['mkdru_sources']['cache'] = BLOCK_NO_CACHE;
340 $blocks['mkdru_sources']['visibility'] = 2;
341 $blocks['mkdru_sources']['pages'] = $visPHP;
342 $blocks['mkdru_subjects']['info'] = t('mkdru - subject facets');
343 $blocks['mkdru_subjects']['cache'] = BLOCK_NO_CACHE;
344 $blocks['mkdru_subjects']['visibility'] = 2;
345 $blocks['mkdru_subjects']['pages'] = $visPHP;
346 $blocks['mkdru_authors']['info'] = t('mkdru - author facets');
347 $blocks['mkdru_authors']['cache'] = BLOCK_NO_CACHE;
348 $blocks['mkdru_authors']['visibility'] = 2;
349 $blocks['mkdru_authors']['pages'] = $visPHP;
351 $result = db_query("SELECT title, nid FROM {node} WHERE type = 'mkdru';");
352 while ($node = db_fetch_object($result)) {
353 $blocks['mkdru_search_' . $node->nid]['info'] =
354 t('mkdru - search box for "' . $node->title . '"');
355 $blocks['mkdru_sources']['cache'] = BLOCK_NO_CACHE;
361 case 'mkdru_sources':
362 $block['subject'] = t('Source');
363 $block['content'] = theme('mkdru_block_facet', 'mkdru-facet-source');
365 case 'mkdru_subjects':
366 $block['subject'] = t('Subject');
367 $block['content'] = theme('mkdru_block_facet', 'mkdru-facet-subject');
369 case 'mkdru_authors':
370 $block['subject'] = t('Author');
371 $block['content'] = theme('mkdru_block_facet', 'mkdru-facet-author');
374 if (substr($delta, 0, 13) == 'mkdru_search_') {
375 $nid = substr($delta, 13);
376 $block['content'] = theme('mkdru_block_search', $nid, '/node/' . $nid);