| 1 |
<?php
|
| 2 |
// $Id: bookreview.module,v 1.20.2.6 2006/06/28 12:29:10 jeremy Exp $
|
| 3 |
|
| 4 |
function bookreview_help($section = '') {
|
| 5 |
$output = '';
|
| 6 |
switch ($section) {
|
| 7 |
case 'admin/modules#description':
|
| 8 |
$output .= t('Write and publish book reviews.');
|
| 9 |
break;
|
| 10 |
case 'node/add#bookreview':
|
| 11 |
$output = t('Write a book review.');
|
| 12 |
break;
|
| 13 |
case 'admin/block/configure/bookreview/0':
|
| 14 |
$output = t('This block will display a custom link to a bookstore next to each of your book reviews. It will dynamically replace the text "%ISBN" with the actual ISBN of the book being reviewed. To use this functionality, paste the HTML snippet provided to you by the remote bookstore into the HTML snippet field. Be sure to replace the actual ISBN in the provided html snippet with the generic text "%ISBN" so this module will be able to automatically insert the correct ISBN for each of your book reviews.');
|
| 15 |
break;
|
| 16 |
}
|
| 17 |
return $output;
|
| 18 |
}
|
| 19 |
|
| 20 |
function bookreview_perm() {
|
| 21 |
return array('create bookreviews');
|
| 22 |
}
|
| 23 |
|
| 24 |
function bookreview_access($op, $node) {
|
| 25 |
switch ($op) {
|
| 26 |
case 'create':
|
| 27 |
case 'update':
|
| 28 |
case 'delete':
|
| 29 |
return user_access('create bookreviews');
|
| 30 |
}
|
| 31 |
}
|
| 32 |
|
| 33 |
function bookreview_node_info() {
|
| 34 |
return array('bookreview' => array('name' => t('book review'), 'base' => 'bookreview'));
|
| 35 |
}
|
| 36 |
|
| 37 |
function bookreview_block($op = 'list', $delta = 0, $edit = array()) {
|
| 38 |
if ($op == 'list') {
|
| 39 |
$blocks[0]['info'] = t('Book review store link');
|
| 40 |
return $blocks;
|
| 41 |
}
|
| 42 |
else if ($op == 'configure') {
|
| 43 |
$form['bookreview_store_blocktitle'] = array(
|
| 44 |
'#type' => 'textfield',
|
| 45 |
'#title' => t('Block title'),
|
| 46 |
'#default_value' => variable_get('bookreview_store_blocktitle', ''),
|
| 47 |
'#size' => 70,
|
| 48 |
'#maxlength' => 255,
|
| 49 |
'#description' => t('Enter the title to use when displaying this block, if any.'),
|
| 50 |
);
|
| 51 |
|
| 52 |
$form['bookreview_store_snippet'] = array(
|
| 53 |
'#type' => 'textarea',
|
| 54 |
'#title' => t('HTML snippet'),
|
| 55 |
'#default_value' => variable_get('bookreview_store_snippet', ''),
|
| 56 |
'#maxlength' => 1024,
|
| 57 |
'#description' => t('Enter the html snippet provided to you by the bookstore you\'d like to link to. The text "%ISBN" (without the quotes) will be replaced with the book\'s actual ISBN.'),
|
| 58 |
);
|
| 59 |
return ($form);
|
| 60 |
}
|
| 61 |
else if ($op == 'save') {
|
| 62 |
variable_set('bookreview_store_blocktitle', $edit['bookreview_store_blocktitle']);
|
| 63 |
variable_set('bookreview_store_snippet', $edit['bookreview_store_snippet']);
|
| 64 |
}
|
| 65 |
else if ($op == 'view') {
|
| 66 |
// only display block when viewing a bookreview that has defined an isbn
|
| 67 |
if (arg(0) == 'node' && is_numeric(arg(1))) {
|
| 68 |
$result = db_query(db_rewrite_sql('SELECT n.nid, b.isbn FROM {node} n INNER JOIN {bookreview} b ON n.nid = b.nid WHERE n.nid = %d AND b.isbn != ""'), arg(1));
|
| 69 |
if (db_num_rows($result) > 0) {
|
| 70 |
$node = db_fetch_object($result);
|
| 71 |
$isbn = preg_replace('/-/', '', $node->isbn);
|
| 72 |
$block['subject'] = variable_get('bookreview_store_blocktitle', '');
|
| 73 |
$content = preg_replace('/%ISBN/', $isbn, variable_get('bookreview_store_snippet', ''));
|
| 74 |
$block['content'] = $content;
|
| 75 |
}
|
| 76 |
}
|
| 77 |
return $block;
|
| 78 |
}
|
| 79 |
}
|
| 80 |
|
| 81 |
function bookreview_insert($node) {
|
| 82 |
db_query("INSERT INTO {bookreview} (nid, booktitle, cover, publisher, copyright, isbn, synopsis, contents, review, pages, price, rating) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)", $node->nid, $node->title, $node->cover, $node->publisher, $node->copyright, $node->isbn, $node->synopsis, $node->contents, $node->review, $node->pages, $node->price, $node->rating);
|
| 83 |
for ($i = 0; $i < $node->numauthors; $i++) {
|
| 84 |
$author = "author-$i";
|
| 85 |
if ($node->$author) {
|
| 86 |
db_query("INSERT INTO {bookreview_authors} (nid, author, weight) VALUES (%d, '%s', %d)", $node->nid, $node->$author, $i);
|
| 87 |
}
|
| 88 |
}
|
| 89 |
|
| 90 |
for ($i = 0; $i < $node->numlinks; $i++) {
|
| 91 |
$booklink = "booklink-$i";
|
| 92 |
$linkdescription = "linkdescription-$i";
|
| 93 |
if ($node->$booklink) {
|
| 94 |
db_query("INSERT INTO {bookreview_links} (nid, booklink, description, weight) VALUES (%d, '%s', '%s', %d)", $node->nid, $node->$booklink, $node->$linkdescription, $i);
|
| 95 |
}
|
| 96 |
}
|
| 97 |
}
|
| 98 |
|
| 99 |
function bookreview_load($node) {
|
| 100 |
$bookreview = db_fetch_object(db_query("SELECT * FROM {bookreview} WHERE nid = '$node->nid'"));
|
| 101 |
$authors = db_query("SELECT author, weight FROM {bookreview_authors} WHERE nid = '$node->nid' ORDER BY weight");
|
| 102 |
while ($author = db_fetch_object($authors)) {
|
| 103 |
$bookreview->authors[$author->weight] = $author->author;
|
| 104 |
}
|
| 105 |
$bookreview->numauthors = count($bookreview->authors);
|
| 106 |
|
| 107 |
$booklinks = db_query("SELECT booklink, description, weight FROM {bookreview_links} WHERE nid = '$node->nid' ORDER BY weight");
|
| 108 |
while ($booklink = db_fetch_object($booklinks)) {
|
| 109 |
$bookreview->booklinks[$booklink->weight] = $booklink->booklink;
|
| 110 |
$bookreview->linkdescriptions[$booklink->weight] = $booklink->description;
|
| 111 |
}
|
| 112 |
$bookreview->numlinks = count($bookreview->booklinks);
|
| 113 |
|
| 114 |
return $bookreview;
|
| 115 |
}
|
| 116 |
|
| 117 |
function bookreview_update($node) {
|
| 118 |
db_query("UPDATE {bookreview} SET booktitle = '%s', cover = '%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->publisher, $node->copyright, $node->isbn, $node->pages, $node->price, $node->rating, $node->synopsis, $node->contents, $node->review, $node->nid);
|
| 119 |
db_query('DELETE FROM {bookreview_authors} WHERE nid = %d', $node->nid);
|
| 120 |
|
| 121 |
for ($i = 0; $i < $node->numauthors; $i++) {
|
| 122 |
$author = "author-$i";
|
| 123 |
if ($node->$author) {
|
| 124 |
db_query("INSERT INTO {bookreview_authors} (nid, author, weight) VALUES (%d, '%s', %d)", $node->nid, $node->$author, $i);
|
| 125 |
}
|
| 126 |
}
|
| 127 |
db_query('DELETE FROM {bookreview_links} WHERE nid = %d', $node->nid);
|
| 128 |
|
| 129 |
for ($i = 0; $i < $node->numlinks; $i++) {
|
| 130 |
$booklink = "booklink-$i";
|
| 131 |
$linkdescription = "linkdescription-$i";
|
| 132 |
if ($node->$booklink) {
|
| 133 |
db_query("INSERT INTO {bookreview_links} (nid, booklink, description, weight) VALUES (%d, '%s', '%s', %d)", $node->nid, $node->$booklink, $node->$linkdescription, $i);
|
| 134 |
}
|
| 135 |
}
|
| 136 |
}
|
| 137 |
|
| 138 |
function bookreview_delete($node) {
|
| 139 |
db_query('DELETE FROM {bookreview} WHERE nid = %d', $node->nid);
|
| 140 |
db_query('DELETE FROM {bookreview_authors} WHERE nid = %d', $node->nid);
|
| 141 |
db_query('DELETE FROM {bookreview_links} WHERE nid = %d', $node->nid);
|
| 142 |
}
|
| 143 |
|
| 144 |
function bookreview_validate(&$node) {
|
| 145 |
if (isset($node->review)) {
|
| 146 |
$word_count = count(explode(' ', $node->review)) - 1;
|
| 147 |
if ($word_count < variable_get('minimum_bookreview_size', 0)) {
|
| 148 |
form_set_error('review', t('The body of your book review is too short. You are required to enter at least %minimum_word_count words, but you\'ve only entered %word_count.', array('%minimum_word_count' => variable_get('minimum_bookreview_size', 0), '%word_count' => $word_count)));
|
| 149 |
}
|
| 150 |
else if (!$node->review) {
|
| 151 |
form_set_error('review', theme('error', t('You are required to enter text for your book review.')));
|
| 152 |
}
|
| 153 |
}
|
| 154 |
}
|
| 155 |
|
| 156 |
function bookreview_submit(&$node) {
|
| 157 |
if (variable_get('teaser_length', 600)) {
|
| 158 |
if ($node->synopsis) {
|
| 159 |
$node->teaser = check_markup(node_teaser($node->synopsis), $node->format);
|
| 160 |
}
|
| 161 |
else {
|
| 162 |
$node->teaser = check_markup(node_teaser($node->review), $node->format);
|
| 163 |
}
|
| 164 |
}
|
| 165 |
else {
|
| 166 |
// teasers are disabled, display whole book review
|
| 167 |
$node->teaser = check_markup($node->body, $node->format);
|
| 168 |
}
|
| 169 |
}
|
| 170 |
|
| 171 |
|
| 172 |
function bookreview_form(&$node) {
|
| 173 |
$edit = $_POST['edit'];
|
| 174 |
|
| 175 |
if ($edit['numauthors']) {
|
| 176 |
// It's a preview ...
|
| 177 |
if ($edit['bookreview_more_authors'] == 1) {
|
| 178 |
// ... and we need more authors
|
| 179 |
if ($edit['numauthors'] % 2) {
|
| 180 |
$node->numauthors = $edit['numauthors'] + 1;
|
| 181 |
}
|
| 182 |
else {
|
| 183 |
$node->numauthors = $edit['numauthors'] + 2;
|
| 184 |
}
|
| 185 |
}
|
| 186 |
else {
|
| 187 |
// we don't want more authors, just see the preview
|
| 188 |
// (numauthors may have change with a previous preview)
|
| 189 |
$node->numauthors = $edit['numauthors'];
|
| 190 |
}
|
| 191 |
}
|
| 192 |
elseif(!$node->numauthors) {
|
| 193 |
// Just created review, start with one author.
|
| 194 |
$node->numauthors = 1;
|
| 195 |
}
|
| 196 |
// else we are editing an old review, we'll use the defaults
|
| 197 |
|
| 198 |
if ($edit['numlinks']) {
|
| 199 |
// It's a preview ...
|
| 200 |
if ($edit['bookreview_more_links'] == 1) {
|
| 201 |
// ... and we need more links
|
| 202 |
$node->numlinks = $edit['numlinks'] + 1;
|
| 203 |
}
|
| 204 |
else {
|
| 205 |
// we don't want more links, just see the preview
|
| 206 |
// (numlinks may have change with a previous preview)
|
| 207 |
$node->numlinks = $edit['numlinks'];
|
| 208 |
}
|
| 209 |
}
|
| 210 |
elseif(!$node->numlinks) {
|
| 211 |
// Just created review, start with one link.
|
| 212 |
$node->numlinks = 1;
|
| 213 |
}
|
| 214 |
// else we are editing an old review, we'll use the defaults
|
| 215 |
|
| 216 |
$form['numauthors'] = array(
|
| 217 |
'#type' => 'hidden',
|
| 218 |
'#value' => $node->numauthors,
|
| 219 |
);
|
| 220 |
|
| 221 |
$form['numlinks'] = array(
|
| 222 |
'#type' => 'hidden',
|
| 223 |
'#value' => $node->numlinks,
|
| 224 |
);
|
| 225 |
|
| 226 |
$form['book_infos'] = array(
|
| 227 |
'#type' => 'fieldset',
|
| 228 |
'#title' => t('General information'),
|
| 229 |
'#collapsible' => TRUE,
|
| 230 |
'#collapsed' => FALSE,
|
| 231 |
);
|
| 232 |
|
| 233 |
$form['book_infos']['title'] = array(
|
| 234 |
'#type' => 'textfield',
|
| 235 |
'#title' => t('Title'),
|
| 236 |
'#default_value' => $node->title,
|
| 237 |
'#size' => 60,
|
| 238 |
'#maxlength' => 255,
|
| 239 |
'#description' => t('The title of the book being reviewed.'),
|
| 240 |
);
|
| 241 |
|
| 242 |
$form['book_infos']['authors'] = array(
|
| 243 |
'#type' => 'fieldset',
|
| 244 |
'#title' => t('Author(s)'),
|
| 245 |
'#collapsible' => TRUE,
|
| 246 |
'#collapsed' => FALSE,
|
| 247 |
);
|
| 248 |
$form['book_infos']['authors']['authors_begin'] = array(
|
| 249 |
'#type' => 'markup',
|
| 250 |
'#value' => '<table>',
|
| 251 |
);
|
| 252 |
for ($i = 0; $i < $node->numauthors; $i++) {
|
| 253 |
$form['book_infos']['authors']["author-$i"] = array(
|
| 254 |
'#type' => 'textfield',
|
| 255 |
'#default_value' => $node->authors[$i],
|
| 256 |
'#size' => 60,
|
| 257 |
'#maxlength' => 255,
|
| 258 |
'#description' => '',
|
| 259 |
'#prefix' => ($i%2) ? '<td>' : '<tr><td>',
|
| 260 |
'#suffix' => ($i%2) ? '</td></tr>' : '</td>',
|
| 261 |
);
|
| 262 |
}
|
| 263 |
$form['book_infos']['authors']['authors_end'] = array(
|
| 264 |
'#type' => 'markup',
|
| 265 |
'#value' => ($node->numauthors+1%2) ? '</table>' : '<td></td></tr></table>',
|
| 266 |
);
|
| 267 |
|
| 268 |
$form['book_infos']['authors']['bookreview_more_authors'] = array(
|
| 269 |
'#type' => 'checkbox',
|
| 270 |
'#title' => t('add more authors'),
|
| 271 |
'#value' => 0,
|
| 272 |
'#description' => t('If the book has more authors, you can create space to list them by checking this box and clicking '). '<strong>'. t('Preview'). '</strong>.',
|
| 273 |
);
|
| 274 |
|
| 275 |
$form['book_infos']['rating'] = array(
|
| 276 |
'#type' => 'select',
|
| 277 |
'#title' => t('Rating'),
|
| 278 |
'#default_value' => $node->rating,
|
| 279 |
'#options' => (array('<' . t('none') . '>') + drupal_map_assoc(range(1, 10))),
|
| 280 |
'#description' => t('Score of the book on a 1 to 10 scale.'),
|
| 281 |
);
|
| 282 |
|
| 283 |
$form['book_detailed_infos'] = array(
|
| 284 |
'#type' => 'fieldset',
|
| 285 |
'#title' => t('Detailed information'),
|
| 286 |
'#collapsible' => TRUE,
|
| 287 |
'#collapsed' => TRUE,
|
| 288 |
);
|
| 289 |
|
| 290 |
$form['book_detailed_infos']['cover'] = array(
|
| 291 |
'#type' => 'textfield',
|
| 292 |
'#title' => t('Cover picture'),
|
| 293 |
'#default_value' => $node->cover,
|
| 294 |
'#size' => 60,
|
| 295 |
'#maxlength' => 255,
|
| 296 |
'#description' => t('URL of book cover image.'),
|
| 297 |
);
|
| 298 |
|
| 299 |
$form['book_detailed_infos']['publisher'] = array(
|
| 300 |
'#type' => 'textfield',
|
| 301 |
'#title' => t('Publisher'),
|
| 302 |
'#default_value' => $node->publisher,
|
| 303 |
'#size' => 60,
|
| 304 |
'#maxlength' => 255,
|
| 305 |
'#description' => t('The publisher of the book being reviewed.'),
|
| 306 |
);
|
| 307 |
|
| 308 |
$form['book_detailed_infos']['copyright'] = array(
|
| 309 |
'#type' => 'textfield',
|
| 310 |
'#title' => t('Copyright'),
|
| 311 |
'#default_value' => $node->copyright,
|
| 312 |
'#maxlength' => 255,
|
| 313 |
'#description' => t('The year the book was published. (Format: YYYY).'),
|
| 314 |
);
|
| 315 |
|
| 316 |
$form['book_detailed_infos']['isbn'] = array(
|
| 317 |
'#type' => 'textfield',
|
| 318 |
'#title' => t('ISBN'),
|
| 319 |
'#default_value' => $node->isbn,
|
| 320 |
'#size' => 60,
|
| 321 |
'#maxlength' => 255,
|
| 322 |
'#description' => t('The ISBN of the book being reviewed.'),
|
| 323 |
);
|
| 324 |
|
| 325 |
$form['book_detailed_infos']['pages'] = array(
|
| 326 |
'#type' => 'textfield',
|
| 327 |
'#title' => t('Pages'),
|
| 328 |
'#default_value' => $node->pages,
|
| 329 |
'#size' => 60,
|
| 330 |
'#maxlength' => 255,
|
| 331 |
'#description' => t('The total number of pages in the book being reviewed.'),
|
| 332 |
);
|
| 333 |
|
| 334 |
$form['book_detailed_infos']['price'] = array(
|
| 335 |
'#type' => 'textfield',
|
| 336 |
'#title' => t('Price'),
|
| 337 |
'#default_value' => $node->price,
|
| 338 |
'#size' => 60,
|
| 339 |
'#maxlength' => 255,
|
| 340 |
'#description' => t('The cost of the book being reviewed.'),
|
| 341 |
);
|
| 342 |
|
| 343 |
$form['offsite_links'] = array(
|
| 344 |
'#type' => 'fieldset',
|
| 345 |
'#title' => t('Offsite links'),
|
| 346 |
'#collapsible' => TRUE,
|
| 347 |
'#collapsed' => TRUE,
|
| 348 |
);
|
| 349 |
|
| 350 |
$form['offsite_links']['booklinks_begin'] = array(
|
| 351 |
'#type' => 'markup',
|
| 352 |
'#value' => '<table>',
|
| 353 |
);
|
| 354 |
for ($i = 0; $i < $node->numlinks; $i++) {
|
| 355 |
$form['offsite_links']["booklink-$i"] = array(
|
| 356 |
'#type' => 'textfield',
|
| 357 |
'#title' => 'URL',
|
| 358 |
'#default_value' => $node->booklinks[$i],
|
| 359 |
'#size' => 45,
|
| 360 |
'#maxlength' => 255,
|
| 361 |
'#description' => '',
|
| 362 |
'#prefix' => '<tr><td>',
|
| 363 |
'#suffix' => '</td>',
|
| 364 |
);
|
| 365 |
$form['offsite_links']["linkdescription-$i"] = array(
|
| 366 |
'#type' => 'textfield',
|
| 367 |
'#title' => 'Description',
|
| 368 |
'#default_value' => $node->linkdescriptions[$i],
|
| 369 |
'#size' => 45,
|
| 370 |
'#maxlength' => 255,
|
| 371 |
'#description' => '',
|
| 372 |
'#prefix' => '<td>',
|
| 373 |
'#suffix' => '</td></tr>',
|
| 374 |
);
|
| 375 |
}
|
| 376 |
$form['offsite_links']['booklinks_end'] = array(
|
| 377 |
'#type' => 'markup',
|
| 378 |
'#value' => '</table>',
|
| 379 |
);
|
| 380 |
|
| 381 |
|
| 382 |
$form['offsite_links']['bookreview_more_links'] = array(
|
| 383 |
'#type' => 'checkbox',
|
| 384 |
'#title' => t('add more links'),
|
| 385 |
'#value' => 0,
|
| 386 |
'#description' => t('If you need to add more links, check this box and click '). '<strong>'. t('Preview'). '</strong>.',
|
| 387 |
);
|
| 388 |
|
| 389 |
// Only display these two fields if longer input format was choosen
|
| 390 |
if (variable_get('bookreview_detail', 0) == 0) {
|
| 391 |
$form['synopsis'] = array(
|
| 392 |
'#type' => 'textarea',
|
| 393 |
'#title' => t('Synopsis'),
|
| 394 |
'#default_value' => $node->synopsis,
|
| 395 |
'#description' => t('A synopsis of the book being reviewed. (For example, the text on the back cover, or inside front cover of most books.)'),
|
| 396 |
);
|
| 397 |
|
| 398 |
$form['contents'] = array(
|
| 399 |
'#type' => 'textarea',
|
| 400 |
'#title' => t('Contents'),
|
| 401 |
'#default_value' => $node->contents,
|
| 402 |
'#description' => t('The table of contents from the book being reviewed.'),
|
| 403 |
);
|
| 404 |
|
| 405 |
}
|
| 406 |
$form['review'] = array(
|
| 407 |
'#type' => 'textarea',
|
| 408 |
'#title' => t('Review'),
|
| 409 |
'#default_value' => $node->review,
|
| 410 |
'#description' => t('This is the actual book review.'),
|
| 411 |
);
|
| 412 |
|
| 413 |
$form['format'] = filter_form($node->format);
|
| 414 |
|
| 415 |
return $form;
|
| 416 |
}
|
| 417 |
|
| 418 |
function bookreview_menu($may_cache) {
|
| 419 |
$items = array();
|
| 420 |
|
| 421 |
if ($may_cache) {
|
| 422 |
$items[] = array('path' => 'node/add/bookreview',
|
| 423 |
'title' => t('book review'),
|
| 424 |
'access' => user_access('create bookreviews'),
|
| 425 |
'callback' => 'node_page');
|
| 426 |
$items[] = array('path' => 'bookreview',
|
| 427 |
'title' => t('book reviews'),
|
| 428 |
'access' => user_access('access content'),
|
| 429 |
'callback' => 'bookreview_page',
|
| 430 |
'type' => MENU_SUGGESTED_ITEM);
|
| 431 |
}
|
| 432 |
else {
|
| 433 |
if ($css = variable_get('bookreview_css', base_path() . drupal_get_path('module', 'bookreview') .'/bookreview.css')) {
|
| 434 |
drupal_set_html_head("\n<style type=\"text/css\">@import \"$css\";</style>\n");
|
| 435 |
}
|
| 436 |
}
|
| 437 |
return $items;
|
| 438 |
}
|
| 439 |
|
| 440 |
function bookreview_settings() {
|
| 441 |
if (!file_check_location(variable_get('bookreview_css', base_path() . drupal_get_path('module', 'bookreview') .'/bookreview.css'))) {
|
| 442 |
$error['bookreview_css'] = theme('error', t('File does not exist, or is not readable.'));
|
| 443 |
}
|
| 444 |
|
| 445 |
$form['bookreview_settings'] = array(
|
| 446 |
'#type' => 'fieldset',
|
| 447 |
'#title' => t('Bookreview settings'),
|
| 448 |
);
|
| 449 |
|
| 450 |
$form['bookreview_settings']['bookreview_css'] = array(
|
| 451 |
'#type' => 'textfield',
|
| 452 |
'#title' => t('Style sheet'),
|
| 453 |
'#default_value' => variable_get('bookreview_css', base_path() . drupal_get_path('module', 'bookreview') .'/bookreview.css'),
|
| 454 |
'#size' => 70,
|
| 455 |
'#maxlength' => 255,
|
| 456 |
'#description' => t("Specify the relative path to your bookreview style sheet. The style sheet specified here will be used to style your bookreview pages. If you prefer to style your bookreview pages in your theme, you can leave this field blank.". $error['bookreview_css'])
|
| 457 |
);
|
| 458 |
|
| 459 |
$form['bookreview_settings']['bookreview_detail'] = array(
|
| 460 |
'#type' => 'radios',
|
| 461 |
'#title' => t('Details to collect'),
|
| 462 |
'#default_value' => variable_get('bookreview_detail', 0),
|
| 463 |
'#options' => array(
|
| 464 |
t('Synopsis, Contents and Review'),
|
| 465 |
t('Review only')),
|
| 466 |
'#description' => t('Details you would like to collect about the books as freeform text.'),
|
| 467 |
);
|
| 468 |
|
| 469 |
$form['bookreview_settings']['bookreview_help'] = array(
|
| 470 |
'#type' => 'textarea',
|
| 471 |
'#title' => t('Explanation or submission guidelines'),
|
| 472 |
'#default_value' => variable_get('bookreview_help', ''),
|
| 473 |
'#description' => t('This text will be displayed at the top of the book review submission form, useful for helping or instructing your users.'),
|
| 474 |
);
|
| 475 |
|
| 476 |
$form['bookreview_settings']['minimum_bookreview_size'] = array(
|
| 477 |
'#type' => 'select',
|
| 478 |
'#title' => t('Minimum number of words'),
|
| 479 |
'#default_value' => variable_get('minimum_bookreview_size', 0),
|
| 480 |
'#options' => drupal_map_assoc(array(0, 10, 25, 50, 75, 100, 125, 150, 175, 200, 500, 1000)),
|
| 481 |
'#description' => t('The minimum number of words a book review must have to be considered valid. This can be useful to prevent submissions that do not meet the site\'s standards, such as short test posts.'),
|
| 482 |
);
|
| 483 |
|
| 484 |
return $form;
|
| 485 |
}
|
| 486 |
|
| 487 |
function bookreview_page() {
|
| 488 |
drupal_set_title(t('Book reviews'));
|
| 489 |
print theme('page', bookreview_overview());
|
| 490 |
}
|
| 491 |
|
| 492 |
function bookreview_overview() {
|
| 493 |
return '<div class="bookreview-list">'. theme('bookreview_list') .'</div>';
|
| 494 |
}
|
| 495 |
|
| 496 |
function theme_bookreview_list() {
|
| 497 |
$header = array(' ', array('data' => t('Title'), 'field' => 'b.booktitle', 'sort' => 'asc'), array('data' => t('Copyright'), 'field' => 'b.copyright'), array('data' => t('ISBN'), 'field' => 'b.isbn'));
|
| 498 |
|
| 499 |
$sql = db_rewrite_sql("SELECT b.nid, n.title, b.booktitle, b.cover, b.publisher, b.isbn, b.copyright, b.pages, b.rating FROM {bookreview} b INNER JOIN {node} n ON b.nid = n.nid WHERE n.type = 'bookreview'");
|
| 500 |
$sql .= tablesort_sql($header);
|
| 501 |
$result = pager_query($sql, 20);
|
| 502 |
|
| 503 |
while ($node = db_fetch_object($result)) {
|
| 504 |
$output = '';
|
| 505 |
$count = 0;
|
| 506 |
$a = db_query('SELECT author, weight FROM {bookreview_authors} WHERE nid = %d ORDER BY weight', $node->nid);
|
| 507 |
$authors = '';
|
| 508 |
while ($author = db_fetch_object($a)) {
|
| 509 |
$count++;
|
| 510 |
if ($authors) {
|
| 511 |
$authors .= ", $author->author";
|
| 512 |
}
|
| 513 |
else {
|
| 514 |
$authors = $author->author;
|
| 515 |
}
|
| 516 |
}
|
| 517 |
if ($authors) {
|
| 518 |
$output = t('<strong>%tag:</strong> %authors', array('%tag' => format_plural($count, 'Author', 'Authors'), '%authors' => $authors)) .'<br />';
|
| 519 |
}
|
| 520 |
if ($node->copyright) {
|
| 521 |
$output .= t('<strong>Copyright:</strong> %copyright', array('%copyright' => $node->copyright)) .'<br />';
|
| 522 |
}
|
| 523 |
if ($node->publisher) {
|
| 524 |
$output .= t('<strong>Publisher:</strong> %publisher', array('%publisher' => $node->publisher)) .'<br />';
|
| 525 |
}
|
| 526 |
if ($node->isbn) {
|
| 527 |
$output .= t('<strong>ISBN:</strong> %isbn', array('%isbn' => $node->isbn)) .'<br />';
|
| 528 |
}
|
| 529 |
if ($node->pages) {
|
| 530 |
$output .= t('<strong>Pages:</strong> %pages', array('%pages' => $node->pages)) .'<br />';
|
| 531 |
}
|
| 532 |
if ($node->rating) {
|
| 533 |
$output .= t('<strong>Rating:</strong> %rating', array('%rating' => $node->rating)) .'<br />';
|
| 534 |
}
|
| 535 |
if ($node->cover) {
|
| 536 |
$cover = "<img src=\"{$node->cover}\" border=\"0\">";
|
| 537 |
}
|
| 538 |
else {
|
| 539 |
$cover = ' ';
|
| 540 |
}
|
| 541 |
$rows[] = array($cover, array('data' => l($node->title, "node/$node->nid", array('title' => t('View this posting.'))) ."<br /><br />$output", 'colspan' => '3'));
|
| 542 |
}
|
| 543 |
|
| 544 |
if (!$rows) {
|
| 545 |
$rows[] = array(array('data' => t('No book reviews available.'), 'colspan' => '4'));
|
| 546 |
}
|
| 547 |
|
| 548 |
$pager = theme('pager', NULL, 20, 0);
|
| 549 |
if (!empty($pager)) {
|
| 550 |
$rows[] = array(array('data' => $pager, 'colspan' => '2'));
|
| 551 |
}
|
| 552 |
|
| 553 |
return theme('table', $header, $rows);
|
| 554 |
}
|
| 555 |
|
| 556 |
function bookreview_view(&$node, $teaser = FALSE, $page = FALSE) {
|
| 557 |
global $theme;
|
| 558 |
|
| 559 |
if ($page) {
|
| 560 |
// Allows themes to override how the review should look like,
|
| 561 |
// but we cannot depend on the theme() functions, since we
|
| 562 |
// need to pass the node by reference!
|
| 563 |
$themefunction = "{$theme}_bookreview_content";
|
| 564 |
if (!function_exists($themefunction)) {
|
| 565 |
$themefunction = 'theme_bookreview_content';
|
| 566 |
}
|
| 567 |
$node = node_prepare($node, $teaser);
|
| 568 |
$themefunction($node, $main, $page);
|
| 569 |
}
|
| 570 |
}
|
| 571 |
|
| 572 |
function theme_bookreview_content(&$node, $main = 0, $page = 0) {
|
| 573 |
$output = "<div class=\"bookreview\">\n";
|
| 574 |
$output .= " <div class=\"header\">\n";
|
| 575 |
/*
|
| 576 |
if($node->title) {
|
| 577 |
$output .= ' <div class="title"><span class="label1">'. check_markup($node->title, $node->format, FALSE) ."</span></div>\n";
|
| 578 |
}
|
| 579 |
*/
|
| 580 |
if($node->cover) {
|
| 581 |
$output .= " <div class=\"cover\"><img src=\"$node->cover\"></div>\n";
|
| 582 |
}
|
| 583 |
if($node->authors[0]) {
|
| 584 |
foreach($node->authors as $author) {
|
| 585 |
if($authors)
|
| 586 |
$authors .= ", $author";
|
| 587 |
else
|
| 588 |
$authors = $author;
|
| 589 |
}
|
| 590 |
$output .= ' <div class="author"><span class="label2">'. format_plural(count($node->authors), 'Author', 'Authors') .':</span><span class="content2">'. check_markup($authors, $node->format, FALSE) ."</span></div>\n";
|
| 591 |
}
|
| 592 |
if($node->publisher) {
|
| 593 |
$output .= ' <div class="publisher"><span class="label3">'. t('Publisher') .':</span><span class="content3">'. check_markup($node->publisher, $node->format, FALSE) ."</span></div>\n";
|
| 594 |
}
|
| 595 |
if($node->copyright) {
|
| 596 |
$output .= ' <div class="copyright"><span class="label3">'. t('Copyright') .':</span><span class="content3">'. check_markup($node->copyright, $node->format, FALSE) ."</span></div>\n";
|
| 597 |
}
|
| 598 |
if($node->isbn) {
|
| 599 |
$output .= ' <div class="isbn"><span class="label3">'. t('ISBN') .':</span><span class="content3">'. check_markup($node->isbn, $node->format, FALSE) ."</span></div>\n";
|
| 600 |
}
|
| 601 |
if($node->pages) {
|
| 602 |
$output .= ' <div class="pages"><span class="label3">'. t('Pages') .':</span><span class="content3">'. check_markup($node->pages, $node->format, FALSE) ."</span></div>\n";
|
| 603 |
}
|
| 604 |
if($node->price) {
|
| 605 |
$output .= ' <div class="price"><span class="label3">'. t('Price') .':</span><span class="content3">'. check_markup($node->price, $node->format, FALSE) ."</span></div>\n";
|
| 606 |
}
|
| 607 |
if($node->rating) {
|
| 608 |
$output .= ' <div class="rating"><span class="label3">'. t('Rating') .':</span><span class="content3">'. check_markup($node->rating, $node->format, FALSE) ."</span></div>\n";
|
| 609 |
}
|
| 610 |
$output .= " </div>\n"; // end of header
|
| 611 |
if($node->synopsis) {
|
| 612 |
$output .= " <div class=\"synopsis\">\n";
|
| 613 |
$output .= ' <span class="label1">'. t('Synopsis') .":</span>\n";
|
| 614 |
$output .= ' <span class="content2">'. check_markup($node->synopsis, $node->format, FALSE) ."</span>\n";
|
| 615 |
$output .= " </div>\n";
|
| 616 |
}
|
| 617 |
if($node->contents) {
|
| 618 |
$output .= " <div class=\"contents\">\n";
|
| 619 |
$output .= ' <span class="label1">'. t('Table of contents') .":</span>\n";
|
| 620 |
$output .= ' <span class="content2">'. check_markup($node->contents, $node->format, FALSE) ."</span>\n";
|
| 621 |
$output .= " </div>\n";
|
| 622 |
}
|
| 623 |
if($node->review) {
|
| 624 |
$output .= " <div class=\"review\">\n";
|
| 625 |
$output .= ' <span class="label1">'. t('Review') .":</span>\n";
|
| 626 |
$output .= ' <span class="content2">'. check_markup($node->review, $node->format, FALSE) ."</span>\n";
|
| 627 |
$output .= " </div>\n";
|
| 628 |
}
|
| 629 |
if($node->booklinks[0]) {
|
| 630 |
$output .= " <div class=\"booklinks\">\n";
|
| 631 |
$output .= ' <span class="label1">'. t('Related links') .":</span>\n";
|
| 632 |
$numlinks = count($node->booklinks);
|
| 633 |
for ($i = 0; $i < $numlinks; $i++) {
|
| 634 |
$booklink = $node->booklinks[$i];
|
| 635 |
$linkdescription = $node->linkdescriptions[$i] ? $node->linkdescriptions[$i] : $node->booklinks[$i];
|
| 636 |
if(ereg('^http://|^https://|ftp://', $booklink)) {
|
| 637 |
// off site link
|
| 638 |
$booklink = "<a href=\"$booklink\">". check_markup($linkdescription, $node->format, FALSE) .'</a>';
|
| 639 |
}
|
| 640 |
elseif($booklink) {
|
| 641 |
// on site link
|
| 642 |
$booklink = l($linkdescription, $booklink);
|
| 643 |
}
|
| 644 |
$output .= ' <span class="content2">'. check_markup($booklink, $node->format, FALSE) ."</span>\n";
|
| 645 |
}
|
| 646 |
$output .= " </div>\n";
|
| 647 |
}
|
| 648 |
$output .= "</div>\n";
|
| 649 |
|
| 650 |
$node->body = $output;
|
| 651 |
}
|