array( 'name' => t('Book review'), // 5.x 'module' => 'bookreview', // 5.x 'description' => t("The bookreview module allows a site to publish book reviews."), // 5.x //'base' => 'bookreview' )); } function bookreview_block($op = 'list', $delta = 0, $edit = array()) { if ($op == 'list') { $blocks[0]['info'] = t('Book review store link'); return $blocks; } else if ($op == 'configure') { $form['bookreview_store_blocktitle'] = array( '#type' => 'textfield', '#title' => t('Block title'), '#default_value' => variable_get('bookreview_store_blocktitle', ''), '#size' => 70, '#maxlength' => 255, '#description' => t('Enter the title to use when displaying this block, if any.'), ); $form['bookreview_store_snippet'] = array( '#type' => 'textarea', '#title' => t('HTML snippet'), '#default_value' => variable_get('bookreview_store_snippet', ''), '#maxlength' => 1024, '#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.'), ); return ($form); } else if ($op == 'save') { variable_set('bookreview_store_blocktitle', $edit['bookreview_store_blocktitle']); variable_set('bookreview_store_snippet', $edit['bookreview_store_snippet']); } else if ($op == 'view') { // only display block when viewing a bookreview that has defined an isbn if (arg(0) == 'node' && is_numeric(arg(1))) { $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)); if (db_num_rows($result) > 0) { $node = db_fetch_object($result); $isbn = preg_replace('/-/', '', $node->isbn); $block['subject'] = variable_get('bookreview_store_blocktitle', ''); $content = preg_replace('/%ISBN/', $isbn, variable_get('bookreview_store_snippet', '')); $block['content'] = $content; } } return $block; } } function bookreview_insert($node) { 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); for ($i = 0; $i < $node->numauthors; $i++) { $author = "author-$i"; if ($node->$author) { db_query("INSERT INTO {bookreview_authors} (nid, author, weight) VALUES (%d, '%s', %d)", $node->nid, $node->$author, $i); } } for ($i = 0; $i < $node->numlinks; $i++) { $booklink = "booklink-$i"; $linkdescription = "linkdescription-$i"; if ($node->$booklink) { db_query("INSERT INTO {bookreview_links} (nid, booklink, description, weight) VALUES (%d, '%s', '%s', %d)", $node->nid, $node->$booklink, $node->$linkdescription, $i); } } } function bookreview_load($node) { $bookreview = db_fetch_object(db_query("SELECT * FROM {bookreview} WHERE nid = '$node->nid'")); $authors = db_query("SELECT author, weight FROM {bookreview_authors} WHERE nid = '$node->nid' ORDER BY weight"); while ($author = db_fetch_object($authors)) { $bookreview->authors[$author->weight] = $author->author; } $bookreview->numauthors = count($bookreview->authors); $booklinks = db_query("SELECT booklink, description, weight FROM {bookreview_links} WHERE nid = '$node->nid' ORDER BY weight"); while ($booklink = db_fetch_object($booklinks)) { $bookreview->booklinks[$booklink->weight] = $booklink->booklink; $bookreview->linkdescriptions[$booklink->weight] = $booklink->description; } $bookreview->numlinks = count($bookreview->booklinks); return $bookreview; } function bookreview_update($node) { 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); db_query('DELETE FROM {bookreview_authors} WHERE nid = %d', $node->nid); for ($i = 0; $i < $node->numauthors; $i++) { $author = "author-$i"; if ($node->$author) { db_query("INSERT INTO {bookreview_authors} (nid, author, weight) VALUES (%d, '%s', %d)", $node->nid, $node->$author, $i); } } db_query('DELETE FROM {bookreview_links} WHERE nid = %d', $node->nid); for ($i = 0; $i < $node->numlinks; $i++) { $booklink = "booklink-$i"; $linkdescription = "linkdescription-$i"; if ($node->$booklink) { db_query("INSERT INTO {bookreview_links} (nid, booklink, description, weight) VALUES (%d, '%s', '%s', %d)", $node->nid, $node->$booklink, $node->$linkdescription, $i); } } } function bookreview_delete($node) { db_query('DELETE FROM {bookreview} WHERE nid = %d', $node->nid); db_query('DELETE FROM {bookreview_authors} WHERE nid = %d', $node->nid); db_query('DELETE FROM {bookreview_links} WHERE nid = %d', $node->nid); } function bookreview_validate(&$node) { // fixed VB if (variable_get('minimum_bookreview_size', 0) && isset($node->review)) { $node_review = trim($node->review); $word_count = count(explode(' ', $node_review)); // 1. TODO: an issue - wrong $word_count if 2 o more seq. spaces; newline issue 2. do not use str_word_count($node_review); if ($word_count < variable_get('minimum_bookreview_size', 0)) { // fixed VB if (!$node_review) form_set_error('review', t('You are required to enter text for your book review.')); else 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))); } /* else if (!$node->review) { form_set_error('review', theme('error', t('You are required to enter text for your book review.'))); } */ } } function bookreview_submit(&$node) { if (variable_get('teaser_length', 600)) { if ($node->synopsis) { $node->teaser = check_markup(node_teaser($node->synopsis), $node->format); } else { $node->teaser = check_markup(node_teaser($node->review), $node->format); } } else { // teasers are disabled, display whole book review $node->teaser = check_markup($node->body, $node->format); } } function bookreview_form(&$node) { $type = node_get_types('type', $node); // 5.x $edit = $_POST['edit']; if ($edit['numauthors']) { // It's a preview ... if ($edit['bookreview_more_authors'] == 1) { // ... and we need more authors if ($edit['numauthors'] % 2) { $node->numauthors = $edit['numauthors'] + 1; } else { $node->numauthors = $edit['numauthors'] + 2; } } else { // we don't want more authors, just see the preview // (numauthors may have change with a previous preview) $node->numauthors = $edit['numauthors']; } } elseif(!$node->numauthors) { // Just created review, start with one author. $node->numauthors = 1; } // else we are editing an old review, we'll use the defaults if ($edit['numlinks']) { // It's a preview ... if ($edit['bookreview_more_links'] == 1) { // ... and we need more links $node->numlinks = $edit['numlinks'] + 1; } else { // we don't want more links, just see the preview // (numlinks may have change with a previous preview) $node->numlinks = $edit['numlinks']; } } elseif(!$node->numlinks) { // Just created review, start with one link. $node->numlinks = 1; } // else we are editing an old review, we'll use the defaults $form['numauthors'] = array( '#type' => 'hidden', '#value' => $node->numauthors, ); $form['numlinks'] = array( '#type' => 'hidden', '#value' => $node->numlinks, ); $form['book_infos'] = array( '#type' => 'fieldset', '#title' => t('General information'), '#collapsible' => TRUE, '#collapsed' => FALSE, ); // We need to define form elements for the node's title and body. $form['title'] = array( '#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5 ); /* $form['book_infos']['title'] = array( '#type' => 'textfield', '#title' => t('Title'), '#default_value' => $node->title, '#size' => 60, '#maxlength' => 255, '#description' => t('The title of the book being reviewed.'), ); */ $form['book_infos']['authors'] = array( '#type' => 'fieldset', '#title' => t('Author(s)'), '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form['book_infos']['authors']['authors_begin'] = array( '#type' => 'markup', '#value' => '', ); for ($i = 0; $i < $node->numauthors; $i++) { $form['book_infos']['authors']["author-$i"] = array( '#type' => 'textfield', '#default_value' => $node->authors[$i], '#size' => 60, '#maxlength' => 255, '#description' => '', '#prefix' => ($i%2) ? '' : '', ); } $form['book_infos']['authors']['authors_end'] = array( '#type' => 'markup', '#value' => ($node->numauthors+1%2) ? '
' : '
', '#suffix' => ($i%2) ? '
' : '', ); $form['book_infos']['authors']['bookreview_more_authors'] = array( '#type' => 'checkbox', '#title' => t('add more authors'), '#value' => 0, '#description' => t('If the book has more authors, you can create space to list them by checking this box and clicking '). ''. t('Preview'). '.', ); $form['book_infos']['rating'] = array( '#type' => 'select', '#title' => t('Rating'), '#default_value' => $node->rating, '#options' => (array('<' . t('none') . '>') + drupal_map_assoc(range(1, 10))), '#description' => t('Score of the book on a 1 to 10 scale.'), ); $form['book_detailed_infos'] = array( '#type' => 'fieldset', '#title' => t('Detailed information'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['book_detailed_infos']['cover'] = array( '#type' => 'textfield', '#title' => t('Cover picture'), '#default_value' => $node->cover, '#size' => 60, '#maxlength' => 255, '#description' => t('URL of book cover image.'), ); $form['book_detailed_infos']['publisher'] = array( '#type' => 'textfield', '#title' => t('Publisher'), '#default_value' => $node->publisher, '#size' => 60, '#maxlength' => 255, '#description' => t('The publisher of the book being reviewed.'), ); $form['book_detailed_infos']['copyright'] = array( '#type' => 'textfield', '#title' => t('Copyright'), '#default_value' => $node->copyright, '#maxlength' => 255, '#description' => t('The year the book was published. (Format: YYYY).'), ); $form['book_detailed_infos']['isbn'] = array( '#type' => 'textfield', '#title' => t('ISBN'), '#default_value' => $node->isbn, '#size' => 60, '#maxlength' => 255, '#description' => t('The ISBN of the book being reviewed.'), ); $form['book_detailed_infos']['pages'] = array( '#type' => 'textfield', '#title' => t('Pages'), '#default_value' => $node->pages, '#size' => 60, '#maxlength' => 255, '#description' => t('The total number of pages in the book being reviewed.'), ); $form['book_detailed_infos']['price'] = array( '#type' => 'textfield', '#title' => t('Price'), '#default_value' => $node->price, '#size' => 60, '#maxlength' => 255, '#description' => t('The cost of the book being reviewed.'), ); $form['offsite_links'] = array( '#type' => 'fieldset', '#title' => t('Offsite links'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['offsite_links']['booklinks_begin'] = array( '#type' => 'markup', '#value' => '', ); for ($i = 0; $i < $node->numlinks; $i++) { $form['offsite_links']["booklink-$i"] = array( '#type' => 'textfield', '#title' => 'URL', '#default_value' => $node->booklinks[$i], '#size' => 45, '#maxlength' => 255, '#description' => '', '#prefix' => '', ); $form['offsite_links']["linkdescription-$i"] = array( '#type' => 'textfield', '#title' => 'Description', '#default_value' => $node->linkdescriptions[$i], '#size' => 45, '#maxlength' => 255, '#description' => '', '#prefix' => '', ); } $form['offsite_links']['booklinks_end'] = array( '#type' => 'markup', '#value' => '
', '#suffix' => '', '#suffix' => '
', ); $form['offsite_links']['bookreview_more_links'] = array( '#type' => 'checkbox', '#title' => t('add more links'), '#value' => 0, '#description' => t('If you need to add more links, check this box and click '). ''. t('Preview'). '.', ); // Only display these two fields if longer input format was choosen if (variable_get('bookreview_detail', 0) == 0) { $form['synopsis'] = array( '#type' => 'textarea', '#title' => t('Synopsis'), '#default_value' => $node->synopsis, '#description' => t('A synopsis of the book being reviewed. (For example, the text on the back cover, or inside front cover of most books.)'), ); $form['contents'] = array( '#type' => 'textarea', '#title' => t('Contents'), '#default_value' => $node->contents, '#description' => t('The table of contents from the book being reviewed.'), ); } $form['review'] = array( '#type' => 'textarea', '#title' => t('Review'), '#default_value' => $node->review, '#description' => t('This is the actual book review.'), ); // We want the body and filter elements to be adjacent. $form['body_filter']['body'] = array( '#type' => 'textarea', '#title' => check_plain($type->body_label), '#default_value' => $node->body, '#required' => FALSE ); $form['body_filter']['filter'] = filter_form($node->format); //$form['format'] = filter_form($node->format); return $form; } function bookreview_menu($may_cache) { $items = array(); // 5.x $items[] = array( 'path' => 'admin/settings/bookreview', 'title' => t('Bookreview settings'), 'description' => t('Change bookreview settings'), 'callback' => 'drupal_get_form', 'callback arguments' => 'bookreview_admin_settings', 'access' => user_access('administer site configuration'), 'type' => MENU_NORMAL_ITEM, ); // 5.x if ($may_cache) { /* $items[] = array('path' => 'node/add/bookreview', 'title' => t('book review'), 'access' => user_access('create bookreviews'), 'callback' => 'node_page'); */ $items[] = array('path' => 'bookreview', 'title' => t('book reviews'), 'access' => user_access('access content'), 'callback' => 'bookreview_page', 'type' => MENU_SUGGESTED_ITEM); } else { //if ($css = variable_get('bookreview_css', base_path() . drupal_get_path('module', 'bookreview') .'/bookreview.css')) { if ($css = variable_get('bookreview_css', drupal_get_path('module', 'bookreview') .'/bookreview.css')) { drupal_add_css($css); // 5.x //drupal_set_html_head("\n\n"); } } return $items; } function bookreview_admin_settings() { // 5.x //function bookreview_settings() { // 4.7.x //if (!file_check_location(variable_get('bookreview_css', base_path() . drupal_get_path('module', 'bookreview') .'/bookreview.css'))) { if (!file_check_location(variable_get('bookreview_css', drupal_get_path('module', 'bookreview') .'/bookreview.css'))) { $error['bookreview_css'] = theme('error', t('File does not exist, or is not readable.')); } $form['bookreview_settings'] = array( '#type' => 'fieldset', '#title' => t('Bookreview settings'), ); $form['bookreview_settings']['bookreview_css'] = array( '#type' => 'textfield', '#title' => t('Style sheet'), '#default_value' => variable_get('bookreview_css', /*base_path() 4.7.x .*/ drupal_get_path('module', 'bookreview') .'/bookreview.css'), '#size' => 70, '#maxlength' => 255, '#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']) ); $form['bookreview_settings']['bookreview_detail'] = array( '#type' => 'radios', '#title' => t('Details to collect'), '#default_value' => variable_get('bookreview_detail', 0), '#options' => array( t('Synopsis, Contents and Review'), t('Review only')), '#description' => t('Details you would like to collect about the books as freeform text.'), ); $form['bookreview_settings']['bookreview_help'] = array( '#type' => 'textarea', '#title' => t('Explanation or submission guidelines'), '#default_value' => variable_get('bookreview_help', ''), '#description' => t('This text will be displayed at the top of the book review submission form, useful for helping or instructing your users.'), ); $form['bookreview_settings']['minimum_bookreview_size'] = array( '#type' => 'select', '#title' => t('Minimum number of words'), '#default_value' => variable_get('minimum_bookreview_size', 0), '#options' => drupal_map_assoc(array(0, 10, 25, 50, 75, 100, 125, 150, 175, 200, 500, 1000)), '#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.'), ); //return $form; return system_settings_form($form); // 5.x } function bookreview_page() { drupal_set_title(t('Book reviews')); print theme('page', bookreview_overview()); } function bookreview_overview() { return '
'. theme('bookreview_list') .'
'; } function theme_bookreview_list() { $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')); $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'"); $sql .= tablesort_sql($header); $result = pager_query($sql, 20); while ($node = db_fetch_object($result)) { $output = ''; $count = 0; $a = db_query('SELECT author, weight FROM {bookreview_authors} WHERE nid = %d ORDER BY weight', $node->nid); $authors = ''; while ($author = db_fetch_object($a)) { $count++; if ($authors) { $authors .= ", $author->author"; } else { $authors = $author->author; } } if ($authors) { $output = t('%tag: %authors', array('%tag' => format_plural($count, 'Author', 'Authors'), '%authors' => $authors)) .'
'; } if ($node->copyright) { $output .= t('Copyright: %copyright', array('%copyright' => $node->copyright)) .'
'; } if ($node->publisher) { $output .= t('Publisher: %publisher', array('%publisher' => $node->publisher)) .'
'; } if ($node->isbn) { $output .= t('ISBN: %isbn', array('%isbn' => $node->isbn)) .'
'; } if ($node->pages) { $output .= t('Pages: %pages', array('%pages' => $node->pages)) .'
'; } if ($node->rating) { $output .= t('Rating: %rating', array('%rating' => $node->rating)) .'
'; } if ($node->cover) { $cover = "cover}\" border=\"0\">"; } else { $cover = ' '; } $rows[] = array($cover, array('data' => l($node->title, "node/$node->nid", array('title' => t('View this posting.'))) ."

$output", 'colspan' => '3')); } if (!$rows) { $rows[] = array(array('data' => t('No book reviews available.'), 'colspan' => '4')); } $pager = theme('pager', NULL, 20, 0); if (!empty($pager)) { $rows[] = array(array('data' => $pager, 'colspan' => '2')); } return theme('table', $header, $rows); } function bookreview_view(&$node, $teaser = FALSE, $page = FALSE) { global $theme; /* 4.7.x if ($page) { // Allows themes to override how the review should look like, // but we cannot depend on the theme() functions, since we // need to pass the node by reference! $themefunction = "{$theme}_bookreview_content"; if (!function_exists($themefunction)) { $themefunction = 'theme_bookreview_content'; } $node = node_prepare($node, $teaser); $themefunction($node, $main, $page); } */ $themefunction = "{$theme}_bookreview_content"; if (!function_exists($themefunction)) { $themefunction = 'bookreview_content'; } $node = node_prepare($node, $teaser); $node->content['bookreview'] = array( '#value' => theme($themefunction, $node), '#weight' => 1, ); return $node; } function theme_bookreview_content(&$node, $main = 0, $page = 0) { $output = "
\n"; $output .= "
\n"; /* if($node->title) { $output .= '
'. check_markup($node->title, $node->format, FALSE) ."
\n"; } */ if($node->cover) { $output .= "
cover\">
\n"; } if($node->authors[0]) { foreach($node->authors as $author) { if($authors) $authors .= ", $author"; else $authors = $author; } $output .= '
'. format_plural(count($node->authors), 'Author', 'Authors') .':'. check_markup($authors, $node->format, FALSE) ."
\n"; } if($node->publisher) { $output .= '
'. t('Publisher') .':'. check_markup($node->publisher, $node->format, FALSE) ."
\n"; } if($node->copyright) { $output .= ' \n"; } if($node->isbn) { $output .= '
'. t('ISBN') .':'. check_markup($node->isbn, $node->format, FALSE) ."
\n"; } if($node->pages) { $output .= '
'. t('Pages') .':'. check_markup($node->pages, $node->format, FALSE) ."
\n"; } if($node->price) { $output .= '
'. t('Price') .':'. check_markup($node->price, $node->format, FALSE) ."
\n"; } if($node->rating) { $output .= '
'. t('Rating') .':'. check_markup($node->rating, $node->format, FALSE) ."
\n"; } $output .= "
\n"; // end of header if($node->synopsis) { $output .= "
\n"; $output .= ' '. t('Synopsis') .":\n"; $output .= ' '. check_markup($node->synopsis, $node->format, FALSE) ."\n"; $output .= "
\n"; } if($node->contents) { $output .= "
\n"; $output .= ' '. t('Table of contents') .":\n"; $output .= ' '. check_markup($node->contents, $node->format, FALSE) ."\n"; $output .= "
\n"; } if($node->review) { $output .= "
\n"; $output .= ' '. t('Review') .":\n"; $output .= ' '. check_markup($node->review, $node->format, FALSE) ."\n"; $output .= "
\n"; } if($node->booklinks[0]) { $output .= "
\n"; $output .= ' '. t('Related links') .":\n"; $numlinks = count($node->booklinks); for ($i = 0; $i < $numlinks; $i++) { $booklink = $node->booklinks[$i]; $linkdescription = $node->linkdescriptions[$i] ? $node->linkdescriptions[$i] : $node->booklinks[$i]; if(ereg('^http://|^https://|ftp://', $booklink)) { // off site link $booklink = "". check_markup($linkdescription, $node->format, FALSE) .''; } elseif($booklink) { // on site link $booklink = l($linkdescription, $booklink); } $output .= ' '. check_markup($booklink, $node->format, FALSE) ."\n"; } $output .= "
\n"; } $output .= "
\n"; //$node->body = $output; // 4.7.x return $output; }