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)) {
51 * Implementation of hook_menu()
53 function mkdru_menu() {
54 $items['admin/settings/mkdru'] = array(
55 'title' => 'mkdru Settings',
56 'description' => 'Settings for mkdru.',
57 'page callback' => 'drupal_get_form',
58 'page arguments' => array('mkdru_admin_settings'),
59 'access arguments' => array('administer site configuration'),
60 'type' => MENU_NORMAL_ITEM,
61 'file' => 'mkdru.admin.inc',
69 * Implementation of hook_form()
71 function mkdru_form(&$node, $form_state) {
72 $type = node_get_types('type', $node);
74 $form['title'] = array(
75 '#type' => 'textfield',
76 '#title' => check_plain($type->title_label),
78 '#default_value' => $node->title,
82 $form['search_settings'] = array(
83 '#type' => 'fieldset',
84 '#title' => t('Pazpar2/Service Proxy search settings'),
85 '#collapsible' => TRUE,
88 $form['search_settings']['pz2_path'] = array(
89 '#type' => 'textfield',
90 '#title' => t('Pazpar2/Service Proxy path'),
91 '#description' => t('Path that takes Pazpar2 commands via HTTP'),
93 '#default_value' => isset($node->mkdru->pz2_path) ? $node->mkdru->pz2_path : '/pazpar2/search.pz2',
95 $form['search_settings']['use_sessions'] = array(
96 '#type' => 'checkbox',
97 '#title' => t('Session handling'),
98 '#description' => t('Disable for use with Service Proxy'),
99 '#default_value' => isset($node->mkdru->use_sessions) ? $node->mkdru->use_sessions : 1,
102 $form['display_settings'] = array(
103 '#type' => 'fieldset',
104 '#title' => t('Display settings'),
105 '#collapsible' => TRUE,
106 '#collapsed' => FALSE
108 $form['display_settings']['source_max'] = array(
109 '#type' => 'textfield',
110 '#title' => t('Number of sources to display'),
112 '#default_value' => isset($node->mkdru->source_max) ? $node->mkdru->source_max : 10,
116 $form['display_settings']['author_max'] = array(
117 '#type' => 'textfield',
118 '#title' => t('Number of authors to display'),
120 '#default_value' => isset($node->mkdru->author_max) ? $node->mkdru->author_max : 10,
124 $form['display_settings']['subject_max'] = array(
125 '#type' => 'textfield',
126 '#title' => t('Number of subjects to display'),
128 '#default_value' => isset($node->mkdru->subject_max) ? $node->mkdru->subject_max : 10,
137 * Implementation of hook_validate()
139 function mkdru_validate($node) {
140 if (!is_numeric($node->source_max)) {
141 form_set_error('source_max', t('Please enter a number.'));
143 if (!is_numeric($node->author_max)) {
144 form_set_error('author_max', t('Please enter a number.'));
146 if (!is_numeric($node->subject_max)) {
147 form_set_error('subject_max', t('Please enter a number.'));
152 * Implementation of hook_insert().
154 function mkdru_insert($node) {
155 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)",
156 $node->nid, $node->vid, $node->pz2_path, $node->use_sessions, $node->source_max, $node->author_max, $node->subject_max);
160 * Implementation of hook_update().
162 function mkdru_update($node) {
163 if ($node->revision) {
164 // New revision; treat it as a new record.
168 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);
173 * Implementation of hook_nodeapi().
175 * When a node revision is deleted, we need to remove the corresponding record
176 * from our table. The only way to handle revision deletion is by implementing
179 function mkdru_nodeapi(&$node, $op, $teaser, $page) {
181 case 'delete revision':
182 db_query('DELETE FROM {mkdru} WHERE vid = %d', $node->vid);
188 * Implementation of hook_delete().
190 * When a node is deleted, we need to remove all related records from our table.
192 function mkdru_delete($node) {
193 // Deleting by nid covers all revisions.
194 db_query('DELETE FROM {mkdru} WHERE nid = %d', $node->nid);
201 * Implementation of hook_load()
203 function mkdru_load($node) {
204 return array('mkdru' => db_fetch_object(db_query(
205 'SELECT * FROM {mkdru} WHERE vid = %d', $node->vid)));
209 * Implementation of hook_theme().
211 function mkdru_theme() {
213 'mkdru_page' => array(
214 'template' => 'mkdru-page',
215 'arguments' => array(),
217 'mkdru_page_js' => array(
218 'arguments' => array('node' => NULL),
220 // 'mkdru_block_facet' => array(
221 // 'template' => 'mkdru-block-facet',
222 // 'arguments' => array('divId' => NULL),
228 * Theme function to include Javascript search client and deps
230 function theme_mkdru_page_js($node) {
231 $path = drupal_get_path('module', 'mkdru');
232 // Include client library.
233 drupal_add_js(variable_get('pz2_js_path', 'pazpar2/js') . '/pz2.js', 'module', 'footer');
234 drupal_add_js($path . '/mkdru.theme.js', 'module', 'footer');
235 drupal_add_js($path . '/mkdru.client.js', 'module', 'footer');
236 drupal_add_js(array('mkdru' => $node->mkdru), 'setting');
240 * Implementation of hook_view()
242 function mkdru_view($node, $teaser = FALSE, $page = FALSE) {
243 $node->content['mkdru_page_js'] = array(
244 '#value' => theme('mkdru_page_js', $node),
247 $node->content['mkdru_page'] = array(
248 '#value' => theme('mkdru_page'),
255 * Implementation of hook_block()
257 function mkdru_block($op='list', $delta='sources', $edit=array()) {
260 $blocks['mkdru_sources']['info'] = t('mkdru - source facets');
261 $blocks['mkdru_sources']['cache'] = BLOCK_NO_CACHE;
262 $blocks['mkdru_subjects']['info'] = t('mkdru - subject facets');
263 $blocks['mkdru_subjects']['cache'] = BLOCK_NO_CACHE;
264 $blocks['mkdru_authors']['info'] = t('mkdru - author facets');
265 $blocks['mkdru_authors']['cache'] = BLOCK_NO_CACHE;
270 // TODO: make the facet themable, I have no clue why this won't work
271 // case 'mkdru_sources':
272 // $block['subject'] = t('Source');
273 // $block['content'] = theme('mkdru_block_facet', 'mkdru-sources');
275 // case 'mkdru_subjects':
276 // $block['subject'] = t('Subject');
277 // $block['content'] = theme('mkdru_block_facet', 'mkdru-subjects');
279 // case 'mkdru_authors':
280 // $block['subject'] = t('Author');
281 // $block['content'] = theme('mkdru_block_facet', 'mkdru-authors');
283 case 'mkdru_sources':
284 $block['subject'] = t('Source');
285 $block['content'] = '<div id="mkdru-sources"> </div>';
287 case 'mkdru_subjects':
288 $block['subject'] = t('Subject');
289 $block['content'] = '<div id="mkdru-subjects"> </div>';
291 case 'mkdru_authors':
292 $block['subject'] = t('Author');
293 $block['content'] = '<div id="mkdru-authors"> </div>';