--- C:/Documents and Settings/Aldo/Local Settings/Temp/TCVde50.tmp/comment.1.596.module	Wed Oct 31 10:34:55 2007
+++ D:/drupal cvs/6.x/drupal/modules/comment/comment.module	Wed Oct 31 10:31:53 2007
@@ -533,6 +533,13 @@
       '#options' => array(t('Disabled'), t('Enabled')),
       '#description' => t('Can users provide a unique subject for their comments?'),
     );
+    $form['comment']['comment_subject_create'] = array(
+      '#type' => 'radios',
+      '#title' => t('Generate comment subject automatically'),
+      '#default_value' => variable_get('comment_subject_create_'. $form['#node_type']->type, 0),
+      '#options' => array(t('Disabled'), t('Enabled')),
+      '#description' => t('Should comment subjects be automatically generated from their parent\'s subjects? If the comment subject field is enabled, user will still be able to change the generated comment.'),
+    );
     $form['comment']['comment_preview'] = array(
       '#type' => 'radios',
       '#title' => t('Preview comment'),
@@ -1597,8 +1604,29 @@
     $form['homepage'] = array('#type' => 'textfield', '#title' => t('Homepage'), '#maxlength' => 255, '#size' => 30, '#default_value' => $edit['homepage']);
   }
 
-  if (variable_get('comment_subject_field_'. $node->type, 1) == 1) {
-    $form['subject'] = array('#type' => 'textfield', '#title' => t('Subject'), '#maxlength' => 64, '#default_value' => !empty($edit['subject']) ? $edit['subject'] : '');
+  $create_subject = (variable_get('comment_subject_create_'. $node->type, 0) == 1);
+  $subject = !empty($edit['subject']) ? $edit['subject']:'';
+
+  if (empty($subject) && $create_subject) {
+    // create subject from node title or parent comment subject
+    if(!empty($edit['pid']) && $edit['pid'] > 0) {
+      $parent = _comment_load(arg($edit['pid']));
+    }
+    else {
+      $parent = node_load(array('nid' => $edit['nid']));
+    }
+    $subject = $parent->title;
+    $pattern = '/^'.preg_quote(t('Re:')).'/i';
+    if(!preg_match($pattern, $subject)) {
+      $subject = t('Re:')." $subject";
+    }
+  }
+
+  if ($create_subject && variable_get('comment_subject_field_'. $node->type, 1) == 1) {
+    $form['subject'] = array('#type' => 'textfield', '#title' => t('Subject'), '#maxlength' => 64, '#default_value' => $subject);
+  }
+  else if(!empty($subject)) {
+    $form['subject'] = array('#type' => 'hidden', '#value' => $subject);
   }
 
   if (!empty($edit['comment'])) {
