--- drupal/modules/comment.module	2004-04-28 15:09:00.000000000 +0200
+++ contributions/sandbox/pablobm/modules/comment.module	2004-04-28 16:28:20.054156448 +0200
@@ -1,5 +1,5 @@
 <?php
-// $Id: comment.module,v 1.235 2004/04/21 13:56:37 dries Exp $
+// $Id: comment.module,v 1.7 2004/03/25 18:37:50 pablobm Exp $
 
 function comment_help($section = "admin/help#comment") {
   $output = "";
@@ -120,6 +120,13 @@
   $group .= form_radios(t("Comment controls"), "comment_controls", variable_get("comment_controls", 0), array(t("Display above the comments"), t("Display below the comments"), t("Display above and below the comments"), t("Do not display")), t("Position of the comment controls box.  The comment controls let the user change the default display mode and display order of comments."));
   $output = form_group(t('Comment viewing options'), $group);
 
+  $group  = form_checkbox(t("Show subject field"), 'comment_subject_field', 1, variable_get('comment_subject_field', 1));
+  $subgroup  = form_checkbox(t('Show author\'s name field'), 'comment_author_field', 1, variable_get('comment_author_field', 0));
+  $subgroup .= form_checkbox(t('Show author\'s e-mail address field'), 'comment_email_field', 1, variable_get('comment_email_field', 0));
+  $subgroup .= form_checkbox(t('Show author\'s homepage field'), 'comment_homepage_field', 1, variable_get('comment_homepage_field', 0));
+  $group .= form_group(t('Anonymous comments'), $subgroup);
+  $output .= form_group(t('Additional fields'), $group);
+
   $group  = form_radios(t("Preview comment"), "comment_preview", variable_get("comment_preview", 1), array(t("Optional"), t("Required")), t("Must users preview comments before submitting?"));
   $group .= form_radios(t("Location of comment submission form"), "comment_form_location", variable_get("comment_form_location", 0), array(t("Display on separate page"), t("Display below post or comments")), t("The location of the comment submission form."));
   $output .= form_group(t('Comment posting settings'), $group);
@@ -173,6 +180,7 @@
 
   $comment = db_fetch_object(db_query("SELECT c.*, u.uid, u.name, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status != 2", $cid));
   $comment = drupal_unpack($comment);
+  $comment = drupal_unpack($comment, "misc");
   if (comment_access("edit", $comment)) {
     return comment_preview(object2array($comment));
   }
@@ -191,6 +199,7 @@
     if ($pid) {
       $comment = db_fetch_object(db_query("SELECT c.*, u.uid, u.name, u.picture, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0", $pid));
       $comment = drupal_unpack($comment);
+      $comment = drupal_unpack($comment, "misc");
       $output .= theme("comment_view", $comment);
     }
     else if (user_access("access content")) {
@@ -246,6 +255,7 @@
   if ($edit["pid"]) {
     $comment = db_fetch_object(db_query("SELECT c.*, u.uid, u.name, u.picture, u.data FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status = 0", $edit["pid"]));
     $comment = drupal_unpack($comment);
+    $comment = drupal_unpack($comment, "misc");
     $output .= theme("comment_view", $comment);
   }
   else {
@@ -372,6 +382,7 @@
 
           // Get the parent comment:
           $parent = db_fetch_object(db_query("SELECT * FROM {comments} WHERE cid = '%d'", $edit["pid"]));
+          $parent = drupal_unpack($parent, "misc");
 
           // Strip the "/" from the end of the parent thread:
           $parent->thread = (string)rtrim((string)$parent->thread, "/");
@@ -411,10 +422,18 @@
           }
         }
 
+        /*
+        ** Additional fields
+        */
+
+        $misc  = serialize(array(
+            'anon_name' => $edit['anon_name'],
+            'anon_email' => $edit['anon_email'],
+            'anon_homepage' => $edit['anon_homepage']));
 
         $edit["cid"] = db_next_id("{comments}_cid");
 
-        db_query("INSERT INTO {comments} (cid, nid, pid, uid, subject, comment, hostname, timestamp, status, score, users, thread) VALUES (%d, %d, %d, %d, '%s', '%s', '%s', %d, %d, %d, '%s', '%s')", $edit["cid"], $edit["nid"], $edit["pid"], $user->uid, $edit["subject"], $edit["comment"], $_SERVER['REMOTE_ADDR'], time(), $status, $score, $users, $thread);
+        db_query("INSERT INTO {comments} (cid, nid, pid, uid, subject, comment, hostname, timestamp, status, score, users, thread, misc) VALUES (%d, %d, %d, %d, '%s', '%s', '%s', %d, %d, %d, '%s', '%s', '%s')", $edit["cid"], $edit["nid"], $edit["pid"], $user->uid, $edit["subject"], $edit["comment"], $_SERVER['REMOTE_ADDR'], time(), $status, $score, $users, $thread, $misc);
 
         /*
         ** Tell the other modules a new comment has been submitted:
@@ -555,7 +574,7 @@
       ** Multiple comments view
       */
 
-      $query .= "SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, u.uid, u.name, u.picture, u.data, c.score, c.users, c.thread FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = '". check_query($nid) ."' AND c.status = 0";
+      $query .= "SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, u.uid, u.name, u.picture, u.data, c.score, c.users, c.thread, c.misc FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = '". check_query($nid) ."' AND c.status = 0";
 
       $query .= " GROUP BY c.cid, c.pid, c.nid, c.subject, c.comment, c.timestamp, u.uid, u.name, u.picture, u.data, c.score, c.users, c.thread";
 
@@ -663,6 +682,7 @@
 
       while ($comment = db_fetch_object($result)) {
         $comment = drupal_unpack($comment);
+        $comment = drupal_unpack($comment, "misc");
         $comment->depth = count(explode(".", $comment->thread)) - 1;
 
         if ($mode == 1) {
@@ -840,7 +860,7 @@
       $comments_per_page = $_POST["comments_per_page"];
 
       comment_save_settings(check_query($mode), check_query($order), check_query($threshold), check_query($comments_per_page));
-      drupal_goto(comment_node_url());
+      drupal_goto(comment_referer_load());
       break;
   }
 }
@@ -880,6 +900,7 @@
   $result = db_query("SELECT c.*, u.name, u.uid FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid = %d AND c.status != 2", $id);
   $comment = db_fetch_object($result);
   $comment = drupal_unpack($comment);
+  $comment = drupal_unpack($comment, "misc");
 
   if ($comment) {
     $form .= form_item(t("Author"), format_name($comment));
@@ -1223,10 +1244,16 @@
   $form .= "<a id=\"comment\"></a>\n";
 
   // name field:
-  $form .= form_item(t("Your name"), format_name($user));
+  $form .= _form_comment_author($user, $edit["anon_name"]);
+  
+  // e-mail field
+  $form .= _form_comment_email($user, $edit["anon_email"]);
+  
+  // homepage field
+  $form .= _form_comment_homepage($user, $edit["anon_homepage"]);
 
   // subject field:
-  $form .= form_textfield(t("Subject"), "subject", $edit["subject"], 50, 64);
+  $form .= _form_comment_subject($user, $edit["anon_homepage"]);
 
   // comment field:
   $form .= form_textarea(t("Comment"), "comment", $edit["comment"] ? $edit["comment"] : $user->signature, 70, 10, filter_tips_short());
@@ -1247,6 +1274,39 @@
   return theme("box", $title, form($form, "post", url("comment/reply/". $edit["nid"])));
 }
 
+function _form_comment_author($user, $default) {
+  $default = $default ? $default : 'anonymous';
+  
+  if ($user->uid) {
+    $form = form_item(t("Your name"), format_name($user));
+  }
+  else if (variable_get('comment_author_field', 0)) {
+    $form = form_textfield(t("Your name"), 'anon_name', $default , 20, 40);
+  }
+  return $form;
+}
+
+function _form_comment_email($user, $default) {
+  if (! $user->uid && variable_get('comment_email_field', 0)) {
+    $form = form_textfield(t("E-Mail"), "anon_email", $default, 20, 40);
+  }
+  return $form;
+}
+
+function _form_comment_homepage($user, $default) {
+  if (! $user->uid && variable_get('comment_homepage_field', 0)) {
+    $form = form_textfield(t("Homepage"), "anon_homepage", $default, 20, 40);
+  }
+  return $form;
+}
+
+function _form_comment_subject($user, $default) {
+  if (variable_get('comment_subject_field', 0)) {
+    $form .= form_textfield(t("Subject"), "subject", $default, 50, 64);
+  }
+  return $form;
+}
+
 function theme_comment_view($comment, $links = "", $visible = 1) {
 
   /*
@@ -1370,17 +1430,48 @@
   $output  = "<div class=\"comment\">\n";
   $output .= "<div class=\"subject\">$comment->subject". ($comment->new ? ' '. theme('mark') : '') ."</div>\n";
   $output .= "<div class=\"moderation\">". $comment->moderation ."</div>\n";
-  $output .= "<div class=\"credit\">". t("by %a on %b", array("%a" => format_name($comment), "%b" => format_date($comment->timestamp))) ."</div>\n";
+
+  $output .= "<div class=\"credit\">";
+  $output .= t("by %a on %b", array("%a" => theme("comment_author", $comment), "%b" => format_date($comment->timestamp))) ."</div>\n";
+  $output .= "</div>\n";
+
   $output .= "<div class=\"body\">". check_output($comment->comment) ."</div>\n";
   $output .= "<div class=\"links\">$links</div>\n";
   $output .= "</div>\n";
   return $output;
 }
 
+function theme_comment_author($comment) {
+  if (! $comment->anon_name) {
+    $output .= format_name($comment);
+  }
+  else {
+    $name = $comment->anon_name;
+    $name = $comment->anon_homepage ? '<a href="' . _comment_format_url($comment->anon_homepage) . '" title="' . t("Link to %a's homepage", array("%a" => $name)) . '">' . $name . '</a>' : $name;
+    $name .= $comment->anon_email ? ' &lt;<a href="mailto://' . $comment->anon_email . '" title="' . t("%a's e-mail address", array("%a" => $comment->anon_name)) . '">' . $comment->anon_email . '</a>&gt;' : '';
+    $output .= $name . t(" (identity not verified)");
+  }
+  return $output;
+}
+
+function _comment_format_url($url) {
+  if($url) {
+    $purl = parse_url($url);
+    if(!$purl['scheme']) {
+      $purl['scheme'] = 'http';
+    }
+    $result = $purl['scheme'] . '://' . $purl['host'] . $purl['path'];
+  }
+  else {
+    $result = '';
+  }
+  return $result;
+}
+
 function theme_comment_folded($comment) {
   $output  = "<div class=\"comment-folded\">\n";
   $output .= " <span class=\"subject\">". l($comment->subject, comment_node_url() ."/$comment->cid", NULL, NULL, "comment-$comment->cid") . ($comment->new ? ' '. theme('mark') : '') ."</span> ";
-  $output .= "<span class=\"credit\">". t("by") ." ". format_name($comment) ."</span>\n";
+  $output .= "<span class=\"credit\">". t("by") ." ". theme("comment_author", $comment) ."</span>\n";
   $output .= "</div>\n";
   return $output;
 }
