array( 'name' => t("Z39.50/SRU metasearch interface"), 'module' => 'mkdru', 'description' => t("Metasearch interface for Z39.50/SRU and other targets via a Pazpar2/Service Proxy backend"), ) ); } /** * Implementation of hook_perm(). */ function mkdru_perm() { return array('create metasearch interface', 'edit any metasearch interface', 'edit own metasearch interface'); } /** * Implementation of hook_access(). */ function mkdru_access($op, $node, $account) { if ($op == 'create') { // Only users with permission to do so may create this node type. return user_access('create metasearch interface', $account); } // Users who create a node may edit or delete it later, assuming they have the // necessary permissions. if ($op == 'update' || $op == 'delete') { if (user_access('edit own metasearch interface', $account) && ($account->uid == $node->uid)) { return TRUE; } elseif (user_access('edit any metasearch interface', $account)) { return TRUE; } } } // Node config /** * Implementation of 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, '#default_value' => $node->title, '#weight' => -5 ); $form['pz2_path'] = array( '#type' => 'textfield', '#title' => t('Pazpar2/Service Proxy path'), '#description' => t('Absolute URL path without leading slash'), '#required' => TRUE, '#default_value' => isset($node->pz2_path) ? $node->pz2_path : 'pazpar2', '#weight' => 0 ); return $form; } /** * Implementation of 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); } /** * Implementation of hook_update(). */ function mkdru_update($node) { if ($node->revision) { // New revision; treat it as a new record. mkdru_insert($node); } else { db_query("UPDATE {mkdru} SET pz2_path = '%s' WHERE vid = '%d'", $node->pz2_path, $node->vid); } } /** * Implementation of 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) { 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. */ function node_example_delete($node) { // Deleting by nid covers all revisions. db_query('DELETE FROM {mkdru} WHERE nid = %d', $node->nid); } // Node rendering /** * Implementation of hook_load() */ function mkdru_load($node) { return db_fetch_object(db_query('SELECT pz2_path FROM {mkdru} WHERE vid = %d', $node->vid)); } /** * Implementation of hook_theme(). */ function mkdru_theme() { return array( 'mkdru_page' => array( 'template' => 'mkdru-page', 'arguments' => array(), ), 'mkdru_page_js' => array( 'arguments' => array(), ), // 'mkdru_block_facet' => array( // 'template' => 'mkdru-block-facet', // 'arguments' => array('divId' => NULL), // ), ); } /** * Theme function to include Javascript search client and deps */ function theme_mkdru_page_js() { $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'); } /** * Implementation of hook_view() */ function mkdru_view($node, $teaser = FALSE, $page = FALSE) { $node->content['mkdru_page_js'] = array( '#value' => theme('mkdru_page_js'), '#weight' => 0, ); $node->content['mkdru_page'] = array( '#value' => theme('mkdru_page'), '#weight' => 1, ); return $node; } /** * Implementation of hook_block() */ function mkdru_block($op='list', $delta='sources', $edit=array()) { switch ($op) { case 'list': $blocks['mkdru_sources']['info'] = t('mkdru - source facets'); $blocks['mkdru_sources']['cache'] = BLOCK_NO_CACHE; $blocks['mkdru_subjects']['info'] = t('mkdru - subject facets'); $blocks['mkdru_subjects']['cache'] = BLOCK_NO_CACHE; $blocks['mkdru_authors']['info'] = t('mkdru - author facets'); $blocks['mkdru_authors']['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'] = '
'; return $block; case 'mkdru_subjects': $block['subject'] = t('Subject'); $block['content'] = '
'; return $block; case 'mkdru_authors': $block['subject'] = t('Author'); $block['content'] = '
'; return $block; } } }