--- C:/Documents and Settings/Aldo/Local Settings/Temp/TCV0d5a.tmp/comment.1.611.module	Fri Dec 28 14:49:32 2007
+++ D:/drupal cvs/6.x/drupal/modules/comment/comment.module	Fri Dec 28 14:47:21 2007
@@ -552,6 +552,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('Automatic comment subjects'),
+      '#default_value' => variable_get('comment_subject_create_'. $form['#node_type']->type, 0),
+      '#options' => array(t('Disabled'), t('Enabled')),
+      '#description' => t('Generate comment subjects from their parent 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'),
@@ -1353,8 +1360,29 @@
     $form['homepage'] = array('#type' => 'textfield', '#title' => t('Homepage'), '#maxlength' => 255, '#size' => 30, '#default_value' => $edit['homepage']);
   }
 
+  $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 (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'] : '');
+    $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'])) {
