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',
67 * Implementation of hook_init()
69 function mkdru_init(){
70 // Applies our module specific CSS to all pages. This works best because
71 // all CSS is aggregated and cached so we reduce the number of HTTP
72 // requests and the size is negligible.
73 drupal_add_css(drupal_get_path('module', 'mkdru') .'/mkdru-page.css');
80 * Implementation of hook_form()
82 function mkdru_form(&$node, $form_state) {
83 $type = node_get_types('type', $node);
85 $form['title'] = array(
86 '#type' => 'textfield',
87 '#title' => check_plain($type->title_label),
89 '#default_value' => $node->title,
93 $form['search_settings'] = array(
94 '#type' => 'fieldset',
95 '#title' => t('Pazpar2/Service Proxy search settings'),
96 '#collapsible' => TRUE,
99 $form['search_settings']['pz2_path'] = array(
100 '#type' => 'textfield',
101 '#title' => t('Pazpar2/Service Proxy path'),
102 '#description' => t('Path that takes Pazpar2 commands via HTTP'),
104 '#default_value' => isset($node->mkdru->pz2_path) ? $node->mkdru->pz2_path : '/pazpar2/search.pz2',
106 $form['search_settings']['use_sessions'] = array(
107 '#type' => 'checkbox',
108 '#title' => t('Session handling'),
109 '#description' => t('Disable for use with Service Proxy'),
110 '#default_value' => isset($node->mkdru->use_sessions) ? $node->mkdru->use_sessions : 1,
113 $form['display_settings'] = array(
114 '#type' => 'fieldset',
115 '#title' => t('Display settings'),
116 '#collapsible' => TRUE,
117 '#collapsed' => FALSE
119 $form['display_settings']['source_max'] = array(
120 '#type' => 'textfield',
121 '#title' => t('Number of sources to display'),
123 '#default_value' => isset($node->mkdru->source_max) ? $node->mkdru->source_max : 10,
127 $form['display_settings']['author_max'] = array(
128 '#type' => 'textfield',
129 '#title' => t('Number of authors to display'),
131 '#default_value' => isset($node->mkdru->author_max) ? $node->mkdru->author_max : 10,
135 $form['display_settings']['subject_max'] = array(
136 '#type' => 'textfield',
137 '#title' => t('Number of subjects to display'),
139 '#default_value' => isset($node->mkdru->subject_max) ? $node->mkdru->subject_max : 10,
148 * Implementation of hook_validate()
150 function mkdru_validate($node) {
151 if (!is_numeric($node->source_max)) {
152 form_set_error('source_max', t('Please enter a number.'));
154 if (!is_numeric($node->author_max)) {
155 form_set_error('author_max', t('Please enter a number.'));
157 if (!is_numeric($node->subject_max)) {
158 form_set_error('subject_max', t('Please enter a number.'));
163 * Implementation of hook_insert().
165 function mkdru_insert($node) {
166 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)",
167 $node->nid, $node->vid, $node->pz2_path, $node->use_sessions, $node->source_max, $node->author_max, $node->subject_max);
171 * Implementation of hook_update().
173 function mkdru_update($node) {
174 if ($node->revision) {
175 // New revision; treat it as a new record.
179 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);
184 * Implementation of hook_nodeapi().
186 * When a node revision is deleted, we need to remove the corresponding record
187 * from our table. The only way to handle revision deletion is by implementing
190 function mkdru_nodeapi(&$node, $op, $teaser, $page) {
192 case 'delete revision':
193 db_query('DELETE FROM {mkdru} WHERE vid = %d', $node->vid);
199 * Implementation of hook_delete().
201 * When a node is deleted, we need to remove all related records from our table.
203 function mkdru_delete($node) {
204 // Deleting by nid covers all revisions.
205 db_query('DELETE FROM {mkdru} WHERE nid = %d', $node->nid);
212 * Implementation of hook_load()
214 function mkdru_load($node) {
215 return array('mkdru' => db_fetch_object(db_query(
216 'SELECT * FROM {mkdru} WHERE vid = %d', $node->vid)));
220 * Implementation of hook_theme().
222 function mkdru_theme() {
224 'mkdru_page' => array(
225 'template' => 'mkdru-page',
226 'arguments' => array(),
228 'mkdru_page_js' => array(
229 'arguments' => array('node' => NULL),
231 // 'mkdru_block_facet' => array(
232 // 'template' => 'mkdru-block-facet',
233 // 'arguments' => array('divId' => NULL),
239 * Theme function to include Javascript search client and deps
241 function theme_mkdru_page_js($node) {
242 $path = drupal_get_path('module', 'mkdru');
243 // Include client library.
244 drupal_add_js(variable_get('pz2_js_path', 'pazpar2/js') . '/pz2.js', 'module', 'footer');
245 drupal_add_js($path . '/mkdru.theme.js', 'module', 'footer');
246 drupal_add_js($path . '/mkdru.client.js', 'module', 'footer');
247 drupal_add_js(array('mkdru' => $node->mkdru), 'setting');
251 * Implementation of hook_view()
253 function mkdru_view($node, $teaser = FALSE, $page = FALSE) {
254 $node->content['mkdru_page_js'] = array(
255 '#value' => theme('mkdru_page_js', $node),
258 $node->content['mkdru_page'] = array(
259 '#value' => theme('mkdru_page'),
266 * Implementation of hook_block()
268 function mkdru_block($op='list', $delta='sources', $edit=array()) {
271 $blocks['mkdru_sources']['info'] = t('mkdru - source facets');
272 $blocks['mkdru_sources']['cache'] = BLOCK_NO_CACHE;
273 $blocks['mkdru_subjects']['info'] = t('mkdru - subject facets');
274 $blocks['mkdru_subjects']['cache'] = BLOCK_NO_CACHE;
275 $blocks['mkdru_authors']['info'] = t('mkdru - author facets');
276 $blocks['mkdru_authors']['cache'] = BLOCK_NO_CACHE;
281 // TODO: make the facet themable, I have no clue why this won't work
282 // case 'mkdru_sources':
283 // $block['subject'] = t('Source');
284 // $block['content'] = theme('mkdru_block_facet', 'mkdru-sources');
286 // case 'mkdru_subjects':
287 // $block['subject'] = t('Subject');
288 // $block['content'] = theme('mkdru_block_facet', 'mkdru-subjects');
290 // case 'mkdru_authors':
291 // $block['subject'] = t('Author');
292 // $block['content'] = theme('mkdru_block_facet', 'mkdru-authors');
294 case 'mkdru_sources':
295 $block['subject'] = t('Source');
296 $block['content'] = '<div id="mkdru-sources"> </div>';
298 case 'mkdru_subjects':
299 $block['subject'] = t('Subject');
300 $block['content'] = '<div id="mkdru-subjects"> </div>';
302 case 'mkdru_authors':
303 $block['subject'] = t('Author');
304 $block['content'] = '<div id="mkdru-authors"> </div>';