diff --git a/nodereview.admin.inc b/nodereview.admin.inc index e7f66b8..1fe5a78 100644 --- a/nodereview.admin.inc +++ b/nodereview.admin.inc @@ -27,6 +27,7 @@ function nodereview_configure_axes(&$form_state, $type, $name) { ); $form['use']['node_type'] = array('#type' => 'hidden', '#value' => $type); + $form['use']['guide'] = array( '#type' => 'textarea', '#title' => t('Usage Guide to the User'), @@ -34,6 +35,14 @@ function nodereview_configure_axes(&$form_state, $type, $name) { '#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), + '#return_value' => 1, + ); $form['axes'] = array( '#type' => 'fieldset', @@ -78,6 +87,9 @@ function nodereview_configure_axes_submit($form, $form_state) { // 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']); + + //save whether or not this axis should be embedded in the node content + variable_set('nodereview_embed_' . $form_values['node_type'], $form_values['embed']); // Regardless, save the user's data, just in case they may want it later foreach ($form_values['axes'] as $axis) { diff --git a/nodereview.install b/nodereview.install index 5843424..d3efb2c 100644 --- a/nodereview.install +++ b/nodereview.install @@ -46,7 +46,7 @@ function nodereview_uninstall() { */ function nodereview_update_1() { $ret = array(); - db_add_field(&$ret, 'nodereview_axes', 'description_required', array('description' => t('Whether or not a vote description is required.'), 'type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0)); return $ret; + db_add_field($ret, 'nodereview_axes', 'description_required', array('description' => t('Whether or not a vote description is required.'), 'type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0)); return $ret; } /** @@ -118,6 +118,7 @@ function nodereview_schema() { 'default' => '', 'description' => t('The decsription about the axes.'), ), + 'description_required' => array( 'type' => 'int', 'not null' => TRUE, diff --git a/nodereview.module b/nodereview.module index 0a0f1d2..2d517a4 100644 --- a/nodereview.module +++ b/nodereview.module @@ -313,6 +313,11 @@ function node_add_review_load($arg) { $add_review = FALSE; $current_node = node_load($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 ) { + return $add_review; + } $axes_count = db_result(db_query("SELECT COUNT(*) FROM {nodereview_axes} WHERE node_type='%s'", $type)); if (variable_get('nodereview_use_' . $type, 0) && $axes_count) { $add_review = db_result(db_query("SELECT n.nid FROM {node} n INNER JOIN {nodereview} nr ON n.nid=nr.nid WHERE uid=%d AND reviewed_nid=%d", $user->uid, $arg)); @@ -330,7 +335,12 @@ function node_edit_review_load($arg) { global $user; $edit_review = FALSE; $current_node = node_load($arg); - $type =$current_node->type; + $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 ) { + return $edit_review; + } $axes_count = db_result(db_query("SELECT COUNT(*) FROM {nodereview_axes} WHERE node_type='%s'", $type)); if (variable_get('nodereview_use_' . $type, 0) && $axes_count) { $edit_review = db_result(db_query("SELECT n.nid FROM {node} n INNER JOIN {nodereview} nr ON n.nid=nr.nid WHERE uid=%d AND reviewed_nid=%d", $user->uid, $arg)); @@ -405,10 +415,28 @@ function nodereview_nodeapi(&$node, $op, $teaser, $page) { '#value' => $total, '#weight' => 0, ); - - break; } - } + } + + //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')) { + $existing_review = db_fetch_object(db_query("SELECT {uid} FROM {node} WHERE type = '%s' and uid = '%d'", 'nodereview', $user->uid)); + //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', + ); + } elseif ($existing_review && user_access('edit own reviews')) { + $edit_review = db_result(db_query("SELECT n.nid FROM {node} n INNER JOIN {nodereview} nr ON n.nid=nr.nid WHERE uid=%d AND reviewed_nid=%d", $user->uid, $node->nid)); + $node->content['nodereview_form'] = array( + '#value' => node_page_edit(node_load($edit_review)), + '#weight' => '5', + ); + } + } break; } }