Index: review.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/review/review.module,v
retrieving revision 1.8
diff -u -r1.8 review.module
--- review.module	17 Dec 2003 08:03:17 -0000	1.8
+++ review.module	6 Dec 2005 09:47:13 -0000
@@ -2,217 +2,203 @@
 // $Id: review.module,v 1.8 2003/12/17 08:03:17 ber Exp $.
 
 function review_help($section) {
-  $output = "";
+  $output = '';
 
   switch ($section) {
-    case 'admin/system/modules#description':
-      $output = t("Reviews allow users to write an article, about something and add a rating to this article.");
-      break;
-      
     case 'admin/help#review':
-      $output = t("Reviews allow users to write an article, about something and add a rating to this article. Typically this rating is set e.g. 8 from 10, A user can also post a link with the article that points to the revieuwed item. So a revieuw about a new film, should contain a link to the homepage of that film.<br />In the settings page there are nine settings that can be set. They are self explaining. However, when you choose to use images to show up as rating, keep in mind that you need to specify those images.");
-      break;
-  }
+      return t('Reviews allow users to write an article, about something and add a rating to this article. Typically this rating is set e.g. 8 from 10.');
+    
+    case 'admin/modules#description':
+      return t('Enable users to submit rated nodes, with a link to the discussed item.');
 
-  return $output;
+    case 'node/add#review':
+      return t('Reviews allow are articles with a rating written.');
+    
+  }
 }
 
-function review_system($field){
-  $system["description"] = t("Enable users to submit rated nodes, with a link to the discussed item.");
-  
-  return $system[$field];
+function review_menu($may_cache) {
+  $items = array();
+
+  if ($may_cache) {
+    $items[] = array('path' => 'node/add/review', 'title' => t('review'),
+      'access' => user_access('create review'));
+  }
+
+  return $items;
 }
 
+
 function review_settings() {
- $output .= form_textarea(t("Explanation or submission guidelines"), "review_help", variable_get("review_help", ""), 55, 5, "This text will be displayed at the top of the review submission form.  Useful for helping or instructing your users.");
- $output .= form_textarea(t("Text Above review browse pages"), "review_text", variable_get("review_text", ""), 55, 5, "This text will show up above the browse pages of the reviews");
- $output .= form_select(t("Minimum number of words"), "minimum_review_size", variable_get("minimum_review_size", 0), array(0 => "0 words", 10 => "10 words", 25 => "25 words",  50 => "50 words", 75 => "75 words", 100 => "100 words", 125 => "125 words",  150 => "150 words", 175 => "175 words", 200 => "200 words"), t("The minimum number of words a review entry should consist of.  This can be useful to rule out submissions that do not meet the site's standards, such as short test posts."));
- $output .= form_select(t("Rating"), "review_rating", variable_get("review_rating", 10), array(1 => "0 to 1", 2 => "0 to 2", 3 => "0 to 3",  4 => "0 to 4", 5 => "0 to 5", 6 => "0 to 6", 7 => "0 to 7",  8 => "0 to 8", 9 => "0 to 9", 10 => "0 to 10"), t("The scale on wich reviewed items are rated. Note that if this is changed when there are already reviews in the database, the existing ratings will become inaccurate. For example, if there is a review with the rating of 7 out of 10, and you later change the settings into '0 to 5', visitors will see: '7 out of 5'."));
- $output .= form_select(t("Show review rate"), "review_show", variable_get("review_show", "text"), array("text"=>"text","Stars"=>"stars"), t("The way the rating is showed. If you choose Stars you should also choose what image to show as a star"));
- $output .= form_select(t("Amount of titles in latest block"), "review_n_latest", variable_get("review_n_latest", 10), array(1 => "1", 2 => "2", 3 => "3",  4 => "4", 5 => "5", 6 => "6", 7 => "7",  8 => "8", 9 => "9", 10 => "10", 15 => "15", 20 => "20", 25 => "25", 30 => "30"), t("Choose the number of items that are shown in the review block"));
- $output .= form_textfield(t("Star image on"), "review_star_on", variable_get("review_star_on", "/misc/star_on.gif"), 60, 64, t("The image file for the on-star"));
- $output .= form_textfield(t("Star image off"), "review_star_off", variable_get("review_star_off", "/misc/star_off.gif"), 60, 64, t("The image file for the off-star"));
- 
- return $output;
+  $form['review_text'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Text Above review browse pages'),
+    '#default_value' => variable_get('review_text', ''),
+    '#cols' => 55,
+    '#rows' => 5,
+    '#description' => 'This text will show up above the browse pages of the reviews'
+  );
+  $form['review_rating'] = array(
+    '#type' => 'select',
+    '#title' => t('Rating'),
+    '#default_value' => variable_get('review_rating', 10),
+    '#options' => array(1 => '0 to 1', 2 => '0 to 2', 3 => '0 to 3',  4 => '0 to 4', 5 => '0 to 5', 6 => '0 to 6', 7 => '0 to 7',  8 => '0 to 8', 9 => '0 to 9', 10 => '0 to 10'),
+    '#description' => t("The scale on wich reviewed items are rated. Note that if this is changed when there are already reviews in the database, the existing ratings will become inaccurate. For example, if there is a review with the rating of 7 out of 10, and you later change the settings into '0 to 5', visitors will see: '7 out of 5'.")
+  );
+  $form['review_show'] = array(
+    '#type' => 'select',
+    '#title' => t('Show review rate'),
+    '#default_value' => variable_get('review_show', 'text'),
+    '#options' => array('text'=>'text','Stars'=>'stars'),
+    '#description' => t("The way the rating is showed. If you choose Stars you should also choose what image to show as a star")
+  );
+  $form['review_n_latest'] = array(
+    '#type' => 'select',
+    '#title' => t('Amount of titles in latest block'),
+    '#default_value' => variable_get('review_n_latest', 10),
+    '#options' => array(1 => '1', 2 => '2', 3 => '3',  4 => '4', 5 => '5', 6 => '6', 7 => '7',  8 => '8', 9 => '9', 10 => '10', 15 => '15', 20 => '20', 25 => '25', 30 => '30'),
+    '#description' => t('Choose the number of items that are shown in the review block')
+  );
+  return $form;
 }
 
-function review_node($field) {
-  $info["name"] = t("review");
-  $info["description"] = t("A review is a post about a certain object. This object is discussed and gets a rating.");
-  
-  return $info[$field];
+function review_node_info() {
+  return array('review' => array('name' => t('review'), 'base' => 'review'));
 }
 
 function review_perm() {
-  return array("create reviews");
+  return array('create reviews');
 }
 
 function review_access($op, $node) {
-  if ($op == "view") {
+  if ($op == 'view') {
     return $node->status;
   }
 
-  if ($op == "create") {
-    return user_access("create reviews");
+  if ($op == 'create') {
+    return user_access('create reviews');
   }
 }
 
 function review_save($op, $node) {
-
-  if ($op == "approve") {
-    return array("status" => 1, "promote" => 1);
+  if ($op == 'approve') {
+    return array('status' => 1, 'promote' => 1);
   }
 
-  if ($op == "create") {
-    if (user_access("administer nodes")) {
-      return array("status" => 0, 
-                   "body" => filter($node->body),
-                   "moderate" => 1,
-                   "teaser" => filter($node->teaser),
-                   "weblink" => filter($node->weblink),
-                   "review_rate" => filter($node->review_rate));
+  if ($op == 'create') {
+    if (user_access('administer nodes')) {
+      return array('status' => 0, 
+                   'body' => filter($node->body),
+                   'moderate' => 1,
+                   'teaser' => filter($node->teaser),
+                   'weblink' => filter($node->weblink),
+                   'review_rate' => filter($node->review_rate));
                    }
     else {
-      return array("moderate" => 1);
+      return array('moderate' => 1);
     }
   }
 
-  if ($op == "decline") {
-    return array("status" => 0, "promote" => 0);
+  if ($op == 'decline') {
+    return array('status' => 0, 'promote' => 0);
   }
 
-  if ($op == "update") {
-    return array("body" => filter($node->body),
-                 "moderate" => 1,
-                 "teaser" => filter($node->teaser),
-                 "weblink" => filter($node->weblink),
-                 "review_rate" => filter($node->review_rate));
+  if ($op == 'update') {
+    return array('body' => filter($node->body),
+                 'moderate' => 1,
+                 'teaser' => filter($node->teaser),
+                 'weblink' => filter($node->weblink),
+                 'review_rate' => filter($node->review_rate));
   }
 }
 
-function review_link($type,  $node = 0) {
-  
-  if ($type == "menu.create" && user_access("create reviews")) {
-    $links[] = l(t("create review"), "node/add/review", array("title" => t("Add a new review.")));
-  }
-  
-  return $links ? $links : array();
-}
-
-function review_form(&$node, &$help, &$error) {
+function review_form(&$node) {
   global $op;
   
-  if (isset($node->body)) {
-
-    /*
-    ** Validate the size of the review:
-    */
-
-    if (count(explode(" ", $node->body)) < variable_get("minimum_review_size", 0)) {
-      $error["body"] = "<div style=\"color: red;\">". t("The body of your review is too short.") ."</div>";
-    }
-
-  }
-  else {
-
-    /*
-    ** Carry out some explanation or submission guidelines:
-    */
-
-    $help = variable_get("review_help", "");
-
-  }
-
-  $output .= form_textfield("Link", "weblink", $node->weblink, 60, 255, t("links should be submitted in a form similar to http://www.linksite.com/"));
-
-  $output .= implode("<p>", taxonomy_node_form("review", $node));
-
-  $output .= form_textarea(t("Body"), "body", $node->body, 60, 15, $error["body"] ? $error["body"] : t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
-
-  $rsa=range(0,variable_get("review_rating", 10));
-
-  $output .= form_select(t("Rating"), "review_rate", ($node->review_rate ? " $node->review_rate" : "5"), $rsa, t("The Rating of the reviewed item."));
-
-  return $output;
-
-}
-
-function related_link_form($review_related_links) {
-  if (function_exists("weblink_node")) {
-    $res = db_query("SELECT n.nid, n.title, w.weblink, w.click FROM {node} n LEFT JOIN {weblink} w on n.nid = w.nid WHERE n.type='weblink' ORDER by n.title DESC");
-
-    while ($node = db_fetch_object($res)) {
-      $related_links[$node->nid] = $node->title;      
+  $form['title'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Title'),
+    '#size' => 60,
+    '#maxlength' => 128,
+    '#required' => TRUE,
+    '#default_value' => $node->title
+  );
+    
+  $form['weblink'] = array(
+    '#type' => 'textfield',
+    '#title' => 'Link',
+    '#default_value' => $node->weblink,
+    '#size' => 60,
+    '#maxlength' => 255,
+    '#description' => t('links should be submitted in a form similar to http://www.example.com/'),
+  );
+  
+  $form['body'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Body'),
+    '#default_value' => $node->body,
+    '#cols' => 60,
+    '#rows' => 15,
+    '#required' => TRUE,
+    '#description' => t('Allowed HTML tags') .': '. htmlspecialchars(variable_get('allowed_html', '')),
+  );
+  
+  $maxrating = variable_get('review_rating', 10);
+  $form['review_rate'] = array(
+    '#type' => 'select',
+    '#title' => t('Rating'),
+    '#default_value' => (isset($node->review_rate) ? $node->review_rate : (integer) ($maxrating / 2)),
+    '#options' => range(0, $maxrating),
+    '#description' => t('The Rating of the reviewed item.')
+  );
+  
+  return $form;
+}
+
+function review_form_validate(&$node) {
+    // Validate the size of the review:
+    if (count(explode(' ', $node->body)) < variable_get('minimum_review_size', 0)) {
+      form_set_error('body', t('The body of your review is too short.'));
     }
-    $rsize = min(12, count($links));
-
-    return form_select(t("Links"),
-                       "review_related_links", 
-                       ($review_related_links ? $review_related_links : ""), 
-                       $related_links, t("Additional Links that point to the reviewed item(s) website."), 
-                       array("size"=>$rsize), 
-                       1);
-  }
-  else {
-    return NULL;
-  }
 }
 
 function review_insert($node) {
-
   db_query("INSERT INTO {review} (nid, review_rate) VALUES ('$node->nid', '$node->review_rate')");
-  db_query("INSERT INTO {weblink} (nid, weblink) VALUES ('$node->nid', '$node->weblink')");
-
 }
 
 function review_update($node) {
-
   db_query("UPDATE {review} SET review_rate = '".$node->review_rate ."' WHERE nid = '". $node->nid ."'");
-  db_query("UPDATE {weblink} SET weblink = '".$node->weblink."' WHERE nid = '".$node->nid."'");
-
 }
 
 function review_delete(&$node) {
   db_query("DELETE FROM {review} WHERE nid = '$node->nid'");
-  db_query("DELETE FROM {weblink} WHERE nid = '$node->nid'");
-  
 }
 
-function review_block($op = "list", $delta = 0) {
+function review_block($op = 'list', $delta = 0) {
   global $theme;
   
-  $block="";
+  $block=array();
 
-  if ($op == "list") {
-    $blocks[0]["info"] = t("Latest Reviews");
+  switch ($op) {
+  case 'list':
+    $blocks[0]['info'] = t('Latest Reviews');
     return $blocks;
-  }
-  else {
-    if (user_access("access content")) {
-      
-      $i=0;
-      $result = db_query("SELECT nid, type, status FROM {node} WHERE status LIKE 1 AND moderate LIKE 0 AND type LIKE 'review' ORDER BY created DESC LIMIT %d", variable_get("review_n_latest", "10")); 
+  case 'configure':
+    return array();
+  case 'view':
+    if (user_access('access content')) {
+      $result = db_query("SELECT nid, type, status FROM {node} WHERE status LIKE 1 AND moderate LIKE 0 AND type = 'review' ORDER BY created DESC LIMIT %d", variable_get("review_n_latest", "10")); 
       
-      // this should actually use the table() function in drupal's core, that one uses <table> and <td>, so untill then, i stick to this CSS-based approach.
+      // this should actually use the table() function in drupal's core, that
+      // one uses <table> and <td>, so untill then, i stick to this CSS-based approach.
+      $rows = array();
       while ($node = db_fetch_object($result)) {
-        if (round(($i/2)) - ($i/2)) {
-          $lightdark="even";
-        }
-        else {
-          $lightdark="odd";
-        }
-        
-        
-        $node = node_load(array("nid" => $node->nid, "type" => $node->type));
-
-        $block["content"] .="<DIV class=\"headline_line_".$lightdark."\">";
-        $block["content"] .=" <SPAN class=\"headline_title\">".$node->title."</SPAN>";
-        $block["content"] .=" <SPAN class=\"headline_link\">".l(t("[read]"),"node/view/".$node->nid, array("title"=>t("Read the whole article") ) )."</SPAN>";
-        $block["content"] .="</DIV>";
-        $i++;
+        $node = node_load(array('nid' => $node->nid, 'type' => $node->type));
+        $rows[] = l($node->title, 'node/'. $node->nid);
       }
 
-      $block["subject"] = t("Latest Reviews");
+      $block['subject'] = t('Latest Reviews');
+      $block['content'] = theme('item_list', $rows);
       
       return $block;
     }
@@ -220,25 +206,13 @@
 }
 
 function review_load($node) {
-
   $review_query = db_query("SELECT review_rate FROM {review} WHERE nid ='".$node->nid."'");
-  $weblink_query = db_query("SELECT weblink, click FROM {weblink} WHERE nid ='".$node->nid."'");
-   
-  $review = db_fetch_object($review_query);
-  
-  $weblink = db_fetch_object($weblink_query);
-  if($weblink) { 
-    foreach ($weblink as $key => $value) {
-      $review->$key = $value;
-    }
-  }
-  
-return $review;
+  return db_fetch_object($review_query);
 }
 
 function review_page() {
   switch (arg(1)) {
-    case "goto":
+    case 'goto':
       review_page_goto(arg(2));
       break;
     default:
@@ -252,73 +226,63 @@
   
   $theme->header();
   
-  $output = "<div>". variable_get("review_text", "") ."</div>";
+  $output = '<div>'. variable_get('review_text', '') .'</div>';
     
   $sresult = pager_query("SELECT n.nid, n.title, n.type, n.teaser, n.body, n.changed, r.review_rate FROM {node} n LEFT JOIN {review} r ON n.nid = r.nid WHERE n.status = 1 AND n.type ='review' GROUP BY n.nid, n.title, n.type, n.changed, r.review_rate ORDER BY changed DESC", 10, 0, "SELECT COUNT(nid) FROM {node}");
 
-  $header = array(t("Category"), t("Title"),  t("Rate"));
+  $header = array(t('Category'), t('Title'),  t('Rate'));
 
   while ($node = db_fetch_object($sresult)) {
  
-    $title = l($node->title, "node/view/$node->nid") ." ". (node_is_new($node->nid, $node->changed) ? theme("theme_mark") : "");
+    $title = l($node->title, "node/view/$node->nid") .' '. (node_is_new($node->nid, $node->changed) ? theme('theme_mark') : '');
     
-    $categories ="";
+    $categories ='';
 
     foreach(taxonomy_node_get_terms($node->nid) as $term) {
       //some if module existsts etc needs to be done here      
       $categories[] = l($term->name,"taxonomy/page/or/$term->tid",array("title"=>t("Show all reviews about "). $term->name));
     }
     
-    $category= implode("<br />",$categories);
+    $category= implode('<br />',$categories);
     
     if ($node->teaser) {
       $teaser = $node->teaser;
-      $teaser .= " ". l(t("more"),"node/view/$node->nid");
+      $teaser .= ' '. l(t('more'),"node/view/$node->nid");
     }
     else {
       $teaser = substr($node->body, 0, 50);
-      $teaser .= l(t("more"),"node/view/$node->nid");
+      $teaser .= l(t('more'),"node/view/$node->nid");
     }
     
     $rate = review_produce_rate($node);
     
-    $rows[] = array(array("data" => $category, "class" => "Category", "rowspan" => 2, "valign" => "top", "align" => "left"), array("data" => $title, "class" => "Title"), array("data" => $rate, "class" => "Rate", "align"=>"left"));
-    $rows[] = array(array("data"=>$teaser, "class"=>"Teaser","colspan"=>2));
+    $rows[] = array(array('data' => $category, 'class' => 'Category', 'rowspan' => 2, 'valign' => 'top', 'align' => 'left'), array('data' => $title, 'class' => 'Title'), array('data' => $rate, 'class' => 'Rate', 'align'=>'left'));
+    $rows[] = array(array('data'=>$teaser, 'class'=>'Teaser','colspan'=>2));
   }
 
   if ($pager = pager_display(NULL, 10)) {
-   $rows[] = array(array("data" => $pager, "colspan" => 3));
+   $rows[] = array(array('data' => $pager, 'colspan' => 3));
   }
 
   $output .= "<div id=\"review\">";
   $output .= table($header, $rows);
-  $output .= "</div>";
+  $output .= '</div>';
 
-  $theme->box(t("Reviews"), $output, 'main');
+  $theme->box(t('Reviews'), $output, 'main');
   $theme->footer();
 
 }
 
-function review_produce_rate($node){
-  $output = "<div class=\"rate\">";
-  
-  if (variable_get("review_show","text") == "text") {
-    $output  = t("Rate: "). $node->review_rate ." ". t("of") ." ". variable_get("review_rating", 10);
-  }
-  else {
-    for($i=0; $i<$node->review_rate; $i++) {
-     $output .= "<img class=\"rateimage\" alt=\"*\" title\"";
-     $output .= $node->review_rate ." ". t("van") ." ". variable_get("review_rating", 10);
-     $output .= "\" src=\"".variable_get("review_star_on", "misc/star_on.gif") ."\" />";
-    }
-    for($i=variable_get("review_rating", 10); $i>$node->review_rate; $i--){
-     $output .= "<img class=\"rateimage\" alt=\"o\" title\"";
-     $output .= $node->review_rate ." ". t("van") ." ". variable_get("review_rating", 10);
-     $output .= "\" src=\"". variable_get("review_star_off", "misc/star_off.gif");     $output .= "\" />";
-    }
+function review_produce_rate($node) {
+  if (variable_get('review_show', 'text') == 'text') {
+    $format = 'review_text_rating';
+  } else {
+    $format = 'review_graphic_rating';
   }
-  $output  .= "</div>";
-  
+
+  $output = '<div class="rate">';
+  $output .= theme($format, $node->review_rate, variable_get('review_rating', 10));
+  $output .= '</div>';
   return $output;
 }
 
@@ -329,29 +293,28 @@
   header("Location: $wl->weblink");
 }
 
-function review_view($node, $main = 0) {
-  global $theme;
-    
-  if (variable_get("weblink_link_display", "0")) {
-    $link_display = $node->weblink;
+function review_view(&$node, $teaser = FALSE, $page = FALSE) {
+  $node = node_prepare($node, $teaser);
+  if (!$teaser) {
+    $node->body .= review_produce_rate($node);
   }
-  else {
-    $link_display = $node->title;
-  }
-  
-  $weblink = $link_display;
+}
 
-  // produce link
-  $node->html_weblink = l($weblink, "review/goto/$node->nid", array("target" => "_blank", "title" => t("Link naar het besproken onderwerp")) )." (". $node->click .")";
-  
-  $node->html_rate = review_produce_rate($node);
-  
-  if ($main) {
-    $theme->node($node, $main);
+
+function theme_review_text_rating($rating, $possible) {
+  return t('Rating: %rating of %possible', array('%rating' => $rating, '%possible' => $possible));
+}
+
+function theme_review_graphic_rating($rating, $possible) {
+  for($i = 0; $i < $rating; $i++) {
+    $output .= '<img class="rateimage" alt="*" title="star"';
+    $output .= ' src="'. drupal_get_path('module', 'review') . '/star_on.gif" />';
   }
-  else {
-    $theme->node($node, 0);
+  for($i = $rating; $i < $possible; $i++){
+    $output .= '<img class="rateimage" alt=" " title="no star"';
+    $output .= ' src="'. drupal_get_path('module', 'review') . '/star_off.gif" />';
   }
+  return $output;
 }
 
 ?>
\ No newline at end of file
Index: review.mysql
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/review/review.mysql,v
retrieving revision 1.1
diff -u -r1.1 review.mysql
--- review.mysql	8 Jun 2003 15:37:55 -0000	1.1
+++ review.mysql	7 Dec 2005 01:12:02 -0000
@@ -1,34 +1,5 @@
-# phpMyAdmin MySQL-Dump
-# version 2.2.0
-# http://phpwizard.net/phpMyAdmin/
-# http://phpmyadmin.sourceforge.net/ (download page)
-#
-# Host: localhost
-# Generatie Tijd: May 13, 2003, 9:53 am
-# Server versie: 3.23.54
-# PHP Versie: 4.2.2
-# Database : `mediarevolution_org`
-# --------------------------------------------------------
-
-#
-# Tabel structuur voor tabel `review`
-#
-
-CREATE TABLE review (
-  nid int(10) NOT NULL default '0',
-  review_rate mediumint(9) default '1',
-  KEY nid (nid)
-) TYPE=MyISAM;
-# --------------------------------------------------------
-
-#
-# Tabel structuur voor tabel `weblink`
-#
-
-CREATE TABLE weblink (
-  nid int(10) unsigned default '0',
-  weblink varchar(128) default NULL,
-  click int(10) unsigned default '0',
-  KEY nid (nid)
-) TYPE=MyISAM;
-
+CREATE TABLE `review` (
+  `nid` int(10) NOT NULL default '0',
+  `review_rate` mediumint(9) default '1',
+  KEY `nid` (`nid`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
\ No newline at end of file

