8 * Implementation of hook_node_info().
10 function mkdru_node_info() {
13 'name' => t("Z39.50/SRU metasearch interface"),
15 'description' => t("Metasearch interface for Z39.50/SRU and other targets via a Pazpar2/Service Proxy backend"),
22 * Implementation of hook_perm().
24 function mkdru_perm() {
25 return array('create metasearch interface', 'edit any metasearch interface', 'edit own metasearch interface');
29 * Implementation of hook_access().
31 function mkdru_access($op, $node, $account) {
33 if ($op == 'create') {
34 // Only users with permission to do so may create this node type.
35 return user_access('create metasearch interface', $account);
38 // Users who create a node may edit or delete it later, assuming they have the
39 // necessary permissions.
40 if ($op == 'update' || $op == 'delete') {
41 if (user_access('edit own metasearch interface', $account) && ($account->uid == $node->uid)) {
44 elseif (user_access('edit any metasearch interface', $account)) {
54 * Implementation of hook_form().
56 function mkdru_form(&$node, $form_state) {
57 $type = node_get_types('type', $node);
59 $form['title'] = array(
60 '#type' => 'textfield',
61 '#title' => check_plain($type->title_label),
63 '#default_value' => $node->title,
67 $form['search_settings'] = array(
68 '#type' => 'fieldset',
69 '#title' => t('Pazpar2/Service Proxy search settings'),
70 '#collapsible' => TRUE,
73 $form['search_settings']['pz2_path'] = array(
74 '#type' => 'textfield',
75 '#title' => t('Pazpar2/Service Proxy path'),
76 '#description' => t('Path that takes Pazpar2 commands via HTTP'),
78 '#default_value' => isset($node->mkdru->pz2_path) ? $node->mkdru->pz2_path : '/pazpar2/search.pz2',
80 $form['search_settings']['use_sessions'] = array(
81 '#type' => 'checkbox',
82 '#title' => t('Session handling'),
83 '#description' => t('Disable for use with Service Proxy'),
84 '#default_value' => isset($node->mkdru->use_sessions) ? $node->mkdru->use_sessions : 1,
87 $form['display_settings'] = array(
88 '#type' => 'fieldset',
89 '#title' => t('Display settings'),
90 '#collapsible' => TRUE,
93 $form['display_settings']['source_max'] = array(
94 '#type' => 'textfield',
95 '#title' => t('Number of sources to display'),
97 '#default_value' => isset($node->mkdru->source_max) ? $node->mkdru->source_max : 10,
101 $form['display_settings']['author_max'] = array(
102 '#type' => 'textfield',
103 '#title' => t('Number of authors to display'),
105 '#default_value' => isset($node->mkdru->author_max) ? $node->mkdru->author_max : 10,
109 $form['display_settings']['subject_max'] = array(
110 '#type' => 'textfield',
111 '#title' => t('Number of subjects to display'),
113 '#default_value' => isset($node->mkdru->subject_max) ? $node->mkdru->subject_max : 10,
122 * Implementation of hook_validate()
124 function mkdru_validate($node) {
125 if (!is_numeric($node->source_max)) {
126 form_set_error('source_max', t('Please enter a number.'));
128 if (!is_numeric($node->author_max)) {
129 form_set_error('author_max', t('Please enter a number.'));
131 if (!is_numeric($node->subject_max)) {
132 form_set_error('subject_max', t('Please enter a number.'));
137 * Implementation of hook_insert().
139 function mkdru_insert($node) {
140 db_query("INSERT INTO {mkdru} (nid, vid, pz2_path, use_sessions, source_max, author_max, subject_max) VALUES (%d, %d, '%s', %d, %d, %d)",
141 $node->nid, $node->vid, $node->pz2_path, $node->use_sessions, $node->source_max, $node->author_max, $node->subject_max);
145 * Implementation of hook_update().
147 function mkdru_update($node) {
148 if ($node->revision) {
149 // New revision; treat it as a new record.
153 db_query("UPDATE {mkdru} SET pz2_path = '%s', use_sessions = %d, source_max = %d, author_max = %d, subject_max = %d WHERE vid = %d", $node->pz2_path, $node->use_sessions, $node->source_max, $node->author_max, $node->subject_max, $node->vid);
158 * Implementation of hook_nodeapi().
160 * When a node revision is deleted, we need to remove the corresponding record
161 * from our table. The only way to handle revision deletion is by implementing
164 function mkdru_nodeapi(&$node, $op, $teaser, $page) {
166 case 'delete revision':
167 db_query('DELETE FROM {mkdru} WHERE vid = %d', $node->vid);
173 * Implementation of hook_delete().
175 * When a node is deleted, we need to remove all related records from our table.
177 function mkdru_delete($node) {
178 // Deleting by nid covers all revisions.
179 db_query('DELETE FROM {mkdru} WHERE nid = %d', $node->nid);
186 * Implementation of hook_load()
188 function mkdru_load($node) {
189 return array('mkdru' => db_fetch_object(db_query(
190 'SELECT * FROM {mkdru} WHERE vid = %d', $node->vid)));
194 * Implementation of hook_theme().
196 function mkdru_theme() {
198 'mkdru_page' => array(
199 'template' => 'mkdru-page',
200 'arguments' => array(),
202 'mkdru_page_js' => array(
203 'arguments' => array('node' => NULL),
205 // 'mkdru_block_facet' => array(
206 // 'template' => 'mkdru-block-facet',
207 // 'arguments' => array('divId' => NULL),
213 * Theme function to include Javascript search client and deps
215 function theme_mkdru_page_js($node) {
216 $path = drupal_get_path('module', 'mkdru');
217 drupal_add_js('pazpar2/js/pz2.js', 'module', 'footer');
218 drupal_add_js($path . '/mkdru.theme.js', 'module', 'footer');
219 drupal_add_js($path . '/mkdru.client.js', 'module', 'footer');
220 drupal_add_js(array('mkdru' => $node->mkdru), 'setting');
224 * Implementation of hook_view()
226 function mkdru_view($node, $teaser = FALSE, $page = FALSE) {
227 $node->content['mkdru_page_js'] = array(
228 '#value' => theme('mkdru_page_js', $node),
231 $node->content['mkdru_page'] = array(
232 '#value' => theme('mkdru_page'),
239 * Implementation of hook_block()
241 function mkdru_block($op='list', $delta='sources', $edit=array()) {
244 $blocks['mkdru_sources']['info'] = t('mkdru - source facets');
245 $blocks['mkdru_sources']['cache'] = BLOCK_NO_CACHE;
246 $blocks['mkdru_subjects']['info'] = t('mkdru - subject facets');
247 $blocks['mkdru_subjects']['cache'] = BLOCK_NO_CACHE;
248 $blocks['mkdru_authors']['info'] = t('mkdru - author facets');
249 $blocks['mkdru_authors']['cache'] = BLOCK_NO_CACHE;
254 // TODO: make the facet themable, I have no clue why this won't work
255 // case 'mkdru_sources':
256 // $block['subject'] = t('Source');
257 // $block['content'] = theme('mkdru_block_facet', 'mkdru-sources');
259 // case 'mkdru_subjects':
260 // $block['subject'] = t('Subject');
261 // $block['content'] = theme('mkdru_block_facet', 'mkdru-subjects');
263 // case 'mkdru_authors':
264 // $block['subject'] = t('Author');
265 // $block['content'] = theme('mkdru_block_facet', 'mkdru-authors');
267 case 'mkdru_sources':
268 $block['subject'] = t('Source');
269 $block['content'] = '<div id="mkdru-sources"> </div>';
271 case 'mkdru_subjects':
272 $block['subject'] = t('Subject');
273 $block['content'] = '<div id="mkdru-subjects"> </div>';
275 case 'mkdru_authors':
276 $block['subject'] = t('Author');
277 $block['content'] = '<div id="mkdru-authors"> </div>';