? rules-addcomment-376648-1.patch
? rules-addcomment-376648-2.patch
? rules-addcomment-376648-3.patch
? rules-addcomment-376648-4.patch
Index: rules/modules/comment.rules.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/rules/rules/modules/Attic/comment.rules.inc,v
retrieving revision 1.1.2.8
diff -u -p -r1.1.2.8 comment.rules.inc
--- rules/modules/comment.rules.inc	19 Aug 2009 14:58:41 -0000	1.1.2.8
+++ rules/modules/comment.rules.inc	13 Oct 2010 10:24:33 -0000
@@ -129,6 +129,15 @@ function comment_rules_action_info() {
       ),
       'module' => 'Comment',
     ),
+    'rules_action_add_comment' => array(
+      'label' => t('Add comment to a node'),
+      'arguments' => array(
+        'node' => array('type' => 'node', 'label' => t('Content')),
+        'author' => array('type' => 'user', 'label' => t('User, who is set as author')),
+      ),
+      'eval input' => array('subject', 'comment'),
+      'module' => 'Comment',
+    ),
   );
 }
 
@@ -140,6 +149,39 @@ function rules_action_load_comment($cid)
 }
 
 /**
+ * Action: Add comment to node.
+ */
+function rules_action_add_comment($node, $user, $settings) {
+  $comment = array();
+  $comment['pid'] = 0;
+  $comment['nid'] = $node->nid;
+  $comment['uid'] = $user->uid;
+  $comment['name'] = $user->name;
+
+  $comment['subject'] = $settings['subject'];
+  $comment['comment'] = $settings['comment'];
+  $comment['format'] = $settings['format'];
+
+  // If comment title is not specified, extract one from the comment's body.
+  // This code borrowed from _comment_form_submit().
+  if (trim($settings['subject']) == '') {
+    // The body may be in any format, so we:
+    // 1) Filter it into HTML
+    // 2) Strip out all HTML tags
+    // 3) Convert entities back to plain-text.
+    // Note: format is checked by check_markup().
+    $comment['subject'] = truncate_utf8(trim(decode_entities(strip_tags(check_markup($settings['comment'], $settings['format'])))), 29, TRUE);
+    // Edge cases where the comment body is populated only by HTML tags will
+    // require a default subject.
+    if ($comment['subject'] == '') {
+      $comment['subject'] = t('(No subject)');
+    }
+  }
+
+  comment_save($comment);
+}
+
+/**
  * Implementation of hook_rules_data_type_info()
  */
 function comment_rules_data_type_info() {
Index: rules/modules/comment.rules_forms.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/rules/rules/modules/Attic/comment.rules_forms.inc,v
retrieving revision 1.1.2.3
diff -u -p -r1.1.2.3 comment.rules_forms.inc
--- rules/modules/comment.rules_forms.inc	15 May 2009 13:03:12 -0000	1.1.2.3
+++ rules/modules/comment.rules_forms.inc	13 Oct 2010 10:24:33 -0000
@@ -18,5 +18,36 @@ function rules_action_load_comment_varia
 }
 
 /**
+ * Action "Add comment to node" form.
+ */
+function rules_action_add_comment_form($settings = array(), &$form, $form_state) {
+  $settings += array('format' => '', 'subject' => '', 'comment' => '');
+  $format_options = array();
+  foreach (filter_formats() as $id => $format) {
+    $format_options[$id] = $format->name;
+  }
+
+  $form['settings']['subject'] = array(
+    '#type' => 'textfield',
+    '#size' => 30,
+    '#title' => t('Subject'),
+    '#default_value' => $settings['subject'],
+  );
+  $form['settings']['comment'] = array(
+    '#type' => 'textarea',
+    '#size' => 30,
+    '#title' => t('Comment'),
+    '#default_value' => $settings['comment'],
+    '#required' => TRUE,
+  );
+  $form['settings']['format'] = array(
+    '#type' => 'select',
+    '#options' => $format_options,
+    '#title' => t('Input format'),
+    '#default_value' => $settings['format'] ? $settings['format'] : variable_get('filter_default_format', 1),
+  );
+}
+
+/**
  * @}
  */
\ No newline at end of file
