Book review stores reviews in table bookreview instead of using the body of table node_revisions. This change places the review back into node_revisions. The change also makes it easier to convert existing nodes to book reviews without having to copy the body text to the bookreview table.
In function bookreview_insert($node) replace:
db_query("INSERT INTO {bookreview} (nid, booktitle, cover, cover_alt, publisher, copyright, isbn, synopsis"
. ", contents, review, pages, price, rating)"
. " VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s'"
. ", '%s', '%s', '%s', '%s', %d)",
$node->nid, $node->title, $node->cover, $node->cover_alt, $node->publisher, $node->copyright, $node->isbn, $node->synopsis,
$node->contents, $node->review, $node->pages, $node->price, $node->rating);
with:
$use_revisions = variable_get('bookreview_use_revisions', false);
if($use_revisions)
{
db_query("INSERT INTO {bookreview} (nid, booktitle, cover, cover_alt, publisher, copyright, isbn, synopsis"
. ", contents, pages, price, rating)"
. " VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s'"
. ", '%s', '%s', '%s', %d)",
$node->nid, $node->title, $node->cover, $node->cover_alt, $node->publisher, $node->copyright, $node->isbn, $node->synopsis,
$node->contents, $node->pages, $node->price, $node->rating);
}
else
{
db_query("INSERT INTO {bookreview} (nid, booktitle, cover, cover_alt, publisher, copyright, isbn, synopsis"
. ", contents, review, pages, price, rating)"
. " VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s'"
. ", '%s', '%s', '%s', '%s', %d)",
$node->nid, $node->title, $node->cover, $node->cover_alt, $node->publisher, $node->copyright, $node->isbn, $node->synopsis,
$node->contents, $node->review, $node->pages, $node->price, $node->rating);
}
in function bookreview_update($node) replace:
db_query("UPDATE {bookreview} SET booktitle = '%s', cover = '%s', cover_alt = '%s', publisher = '%s', copyright = '%s'"
. ", isbn = '%s', pages = '%s', price = '%s', rating = %d, synopsis = '%s', contents = '%s', review = '%s'"
. " WHERE nid = %d",
$node->title, $node->cover, $node->cover_alt, $node->publisher, $node->copyright,
$node->isbn, $node->pages, $node->price, $node->rating, $node->synopsis, $node->contents, $node->review,
$node->nid);
with:
$use_revisions = variable_get('bookreview_use_revisions', false);
if($use_revisions)
{
db_query("UPDATE {bookreview} SET booktitle = '%s', cover = '%s', cover_alt = '%s', publisher = '%s', copyright = '%s'"
. ", isbn = '%s', pages = '%s', price = '%s', rating = %d, synopsis = '%s', contents = '%s'"
. " WHERE nid = %d",
$node->title, $node->cover, $node->cover_alt, $node->publisher, $node->copyright,
$node->isbn, $node->pages, $node->price, $node->rating, $node->synopsis, $node->contents,
$node->nid);
}
else
{
db_query("UPDATE {bookreview} SET booktitle = '%s', cover = '%s', cover_alt = '%s', publisher = '%s', copyright = '%s'"
. ", isbn = '%s', pages = '%s', price = '%s', rating = %d, synopsis = '%s', contents = '%s', review = '%s'"
. " WHERE nid = %d",
$node->title, $node->cover, $node->cover_alt, $node->publisher, $node->copyright,
$node->isbn, $node->pages, $node->price, $node->rating, $node->synopsis, $node->contents, $node->review,
$node->nid);
}
In function bookreview_form(&$node) replace:
$form['review'] = array(
'#type' => 'textarea',
'#title' => t('Review'),
'#default_value' => $node->review,
'#description' => t('This is the actual book review.'),
'#rows' => 20
);
with:
$use_revisions = variable_get('bookreview_use_revisions', false);
if($use_revisions)
{
$form['body'] =
array(
'#type' => 'textarea',
'#title' => t('Review'),
'#default_value' => $node->body,
'#description' => t('This is the actual book review.'),
'#rows' => 20
);
}
else
{
$form['review'] =
array(
'#type' => 'textarea',
'#title' => t('Review'),
'#default_value' => $node->review,
'#description' => t('This is the actual book review.'),
'#rows' => 20
);
}
In function bookreview_settings() add the following just before return $form;:
$form['bookreview_settings']['bookreview_use_revisions'] =
array(
'#type' => 'checkbox',
'#title' => t('Use revisions'),
'#default_value' => variable_get('bookreview_use_revisions', false),
'#description' => t('Store the review in node_revisions.body instead of bookreview.review.'),
);
In function theme_bookreview_content() replace:
if($node->review) {
$output .= " <div class=\"review\">\n";
$output .= ' <span class="label1">'. t('Review') .":</span>\n";
$output .= ' <span class="content2">'. check_markup($node->review, $node->format, FALSE) ."</span>\n";
$output .= " </div>\n";
}
with:
$use_revisions = variable_get('bookreview_use_revisions', false);
if($use_revisions)
{
if($node->body)
{
$node_review = $node->body;
}
}
else
{
if($node->review)
{
$node_review = $node->review;
}
}
if($node_review)
{
$output .= " <div class=\"review\">\n";
$output .= ' <span class="label1">'. t('Review') .":</span>\n";
$output .= ' <span class="content2">'. check_markup($node_review, $node->format, FALSE) ."</span>\n";
$output .= " </div>\n";
}