From: Jason Skomorowski Date: Wed, 24 Nov 2010 07:07:46 +0000 (+0100) Subject: Node config. X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=858d62aff8278c4df989c93a88f14059cebfbce5;p=mkdru-moved-to-drupal.org.git Node config. --- diff --git a/mkdru.admin.inc b/mkdru.admin.inc index c07ac31..47a2524 100644 --- a/mkdru.admin.inc +++ b/mkdru.admin.inc @@ -1,40 +1,10 @@ '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.')); - } -} diff --git a/mkdru.client.js b/mkdru.client.js index ae1ccca..1eb7ece 100644 --- a/mkdru.client.js +++ b/mkdru.client.js @@ -1,8 +1,8 @@ // Set up namespace and some state. var mkdru = { // Settings to pass to pz2.js - usesessions: true, - showResponseType: '', + usesessions: Drupal.settings.mkdru.use_sessions === '1', + showResponseType: 'json', // Variables curPage: 1, recPerPage: 20, @@ -10,11 +10,11 @@ var mkdru = { curSort: 'relevance', curFilter: null, submitted: false, - sourceMax: 16, // facets - subjectMax: 10, - authorMax: 10, + sourceMax: Drupal.settings.mkdru.source_max, + subjectMax: Drupal.settings.mkdru.subject_max, + authorMax: Drupal.settings.mkdru.author_max, pz2: null, - pazpar2Path: '/pazpar2/search.pz2', + pazpar2Path: Drupal.settings.mkdru.pz2_path }; diff --git a/mkdru.install b/mkdru.install index e69de29..a2d828a 100644 --- a/mkdru.install +++ b/mkdru.install @@ -0,0 +1,83 @@ + 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'); +} +?> diff --git a/mkdru.module b/mkdru.module index 9996cd9..a89db52 100644 --- a/mkdru.module +++ b/mkdru.module @@ -1,4 +1,8 @@ '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); } /** @@ -87,7 +150,7 @@ function mkdru_update($node) { 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); } } @@ -98,10 +161,9 @@ function mkdru_update($node) { * 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; } @@ -112,7 +174,7 @@ function node_example_nodeapi(&$node, $op, $teaser, $page) { * * 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); } @@ -124,7 +186,8 @@ function node_example_delete($node) { * 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))); } /** @@ -137,7 +200,7 @@ function mkdru_theme() { 'arguments' => array(), ), 'mkdru_page_js' => array( - 'arguments' => array(), + 'arguments' => array('node' => NULL), ), // 'mkdru_block_facet' => array( // 'template' => 'mkdru-block-facet', @@ -149,11 +212,12 @@ function mkdru_theme() { /** * 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'); } /** @@ -161,7 +225,7 @@ function theme_mkdru_page_js() { */ 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(