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' =>
31 'use_sessions' => variable_get('use_sessions', '1'),
32 'pz2_path' => variable_get('pz2_path', '/pazpar2/search.pz2'),
33 'sp_user' => variable_get('sp_user', ''),
34 'sp_pass' => variable_get('sp_pass', ''),
35 'query' => $params['keys']
38 return array("content" => $html);
42 * Implements hook_perm()
44 function mkdru_perm() {
45 return array('create metasearch interface', 'edit any metasearch interface', 'edit own metasearch interface');
49 * Implements hook_access()
51 function mkdru_access($op, $node, $account) {
53 if ($op == 'create') {
54 // Only users with permission to do so may create this node type.
55 return user_access('create metasearch interface', $account);
58 // Users who create a node may edit or delete it later, assuming they have the
59 // necessary permissions.
60 if ($op == 'update' || $op == 'delete') {
61 if (user_access('edit own metasearch interface', $account) && ($account->uid == $node->uid)) {
64 elseif (user_access('edit any metasearch interface', $account)) {
71 * Implements hook_menu()
73 function mkdru_menu() {
74 $items['admin/settings/mkdru'] = array(
75 'title' => 'mkdru Settings',
76 'description' => 'Settings for mkdru.',
77 'page callback' => 'drupal_get_form',
78 'page arguments' => array('mkdru_admin_settings'),
79 'access arguments' => array('administer site configuration'),
80 'type' => MENU_NORMAL_ITEM,
81 'file' => 'mkdru.admin.inc',
87 * Implements hook_init()
89 function mkdru_init() {
90 // Applies our module specific CSS to all pages. This works best because
91 // all CSS is aggregated and cached so we reduce the number of HTTP
92 // requests and the size is negligible.
93 drupal_add_css(drupal_get_path('module', 'mkdru') .'/mkdru.css');
100 * Implements hook_form()
102 function mkdru_form(&$node, $form_state) {
103 $type = node_get_types('type', $node);
105 $form['title'] = array(
106 '#type' => 'textfield',
107 '#title' => check_plain($type->title_label),
108 '#required' => FALSE,
109 '#default_value' => $node->title,
113 $form['search_settings'] = array(
114 '#type' => 'fieldset',
115 '#title' => t('Pazpar2/Service Proxy search settings'),
116 '#collapsible' => TRUE,
117 '#collapsed' => FALSE
119 $form['search_settings']['pz2_path'] = array(
120 '#type' => 'textfield',
121 '#title' => t('Pazpar2/Service Proxy path'),
122 '#description' => t('Path that takes Pazpar2 commands via HTTP'),
124 '#default_value' => isset($node->mkdru->pz2_path) ? $node->mkdru->pz2_path : '/pazpar2/search.pz2',
126 $form['search_settings']['use_sessions'] = array(
127 '#type' => 'checkbox',
128 '#title' => t('Session handling'),
129 '#description' => t('Disable for use with Service Proxy'),
130 '#default_value' => isset($node->mkdru->use_sessions) ? $node->mkdru->use_sessions : 1,
133 $form['sp_settings'] = array(
134 '#type' => 'fieldset',
135 '#title' => t('Service Proxy specific settings'),
136 '#collapsible' => TRUE,
137 '#collapsed' => FALSE
139 $form['sp_settings']['sp_user'] = array(
140 '#type' => 'textfield',
141 '#title' => t('Service Proxy username'),
142 '#description' => t('Service Proxy username'),
143 '#required' => FALSE,
144 '#default_value' => isset($node->mkdru->sp_user) ?
145 $node->mkdru->sp_user : '',
147 $form['sp_settings']['sp_pass'] = array(
148 '#type' => 'textfield',
149 '#title' => t('Service Proxy password'),
150 '#description' => t('Service Proxy password'),
151 '#required' => FALSE,
152 '#default_value' => isset($node->mkdru->sp_pass) ?
153 $node->mkdru->sp_pass : '',
156 $form['display_settings'] = array(
157 '#type' => 'fieldset',
158 '#title' => t('Display settings'),
159 '#collapsible' => TRUE,
160 '#collapsed' => FALSE
162 $form['display_settings']['source_max'] = array(
163 '#type' => 'textfield',
164 '#title' => t('Number of sources to display'),
166 '#default_value' => isset($node->mkdru->source_max) ? $node->mkdru->source_max : 10,
170 $form['display_settings']['author_max'] = array(
171 '#type' => 'textfield',
172 '#title' => t('Number of authors to display'),
174 '#default_value' => isset($node->mkdru->author_max) ? $node->mkdru->author_max : 10,
178 $form['display_settings']['subject_max'] = array(
179 '#type' => 'textfield',
180 '#title' => t('Number of subjects to display'),
182 '#default_value' => isset($node->mkdru->subject_max) ? $node->mkdru->subject_max : 10,
191 * Implements hook_validate()
193 function mkdru_validate($node) {
194 if (!is_numeric($node->source_max)) {
195 form_set_error('source_max', t('Please enter a number.'));
197 if (!is_numeric($node->author_max)) {
198 form_set_error('author_max', t('Please enter a number.'));
200 if (!is_numeric($node->subject_max)) {
201 form_set_error('subject_max', t('Please enter a number.'));
206 * Implements hook_insert().
208 function mkdru_insert($node) {
209 drupal_write_record('mkdru', $node);
213 * Implements hook_update().
215 function mkdru_update($node) {
216 if ($node->revision) {
217 // New revision; treat it as a new record.
221 drupal_write_record('mkdru', $node, 'vid');
226 * Implements hook_nodeapi().
228 * When a node revision is deleted, we need to remove the corresponding record
229 * from our table. The only way to handle revision deletion is by implementing
232 function mkdru_nodeapi(&$node, $op, $teaser, $page) {
234 case 'delete revision':
235 db_query('DELETE FROM {mkdru} WHERE vid = %d', $node->vid);
241 * Implements hook_delete().
243 function mkdru_delete($node) {
244 // Deleting by nid covers all revisions.
245 db_query('DELETE FROM {mkdru} WHERE nid = %d', $node->nid);
252 * Implements hook_load()
254 function mkdru_load($node) {
255 return array('mkdru' => db_fetch_object(db_query(
256 'SELECT * FROM {mkdru} WHERE vid = %d', $node->vid)));
260 * Implements hook_theme().
262 function mkdru_theme() {
264 'mkdru_form' => array(
265 'template' => 'mkdru-form',
266 'arguments' => array(),
268 'mkdru_results' => array(
269 'template' => 'mkdru-results',
270 'arguments' => array(),
273 'arguments' => array('node' => NULL),
275 'mkdru_block_search' => array(
276 'template' => 'mkdru-block-search',
277 'arguments' => array('nid' => NULL, 'path' => NULL),
279 'mkdru_block_facet' => array(
280 'template' => 'mkdru-block-facet',
281 'arguments' => array('class' => NULL)
287 * Theme function to include Javascript search client and deps
289 function theme_mkdru_js($node) {
290 $path = drupal_get_path('module', 'mkdru');
291 // Pazpar2 client library.
292 drupal_add_js(variable_get('pz2_js_path', 'pazpar2/js') . '/pz2.js', 'module', 'footer', TRUE, TRUE, FALSE);
293 // jQuery plugin for query string/history manipulation.
294 drupal_add_js($path . '/jquery.ba-bbq.js', 'module', 'footer', TRUE, TRUE, FALSE);
295 drupal_add_js($path . '/mkdru.theme.js', 'module', 'footer', TRUE, TRUE, FALSE);
296 drupal_add_js($path . '/mkdru.client.js', 'module', 'footer', TRUE, TRUE, FALSE);
297 drupal_add_js(array('mkdru' => $node->mkdru), 'setting');
301 * Implements hook_view()
303 function mkdru_view($node, $teaser = FALSE, $page = FALSE) {
304 $node->content['mkdru_js'] = array(
305 '#value' => theme('mkdru_js', $node),
308 $node->content['mkdru_form'] = array(
309 '#value' => theme('mkdru_form'),
312 $node->content['mkdru_results'] = array(
313 '#value' => theme('mkdru_results'),
320 * Implements hook_block()
322 function mkdru_block($op='list', $delta='sources', $edit=array()) {
326 // D6 has no setting for note type visibility, set
327 // the default to limit facet display to this type
329 if (arg(0) == "node" && is_numeric(arg(1))) {
330 $node = node_load(array("nid" => arg(1)));
331 return $node->type == "mkdru";
335 // NB: block caching is redundant for static content
336 $blocks['mkdru_sources']['info'] = t('mkdru - source facets');
337 $blocks['mkdru_sources']['cache'] = BLOCK_NO_CACHE;
338 $blocks['mkdru_sources']['visibility'] = 2;
339 $blocks['mkdru_sources']['pages'] = $visPHP;
340 $blocks['mkdru_subjects']['info'] = t('mkdru - subject facets');
341 $blocks['mkdru_subjects']['cache'] = BLOCK_NO_CACHE;
342 $blocks['mkdru_subjects']['visibility'] = 2;
343 $blocks['mkdru_subjects']['pages'] = $visPHP;
344 $blocks['mkdru_authors']['info'] = t('mkdru - author facets');
345 $blocks['mkdru_authors']['cache'] = BLOCK_NO_CACHE;
346 $blocks['mkdru_authors']['visibility'] = 2;
347 $blocks['mkdru_authors']['pages'] = $visPHP;
349 $result = db_query("SELECT title, nid FROM {node} WHERE type = 'mkdru';");
350 while ($node = db_fetch_object($result)) {
351 $blocks['mkdru_search_' . $node->nid]['info'] =
352 t('mkdru - search box for "' . $node->title . '"');
353 $blocks['mkdru_sources']['cache'] = BLOCK_NO_CACHE;
359 case 'mkdru_sources':
360 $block['subject'] = t('Source');
361 $block['content'] = theme('mkdru_block_facet', 'mkdru-facet-source');
363 case 'mkdru_subjects':
364 $block['subject'] = t('Subject');
365 $block['content'] = theme('mkdru_block_facet', 'mkdru-facet-subject');
367 case 'mkdru_authors':
368 $block['subject'] = t('Author');
369 $block['content'] = theme('mkdru_block_facet', 'mkdru-facet-author');
372 if (substr($delta, 0, 13) == 'mkdru_search_') {
373 $nid = substr($delta, 13);
374 $block['content'] = theme('mkdru_block_search', $nid, '/node/' . $nid);