Index: nodereview.info
===================================================================
--- nodereview.info	(revision 964da59ed87acf8a8a90c2c9dc3bdbf76fb1553e)
+++ nodereview.info	(revision )
@@ -1,5 +1,11 @@
 name = Node Review
 description = "Add reviews to arbitrary node types."
+
+core = 7.x
+project = "nodereview"
+package = Node Review
+
 dependencies[] = votingapi
 dependencies[] = views
-core = 7.x
+
+configure = admin/config/nodereview/types
Index: nodereview.views.inc
===================================================================
--- nodereview.views.inc	(revision 964da59ed87acf8a8a90c2c9dc3bdbf76fb1553e)
+++ nodereview.views.inc	(revision )
@@ -1,11 +1,14 @@
 <?php
   /**
-   * @file
-   * This is to implement view functionality
-   */
+ * @file
+ * This is to implement view functionality
+ */
 
+/**
+ * @return array
+ */
 function nodereview_views_data() {
-  $data['nodereview']['table']['group']  =t('Node Review');
+  $data['nodereview']['table']['group'] = t('Node Review');
   $data['nodereview']['table']['join']['node'] = array(
     'left_field' => 'nid',
     'field' => 'nid',
Index: nodereview.views_default.inc
===================================================================
--- nodereview.views_default.inc	(revision 964da59ed87acf8a8a90c2c9dc3bdbf76fb1553e)
+++ nodereview.views_default.inc	(revision )
@@ -1,156 +1,152 @@
 <?php
 
-
-  /**
-   * @file
-   * this is the deafult view
-   */
+/**
+ * @file
+ * this is the deafult view
+ */
 
 /**
- * Implementation of hook_views_default_views().
+ * Implements of hook_views_default_views().
  */
 function nodereview_views_default_views() {
 
-$view = new view;
-$view->name = 'review_list';
-$view->description = 'A list of teasers for reviews of a given node';
-$view->tag = 'nodereview';
-$view->view_php = '';
-$view->base_table = 'node';
-$view->is_cacheable = FALSE;
-$view->api_version = 2;
-$view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */
-$handler = $view->new_display('default', 'Defaults', 'default');
-$handler->override_option('fields', array(
-  'title' => array(
-    'label' => 'Title',
-    'link_to_node' => 1,
-    'exclude' => 0,
-    'id' => 'title',
-    'table' => 'node',
-    'field' => 'title',
-    'override' => array(
-      'button' => 'Override',
-    ),
-    'relationship' => 'none',
-  ),
-  'changed' => array(
-    'label' => 'Updated',
-    'date_format' => 'small',
-    'custom_date_format' => '',
-    'exclude' => 0,
-    'id' => 'changed',
-    'table' => 'node',
-    'field' => 'changed',
-    'override' => array(
-      'button' => 'Override',
-    ),
-    'relationship' => 'none',
-  ),
-));
-$handler->override_option('sorts', array(
-  'changed' => array(
-    'order' => 'DESC',
-    'granularity' => 'second',
-    'id' => 'changed',
-    'table' => 'node',
-    'field' => 'changed',
-    'override' => array(
-      'button' => 'Override',
-    ),
-    'relationship' => 'none',
-  ),
-));
-$handler->override_option('arguments', array(
-  'reviewed_nid' => array(
-    'default_action' => 'not found',
-    'style_plugin' => 'default_summary',
-    'style_options' => array(),
-    'wildcard' => '',
-    'wildcard_substitution' => '',
-    'title' => '',
-    'default_argument_type' => 'fixed',
-    'default_argument' => '',
-    'validate_type' => 'none',
-    'validate_fail' => 'not found',
-    'break_phrase' => 0,
-    'not' => 0,
-    'id' => 'reviewed_nid',
-    'table' => 'nodereview',
-    'field' => 'reviewed_nid',
-    'relationship' => 'none',
-    'default_options_div_prefix' => '',
-    'default_argument_user' => 0,
-    'default_argument_fixed' => '',
-    'default_argument_php' => '',
-    'validate_argument_node_type' => array(
-      'nodereview' => 0,
-      'page' => 0,
-      'story' => 0,
-    ),
-    'validate_argument_node_access' => 0,
-    'validate_argument_nid_type' => 'nid',
-    'validate_argument_vocabulary' => array(),
-    'validate_argument_type' => 'tid',
-    'validate_argument_php' => '',
-  ),
-));
-$handler->override_option('filters', array(
-  'type' => array(
-    'operator' => 'in',
-    'value' => array(
-      'nodereview' => 'nodereview',
-    ),
-    'group' => '0',
-    'exposed' => FALSE,
-    'expose' => array(
-      'operator' => FALSE,
-      'label' => '',
-    ),
-    'id' => 'type',
-    'table' => 'node',
-    'field' => 'type',
-    'override' => array(
-      'button' => 'Override',
-    ),
-    'relationship' => 'none',
-  ),
-));
-$handler->override_option('access', array(
-  'type' => 'none',
-));
-$handler->override_option('title', 'Reviews');
-$handler->override_option('empty', 'No reviews have been submitted.  Maybe you should be the first?');
-$handler->override_option('empty_format', '1');
-$handler->override_option('use_pager', '1');
-$handler->override_option('distinct', 0);
-$handler->override_option('style_options', NULL);
-$handler->override_option('row_plugin', 'node');
-$handler->override_option('row_options', array(
-  'teaser' => 1,
-  'links' => 1,
-  'comments' => 0,
-));
-$handler = $view->new_display('page', 'Reviews', 'page_1');
-$handler->override_option('path', 'node/%/reviews');
-$handler->override_option('menu', array(
-  'type' => 'tab',
-  'title' => 'Reviews',
-  'description' => '',
-  'weight' => '0',
-  'name' => 'navigation',
-));
-$handler->override_option('tab_options', array(
-  'type' => 'none',
-  'title' => '',
-  'description' => '',
-  'weight' => 0,
-  'name' => 'navigation',
-));
+  $view = new view;
+  $view->name = 'review_list';
+  $view->description = 'A list of teasers for reviews of a given node';
+  $view->tag = 'nodereview';
+  $view->view_php = '';
+  $view->base_table = 'node';
+  $view->is_cacheable = FALSE;
+  $view->api_version = 2;
+  $view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */
+  $handler = $view->new_display('default', 'Defaults', 'default');
+  $handler->override_option('fields', array(
+                                            'title' => array(
+                                              'label' => 'Title',
+                                              'link_to_node' => 1,
+                                              'exclude' => 0,
+                                              'id' => 'title',
+                                              'table' => 'node',
+                                              'field' => 'title',
+                                              'override' => array(
+                                                'button' => 'Override',
+                                              ),
+                                              'relationship' => 'none',
+                                            ),
+                                              'changed' => array(
+                                              'label' => 'Updated',
+                                              'date_format' => 'small',
+                                              'custom_date_format' => '',
+                                              'exclude' => 0,
+                                              'id' => 'changed',
+                                              'table' => 'node',
+                                              'field' => 'changed',
+                                              'override' => array(
+                                                'button' => 'Override',
+                                              ),
+                                              'relationship' => 'none',
+                                            ),
+                                      ));
+  $handler->override_option('sorts', array(
+                                            'changed' => array(
+                                              'order' => 'DESC',
+                                              'granularity' => 'second',
+                                              'id' => 'changed',
+                                              'table' => 'node',
+                                              'field' => 'changed',
+                                              'override' => array(
+                                                'button' => 'Override',
+                                                ),
+                                              'relationship' => 'none',
+                                              ),
+                                            ));
+  $handler->override_option('arguments', array(
+                                            'reviewed_nid' => array(
+                                              'default_action' => 'not found',
+                                              'style_plugin' => 'default_summary',
+                                              'style_options' => array(),
+                                              'wildcard' => '',
+                                              'wildcard_substitution' => '',
+                                              'title' => '',
+                                              'default_argument_type' => 'fixed',
+                                              'default_argument' => '',
+                                              'validate_type' => 'none',
+                                              'validate_fail' => 'not found',
+                                              'break_phrase' => 0,
+                                              'not' => 0,
+                                              'id' => 'reviewed_nid',
+                                              'table' => 'nodereview',
+                                              'field' => 'reviewed_nid',
+                                              'relationship' => 'none',
+                                              'default_options_div_prefix' => '',
+                                              'default_argument_user' => 0,
+                                              'default_argument_fixed' => '',
+                                              'default_argument_php' => '',
+                                              'validate_argument_node_type' => array(
+                                                'nodereview' => 0,
+                                                'page' => 0,
+                                                'story' => 0,
+                                                ),
+                                              'validate_argument_node_access' => 0,
+                                              'validate_argument_nid_type' => 'nid',
+                                              'validate_argument_vocabulary' => array(),
+                                              'validate_argument_type' => 'tid',
+                                              'validate_argument_php' => '',
+                                            ),
+                                            ));
+  $handler->override_option('filters', array(
+                                            'type' => array(
+                                              'operator' => 'in',
+                                              'value' => array(
+                                                'nodereview' => 'nodereview',
+                                                ),
+                                              'group' => '0',
+                                              'exposed' => FALSE,
+                                              'expose' => array(
+                                                'operator' => FALSE,
+                                                'label' => '',
+                                                ),
+                                              'id' => 'type',
+                                              'table' => 'node',
+                                              'field' => 'type',
+                                              'override' => array(
+                                                'button' => 'Override',
+                                                ),
+                                              'relationship' => 'none',
+                                              ),
+                                            ));
+  $handler->override_option('access', array(
+                                            'type' => 'none',
+                                          ));
+  $handler->override_option('title', 'Reviews');
+  $handler->override_option('empty', 'No reviews have been submitted.  Maybe you should be the first?');
+  $handler->override_option('empty_format', '1');
+  $handler->override_option('use_pager', '1');
+  $handler->override_option('distinct', 0);
+  $handler->override_option('style_options', NULL);
+  $handler->override_option('row_plugin', 'node');
+  $handler->override_option('row_options', array(
+                                                'teaser' => 1,
+                                                'links' => 1,
+                                                'comments' => 0,
+                                              ));
+  $handler = $view->new_display('page', 'Reviews', 'page_1');
+  $handler->override_option('path', 'node/%/reviews');
+  $handler->override_option('menu', array(
+                                          'type' => 'tab',
+                                          'title' => 'Reviews',
+                                          'description' => '',
+                                          'weight' => '0',
+                                          'name' => 'navigation',
+                                        ));
+  $handler->override_option('tab_options', array(
+                                                'type' => 'none',
+                                                'title' => '',
+                                                'description' => '',
+                                                'weight' => 0,
+                                                'name' => 'navigation',
+                                              ));
 
- $views[$view->name] = $view;
+  $views[$view->name] = $view;
   return $views;
 }
-
-
-
Index: nodereview_node_nodereview.inc
===================================================================
--- nodereview_node_nodereview.inc	(revision 964da59ed87acf8a8a90c2c9dc3bdbf76fb1553e)
+++ nodereview_node_nodereview.inc	(revision )
@@ -5,9 +5,8 @@
  * Used to build the nodereview content type form
  */
 
-
 /**
- * Implementation of hook_access().
+ * Implements of hook_access().
  *
  */
 function nodereview_access($op, $node) {
@@ -32,34 +31,31 @@
   }
 }
 
-
 /**
- * Implementation of hook_form().
- *
+ * Implements of hook_form().
  */
 function nodereview_form($node, &$form_state) {
-
   // This is for the LOCAL_TASK version, node/nid/addreview
-  if (!isset($node->reviewed_nid)) {
-    $node->reviewed_nid = arg(1);
+  if (empty($node->reviewed_nid)) {
+    return array();
   }
   $type = node_type_get_type($node);
 
   $form = array();
   $form['reviewed_nid'] = array(
     '#type' => 'hidden',
-    '#value' => isset($node->reviewed_nid) ? $node->reviewed_nid: '',
+    '#value' => (!empty($node->reviewed_nid)) ? $node->reviewed_nid : '',
   );
 
   $form['title'] = array(
     '#type' => 'textfield',
-    '#title' => t($type->title_label),
-    '#default_value' => isset($node->title) ? $node->title: '',
+    '#title' => check_plain(t($type->title_label)),
+    '#default_value' => (!empty($node->title)) ? $node->title : '',
     '#required' => TRUE,
     '#weight' => -50,
   );
 
-  $reviewed_node = node_load(array('nid' => $node->reviewed_nid));
+  $reviewed_node = node_load((int)$node->reviewed_nid);
 
   $form['reviews']['#tree'] = TRUE;
   $form['reviews']['#weight'] = 0;
@@ -69,14 +65,12 @@
           ORDER BY weight, tag";
 
   $result = db_query($sql, array(':type' => $reviewed_node->type));
-
-  while ($record = $result->fetchObject()) {  
+  while ($record = $result->fetchObject()) {
     _nodereview_form_review($form, $record, $node);
   }
 
   // We'll use a single filter format for all textareas on the page
   //$form['filter'] = filter_process_format($node->format);
-
   return $form;
 }
 
@@ -92,24 +86,23 @@
  * @param $votes
  *  An array of votes (scores) for this review, keyed by axis name
  */
-//function _nodereview_form_review(&$form, $axis, $reviews, $votes) {
 function _nodereview_form_review(&$form, $axis, $node) {
-  
+
-  $average_rating = round(NODEREVIEW_MAXRATING/2) * 10;
+  $average_rating = round(NODEREVIEW_MAXRATING / 2) * 10;
-  
+
   for ($i = 1; $i < (NODEREVIEW_MAXRATING + 1); $i++) {
-    $option_value = round(($i/NODEREVIEW_MAXRATING) * 100);
+    $option_value = round(($i / NODEREVIEW_MAXRATING) * 100);
     if (NODEREVIEW_LABEL_ENABLE) {
       $options[$option_value] = variable_get('nodereview_rating_label' . $i, '');
-    } 
+    }
     else {
       $options[$option_value] = $i;
     }
   }
-  
+
   $form['reviews'][$axis->aid] = array(
     '#type' => 'fieldset',
-    '#title' => isset($axis->tag) ? $axis->tag: '',
+    '#title' => (!empty($axis->tag)) ? $axis->tag : '',
     '#collapsible' => TRUE,
     '#collapsed' => FALSE,
   );
@@ -118,181 +111,161 @@
     '#type' => 'select',
     '#title' => t('Score'),
     '#options' => $options,
-    '#default_value' => isset($node->reviews[$axis->aid]['score']) ? $node->reviews[$axis->aid]['score'] : $average_rating,
+    '#default_value' => (!empty($node->review->score)) ? $node->review->score
+      : $average_rating,
     '#description' => $axis->description,
     '#required' => TRUE,
   );
-
+  
   if (NODEREVIEW_FIVESTAR_ENABLE) {
     $form['reviews'][$axis->aid]['score']['#type'] = 'fivestar';
     $form['reviews'][$axis->aid]['score']['#stars'] = NODEREVIEW_MAXRATING;
   }
 
-  //the #required field now looks at the field we've added to the database indicating whether 
+  // the #required field now looks at the field we've added to the database indicating whether
-  //or not a description/comments are required per axis  
+  // or not a description/comments are required per axis
   $form['reviews'][$axis->aid]['review'] = array(
     '#type' => 'textarea',
     '#title' => t('Review'),
-    '#default_value' => isset($node->reviews[$axis->aid]['review']) ? $node->reviews[$axis->aid]['review']: '',
+    '#default_value' => (!empty($node->review->review)) ? $node->review->review
+      : '',
     '#required' => $axis->description_required,
   );
- 
+
 }
 
 /**
- * Implementation of hook_validate().
- *
+ * Implements of hook_validate().
  */
-function nodereview_validate($node, $form, &$form_state) { 
+function nodereview_validate($node, $form, &$form_state) {
-
-  $review_count = db_query("SELECT Count(*) FROM {node} WHERE nid = :nid", array(':nid' => $node->reviewed_nid))->fetchObject();     
-      
+  $review_count = db_query("SELECT Count(*) FROM {node} WHERE nid = :nid", array(':nid' => $node->reviewed_nid))->fetchObject();
+
-  if (! $node->reviewed_nid || !$review_count) {
+  if (!$node->reviewed_nid || !$review_count) {
     // There is no such node, so error
     form_set_error('reviewed_nid', t('The node you are trying to review does not exist.'));
   }
+  if (!empty($node->reviews)) {
-  foreach ($node->reviews as $aid => $review) {
+    foreach ($node->reviews as $aid => $review) {
-    if (! $review['score']) {
+      if (!$review['score']) {
-      form_set_error('', t('You must enter a score for every axis.'));
-    }
-    //updates so that if there is no review and a view is required that the form won't validate
+        form_set_error('', t('You must enter a score for every axis.'));
+      }
+      //updates so that if there is no review and a view is required that the form won't validate
-    if (! $review['review'] && $review['review']['required'] == 1) {
-      //form_set_error('', t('You must enter a review for every axis.'), NULL);
+      if (empty($review['review'])) {
+        form_set_error('', t('You must enter a review for every axis.'), NULL);
-    }
-  }
-}
+      }
+    }
+  }
+}
 
 /**
- * Implementation of hook_load().
- * 
- *
+ * Implements of hook_load().
+ */
 function nodereview_load($nodes) {
-  $arg = arg(1);
-  if (is_numeric($arg)) {
-  $node = node_load(arg(1));
-  // Get the basic information from the nodereview node table
-  $reviews = db_query("SELECT reviewed_nid FROM {nodereview} WHERE nid = :nid", array(':nid' => $node->nid))->fetchObject();     
+  foreach ($nodes as &$node) {
+    $node->reviewed_nid = db_query("SELECT reviewed_nid FROM {nodereview} WHERE nid = :nid", array(':nid' => $node->nid))->fetchField();
+    $reviewed_node = node_load($node->reviewed_nid);
-  // And now get the actual review info.  The numeric scores are stored with voteapi,
-  // while textual reviews are in our own auxiliary table.  We need to merge them properly
+    // And now get the actual review info.  The numeric scores are stored with voteapi,
+    // while textual reviews are in our own auxiliary table.  We need to merge them properly
-
-  $criteria = array(
-    'entity_type' => 'node',
+    $criteria = array(
+      'entity_type' => 'node',
-    'entity_id' => isset($reviews->reviewed_nid) ? $reviews->reviewed_nid: '',
+      'entity_id' => $reviewed_node->nid,
-    'uid' => $node->uid,
-  );
+      'uid' => $node->uid,
+    );
-
-  $votes_obj = votingapi_select_votes($criteria);
+    $votes_obj = votingapi_select_votes($criteria);
-
-
-  //  $votes_obj = votingapi_get_user_votes('node', $additions->reviewed_nid, $node->uid);
-  $votes = array();
-  foreach ($votes_obj as $vote) {
+    foreach ($votes_obj as $vote) {
-    $votes[$vote['tag']] = $vote;
+      $votes[trim($vote['tag'])] = $vote;
-  }
+    }
 
-  $sql = "SELECT nr.aid, tag, review 
-          FROM {nodereview_reviews} nr 
-          INNER JOIN {nodereview_axes} na ON nr.aid=na.aid 
-          WHERE nid = :nid 
-          ORDER BY na.weight, na.tag";
+    $query = db_select('nodereview_reviews', 'nr');
+    $query->join('nodereview_axes', 'na', 'nr.aid=na.aid');
+    $query->fields('nr', array('aid', 'review'));
+    $query->fields('na', array('tag'));
+    $query->condition('nid', (int)$node->nid);
+    $node->review = (object)$query->execute()->fetchAssoc();
 
-  $result = db_query($sql, array(':nid' => $node->nid));
-
-  $reviews = array();
-  while ($record = $result->fetchObject()) {    
-    // Add in the numeric scores
-    //$record->score = $votes[$record->tag]['value'];
-    // issue: http://drupal.org/node/1215138
-    $record->score = $votes[substr($record->tag,0,64)]['value'];
-    $reviews[$record->aid] = (array)$record;
+    $node->review->score = $votes[trim($node->review->tag)]['value'];
   }
-  $nodes[$node->nid]->reviews = $reviews;
-  //return $additions;
-  }
+}
-}
 
-
 /**
- * Implementation of hook_insert().
- *
+ * Implements of hook_insert().
  */
 function nodereview_insert($node) {
-
   db_insert('nodereview')
     ->fields(array('nid', 'reviewed_nid'))
     ->values(array(
-      'nid'          => $node->nid,
+                    'nid' => $node->nid,
-      'reviewed_nid' => $node->reviewed_nid,      
-    ))
+                    'reviewed_nid' => $node->reviewed_nid,
+                  ))
     ->execute();
-    
+
   nodereview_save_reviews($node);
 }
 
 /**
- * Implementation of hook_update().
- *
+ * Implements of hook_update().
  */
 function nodereview_update($node) {
-
-  db_update('nodereview') // Table name no longer needs {}
+  // Table name no longer needs {}
+  db_update('nodereview')
-        ->fields(array(
-           'reviewed_nid' => $node->reviewed_nid,
-         ))
-         ->condition('nid', $node->nid, '=')
-         ->execute();
-         
+    ->fields(array(
+                  'reviewed_nid' => $node->reviewed_nid,
+                ))
+    ->condition('nid', $node->nid, '=')
+    ->execute();
+
   // Delete and rebuild the textual reviews, but the votingapi takes care of overwriting old values
   db_delete('nodereview_reviews')
     ->condition('nid', $node->nid, '=')
-    ->execute(); 
+    ->execute();
 
   nodereview_save_reviews($node);
 }
 
+/**
+ * This function implements save a node of type nodereview
+ * @param $node
+ * @return void
+ */
 function nodereview_save_reviews($node) {
-  global $user;
-
   $votes = array();
 
-  $reviewed_nid = db_query("SELECT type FROM {node} WHERE nid = :nid", array(':nid' => $node->reviewed_nid))->fetchObject();     
-    
+  $reviewed_nid = db_query("SELECT type FROM {node} WHERE nid = :nid", array(':nid' => $node->reviewed_nid))->fetchObject();
+
-  $axes = nodereview_list_axes($reviewed_nid);
-  
+  $axes = nodereview_list_axes($reviewed_nid->type);
+  if (!empty($node->reviews)) {
-  foreach ($node->reviews as $aid => $review) {
-    // Save the text review
-    db_insert('nodereview_reviews')
-      ->fields(array('nid', 'aid', 'review'))
-      ->values(array(
+    foreach ($node->reviews as $aid => $review) {
+      // Save the text review
+      db_insert('nodereview_reviews')
+        ->fields(array('nid', 'aid', 'review'))
+        ->values(array(
-        'nid'    => $node->nid,
-        'aid'    => $aid,  
-        'review' => $review['review'],                    
+                        'nid' => (int)$node->nid,
+                        'aid' => (int)$aid,
+                        'review' => check_plain($review['review']),
-       ))
-       ->execute();
+                      ))
+        ->execute();
-
-    // And use the votingapi to save the score
-    $votes[] = array('value' => $review['score'], 'tag' => $axes[$aid], 'entity_type' => 'node', 'entity_id' => $node->reviewed_nid);
+      // And use the votingapi to save the score
+      $votes[] = array('value' => $review['score'], 'tag' => $axes[$aid], 'entity_type' => 'node', 'entity_id' => $node->reviewed_nid);
 
-  }
+    }
-  //  votingapi_set_vote('node', $node->reviewed_nid, $votes, $node->uid);
+  }
   votingapi_set_votes($votes);
 }
 
 /**
- * Implementation of hook_delete().
- *
+ * Implements of hook_delete().
  */
 function nodereview_delete($node) {
 
   db_delete('nodereview')
     ->condition('nid', $node->nid, '=')
-    ->execute();  
+    ->execute();
 
   db_delete('nodereview_reviews')
     ->condition('nid', $node->nid, '=')
-    ->execute();  
-    
- $criteria = array(
+    ->execute();
+
+  $criteria = array(
     'entity_type' => 'node',
     'entity_id' => $node->reviewed_nid,
     'uid' => $node->uid,
@@ -304,60 +277,41 @@
   votingapi_recalculate_results('node', $node->reviewed_nid);
 }
 
-
 /**
- * Implementation of hook_view().
- *
+ * Implements of hook_view().
  */
 function nodereview_view($node, $view_mode) {
-
-  //$node = node_object_prepare($node, $teaser);
-  $aids = array_keys($node->reviews);
-  $num_aids = sizeof($aids);
   // Previews are just plain ugly, because the $node object is not really a node
   // but a mutated $_POST.  It has to be handled completely differently.
-
-  if ($node->op == 'Preview') {
+  if (!empty($node->op) && $node->op == 'Preview') {
     // We have to load in our axis data, which the $_POST doesn't have but we need
-    $sql = "SELECT tag, aid
-            FROM {nodereview_axes} na
-            INNER JOIN {node} n ON na.node_type=n.type
-            WHERE n.nid = :nid";
+    $query = db_select('nodereview_axes', 'na');
+    $query->join('node', 'n', 'na.node_type=n.type');
+    $query->fields('na', array('tag', 'aid'));
+    $query->condition('n.nid', (int)$node->reviewed_nid);
+    $node->review->tag = $query->execute()->fetchField();
+    $node->review->tag = trim($node->review->tag);
+    $node->review->score = (int) ($_POST['reviews'][1]['score']);
+    $node->review->review = check_plain($_POST['reviews'][1]['review']);
 
-    $result = db_query($sql, array(':nid' => $node->reviewed_nid));
-    
-    while ($record = $result->fetchObject()) {                        
-      $node->reviews[$record['aid']]['tag'] = $record['tag'];
-    }
-
-    foreach ($node->reviews as $review) {
-      $node->content['reviews'][$review['tag']] = array(
-        '#value' => theme('nodereview_review_preview', array('review' => $review, 'node' => $node)),
+    $node->content['review'][$node->review->tag] = array(
+      '#markup' => theme('nodereview_review_preview', array('review' => $node->review, 'node' => $node)),
-      );
-    }
+    );
+  }
-  }
   else {
-    $node = node_object_prepare($node);
-
     // Do a markup check on the fields
-    for ($i=0; $i < $num_aids; $i++) {
-      $node->reviews[$aids[$i]]['review'] = check_markup($node->reviews[$aids[$i]]['review']);
-    }
+    $node->review->review = check_markup($node->review->review);
     if ($view_mode == 'teaser') {
-      $node->content['reviews'] = array(
-          '#value' => theme('nodereview_teaser', array('node' => $node)),
+      $node->content['review'] = array(
+        '#markup' => theme('nodereview_teaser', array('node' => $node)),
-        );
+      );
     }
-    if ($view_mode == 'full') {
-      foreach ($node->reviews as $review) {
-        $node->content['reviews'][$review['tag']] = array(
-          '#value' => theme('nodereview_review_body', array('review' => $review, 'node' => $node)),
+    else {
+      $node->content['review'][$node->review->tag] = array(
+        '#markup' => theme('nodereview_review_body', array('review' => $node->review, 'node' => $node)),
-        );
-      }
+      );
+    }
-    }
 
-
-
   }
-  return $node;  
+  return $node;
 }
Index: nodereview.theme.inc
===================================================================
--- nodereview.theme.inc	(revision 964da59ed87acf8a8a90c2c9dc3bdbf76fb1553e)
+++ nodereview.theme.inc	(revision )
@@ -1,9 +1,9 @@
 <?php
 
-  /**
-   * @file
-   * This is to implement theme functions for nodereview module
-   */
+/**
+ * @file
+ * This is to implement theme functions for nodereview module
+ */
 
 /**
  * Implementation of theme_nodereview_configure_axes()
@@ -30,17 +30,17 @@
     $row[] = drupal_render($form['axes'][$key]['weight']);
     $rows[] = array(
       'data' => $row,
-      'id' => 'nodereview-row-'. $key,
+      'id' => 'nodereview-row-' . $key,
       'class' => array('draggable', 'tabledrag-leaf'),
-    );    
-    
-    
+    );
+
+
   }
-  
+
   $header = array('Use', 'Name', 'Description', 'Require Vote Comments', 'Weight');
 
   // This is how we get the table to be "inside" the fieldset
-  $form['axes']['#children'] = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' =>  array('id' => 'nodereview-axes')));
+  $form['axes']['#children'] = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'nodereview-axes')));
 
   //OPTIONS: drupal_add_tabledrag($table_id, $action, $relationship, $group, $subgroup = NULL, $source = NULL, $hidden = TRUE, $limit = 0);
   drupal_add_tabledrag('nodereview-axes', 'order', 'group', 'weight', NULL, NULL, FALSE);
@@ -55,97 +55,97 @@
  * view
  *
  */
-
 function theme_nodereview_review_body($vars) {
   $review = $vars['review'];
-  $node   = $vars['node'];
-  //Logger::debug_var('review', $review);
+  $maxrating_proportion = round(($review->score / 100) * NODEREVIEW_MAXRATING);
 
-  $maxrating_proportion = round(($review['score']/100) * NODEREVIEW_MAXRATING);
-      
   $fivestar = '';
-  $title = $review['tag'];
+  $title = $review->tag;
   if (NODEREVIEW_FIVESTAR_ENABLE) {
-    $fivestar = theme('fivestar_static', $review['score'], NODEREVIEW_MAXRATING);
+    $fivestar_args = array('rating' => $review->score, 'stars' => 5, 'tag' => $review->tag);
+    $fivestar = theme('fivestar_static', $fivestar_args);
   }
   elseif (NODEREVIEW_LABEL_ENABLE) {
     $title .= ' ' . variable_get('nodereview_rating_label' . $maxrating_proportion, '');
-  }  
+  }
   else {
     $title .= ': ' . $maxrating_proportion . '/' . NODEREVIEW_MAXRATING;
   }
-  $output = '<h3>' . $title . '</h3><div class="content">' . $fivestar . $review['review'] . '</div>';
 
+  $output = '<h3>' . $title . '</h3><div class="content">' . $fivestar . $review->review . '</div>';
+
   return $output;
 }
 
-
 /**
  * Implementation of  theme_nodereview_review_preview
  * We declare this function to theme the node preview
  *
  */
-
 function theme_nodereview_review_preview($vars) {
   $review = $vars['review'];
-  $node   = $vars['node'];
-  
-  $output = '';
-
-  $maxrating_proportion = round(($review['score']/100) * NODEREVIEW_MAXRATING);
-    
-  $title = $review['tag'];
+  $maxrating_proportion = round(($review->score / 100) * NODEREVIEW_MAXRATING);
+  $title = $review->tag;
   $fivestar = '';
   if (NODEREVIEW_FIVESTAR_ENABLE) {
-    $fivestar = theme('fivestar_static', $review['score']);
+    $fivestar_args = array(
+      'rating' => $review->score,
+      'stars' => 5,
+      'tag' => $review->tag
+    );
+    $fivestar = theme('fivestar_static', $fivestar_args);
   }
   elseif (NODEREVIEW_LABEL_ENABLE) {
-    $title .= ' ' . variable_get('nodereview_rating_label' . $maxrating_proportion, '');
+    $title = ' '
+             . variable_get('nodereview_rating_label' . $maxrating_proportion, '');
   }
   else {
-    $title .= ': ' . $maxrating_proportion . '/' . NODEREVIEW_MAXRATING;
+    $title = ': '
+             . $maxrating_proportion . '/' . NODEREVIEW_MAXRATING;
   }
-  $output ='<h3>' . $title . '</h3><div class="content">' . $fivestar . check_markup($review['review'] . $node->format) . '</div>';
+  $output = '<h3>'
+            . $title
+            . '</h3><div class="content">'
+            . $fivestar
+            . check_markup($review->review /* . $node->format*/)
+            . '</div>';
 
   return $output;
 }
 
-
 /**
  * Implementation of  theme_nodereview_teaser
  * We declare this function to theme the node teaser
  * view
  *
  */
-
 function theme_nodereview_teaser($vars) {
-  $node   = $vars['node'];
+  $node = $vars['node'];
   $output = '';
   static $header;
-  
+
   // Presumably teaser will be called multiple times on different nodes
   // on the same page, so static cache the static strings
-  if (!isset($header)) {
+  if (empty($header)) {
     $header = array(t('axis'), t('score'), t('review'));
   }
 
-  foreach ($node->reviews as $review) {
-    $maxrating_proportion = round(($review['score']/100) * NODEREVIEW_MAXRATING);
+  $maxrating_proportion = round(($node->review->score / 100) * NODEREVIEW_MAXRATING);
-    $row = array();
+  $row = array();
-    $row[] = $review['tag'];
+  $row[] = $node->review->tag;
-    if (NODEREVIEW_FIVESTAR_ENABLE) {
+  if (NODEREVIEW_FIVESTAR_ENABLE) {
-      $row[] = theme('fivestar_static', $review['score'], NODEREVIEW_MAXRATING);
+    $fivestar_args = array('rating' => $node->review->score, 'stars' => 5, 'tag' => $node->review->tag);
+    $row[] = theme('fivestar_static', $fivestar_args, NODEREVIEW_MAXRATING);
-    }
-    elseif (NODEREVIEW_LABEL_ENABLE) {
-      $row[] = variable_get('nodereview_rating_label' . $maxrating_proportion, '');
-    }      
-    else {
-      $row[] = $maxrating_proportion . '/' . NODEREVIEW_MAXRATING;
-    }
+  }
+  elseif (NODEREVIEW_LABEL_ENABLE) {
+    $row[] = variable_get('nodereview_rating_label' . $maxrating_proportion, '');
+  }
+  else {
+    $row[] = $maxrating_proportion . '/' . NODEREVIEW_MAXRATING;
+  }
-    $row[] = truncate_utf8($review['review'], 50, TRUE, TRUE);
+  $row[] = truncate_utf8($node->review->review, 50, TRUE, TRUE);
-    $rows[] = $row;
+  $rows[] = $row;
-  }
 
-  $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' =>  array('class' => array('review-teaser'))));
+  $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('class' => array('review-teaser'))));
   return $output;
 }
Index: nodereview.admin.inc
===================================================================
--- nodereview.admin.inc	(revision 964da59ed87acf8a8a90c2c9dc3bdbf76fb1553e)
+++ nodereview.admin.inc	(revision )
@@ -18,29 +18,29 @@
 function nodereview_configure_axes($form, &$form_state, $type, $name) {
 
   drupal_set_title(t('Reviews for %type nodes', array('%type' => check_plain($name))), PASS_THROUGH);
-  
+
   $form['use'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Reviews'),
-      '#collapsible' => TRUE,
-      '#collapsed' => FALSE,
+    '#type' => 'fieldset',
+    '#title' => t('Reviews'),
+    '#collapsible' => TRUE,
+    '#collapsed' => FALSE,
   );
 
   $form['use']['node_type'] = array('#type' => 'hidden', '#value' => $type);
-  
+
   $form['use']['guide'] = array(
     '#type' => 'textarea',
     '#title' => t('Usage Guide to the User'),
     '#return_value' => 1,
-    '#default_value' => variable_get('nodereview_guide_'. $type, ''),
+    '#default_value' => variable_get('nodereview_guide_' . $type, ''),
     '#description' => t('Instructions to users for how to use this review.  These will be shown on the "Add Review" page. Note that if you have help text defined on admin/settings/content-types/nodereview, this value will override it.'),
   );
-  
+
   $form['use']['embed'] = array(
     '#type' => 'checkbox',
     '#title' => t('Embed the node reviews within the node content being reviewed.'),
     '#description' => t('Embed the node review form within the actual node content being reviewed instead of using a seperate menu tab'),
-    '#default_value' => variable_get('nodereview_embed_'. $type, 0),
+    '#default_value' => variable_get('nodereview_embed_' . $type, 0),
     '#return_value' => 1,
   );
 
@@ -62,7 +62,7 @@
 
   $axes = array();
 
-  while ($record = $result->fetchObject()) {  
+  while ($record = $result->fetchObject()) {
     $axes[] = _nodereview_configure_axis($record);
   }
 
@@ -75,7 +75,6 @@
   $form['axes'] += $axes;
 
   $form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
-
   return $form;
 
 }
@@ -91,8 +90,8 @@
   $form_values = $form_state['values'];
   // Save whether or not we're reviewing this node type
   // variable_set('nodereview_use_' . $form_values['node_type'], $form_values['use']);
-  variable_set('nodereview_guide_'. $form_values['node_type'], $form_values['guide']);
+  variable_set('nodereview_guide_' . $form_values['node_type'], $form_values['guide']);
-  
+
   //save whether or not this axis should be embedded in the node content
   variable_set('nodereview_embed_' . $form_values['node_type'], $form_values['embed']);
 
@@ -103,36 +102,37 @@
       $axis['description'] = check_plain($axis['description']);
 
       //this ensures any changes to the required description checkbox get recorded when updating the admin page
-      db_update('nodereview_axes') // Table name no longer needs {}
+      // Table name no longer needs {}
+      db_update('nodereview_axes')
         ->fields(array(
-           'tag'                   => $axis['tag'],
+                      'tag' => $axis['tag'],
-           'description'           => $axis['description'],
+                      'description' => $axis['description'],
-           'description_required'  => $axis['description_required'],
+                      'description_required' => $axis['description_required'],
-           'weight'                => $axis['weight'],
+                      'weight' => $axis['weight'],
-         ))
-         ->condition('aid', $axis['aid'], '=')
-         ->execute();
+                    ))
+        ->condition('aid', $axis['aid'], '=')
+        ->execute();
 
     }
-    elseif ($axis['aid'] && ! $axis['use']) {
+    elseif ($axis['aid'] && !$axis['use']) {
       // Delete an existing axis
       db_delete('nodereview_axes')
         ->condition('aid', $axis['aid'], '=')
-        ->execute(); 
+        ->execute();
     }
-    elseif ($axis['use'] && ! $axis['aid']) {
+    elseif ($axis['use'] && !$axis['aid']) {
       // Create a new axis
       $axis['description'] = check_plain($axis['description']);
 
       db_insert('nodereview_axes')
         ->fields(array('node_type', 'tag', 'description', 'weight', 'description_required'))
         ->values(array(
-          'node_type'            => $form_values['node_type'],
+                      'node_type' => $form_values['node_type'],
-          'tag'                  => $axis['tag'],  
+                      'tag' => $axis['tag'],
-          'description'          => $axis['description'],                    
+                      'description' => $axis['description'],
-          'weight'               => $axis['weight'],
+                      'weight' => $axis['weight'],
-          'description_required' => $axis['description_required'],                                                                          
-        ))
+                      'description_required' => $axis['description_required'],
+                    ))
         ->execute();
     }
     else {
@@ -151,7 +151,7 @@
 function _nodereview_configure_axis($record) {
   $form['aid'] = array(
     '#type' => 'hidden',
-    '#value' => isset($record->aid) ? $record->aid: '',
+    '#value' => (!empty($record->aid)) ? $record->aid : '',
   );
   $form['use'] = array(
     '#type' => 'checkbox',
@@ -164,28 +164,29 @@
     '#type' => 'textfield',
     '#title' => t('name'),
     '#return_value' => 1,
-    '#default_value' => isset($record->tag) ? $record->tag: '',
+    '#default_value' => (!empty($record->tag)) ? $record->tag : '',
     '#size' => 30,
   );
   $form['description'] = array(
     '#type' => 'textarea',
     '#title' => t('description'),
     '#return_value' => 1,
-    '#default_value' => isset($record->description) ? $record->description: '',
+    '#default_value' => (!empty($record->description)) ? $record->description : '',
     '#rows' => 2,
   );
   $form['description_required'] = array(
     '#type' => 'checkbox',
     '#title' => t('require a vote description'),
     '#return_value' => 1,
-    '#default_value' => isset($record->description_required) ? $record->description_required: '',
+    '#default_value' => (!empty($record->description_required))
+      ? $record->description_required : '',
     '#description' => t(''),
-  );  
+  );
   $form['weight'] = array(
     '#type' => 'weight',
     '#title' => t('weight'),
     '#delta' => 50,
-    '#default_value' => isset($record->weight) ? $record->weight: '',
+    '#default_value' => (!empty($record->weight)) ? $record->weight : '',
     '#attributes' => array('class' => array('weight')),
   );
 
@@ -204,11 +205,11 @@
   $default = array();
   foreach (node_type_get_types() as $type => $info) {
     $options[$type] = $info->name;
-    if (variable_get('nodereview_use_'. $type, 0)) {
+    if (variable_get('nodereview_use_' . $type, 0)) {
       $default[] = $type;
     }
   }
-  
+
   $form['nodereview'] = array(
     '#type' => 'fieldset',
     '#title' => t('Review types'),
@@ -222,13 +223,13 @@
     '#options' => $options,
     '#description' => t('Specify which content types can be reviewed.'),
   );
-  
+
   $rating_options['normal'] = 'Normal (Numerical Ratings, eg. 1 to 10)';
   $rating_options['label'] = 'Label (Word Ratings, Good, Better, ...)';
   if (module_exists('fivestar')) {
     $rating_options['fivestar'] = 'Five Star Rating';
   }
-  
+
   $form['ratings'] = array(
     '#type' => 'fieldset',
     '#title' => t('Ratings'),
@@ -239,10 +240,10 @@
   $form['ratings']['maxrating'] = array(
     '#type' => 'textfield',
     '#title' => t('Maximum Rating'),
-    '#default_value' => (NODEREVIEW_MAXRATING) ? NODEREVIEW_MAXRATING: 5,
+    '#default_value' => (NODEREVIEW_MAXRATING) ? NODEREVIEW_MAXRATING : 5,
     '#description' => t('Allowed values: 1 to 100'),
-  );  
-  
+  );
+
   $form['ratings']['type'] = array(
     '#type' => 'radios',
     '#title' => t('Type of ratings'),
@@ -250,15 +251,15 @@
     '#options' => $rating_options,
     '#description' => t(''),
   );
-  
+
   $form['labels'] = array(
     '#type' => 'fieldset',
     '#title' => t('Labels'),
     '#collapsible' => TRUE,
     '#collapsed' => TRUE,
     '#tree' => TRUE,
-  ); 
-   
+  );
+
   for ($i = 1; $i < (NODEREVIEW_MAXRATING + 1); $i++) {
     $form['labels']['label' . $i] = array(
       '#type' => 'textfield',
@@ -267,8 +268,8 @@
       '#default_value' => variable_get('nodereview_rating_label' . $i, ''),
       '#description' => t(''),
     );
-  }   
- /*  
+  }
+  /*
   if (module_exists('fivestar')) {
     $form['ratings']['enable'] = array(
       '#type' => 'checkbox',
@@ -300,7 +301,11 @@
   return $form;
 }
 
-
+/**
+ * @param $form
+ * @param $form_state
+ * @return void
+ */
 function nodereview_configure_submit($form, $form_state) {
   $form_values = $form_state['values'];
   if (($form_values['ratings']['maxrating'] > 100) || !is_numeric($form_values['ratings']['maxrating'])) {
@@ -312,12 +317,12 @@
   }
   variable_set('nodereview_maxrating', $maxrating);
   variable_set('nodereview_rating_type', $form_values['ratings']['type']);
-    
+
   for ($i = 1; $i < (NODEREVIEW_MAXRATING + 1); $i++) {
     variable_set('nodereview_rating_label' . $i, $form_values['labels']['label' . $i]);
-  }   
+  }
   foreach ($form_values['types'] as $type => $checked) {
-    variable_set('nodereview_use_'. $type, (bool)$checked);
+    variable_set('nodereview_use_' . $type, (bool)$checked);
   }
   cache_clear_all();
   menu_rebuild();
Index: nodereview.install
===================================================================
--- nodereview.install	(revision 964da59ed87acf8a8a90c2c9dc3bdbf76fb1553e)
+++ nodereview.install	(revision )
@@ -1,38 +1,35 @@
 <?php
 
-  /**
-   * @file
-   * Install script to install the nodereview module
-   *
-   */
+/**
+ * @file
+ * Install script to install the nodereview module
+ *
+ */
 
 /**
- * Implementation of hook_install().
+ * Implements of hook_install().
  */
-
 function nodereview_install() {
 
-  // Use schema API to create database table.
-  drupal_install_schema('nodereview');
 }
 
 /**
- * Implementation of hook_uninstall().
+ * Implements of hook_uninstall().
  */
 function nodereview_uninstall() {
-  // Use schema API to delete database table.
-  drupal_uninstall_schema('nodereview');
-
   //Delete all the node type entry from nodetype table
-  $sql = "DELETE FROM {node_type} 
-          WHERE type = :type";
+  node_type_delete('nodereview');
 
- 
-  $result = db_query($sql, array(':type' =>'nodereview'));
-    
+  // Delete all nodes with nodetype 'nodereview'
+  $nids = db_select('node', 'n')
+    ->fields('n', array('nid'))
+    ->condition('type', 'nodereview')
+    ->execute()
+    ->fetchCol();
+  node_delete_multiple($nids);
   //Delet all nodereview labels
   for ($i = 1; $i < 11; $i++) {
-      variable_del('nodereview_rating_label' . $i);
+    variable_del('nodereview_rating_label' . $i);
   }
   //Delete nodereview maximum rating and rating type
   variable_del('nodereview_maxrating');
@@ -46,7 +43,7 @@
 }
 
 /**
- * Implementation of hook_schema().
+ * Implements of hook_schema().
  */
 function nodereview_schema() {
 
@@ -103,8 +100,8 @@
       'weight' => array(
         'type' => 'int',
         'not null' => TRUE,
-        'length'   => 11,
+        'length' => 11,
-        'default'  => 0,
+        'default' => 0,
         'description' => t('The axes weight.'),
       ),
 
@@ -113,12 +110,12 @@
         'not null' => FALSE,
         'description' => t('The decsription about the axes.'),
       ),
-      
+
       'description_required' => array(
         'type' => 'int',
         'not null' => TRUE,
         'size' => 'tiny',
-        'default'  => 0,
+        'default' => 0,
         'description' => t('Whether or not a vote description is required.'),
       ),
     ),
@@ -126,13 +123,12 @@
   );
 
 
-
   $schema['nodereview_reviews'] = array(
     'description' => t('Stores reviews.'),
     'fields' => array(
       'nid' => array(
         'type' => 'int',
-        'length'   => 11,
+        'length' => 11,
         'not null' => TRUE,
         'default' => 0,
         'description' => t('The {node}.nid of the review.'),
@@ -141,8 +137,8 @@
       'aid' => array(
         'type' => 'int',
         'not null' => TRUE,
-        'length'   => 11,
+        'length' => 11,
-        'default'  => 0,
+        'default' => 0,
         'description' => t('The {axes}.nid of the review.'),
       ),
 
@@ -157,5 +153,3 @@
   );
   return $schema;
 }
-
-
Index: nodereview.module
===================================================================
--- nodereview.module	(revision 964da59ed87acf8a8a90c2c9dc3bdbf76fb1553e)
+++ nodereview.module	(revision )
@@ -4,15 +4,10 @@
 define('NODEREVIEW_LABEL_ENABLE', (variable_get('nodereview_rating_type', '') == 'label'));
 define('NODEREVIEW_MAXRATING', variable_get('nodereview_maxrating', 5));
 
-        
+
-//if(!function_exists("node_object_prepare")) {
-  include_once(drupal_get_path('module', 'node') . '/node.pages.inc');
-//}
+module_load_include('pages.inc', 'node');
+module_load_include('inc', 'nodereview', 'nodereview_node_nodereview');
 
-require_once(drupal_get_path('module', 'nodereview') . '/nodereview_node_nodereview.inc');
-
-
-
 /**
  * @file
  * This module adds user reviews to specified node types, on multiple axes and with
@@ -20,45 +15,36 @@
  * (required) for some displays.
  */
 
-
 /**
- * Implementation of hook_help().
- *
+ * Implements of hook_help().
  */
 function nodereview_help($path, $arg) {
+  switch ($path) {
 
-  // We want to show custom help text on both the add and edit pages, which
-  // have very different path structures
-  if ('node' == arg(0)) {
-    if ('addreview' == arg(2)) {
-      $reviewed_nid = arg(1);
+    case 'node/%/addreview':
+      $reviewed_nid = $arg[1];
       $reviewed_node = node_load($reviewed_nid);
-      $help_text = filter_xss_admin(variable_get('nodereview_guide_'. $reviewed_node->type, ''));
+      $help_text = filter_xss_admin(variable_get('nodereview_guide_' . $reviewed_node->type, ''));
-      if ($help_text) return $help_text;
-    }
-    elseif ('edit' == arg(2)) {
+      return $help_text;
+
+    case 'node/%/editreview':
       // Get the type of the node we're reviewing, which is not the nid in the path
       $sql = "SELECT n.type
               FROM {node} n
-              INNER JOIN {nodereview} nr ON n.nid = nr.reviewed_nid
-              WHERE nr.nid = :nid";
+              INNER join {nodereview} nr ON n.nid = nr.reviewed_nid
+              WHERE nr.reviewed_nid = :nid";
 
-      $result = db_query($sql, array(':nid' => arg(1)));
+      $record = db_query($sql, array(':nid' => $arg[1]));
+      $record = (object)$record->fetchAssoc();
 
-      $record = $result->fetchObject();
-  
-      $help_text = filter_xss_admin(variable_get('nodereview_guide_'. $record->type, ''));
+      $help_text = filter_xss_admin(variable_get('nodereview_guide_' . $record->type, ''));
-      if ($help_text) return $help_text;
+      return $help_text;
-    }
-  }
+  }
+}
-}
 
-
 /**
- * Implementation of hook_node_info().
- *
+ * Implements of hook_node_info().
  */
-
 function nodereview_node_info() {
   return array(
     'nodereview' => array(
@@ -73,85 +59,58 @@
   );
 }
 
-
 /**
- * Implementation of hook_perm().
- *
+ * Implements of hook_permission().
  */
-function nodereview_perm() {
+function nodereview_permission() {
   return array(
-    'administer reviews',
-    'read reviews',
-    'submit reviews',
-    'edit own reviews'
+    'administer reviews' => array(
+      'title' => t('Administer reviews'),
+    ),
+    'read reviews' => array(
+      'title' => t('Read reviews'),
+    ),
+    'submit reviews' => array(
+      'title' => t('Submit reviews'),
+    ),
+    'edit own reviews' => array(
+      'title' => t('Edit own reviews'),
+    ),
   );
 }
 
 /**
- * Implementation of hook_link().
- *
+ * Implements of hook_menu().
  */
-function nodereview_link($type, $node = NULL, $teaser = FALSE) {
-  $links = array();
-  global $user;
-
-  if ($type == 'node' && $node->type == 'nodereview') {
-
-    $sql = "SELECT type FROM {node} 
-            WHERE nid = :nid";
-
-    $result = db_query($sql, array(':nid' => $node->reviewed_nid));
-
-    $record = $result->fetchObject();
-                  
-    // Add a link back to the node being reviewed by this node
-    $reviewed_type = node_type_get_types('type', $record->type);
-    $reviewed_type = $reviewed_type->name;
-
-    $links['nodereview_reviewed_node'] = array(
-    'title' => t('View @type', array('@type' => $reviewed_type)),
-    'href' => "node/{$node->reviewed_nid}",
-    'attributes' => array('title' => t('View the @type being reviewed', array('@type' => $reviewed_type))),
-   );
-  }
-
-  return $links;
-}
-
-/**
- * Implementation of hook_menu().
- *
- */
 function nodereview_menu() {
   $items = array();
-  global $user;
 
-  $items['admin/structure/nodereview'] = array(
-    'title' => t('Review types'),
+  $items['admin/config/nodereview'] = array(
+    'title' => 'Review types',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('nodereview_configure'),
     'file' => 'nodereview.admin.inc',
     'access arguments' => array('administer reviews'),
-    'description' => t('Configure the axes for node type review'),
+    'description' => 'Configure the axes for node type review',
-    );
+  );
 
-  $items['admin/structure/nodereview/types'] = array(
-    'title' => t('List'),
+  $items['admin/config/nodereview/types'] = array(
+    'title' => 'List',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('nodereview_configure'),
     'file' => 'nodereview.admin.inc',
     'access arguments' => array('administer reviews'),
     'type' => MENU_DEFAULT_LOCAL_TASK,
     'weight' => -1,
-    );
+  );
 
 
   // Add a tab for each node type that we can review
   // It's slow to put this here, as it should go in
 
   foreach (node_type_get_types() as $type => $info) {
-    if (variable_get('nodereview_use_'. $type, 0)) {
+    if (variable_get('nodereview_use_' . $type, 0)) {
-      $items['admin/structure/nodereview/' . $type] = array(
+      $items['admin/config/nodereview/' . $type] = array(
         'title callback' => 'check_plain',
         'title arguments' => array($info->name),
         'page callback' => 'drupal_get_form',
@@ -163,7 +122,7 @@
     }
   }
   $items['node/%/reviews'] = array(
-    'title' => t('Reviews'),
+    'title' => 'Reviews',
     'page callback' => 'views_page',
     'page arguments' => array('review_list', 'page_1', 1),
     'access callback' => 'read_reviews_access',
@@ -175,9 +134,9 @@
   );
 
   $items['node/%node_add_review/addreview'] = array(
-    'title' => t('Add review'),
-    'page callback' => 'node_add',
-    'page arguments' => array('nodereview'),
+    'title callback' => 'nodereview_add_review_title',
+    'page callback' => 'nodereview_node_add_form',
+    'page arguments' => array(1),
     'access callback' => 'addreview_access',
     'access arguments' => array(1),
     'type' => MENU_LOCAL_TASK,
@@ -185,7 +144,7 @@
   );
 
   $items['node/%node_edit_review/editreview'] = array(
-    'title' => t('Edit your review'),
+    'title' => 'Edit your review',
     'page callback' => 'node_page_edit',
     'page arguments' => array(1),
     'access arguments' => array('edit own reviews'),
@@ -196,25 +155,44 @@
   return $items;
 }
 
+/**
+ * Create title for page add node of type nodereview
+ * @return string
+ */
+function nodereview_add_review_title() {
+  drupal_set_title(t('Create @name', array('@name' => 'nodereview')), PASS_THROUGH);
+  return 'Add review';
+}
 
+/**
+ * Returned node_add form for add/edit nodereview content type
+ * @param int $reviewed_nid
+ * @return array
+ */
+function nodereview_node_add_form($reviewed_nid) {
+  global $user;
+  $new_nodereview = (object)array(
+    'uid' => $user->uid,
+    'name' => (!empty($user->name) ? $user->name : ''),
+    'type' => 'nodereview',
+    'language' => LANGUAGE_NONE,
+    'reviewed_nid' => $reviewed_nid,
+  );
+  return drupal_get_form('nodereview_node_form', $new_nodereview);
+}
 
 /**
- * Implementation of hook_menu_alter()
- *
+ * Implements of hook_menu_alter().
  */
 function nodereview_menu_alter(&$callbacks) {
   // Hide the normal node-add page, since we never want users to see it
   unset($callbacks['node/add/nodereview']);
 }
 
-
-
 /**
- * Implementation of hook_form_alter()
- *
+ * Implements of hook_form_alter().
  */
 function nodereview_form_alter(&$form, &$form_state, $form_id) {
-
   if ($form_id == 'node_type_form') {
 
     // variable_set('nodereview_node_types', array());
@@ -232,25 +210,24 @@
       '#title' => t('Enable user reviews'),
       '#default_value' => variable_get('nodereview_use_' . $node_type, 0),
       '#options' => array(0 => t('Disabled'), 1 => t('Enabled')),
-      '#description' => t('You can configure axes for reviewable nodes on the <a href="!url">reviews page</a>.', array('!url' => url('admin/structure/nodereview'))),
+      '#description' => t('You can configure axes for reviewable nodes on the <a href="!url">reviews page</a>.', array('!url' => url('admin/config/nodereview'))),
     );
   }
 }
 
-
 /**
-  * Implementation of hook_theme().
+ * Implements of hook_theme().
+ *
-  * We declare  nodereview_configure_axes so
+ * We declare  nodereview_configure_axes so
-  * Drupal will look for a function
-  * named theme_nodereview_configure_axes().
+ * Drupal will look for a function named theme_nodereview_configure_axes().
-  */
+ */
 function nodereview_theme() {
   return array(
     'nodereview_configure_axes' => array(
       'render element' => 'form',
       'file' => 'nodereview.theme.inc',
     ),
-    /*
+
     'nodereview_review_body' => array(
       'variables' => array('review' => NULL, 'node' => NULL),
       'file' => 'nodereview.theme.inc',
@@ -262,41 +239,29 @@
     'nodereview_teaser' => array(
       'variables' => array('node' => NULL),
       'file' => 'nodereview.theme.inc',
-    ),*/
+    ),
   );
 }
 
-
-function nodereview_view_reviews($nid) {
-
-  $output = 'test ' . $nid;
-
-  drupal_set_title('Reviews');
-
-  return $output;
-}
-
-
+/**
+ * @param $node_type
+ * @return null
+ */
 function nodereview_list_axes($node_type) {
   static $axes = array();
-
-  if (! isset($axes[$node_type])) {
-    $sql = "SELECT na.aid, na.tag 
-            FROM {nodereview_axes} na 
-            WHERE na.node_type = :type";
-
+  if (empty($axes[$node_type])) {
+    $sql = "SELECT na.aid, na.tag FROM {nodereview_axes} na WHERE na.node_type = :type";
     $result = db_query($sql, array(':type' => $node_type));
-    
+
     while ($record = $result->fetchObject()) {
       $axes[$node_type][$record->aid] = $record->tag;
     }
   }
-  return $axes[$node_type];
+  return (!empty($axes[$node_type])) ? $axes[$node_type] : NULL;
 }
 
-
 /**
- * Implementation of hook_node_type()
+ * Implements of hook_node_type().
  *
  * To clear the cache when a content type
  * is modified and the changes to reflect
@@ -308,9 +273,8 @@
   menu_rebuild();
 }
 
-
 /**
- * Implementation of hook_views_api()
+ * Implements of hook_views_api().
  *
  */
 function nodereview_views_api() {
@@ -320,7 +284,6 @@
   );
 }
 
-
 /**
  * Menu callback
  * Returns TRUE if no review for the current node from current user
@@ -329,23 +292,21 @@
 function node_add_review_load($arg) {
   global $user;
   $add_review = FALSE;
-  $current_node = node_load($arg);
+  $current_node = node_load((int)$arg);
   $type = $current_node->type;
   //check to see if the nodereview form should be embedded. If it should, just
   //return FALSE immediately becuase there is no point querying the DB.
-  if(variable_get('nodereview_embed_'. $type, 0) == 1 ) {
+  if (variable_get('nodereview_embed_' . $type, 0) == 1) {
     return $add_review;
   }
-  
+
-  $axes_count = db_query("SELECT COUNT(*) FROM {nodereview_axes} WHERE node_type = :type", array(':type' => $type))->fetchObject(); 
-  
-  if (variable_get('nodereview_use_' . $type, 0) && $axes_count) {
+  $is_axes = db_query("SELECT COUNT(*) as qty FROM {nodereview_axes} WHERE node_type = :type", array(':type' => $type))->fetchField();
+  if (variable_get('nodereview_use_' . $type, 0) && $is_axes) {
-    $add_review = db_query("SELECT n.nid FROM {node} n INNER JOIN {nodereview} nr ON n.nid = nr.nid WHERE uid = :uid AND reviewed_nid = :nid", array(':uid' => $user->uid, ':nid' => $arg))->fetchObject(); 
+    $add_review = db_query("SELECT n.nid FROM {node} n INNER JOIN {nodereview} nr ON n.nid = nr.nid WHERE uid = :uid AND reviewed_nid = :nid", array(':uid' => $user->uid, ':nid' => $arg))->fetchObject();
   }
   return $add_review ? FALSE : $arg;
 }
 
-
 /**
  * Menu callback
  * Returns FALSE if no review for the current node from current user
@@ -354,29 +315,29 @@
 function node_edit_review_load($arg) {
   global $user;
   $edit_review = FALSE;
-  $current_node = node_load($arg);
+  $current_node = node_load((int)$arg);
   $type = $current_node->type;
   //check to see if the nodereview form should be embedded. If it should, just
   //return FALSE immediately becuase there is no point querying the DB.
-  if(variable_get('nodereview_embed_'. $type, 0) == 1 ) {
+  if (variable_get('nodereview_embed_' . $type, 0) == 1) {
     return $edit_review;
   }
-  
-  $axes_count = db_query("SELECT COUNT(*) FROM {nodereview_axes} WHERE node_type = :type", array(':type' => $type))->fetchObject();   
-  
+
+  $axes_count = db_query("SELECT COUNT(*) FROM {nodereview_axes} WHERE node_type = :type", array(':type' => $type))->fetchObject();
+
   if (variable_get('nodereview_use_' . $type, 0) && $axes_count) {
-    $edit_review = db_query("SELECT n.nid FROM {node} n INNER JOIN {nodereview} nr ON n.nid = nr.nid WHERE uid = :uid AND reviewed_nid = :nid", array(':uid' => $user->uid, ':nid' => $arg))->fetchObject();     
+    $edit_review = db_query("SELECT n.nid FROM {node} n INNER JOIN {nodereview} nr ON n.nid = nr.nid WHERE uid = :uid AND reviewed_nid = :nid", array(':uid' => $user->uid, ':nid' => $arg))->fetchObject();
   }
-  return $edit_review ? node_load($edit_review) : FALSE;
+  return $edit_review ? node_load($edit_review->nid) : FALSE;
 }
 
 /**
  * Custom access menucallback for add review
  */
-function addreview_access($arg) {
-  $current_node = node_load($arg);
+function addreview_access($arg, $account = NULL) {
+  $current_node = node_load((int)$arg);
   $type = $current_node->type;
-  $axes_count = db_query("SELECT COUNT(*) FROM {nodereview_axes} WHERE node_type = :type", array(':type' => $type))->fetchObject();     
+  $axes_count = db_query("SELECT COUNT(*) FROM {nodereview_axes} WHERE node_type = :type", array(':type' => $type))->fetchObject();
   return variable_get('nodereview_use_' . $type, 0) && $axes_count && user_access('submit reviews');
 }
 
@@ -384,40 +345,39 @@
  * Custom access menucallback for read review
  */
 function read_reviews_access($arg) {
-  $current_node = node_load($arg);
+  $current_node = node_load((int)$arg);
   $type = $current_node->type;
   return variable_get('nodereview_use_' . $type, 0) && user_access('read reviews');
 }
 
-
 /**
- * Implementation of hook_node_view().
+ * Implements of hook_node_view().
-*/
+ */
 function nodereview_node_view($node, $view_mode, $langcode) {
   global $user;
   // The 'view' operation means the node is about to be displayed.
-  
+
   // Abort if it's not a page
-  if ($view_mode != 'full') return '';
+  if ($view_mode != 'full') {
+    return '';
+  }
 
   // Should only appear and process on content type with review.
-  if (variable_get('nodereview_use_' . $node->type, 0)) { 
+  if (variable_get('nodereview_use_' . $node->type, 0)) {
 
     //Get node id, tags and value for this node
-    $sql = "SELECT vote_id, value, uid 
-            FROM {votingapi_vote} 
-            WHERE entity_id = :entity_id";  
+    $sql = "SELECT vote_id, value, uid FROM {votingapi_vote} WHERE entity_id = :entity_id";
-    
+
-    $result = db_query($sql, array(':entity_id' =>  $node->nid));
+    $result = db_query($sql, array(':entity_id' => $node->nid));
 
-    $votes = array();   
-    $total_value = ''; 
-    while ($record = $result->fetchObject()) {  
+    $votes = array();
+    $total_value = '';
+    while ($record = $result->fetchObject()) {
       $votes[] = $record->vote_id;
       $total_value += $record->value;
       $users[$record->uid] = 1;
-    } 
-    if (!empty($total_value)) {  
+    }
+    if (!empty($total_value)) {
       $vote_count = count($votes);
       //print $vote_count . ' votes <br />';
       //print $total_value . ' total value <br />';
@@ -425,17 +385,19 @@
       //print $user_count . ' users <br />';
       $total = round($total_value / count($votes));
       //print $total . ' avarage <br />';
-      $maxrating_proportion = round(($total/100) * NODEREVIEW_MAXRATING);
+      $maxrating_proportion = round(($total / 100) * NODEREVIEW_MAXRATING);
       //print $maxrating_proportion . ' maxrating proportion <br />';
       //print NODEREVIEW_MAXRATING . ' maxrating (global)';
-       
+
       if (NODEREVIEW_FIVESTAR_ENABLE) {
-        $total = round($total_value/$vote_count) . '%';
+        $total = round($total_value / $vote_count) . '%';
       }
       elseif (NODEREVIEW_LABEL_ENABLE) {
         $total = variable_get('nodereview_rating_label' . $maxrating_proportion, '');
-        if (!$total) drupal_set_message(t('You have no assigned label rating on your settings.'), 'error', TRUE);      
+        if (!$total) {
+          drupal_set_message(t('You have no assigned label rating on your settings.'), 'error', TRUE);
-      }
+        }
+      }
       else {
         $total = $maxrating_proportion . '/' . NODEREVIEW_MAXRATING;
       }
@@ -443,34 +405,51 @@
       $node->content['review_total'] = array(
         '#prefix' => '<div class="box nodereview-average-rating"><h2><span class="label">Average Review Rating:</span> ',
         '#suffix' => '</h2><h3>Total Reviews: ' . $user_count . '</h3></div> ',
-        '#value' => $total, 
+        '#value' => $total,
         '#weight' => 0,
       );
     }
   }
-    
+
+  if ($node->type == 'nodereview') {
+    $query = db_select('node', 'n')
+      ->fields('n', array('type'))
+      ->condition('nid', (int)$node->reviewed_nid)
+      ->execute();
+    $reviewed_type = $query->fetchField();
+
+    // Add a link back to the node being reviewed by this node
+    $node->content['links']['#links']['nodereview'] = array(
+      'title' => t('View @type', array('@type' => $reviewed_type)),
+      'href' => "node/{$node->reviewed_nid}",
+      'attributes' => array('title' => t('View the @type being reviewed', array('@type' => $reviewed_type))),
+    );
+
+  }
+  
   //Check to see if this node type should have embedded reviews and that the user
   //has accesss to submit reviews.
-  if (variable_get('nodereview_embed_'. $node->type, 0) == 1 && user_access('submit reviews')) {
+  if (variable_get('nodereview_embed_' . $node->type, 0) == 1 && user_access('submit reviews')) {
-  
+
-    $existing_review = db_query("SELECT uid FROM {node} WHERE type = :type and uid = :uid", array(':type' => 'nodereview', ':uid' => $user->uid))->fetchObject();     
+    $query = db_select('node', 'n');
+    $query->join('nodereview', 'nr', 'nr.nid = n.nid');
+    $query->fields('n', array('uid'));
+    $query->condition('nr.reviewed_nid', (int)$node->nid, '=');
+    $query->condition('type', 'nodereview', '=');
+    $query->condition('uid', (int)$user->uid, '=');
+    $existing_review = $query->execute()->fetchField();
-    
+
     //If there is no existing review, embed the node_add form for nodereviews.
     //If there is an existing review and the user has access to edit own reviews, load the review and pass it to node_page_edit.
-    if (!$existing_review) {
-      $node->content['nodereview_form'] = array(
-        '#value' => node_add('nodereview'),
-        '#weight' => '5',
-      );
+    if (empty($existing_review)) {
+      $node->content['nodereview_form'] = nodereview_node_add_form($node->nid);
+      $node->content['nodereview_form']['#weight'] = 5;
     }
     elseif ($existing_review && user_access('edit own reviews')) {
-    
-      $edit_review = db_query("SELECT n.nid FROM {node} n INNER JOIN {nodereview} nr ON n.nid = nr.nid WHERE uid = :uid AND reviewed_nid = :nid", array(':uid' => $user->uid, ':nid' => $node->nid))->fetchObject();     
+      $edit_review = db_query("SELECT n.nid FROM {node} n INNER JOIN {nodereview} nr ON n.nid = nr.nid WHERE uid = :uid AND reviewed_nid = :nid", array(':uid' => $user->uid, ':nid' => $node->nid))->fetchObject();
-        
-      $node->content['nodereview_form'] = array(
-        '#value' => node_page_edit(node_load($edit_review)),
-        '#weight' => '5',
-      );
+      $review_node = node_load((int)$edit_review->nid);
+      $node->content['nodereview_form'] = drupal_get_form('nodereview_node_form', $review_node);
+      $node->content['nodereview_form']['#weight'] = 5;
     }
   }
 
@@ -478,52 +457,52 @@
 }
 
 /**
- * Implements hook_token_values().
+ * Implements of hook_token_values().
  *
 function nodereview_token_values($type, $object = NULL) {
-  module_load_include('tokens.inc', 'nodereview');
-  return _nodereview_token_values($type, $object);
+module_load_include('tokens.inc', 'nodereview');
+return _nodereview_token_values($type, $object);
 }
 /**
- * Implementation of hook_token_values().
+ * Implements of hook_token_values().
  *
 function _nodereview_token_values($type, $object = NULL) {
-  $values = array();
-  $node = node_load(arg(1));
-  if ($type == 'node' && !empty($object)) {
+$values = array();
+$node = node_load(arg(1));
+if ($type == 'node' && !empty($object)) {
 
-      $reviewed_nid = db_query("SELECT reviewed_nid FROM {nodereview} WHERE nid = :nid", array(':nid' => $node->nid))->fetchObject();     
-        
-      $reviewed = node_load($reviewed_nid);
-      $values['node-reviewed-nid'] = $reviewed_nid;
-      $values['node-reviewed-path-alias'] = drupal_get_path_alias('node/'. $reviewed_nid);
-      $values['node-reviewed-title-raw'] = $reviewed->title;
+$reviewed_nid = db_query("SELECT reviewed_nid FROM {nodereview} WHERE nid = :nid", array(':nid' => $node->nid))->fetchObject();
+
+$reviewed = node_load($reviewed_nid);
+$values['node-reviewed-nid'] = $reviewed_nid;
+$values['node-reviewed-path-alias'] = drupal_get_path_alias('node/'. $reviewed_nid);
+$values['node-reviewed-title-raw'] = $reviewed->title;
 
-  }
+}
 
-  return $values;
+return $values;
 }
 
 /**
- * Implements hook_token_list().
+ * Implements of hook_token_list().
  *
 function nodereview_token_list($type = 'all') {
-  module_load_include('tokens.inc', 'nodereview');
-  return _nodereview_token_list($type);
+module_load_include('tokens.inc', 'nodereview');
+return _nodereview_token_list($type);
 }
 
 /**
- * Implementation of hook_token_list().
+ * Implements of hook_token_list().
  *
 function _nodereview_token_list($type = 'all') {
-  $tokens = array();
+$tokens = array();
 
-  if ($type == 'node' || $type == 'all') {
-    $tokens['node']['node-reviewed-nid'] = t('The reviewed node id. This will only appear for nodereview type nodes.');
-    $tokens['node']['node-reviewed-path-alias'] = t('The reviewed node path. This will only appear for nodereview type nodes.');
-    $tokens['node']['node-reviewed-title-raw'] = t('Title of the reviewed node. This will only appear for nodereview type nodes.');
-    // Node tokens here.
-  }
+if ($type == 'node' || $type == 'all') {
+$tokens['node']['node-reviewed-nid'] = t('The reviewed node id. This will only appear for nodereview type nodes.');
+$tokens['node']['node-reviewed-path-alias'] = t('The reviewed node path. This will only appear for nodereview type nodes.');
+$tokens['node']['node-reviewed-title-raw'] = t('Title of the reviewed node. This will only appear for nodereview type nodes.');
+// Node tokens here.
+}
 
-  return $tokens;
+return $tokens;
 }*/
Index: LICENSE.txt
===================================================================
--- LICENSE.txt	(revision )
+++ LICENSE.txt	(revision )
@@ -0,0 +1,274 @@
+GNU GENERAL PUBLIC LICENSE
+
+              Version 2, June 1991
+
+Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave,
+Cambridge, MA 02139, USA. Everyone is permitted to copy and distribute
+verbatim copies of this license document, but changing it is not allowed.
+
+                  Preamble
+
+The licenses for most software are designed to take away your freedom to
+share and change it. By contrast, the GNU General Public License is
+intended to guarantee your freedom to share and change free software--to
+make sure the software is free for all its users. This General Public License
+applies to most of the Free Software Foundation's software and to any other
+program whose authors commit to using it. (Some other Free Software
+Foundation software is covered by the GNU Library General Public License
+instead.) You can apply it to your programs, too.
+
+When we speak of free software, we are referring to freedom, not price. Our
+General Public Licenses are designed to make sure that you have the
+freedom to distribute copies of free software (and charge for this service if
+you wish), that you receive source code or can get it if you want it, that you
+can change the software or use pieces of it in new free programs; and that
+you know you can do these things.
+
+To protect your rights, we need to make restrictions that forbid anyone to
+deny you these rights or to ask you to surrender the rights. These restrictions
+translate to certain responsibilities for you if you distribute copies of the
+software, or if you modify it.
+
+For example, if you distribute copies of such a program, whether gratis or for
+a fee, you must give the recipients all the rights that you have. You must make
+sure that they, too, receive or can get the source code. And you must show
+them these terms so they know their rights.
+
+We protect your rights with two steps: (1) copyright the software, and (2)
+offer you this license which gives you legal permission to copy, distribute
+and/or modify the software.
+
+Also, for each author's protection and ours, we want to make certain that
+everyone understands that there is no warranty for this free software. If the
+software is modified by someone else and passed on, we want its recipients
+to know that what they have is not the original, so that any problems
+introduced by others will not reflect on the original authors' reputations.
+
+Finally, any free program is threatened constantly by software patents. We
+wish to avoid the danger that redistributors of a free program will individually
+obtain patent licenses, in effect making the program proprietary. To prevent
+this, we have made it clear that any patent must be licensed for everyone's
+free use or not licensed at all.
+
+The precise terms and conditions for copying, distribution and modification
+follow.
+
+           GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND
+               MODIFICATION
+
+0. This License applies to any program or other work which contains a notice
+placed by the copyright holder saying it may be distributed under the terms
+of this General Public License. The "Program", below, refers to any such
+program or work, and a "work based on the Program" means either the
+Program or any derivative work under copyright law: that is to say, a work
+containing the Program or a portion of it, either verbatim or with
+modifications and/or translated into another language. (Hereinafter, translation
+is included without limitation in the term "modification".) Each licensee is
+addressed as "you".
+
+Activities other than copying, distribution and modification are not covered
+by this License; they are outside its scope. The act of running the Program is
+not restricted, and the output from the Program is covered only if its contents
+constitute a work based on the Program (independent of having been made
+by running the Program). Whether that is true depends on what the Program
+does.
+
+1. You may copy and distribute verbatim copies of the Program's source
+code as you receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice and
+disclaimer of warranty; keep intact all the notices that refer to this License
+and to the absence of any warranty; and give any other recipients of the
+Program a copy of this License along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and you
+may at your option offer warranty protection in exchange for a fee.
+
+2. You may modify your copy or copies of the Program or any portion of it,
+thus forming a work based on the Program, and copy and distribute such
+modifications or work under the terms of Section 1 above, provided that you
+also meet all of these conditions:
+
+a) You must cause the modified files to carry prominent notices stating that
+you changed the files and the date of any change.
+
+b) You must cause any work that you distribute or publish, that in whole or in
+part contains or is derived from the Program or any part thereof, to be
+licensed as a whole at no charge to all third parties under the terms of this
+License.
+
+c) If the modified program normally reads commands interactively when run,
+you must cause it, when started running for such interactive use in the most
+ordinary way, to print or display an announcement including an appropriate
+copyright notice and a notice that there is no warranty (or else, saying that
+you provide a warranty) and that users may redistribute the program under
+these conditions, and telling the user how to view a copy of this License.
+(Exception: if the Program itself is interactive but does not normally print such
+an announcement, your work based on the Program is not required to print
+an announcement.)
+
+These requirements apply to the modified work as a whole. If identifiable
+sections of that work are not derived from the Program, and can be
+reasonably considered independent and separate works in themselves, then
+this License, and its terms, do not apply to those sections when you distribute
+them as separate works. But when you distribute the same sections as part
+of a whole which is a work based on the Program, the distribution of the
+whole must be on the terms of this License, whose permissions for other
+licensees extend to the entire whole, and thus to each and every part
+regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest your rights to
+work written entirely by you; rather, the intent is to exercise the right to
+control the distribution of derivative or collective works based on the
+Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of a
+storage or distribution medium does not bring the other work under the scope
+of this License.
+
+3. You may copy and distribute the Program (or a work based on it, under
+Section 2) in object code or executable form under the terms of Sections 1
+and 2 above provided that you also do one of the following:
+
+a) Accompany it with the complete corresponding machine-readable source
+code, which must be distributed under the terms of Sections 1 and 2 above
+on a medium customarily used for software interchange; or,
+
+b) Accompany it with a written offer, valid for at least three years, to give
+any third party, for a charge no more than your cost of physically performing
+source distribution, a complete machine-readable copy of the corresponding
+source code, to be distributed under the terms of Sections 1 and 2 above on
+a medium customarily used for software interchange; or,
+
+c) Accompany it with the information you received as to the offer to distribute
+corresponding source code. (This alternative is allowed only for
+noncommercial distribution and only if you received the program in object
+code or executable form with such an offer, in accord with Subsection b
+above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source code
+means all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation and
+installation of the executable. However, as a special exception, the source
+code distributed need not include anything that is normally distributed (in
+either source or binary form) with the major components (compiler, kernel,
+and so on) of the operating system on which the executable runs, unless that
+component itself accompanies the executable.
+
+If distribution of executable or object code is made by offering access to
+copy from a designated place, then offering equivalent access to copy the
+source code from the same place counts as distribution of the source code,
+even though third parties are not compelled to copy the source along with the
+object code.
+
+4. You may not copy, modify, sublicense, or distribute the Program except as
+expressly provided under this License. Any attempt otherwise to copy,
+modify, sublicense or distribute the Program is void, and will automatically
+terminate your rights under this License. However, parties who have received
+copies, or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+5. You are not required to accept this License, since you have not signed it.
+However, nothing else grants you permission to modify or distribute the
+Program or its derivative works. These actions are prohibited by law if you
+do not accept this License. Therefore, by modifying or distributing the
+Program (or any work based on the Program), you indicate your acceptance
+of this License to do so, and all its terms and conditions for copying,
+distributing or modifying the Program or works based on it.
+
+6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the original
+licensor to copy, distribute or modify the Program subject to these terms and
+conditions. You may not impose any further restrictions on the recipients'
+exercise of the rights granted herein. You are not responsible for enforcing
+compliance by third parties to this License.
+
+7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues), conditions
+are imposed on you (whether by court order, agreement or otherwise) that
+contradict the conditions of this License, they do not excuse you from the
+conditions of this License. If you cannot distribute so as to satisfy
+simultaneously your obligations under this License and any other pertinent
+obligations, then as a consequence you may not distribute the Program at all.
+For example, if a patent license would not permit royalty-free redistribution
+of the Program by all those who receive copies directly or indirectly through
+you, then the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply and
+the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any patents or
+other property right claims or to contest validity of any such claims; this
+section has the sole purpose of protecting the integrity of the free software
+distribution system, which is implemented by public license practices. Many
+people have made generous contributions to the wide range of software
+distributed through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing to
+distribute software through any other system and a licensee cannot impose
+that choice.
+
+This section is intended to make thoroughly clear what is believed to be a
+consequence of the rest of this License.
+
+8. If the distribution and/or use of the Program is restricted in certain
+countries either by patents or by copyrighted interfaces, the original copyright
+holder who places the Program under this License may add an explicit
+geographical distribution limitation excluding those countries, so that
+distribution is permitted only in or among countries not thus excluded. In such
+case, this License incorporates the limitation as if written in the body of this
+License.
+
+9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will be
+similar in spirit to the present version, but may differ in detail to address new
+problems or concerns.
+
+Each version is given a distinguishing version number. If the Program specifies
+a version number of this License which applies to it and "any later version",
+you have the option of following the terms and conditions either of that
+version or of any later version published by the Free Software Foundation. If
+the Program does not specify a version number of this License, you may
+choose any version ever published by the Free Software Foundation.
+
+10. If you wish to incorporate parts of the Program into other free programs
+whose distribution conditions are different, write to the author to ask for
+permission. For software which is copyrighted by the Free Software
+Foundation, write to the Free Software Foundation; we sometimes make
+exceptions for this. Our decision will be guided by the two goals of
+preserving the free status of all derivatives of our free software and of
+promoting the sharing and reuse of software generally.
+
+               NO WARRANTY
+
+11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE,
+THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT
+PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE
+STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
+WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
+PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
+NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR
+AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR
+ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE
+LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL,
+SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
+ARISING OUT OF THE USE OR INABILITY TO USE THE
+PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA
+OR DATA BEING RENDERED INACCURATE OR LOSSES
+SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE
+PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN
+IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF
+THE POSSIBILITY OF SUCH DAMAGES.
+
+          END OF TERMS AND CONDITIONS
