<?php
-function jsdemo2_admin_settings() {
- $form['jsdemo2_author_max']=array(
+function mkdru_admin_settings() {
+ $form['pz2_js_path']=array(
'#type' => 'textfield',
- '#title' => t('Maximum authors to display'),
- '#default_value' => variable_get('jsdemo2_author_max', 10),
- '#size' => 3,
- '#maxlength' => 3,
- );
-
- $form['jsdemo2_source_max']=array(
- '#type' => 'textfield',
- '#title' => t('Maximum sources to display'),
- '#default_value' => variable_get('jsdemo2_source_max', 16),
- '#size' => 3,
- '#maxlength' => 3,
- );
-
- $form['jsdemo2_subject_max']=array(
- '#type' => 'textfield',
- '#title' => t('Maximum subjects to display'),
- '#default_value' => variable_get('jsdemo2_subject_max', 10),
- '#size' => 3,
- '#maxlength' => 3,
+ '#title' => t('Path to Pazpar2 client library, pz2.js'),
+ '#default_value' => variable_get('pz2_js_path', '/pazpar2/pz2.js'),
);
return system_settings_form($form);
}
-
-function jsdemo2_admin_settings_validate($form, $form_state) {
- if (!is_numeric($form_state['values']['jsdemo2_source_max'])) {
- form_set_error('jsdemo2_source_max', t('Please enter a number.'));
- }
- if (!is_numeric($form_state['values']['jsdemo2_author_max'])) {
- form_set_error('jsdemo2_author_max', t('Please enter a number.'));
- }
- if (!is_numeric($form_state['values']['jsdemo2_subject_max'])) {
- form_set_error('jsdemo2_subject_max', t('Please enter a number.'));
- }
-}
+<?php
+// $Id$
+/**
+ * @file
+ * Install, update and uninstall functions.
+ */
+
+/**
+* Implementation of hook_schema().
+*/
+function mkdru_schema() {
+ $schema['mkdru'] = array(
+ 'description' => t('Stores settings for mkdru nodes.'),
+ 'fields' => array (
+ 'nid' => array(
+ 'description' => t('The primary identifier for a node.'),
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0
+ ),
+ 'vid' => array(
+ 'description' => t('The current {node_revisions}.vid version identifier.'),
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0
+ ),
+ 'pz2_path' => array(
+ 'type' => 'text',
+ 'not null' => TRUE,
+ 'description' => t('Path to Pazpar2 or Service Proxy.')
+ ),
+ 'use_sessions' => array(
+ 'description' => t('Session handling toggle.'),
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ ),
+ 'source_max' => array(
+ 'description' => t('Number of sources to display'),
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ ),
+ 'author_max' => array(
+ 'description' => t('Number of authors to display'),
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ ),
+ 'subject_max' => array(
+ 'description' => t('Number of subjects to display'),
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ ),
+ ),
+ 'primary key' => array('nid', 'vid'),
+ 'unique keys' => array('vid' => array('vid')),
+ 'indexes' => array('nid' => array('nid')),
+ );
+ return $schema;
+}
+
+/**
+* Implementation of hook_install().
+*/
+function mkdru_install() {
+ // Disable comments by default
+ variable_set('comment_mkdru', COMMENT_NODE_DISABLED);
+ // Create table.
+ drupal_install_schema('mkdru');
+}
+
+/**
+* Implementation of hook_uninstall().
+*/
+function mkdru_uninstall() {
+ // Drop table.
+ drupal_uninstall_schema('mkdru');
+}
+?>
<?php
+// $Id$
+
+
+
// Module metainfo
/**
* Implementation of hook_node_info().
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
- '#required' => TRUE,
+ '#required' => FALSE,
'#default_value' => $node->title,
'#weight' => -5
);
- $form['pz2_path'] = array(
+
+ $form['search_settings'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Pazpar2/Service Proxy search settings'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE
+ );
+ $form['search_settings']['pz2_path'] = array(
'#type' => 'textfield',
'#title' => t('Pazpar2/Service Proxy path'),
- '#description' => t('Absolute URL path without leading slash'),
+ '#description' => t('Path that takes Pazpar2 commands via HTTP'),
+ '#required' => TRUE,
+ '#default_value' => isset($node->mkdru->pz2_path) ? $node->mkdru->pz2_path : '/pazpar2/search.pz2',
+ );
+ $form['search_settings']['use_sessions'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Session handling'),
+ '#description' => t('Disable for use with Service Proxy'),
+ '#default_value' => isset($node->mkdru->use_sessions) ? $node->mkdru->use_sessions : 1,
+ );
+
+ $form['display_settings'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Display settings'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE
+ );
+ $form['display_settings']['source_max'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Number of sources to display'),
'#required' => TRUE,
- '#default_value' => isset($node->pz2_path) ? $node->pz2_path : 'pazpar2',
- '#weight' => 0
+ '#default_value' => isset($node->mkdru->source_max) ? $node->mkdru->source_max : 10,
+ '#size' => 3,
+ '#maxlength' => 3,
+ );
+ $form['display_settings']['author_max'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Number of authors to display'),
+ '#required' => TRUE,
+ '#default_value' => isset($node->mkdru->author_max) ? $node->mkdru->author_max : 10,
+ '#size' => 3,
+ '#maxlength' => 3,
+ );
+ $form['display_settings']['subject_max'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Number of subjects to display'),
+ '#required' => TRUE,
+ '#default_value' => isset($node->mkdru->subject_max) ? $node->mkdru->subject_max : 10,
+ '#size' => 3,
+ '#maxlength' => 3,
);
return $form;
}
+
+/**
+* Implementation of hook_validate()
+*/
+function mkdru_validate($node) {
+ if (!is_numeric($node->source_max)) {
+ form_set_error('source_max', t('Please enter a number.'));
+ }
+ if (!is_numeric($node->author_max)) {
+ form_set_error('author_max', t('Please enter a number.'));
+ }
+ if (!is_numeric($node->subject_max)) {
+ form_set_error('subject_max', t('Please enter a number.'));
+ }
+}
+
/**
* Implementation of hook_insert().
*/
function mkdru_insert($node) {
- db_query("INSERT INTO {mkdru} (nid, vid, pz2_path) VALUES (%d, %d, '%s')",
- $node->nid, $node->vid, $node->pz2_path);
+ db_query("INSERT INTO {mkdru} (nid, vid, pz2_path, use_sessions, source_max, author_max, subject_max) VALUES (%d, %d, '%s', %d, %d, %d)",
+ $node->nid, $node->vid, $node->pz2_path, $node->use_sessions, $node->source_max, $node->author_max, $node->subject_max);
}
/**
mkdru_insert($node);
}
else {
- db_query("UPDATE {mkdru} SET pz2_path = '%s' WHERE vid = '%d'", $node->pz2_path, $node->vid);
+ 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);
}
}
* from our table. The only way to handle revision deletion is by implementing
* hook_nodeapi().
*/
-function node_example_nodeapi(&$node, $op, $teaser, $page) {
+function mkdru_nodeapi(&$node, $op, $teaser, $page) {
switch ($op) {
case 'delete revision':
- // Notice that we're matching a single revision based on the node's vid.
db_query('DELETE FROM {mkdru} WHERE vid = %d', $node->vid);
break;
}
*
* When a node is deleted, we need to remove all related records from our table.
*/
-function node_example_delete($node) {
+function mkdru_delete($node) {
// Deleting by nid covers all revisions.
db_query('DELETE FROM {mkdru} WHERE nid = %d', $node->nid);
}
* Implementation of hook_load()
*/
function mkdru_load($node) {
- return db_fetch_object(db_query('SELECT pz2_path FROM {mkdru} WHERE vid = %d', $node->vid));
+ return array('mkdru' => db_fetch_object(db_query(
+ 'SELECT * FROM {mkdru} WHERE vid = %d', $node->vid)));
}
/**
'arguments' => array(),
),
'mkdru_page_js' => array(
- 'arguments' => array(),
+ 'arguments' => array('node' => NULL),
),
// 'mkdru_block_facet' => array(
// 'template' => 'mkdru-block-facet',
/**
* Theme function to include Javascript search client and deps
*/
-function theme_mkdru_page_js() {
+function theme_mkdru_page_js($node) {
$path = drupal_get_path('module', 'mkdru');
drupal_add_js('pazpar2/js/pz2.js', 'module', 'footer');
drupal_add_js($path . '/mkdru.theme.js', 'module', 'footer');
drupal_add_js($path . '/mkdru.client.js', 'module', 'footer');
+ drupal_add_js(array('mkdru' => $node->mkdru), 'setting');
}
/**
*/
function mkdru_view($node, $teaser = FALSE, $page = FALSE) {
$node->content['mkdru_page_js'] = array(
- '#value' => theme('mkdru_page_js'),
+ '#value' => theme('mkdru_page_js', $node),
'#weight' => 0,
);
$node->content['mkdru_page'] = array(