4 * Implementation of hook_node_info().
6 function mkdru_node_info() {
9 'name' => t("Z39.50/SRU metasearch interface"),
11 'description' => t("Metasearch interface for Z39.50/SRU and other targets via a Pazpar2/Service Proxy backend"),
18 * Implementation of hook_perm().
20 function mkdru_perm() {
21 return array('create metasearch interface', 'edit any metasearch interface', 'edit own metasearch interface');
25 * Implementation of hook_access().
27 function mkdru_access($op, $node, $account) {
29 if ($op == 'create') {
30 // Only users with permission to do so may create this node type.
31 return user_access('create metasearch interface', $account);
34 // Users who create a node may edit or delete it later, assuming they have the
35 // necessary permissions.
36 if ($op == 'update' || $op == 'delete') {
37 if (user_access('edit own metasearch interface', $account) && ($account->uid == $node->uid)) {
40 elseif (user_access('edit any metasearch interface', $account)) {
50 * Implementation of hook_form().
52 function mkdru_form(&$node, $form_state) {
53 $type = node_get_types('type', $node);
55 $form['title'] = array(
56 '#type' => 'textfield',
57 '#title' => check_plain($type->title_label),
59 '#default_value' => $node->title,
62 $form['pz2_path'] = array(
63 '#type' => 'textfield',
64 '#title' => t('Pazpar2/Service Proxy path'),
65 '#description' => t('Absolute URL path without leading slash'),
67 '#default_value' => isset($node->pz2_path) ? $node->pz2_path : 'pazpar2',
74 * Implementation of hook_insert().
76 function mkdru_insert($node) {
77 db_query("INSERT INTO {mkdru} (nid, vid, pz2_path) VALUES (%d, %d, '%s')",
78 $node->nid, $node->vid, $node->pz2_path);
82 * Implementation of hook_update().
84 function mkdru_update($node) {
85 if ($node->revision) {
86 // New revision; treat it as a new record.
90 db_query("UPDATE {mkdru} SET pz2_path = '%s' WHERE vid = '%d'", $node->pz2_path, $node->vid);
95 * Implementation of hook_nodeapi().
97 * When a node revision is deleted, we need to remove the corresponding record
98 * from our table. The only way to handle revision deletion is by implementing
101 function node_example_nodeapi(&$node, $op, $teaser, $page) {
103 case 'delete revision':
104 // Notice that we're matching a single revision based on the node's vid.
105 db_query('DELETE FROM {mkdru} WHERE vid = %d', $node->vid);
111 * Implementation of hook_delete().
113 * When a node is deleted, we need to remove all related records from our table.
115 function node_example_delete($node) {
116 // Deleting by nid covers all revisions.
117 db_query('DELETE FROM {mkdru} WHERE nid = %d', $node->nid);
124 * Implementation of hook_load()
126 function mkdru_load($node) {
127 return db_fetch_object(db_query('SELECT pz2_path FROM {mkdru} WHERE vid = %d', $node->vid));
131 * Implementation of hook_theme().
133 function mkdru_theme() {
135 'mkdru_page' => array(
136 'template' => 'mkdru-page',
137 'arguments' => array(),
139 'mkdru_page_js' => array(
140 'arguments' => array(),
142 // 'mkdru_block_facet' => array(
143 // 'template' => 'mkdru-block-facet',
144 // 'arguments' => array('divId' => NULL),
150 * Theme function to include Javascript search client and deps
152 function theme_mkdru_page_js() {
153 $path = drupal_get_path('module', 'mkdru');
154 drupal_add_js('pazpar2/js/pz2.js', 'module', 'footer');
155 drupal_add_js($path . '/mkdru.theme.js', 'module', 'footer');
156 drupal_add_js($path . '/mkdru.client.js', 'module', 'footer');
160 * Implementation of hook_view()
162 function mkdru_view($node, $teaser = FALSE, $page = FALSE) {
163 $node->content['mkdru_page_js'] = array(
164 '#value' => theme('mkdru_page_js'),
167 $node->content['mkdru_page'] = array(
168 '#value' => theme('mkdru_page'),
175 * Implementation of hook_block()
177 function mkdru_block($op='list', $delta='sources', $edit=array()) {
180 $blocks['mkdru_sources']['info'] = t('mkdru - source facets');
181 $blocks['mkdru_sources']['cache'] = BLOCK_NO_CACHE;
182 $blocks['mkdru_subjects']['info'] = t('mkdru - subject facets');
183 $blocks['mkdru_subjects']['cache'] = BLOCK_NO_CACHE;
184 $blocks['mkdru_authors']['info'] = t('mkdru - author facets');
185 $blocks['mkdru_authors']['cache'] = BLOCK_NO_CACHE;
190 // TODO: make the facet themable, I have no clue why this won't work
191 // case 'mkdru_sources':
192 // $block['subject'] = t('Source');
193 // $block['content'] = theme('mkdru_block_facet', 'mkdru-sources');
195 // case 'mkdru_subjects':
196 // $block['subject'] = t('Subject');
197 // $block['content'] = theme('mkdru_block_facet', 'mkdru-subjects');
199 // case 'mkdru_authors':
200 // $block['subject'] = t('Author');
201 // $block['content'] = theme('mkdru_block_facet', 'mkdru-authors');
203 case 'mkdru_sources':
204 $block['subject'] = t('Source');
205 $block['content'] = '<div id="mkdru-sources"> </div>';
207 case 'mkdru_subjects':
208 $block['subject'] = t('Subject');
209 $block['content'] = '<div id="mkdru-subjects"> </div>';
211 case 'mkdru_authors':
212 $block['subject'] = t('Author');
213 $block['content'] = '<div id="mkdru-authors"> </div>';