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"),
20 function mkdru_ting_search_show($params) {
21 return array("content" => "You have searched for '".$params['keys']."'.");
25 * Implementation of hook_perm()
27 function mkdru_perm() {
28 return array('create metasearch interface', 'edit any metasearch interface', 'edit own metasearch interface');
32 * Implementation of hook_access()
34 function mkdru_access($op, $node, $account) {
36 if ($op == 'create') {
37 // Only users with permission to do so may create this node type.
38 return user_access('create metasearch interface', $account);
41 // Users who create a node may edit or delete it later, assuming they have the
42 // necessary permissions.
43 if ($op == 'update' || $op == 'delete') {
44 if (user_access('edit own metasearch interface', $account) && ($account->uid == $node->uid)) {
47 elseif (user_access('edit any metasearch interface', $account)) {
54 * Implementation of hook_menu()
56 function mkdru_menu() {
57 $items['admin/settings/mkdru'] = array(
58 'title' => 'mkdru Settings',
59 'description' => 'Settings for mkdru.',
60 'page callback' => 'drupal_get_form',
61 'page arguments' => array('mkdru_admin_settings'),
62 'access arguments' => array('administer site configuration'),
63 'type' => MENU_NORMAL_ITEM,
64 'file' => 'mkdru.admin.inc',
70 * Implementation of hook_init()
72 function mkdru_init(){
73 // Applies our module specific CSS to all pages. This works best because
74 // all CSS is aggregated and cached so we reduce the number of HTTP
75 // requests and the size is negligible.
76 drupal_add_css(drupal_get_path('module', 'mkdru') .'/mkdru.css');
83 * Implementation of hook_form()
85 function mkdru_form(&$node, $form_state) {
86 $type = node_get_types('type', $node);
88 $form['title'] = array(
89 '#type' => 'textfield',
90 '#title' => check_plain($type->title_label),
92 '#default_value' => $node->title,
96 $form['search_settings'] = array(
97 '#type' => 'fieldset',
98 '#title' => t('Pazpar2/Service Proxy search settings'),
99 '#collapsible' => TRUE,
100 '#collapsed' => FALSE
102 $form['search_settings']['pz2_path'] = array(
103 '#type' => 'textfield',
104 '#title' => t('Pazpar2/Service Proxy path'),
105 '#description' => t('Path that takes Pazpar2 commands via HTTP'),
107 '#default_value' => isset($node->mkdru->pz2_path) ? $node->mkdru->pz2_path : '/pazpar2/search.pz2',
109 $form['search_settings']['use_sessions'] = array(
110 '#type' => 'checkbox',
111 '#title' => t('Session handling'),
112 '#description' => t('Disable for use with Service Proxy'),
113 '#default_value' => isset($node->mkdru->use_sessions) ? $node->mkdru->use_sessions : 1,
116 $form['display_settings'] = array(
117 '#type' => 'fieldset',
118 '#title' => t('Display settings'),
119 '#collapsible' => TRUE,
120 '#collapsed' => FALSE
122 $form['display_settings']['source_max'] = array(
123 '#type' => 'textfield',
124 '#title' => t('Number of sources to display'),
126 '#default_value' => isset($node->mkdru->source_max) ? $node->mkdru->source_max : 10,
130 $form['display_settings']['author_max'] = array(
131 '#type' => 'textfield',
132 '#title' => t('Number of authors to display'),
134 '#default_value' => isset($node->mkdru->author_max) ? $node->mkdru->author_max : 10,
138 $form['display_settings']['subject_max'] = array(
139 '#type' => 'textfield',
140 '#title' => t('Number of subjects to display'),
142 '#default_value' => isset($node->mkdru->subject_max) ? $node->mkdru->subject_max : 10,
151 * Implementation of hook_validate()
153 function mkdru_validate($node) {
154 if (!is_numeric($node->source_max)) {
155 form_set_error('source_max', t('Please enter a number.'));
157 if (!is_numeric($node->author_max)) {
158 form_set_error('author_max', t('Please enter a number.'));
160 if (!is_numeric($node->subject_max)) {
161 form_set_error('subject_max', t('Please enter a number.'));
166 * Implementation of hook_insert().
168 function mkdru_insert($node) {
169 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)",
170 $node->nid, $node->vid, $node->pz2_path, $node->use_sessions, $node->source_max, $node->author_max, $node->subject_max);
174 * Implementation of hook_update().
176 function mkdru_update($node) {
177 if ($node->revision) {
178 // New revision; treat it as a new record.
182 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);
187 * Implementation of hook_nodeapi().
189 * When a node revision is deleted, we need to remove the corresponding record
190 * from our table. The only way to handle revision deletion is by implementing
193 function mkdru_nodeapi(&$node, $op, $teaser, $page) {
195 case 'delete revision':
196 db_query('DELETE FROM {mkdru} WHERE vid = %d', $node->vid);
202 * Implementation of hook_delete().
204 function mkdru_delete($node) {
205 // Deleting by nid covers all revisions.
206 db_query('DELETE FROM {mkdru} WHERE nid = %d', $node->nid);
213 * Implementation of hook_load()
215 function mkdru_load($node) {
216 return array('mkdru' => db_fetch_object(db_query(
217 'SELECT * FROM {mkdru} WHERE vid = %d', $node->vid)));
221 * Implementation of hook_theme().
223 function mkdru_theme() {
225 'mkdru_form' => array(
226 'template' => 'mkdru-form',
227 'arguments' => array(),
229 'mkdru_results' => array(
230 'template' => 'mkdru-results',
231 'arguments' => array(),
234 'arguments' => array('node' => NULL),
236 // 'mkdru_block_facet' => array(
237 // 'template' => 'mkdru-block-facet',
238 // 'arguments' => array('divId' => NULL),
244 * Theme function to include Javascript search client and deps
246 function theme_mkdru_js($node) {
247 $path = drupal_get_path('module', 'mkdru');
248 // Include client library.
249 drupal_add_js(variable_get('pz2_js_path', 'pazpar2/js') . '/pz2.js', 'module', 'footer');
250 drupal_add_js($path . '/mkdru.theme.js', 'module', 'footer');
251 drupal_add_js($path . '/mkdru.client.js', 'module', 'footer');
252 drupal_add_js(array('mkdru' => $node->mkdru), 'setting');
256 * Implementation of hook_view()
258 function mkdru_view($node, $teaser = FALSE, $page = FALSE) {
259 $node->content['mkdru_js'] = array(
260 '#value' => theme('mkdru_js', $node),
263 $node->content['mkdru_form'] = array(
264 '#value' => theme('mkdru_form'),
267 $node->content['mkdru_results'] = array(
268 '#value' => theme('mkdru_results'),
275 * Implementation of hook_block()
277 function mkdru_block($op='list', $delta='sources', $edit=array()) {
280 $blocks['mkdru_sources']['info'] = t('mkdru - source facets');
281 $blocks['mkdru_sources']['cache'] = BLOCK_NO_CACHE;
282 $blocks['mkdru_subjects']['info'] = t('mkdru - subject facets');
283 $blocks['mkdru_subjects']['cache'] = BLOCK_NO_CACHE;
284 $blocks['mkdru_authors']['info'] = t('mkdru - author facets');
285 $blocks['mkdru_authors']['cache'] = BLOCK_NO_CACHE;
290 // TODO: make the facet themable, I have no clue why this won't work
291 // case 'mkdru_sources':
292 // $block['subject'] = t('Source');
293 // $block['content'] = theme('mkdru_block_facet', 'mkdru-sources');
295 // case 'mkdru_subjects':
296 // $block['subject'] = t('Subject');
297 // $block['content'] = theme('mkdru_block_facet', 'mkdru-subjects');
299 // case 'mkdru_authors':
300 // $block['subject'] = t('Author');
301 // $block['content'] = theme('mkdru_block_facet', 'mkdru-authors');
303 case 'mkdru_sources':
304 $block['subject'] = t('Source');
305 $block['content'] = '<div class="mkdru-facet mkdru-facet-sources"> </div>';
307 case 'mkdru_subjects':
308 $block['subject'] = t('Subject');
309 $block['content'] = '<div class="mkdru-facet mkdru-facet-subjects"> </div>';
311 case 'mkdru_authors':
312 $block['subject'] = t('Author');
313 $block['content'] = '<div class="mkdru-facet mkdru-facet-authors"> </div>';