Index: modules/forum.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/forum.module,v
retrieving revision 1.188
diff -u -F^f -r1.188 forum.module
--- modules/forum.module	8 Jul 2004 15:19:08 -0000	1.188
+++ modules/forum.module	8 Jul 2004 23:28:20 -0000
@@ -223,6 +223,9 @@ function forum_view($node, $teaser = FAL
     $breadcrumb[] = array('path' => 'node/'. $node->nid);
     menu_set_location($breadcrumb);
   }
+  // Change the created by name in the node to the displayname if it's an anonymous post
+  $topic = db_fetch_object(db_query_range("SELECT u.name AS name, u.uid AS uid, f.displayname FROM {forum} f INNER JOIN {node} n ON n.nid = f.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.nid = %d", $node->nid, 0,1));
+  $node->name = $topic->uid ? $topic->name : $topic->displayname;
 
   return theme('node', forum_content($node, $teaser), $teaser, $page);
 }
@@ -232,6 +235,7 @@ function forum_view($node, $teaser = FAL
  *
  * Check in particular that only a "leaf" term in the associated taxonomy
  * vocabulary is selected, not a "container" term.
+ * Also check the validity of the anonymous name, email and homepage strings if given
  */
 function forum_validate(&$node) {
   // Make sure all fields are set properly:
@@ -254,6 +258,38 @@ function forum_validate(&$node) {
       }
     }
   }
+  
+  // Check validity of name, mail and homepage (if given)
+  if (!$user->uid) {
+    if (variable_get('comment_anonymous', 0) > 0) {
+      if ($edit['displayname']) {
+        $taken = db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE LOWER(name) = '%s'", strip_tags($edit['displayname'])), 0);
+
+        if ($taken != 0) {
+          form_set_error('name', t('The name you used belongs to a registered user.'));
+        }
+
+      }
+      else if (variable_get('comment_anonymous', 0) == 2) {
+        form_set_error('name', t('You have to leave your name.'));
+      }
+
+      if ($edit['mail']) {
+        if (!valid_email_address($edit['mail'])) {
+          form_set_error('mail', t('The e-mail address you specified is not valid.'));
+        }
+      }
+      else if (variable_get('comment_anonymous', 0) == 2) {
+        form_set_error('mail', t('You have to leave an e-mail address.'));
+      }
+
+      if ($edit['homepage']) {
+        if (!valid_url($edit['homepage'], TRUE)) {
+          form_set_error('homepage', t('The URL of your homepage is not valid.  Remember that it must be fully qualified, i.e. of the form <code>http://example.com/directory</code>.'));
+        }
+      }
+    }
+  }
 }
 
 /**
@@ -265,7 +301,14 @@ function forum_form(&$node) {
     $node->taxonomy[] = arg(3);
   }
 
-  $output = implode('', taxonomy_node_form('forum', $node));
+  // contact information:
+  if (!$user->uid) {
+    $output = form_textfield(t('Your name'), 'displayname', $node->displayname ? $node->displayname : variable_get('anonymous', 'Anonymous') , 20, 40);
+    $output .= form_textfield(t('E-mail'), 'mail', $node->mail, 20, 40);
+    $output .= form_textfield(t('Homepage'), 'homepage', $node->homepage, 20, 40);
+  }
+
+  $output .= implode('', taxonomy_node_form('forum', $node));
 
   if ($node->nid) {
     // if editing, give option to leave shadows
@@ -281,14 +324,14 @@ function forum_form(&$node) {
  * Implementation of hook_insert().
  */
 function forum_insert($node) {
-  db_query('INSERT INTO {forum} (nid, shadow, tid) VALUES (%d, %d, %d)', $node->nid, $node->shadow, $node->tid);
+  db_query('INSERT INTO {forum} (nid, shadow, tid, displayname, mail, homepage) VALUES (%d, %d, %d, \'%s\', \'%s\', \'%s\')', $node->nid, $node->shadow, $node->tid, $node->displayname, $node->mail, $node->homepage);
 }
 
 /**
  * Implementation of hook_update().
  */
 function forum_update($node) {
-  db_query('UPDATE {forum} SET shadow = %d, tid = %d WHERE nid = %d', $node->shadow, $node->tid, $node->nid);
+  db_query('UPDATE {forum} SET shadow = %d, tid = %d, displayname = \'%s\', mail = \'%s\', homepage = \'%s\' WHERE nid = %d', $node->shadow, $node->tid, $node->nid, $node->displayname, $node->mail, $node->homepage);
 }
 
 /**
@@ -375,7 +418,8 @@ function _forum_topics_read($term, $uid)
 }
 
 function _forum_last_post($term) {
-  $topic = db_fetch_object(db_query_range("SELECT n.nid, n.created AS timestamp, u.name AS name, u.uid AS uid FROM {forum} f INNER JOIN {node} n ON n.nid = f.nid INNER JOIN {users} u ON n.uid = u.uid WHERE f.tid = %d AND n.nid = f.nid AND n.type = 'forum' AND n.status = 1 ORDER BY timestamp DESC", $term, 0, 1));
+  $topic = db_fetch_object(db_query_range("SELECT n.nid, n.created AS timestamp, u.name AS name, u.uid AS uid, f.displayname FROM {forum} f INNER JOIN {node} n ON n.nid = f.nid INNER JOIN {users} u ON n.uid = u.uid WHERE f.tid = %d AND n.nid = f.nid AND n.type = 'forum' AND n.status = 1 ORDER BY timestamp DESC", $term, 0, 1));
+  $topic->name = $topic->uid ? $topic->name : $topic->displayname;
 
   $reply = db_fetch_object(db_query_range("SELECT n.nid, c.timestamp, c.name AS anonymous_name, u.name AS name, u.uid AS uid FROM {forum} f INNER JOIN {node} n ON n.nid = f.nid INNER JOIN {comments} c ON n.nid = c.nid INNER JOIN {users} u ON c.uid = u.uid WHERE f.tid = %d AND n.nid = f.nid AND n.type = 'forum' AND n.status = 1 AND c.status = 0 ORDER BY c.timestamp DESC", $term, 0, 1));
   $reply->name = $reply->uid ? $reply->name : $reply->anonymous_name;
@@ -410,7 +454,7 @@ function forum_get_topics($tid, $sortby,
   // show topics with the correct tid, or in the forum but with shadow = 1
   // @TODO: this is not ANSI SQL! ("user error: 'n.created' isn't in GROUP BY")
   // @TODO: timestamp is a sql reserved word. are there more?
-  $sql = "SELECT n.nid, n.title, n.sticky, u.name AS name, u.uid AS uid, n.created AS timestamp, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments, n.comment AS comment_mode, f.tid FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {forum} f ON n.nid = f.nid WHERE n.nid = r.nid AND ((r.tid = $check_tid AND f.shadow = 1) OR f.tid = $check_tid) AND n.status = 1 AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid";
+  $sql = "SELECT n.nid, n.title, u.name AS name, u.uid AS uid, n.created AS timestamp, GREATEST(n.created, MAX(c.timestamp)) AS date_sort, COUNT(c.nid) AS num_comments, n.comment AS comment_mode, f.tid, f.displayname FROM {node} n INNER JOIN {term_node} r ON n.nid = r.nid INNER JOIN {users} u ON n.uid = u.uid LEFT JOIN {comments} c ON n.nid = c.nid INNER JOIN {forum} f ON n.nid = f.nid WHERE n.nid = r.nid AND ((r.tid = $check_tid AND f.shadow = 1) OR f.tid = $check_tid) AND n.status = 1 AND n.type = 'forum' GROUP BY n.nid, n.title, u.name, u.uid, n.created, n.comment, f.tid";
   $sql .= tablesort_sql($forum_topic_list_header, 'n.sticky DESC,');
 
   $sql_count = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {forum} f ON n.nid = f.nid INNER JOIN {term_node} r ON n.nid = r.nid WHERE n.nid = r.nid AND ( (r.tid = $check_tid AND f.shadow = 1) OR f.tid = $check_tid) AND n.status = 1 AND n.type = 'forum'";
@@ -433,6 +477,7 @@ function forum_get_topics($tid, $sortby,
     }
     else {
       // Do not track "new replies" status for topics if the user is anonymous.
+      $topic->name = $topic->displayname;
       $topic->new_replies = 0;
       $topic->new = 0;
     }
