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"),
21 * Implementation of hook_perm()
23 function mkdru_perm() {
24 return array('create metasearch interface', 'edit any metasearch interface', 'edit own metasearch interface');
28 * Implementation of hook_access()
30 function mkdru_access($op, $node, $account) {
32 if ($op == 'create') {
33 // Only users with permission to do so may create this node type.
34 return user_access('create metasearch interface', $account);
37 // Users who create a node may edit or delete it later, assuming they have the
38 // necessary permissions.
39 if ($op == 'update' || $op == 'delete') {
40 if (user_access('edit own metasearch interface', $account) && ($account->uid == $node->uid)) {
43 elseif (user_access('edit any metasearch interface', $account)) {
50 * Implementation of hook_menu()
52 function mkdru_menu() {
53 $items['admin/settings/mkdru'] = array(
54 'title' => 'mkdru Settings',
55 'description' => 'Settings for mkdru.',
56 'page callback' => 'drupal_get_form',
57 'page arguments' => array('mkdru_admin_settings'),
58 'access arguments' => array('administer site configuration'),
59 'type' => MENU_NORMAL_ITEM,
60 'file' => 'mkdru.admin.inc',
66 * Implementation of hook_init()
68 function mkdru_init(){
69 // Applies our module specific CSS to all pages. This works best because
70 // all CSS is aggregated and cached so we reduce the number of HTTP
71 // requests and the size is negligible.
72 drupal_add_css(drupal_get_path('module', 'mkdru') .'/mkdru.css');
79 * Implementation of hook_form()
81 function mkdru_form(&$node, $form_state) {
82 $type = node_get_types('type', $node);
84 $form['title'] = array(
85 '#type' => 'textfield',
86 '#title' => check_plain($type->title_label),
88 '#default_value' => $node->title,
92 $form['search_settings'] = array(
93 '#type' => 'fieldset',
94 '#title' => t('Pazpar2/Service Proxy search settings'),
95 '#collapsible' => TRUE,
98 $form['search_settings']['pz2_path'] = array(
99 '#type' => 'textfield',
100 '#title' => t('Pazpar2/Service Proxy path'),
101 '#description' => t('Path that takes Pazpar2 commands via HTTP'),
103 '#default_value' => isset($node->mkdru->pz2_path) ? $node->mkdru->pz2_path : '/pazpar2/search.pz2',
105 $form['search_settings']['use_sessions'] = array(
106 '#type' => 'checkbox',
107 '#title' => t('Session handling'),
108 '#description' => t('Disable for use with Service Proxy'),
109 '#default_value' => isset($node->mkdru->use_sessions) ? $node->mkdru->use_sessions : 1,
112 $form['display_settings'] = array(
113 '#type' => 'fieldset',
114 '#title' => t('Display settings'),
115 '#collapsible' => TRUE,
116 '#collapsed' => FALSE
118 $form['display_settings']['source_max'] = array(
119 '#type' => 'textfield',
120 '#title' => t('Number of sources to display'),
122 '#default_value' => isset($node->mkdru->source_max) ? $node->mkdru->source_max : 10,
126 $form['display_settings']['author_max'] = array(
127 '#type' => 'textfield',
128 '#title' => t('Number of authors to display'),
130 '#default_value' => isset($node->mkdru->author_max) ? $node->mkdru->author_max : 10,
134 $form['display_settings']['subject_max'] = array(
135 '#type' => 'textfield',
136 '#title' => t('Number of subjects to display'),
138 '#default_value' => isset($node->mkdru->subject_max) ? $node->mkdru->subject_max : 10,
147 * Implementation of hook_validate()
149 function mkdru_validate($node) {
150 if (!is_numeric($node->source_max)) {
151 form_set_error('source_max', t('Please enter a number.'));
153 if (!is_numeric($node->author_max)) {
154 form_set_error('author_max', t('Please enter a number.'));
156 if (!is_numeric($node->subject_max)) {
157 form_set_error('subject_max', t('Please enter a number.'));
162 * Implementation of hook_insert().
164 function mkdru_insert($node) {
165 db_query("INSERT INTO {mkdru} (nid, vid, pz2_path, use_sessions, source_max, author_max, subject_max) VALUES (%d, %d, '%s', %d, %d, %d, %d)",
166 $node->nid, $node->vid, $node->pz2_path, $node->use_sessions, $node->source_max, $node->author_max, $node->subject_max);
170 * Implementation of hook_update().
172 function mkdru_update($node) {
173 if ($node->revision) {
174 // New revision; treat it as a new record.
178 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);
183 * Implementation of hook_nodeapi().
185 * When a node revision is deleted, we need to remove the corresponding record
186 * from our table. The only way to handle revision deletion is by implementing
189 function mkdru_nodeapi(&$node, $op, $teaser, $page) {
191 case 'delete revision':
192 db_query('DELETE FROM {mkdru} WHERE vid = %d', $node->vid);
198 * Implementation of hook_delete().
200 function mkdru_delete($node) {
201 // Deleting by nid covers all revisions.
202 db_query('DELETE FROM {mkdru} WHERE nid = %d', $node->nid);
209 * Implementation of hook_load()
211 function mkdru_load($node) {
212 return array('mkdru' => db_fetch_object(db_query(
213 'SELECT * FROM {mkdru} WHERE vid = %d', $node->vid)));
217 * Implementation of hook_theme().
219 function mkdru_theme() {
221 'mkdru_form' => array(
222 'template' => 'mkdru-form',
223 'arguments' => array(),
225 'mkdru_results' => array(
226 'template' => 'mkdru-results',
227 'arguments' => array(),
230 'arguments' => array('node' => NULL),
232 // 'mkdru_block_facet' => array(
233 // 'template' => 'mkdru-block-facet',
234 // 'arguments' => array('divId' => NULL),
240 * Theme function to include Javascript search client and deps
242 function theme_mkdru_js($node) {
243 $path = drupal_get_path('module', 'mkdru');
244 // Include client library.
245 drupal_add_js(variable_get('pz2_js_path', 'pazpar2/js') . '/pz2.js', 'module', 'footer');
246 drupal_add_js($path . '/mkdru.theme.js', 'module', 'footer');
247 drupal_add_js($path . '/mkdru.client.js', 'module', 'footer');
248 drupal_add_js(array('mkdru' => $node->mkdru), 'setting');
252 * Implementation of hook_view()
254 function mkdru_view($node, $teaser = FALSE, $page = FALSE) {
255 $node->content['mkdru_js'] = array(
256 '#value' => theme('mkdru_js', $node),
259 $node->content['mkdru_form'] = array(
260 '#value' => theme('mkdru_form'),
263 $node->content['mkdru_results'] = array(
264 '#value' => theme('mkdru_results'),
271 * Implementation of hook_block()
273 function mkdru_block($op='list', $delta='sources', $edit=array()) {
276 $blocks['mkdru_sources']['info'] = t('mkdru - source facets');
277 $blocks['mkdru_sources']['cache'] = BLOCK_NO_CACHE;
278 $blocks['mkdru_subjects']['info'] = t('mkdru - subject facets');
279 $blocks['mkdru_subjects']['cache'] = BLOCK_NO_CACHE;
280 $blocks['mkdru_authors']['info'] = t('mkdru - author facets');
281 $blocks['mkdru_authors']['cache'] = BLOCK_NO_CACHE;
286 // TODO: make the facet themable, I have no clue why this won't work
287 // case 'mkdru_sources':
288 // $block['subject'] = t('Source');
289 // $block['content'] = theme('mkdru_block_facet', 'mkdru-sources');
291 // case 'mkdru_subjects':
292 // $block['subject'] = t('Subject');
293 // $block['content'] = theme('mkdru_block_facet', 'mkdru-subjects');
295 // case 'mkdru_authors':
296 // $block['subject'] = t('Author');
297 // $block['content'] = theme('mkdru_block_facet', 'mkdru-authors');
299 case 'mkdru_sources':
300 $block['subject'] = t('Source');
301 $block['content'] = '<div class="mkdru-facet mkdru-facet-sources"> </div>';
303 case 'mkdru_subjects':
304 $block['subject'] = t('Subject');
305 $block['content'] = '<div class="mkdru-facet mkdru-facet-subjects"> </div>';
307 case 'mkdru_authors':
308 $block['subject'] = t('Author');
309 $block['content'] = '<div class="mkdru-facet mkdru-facet-authors"> </div>';