diff --git a/mollom.module b/mollom.module index 2960ab3..ee555aa 100644 --- a/mollom.module +++ b/mollom.module @@ -3951,3 +3951,85 @@ function profile_mollom_form_info_alter(&$form_info, $form_id) { /** * @} End of "name mollom_profile". */ + +/** + * @name mollom_action Actions module integration for Mollom. + * @{ + */ + +/** + * Implements hook_action_info(). + */ +function mollom_action_info() { + return array( + // Unpublish Action + 'mollom_unpublish_comment' => array( + 'label' => t('Report to Mollom as spam and unpublish'), + 'type' => 'comment', + 'configurable' => FALSE, + 'triggers' => array( + 'comment_insert', + 'comment_update', + ), + 'aggregate' => TRUE, + ), + // Delete action + 'mollom_delete_comment' => array( + 'label' => t('Report to Mollom as spam and delete'), + 'type' => 'comment', + 'configurable' => FALSE, + 'triggers' => array( + 'comment_insert', + 'comment_update', + ), + 'aggregate' => TRUE, + ), + ); +} + +/** + * Action callback to report to mollom and unpublish. + */ +function mollom_unpublish_comment($comments, $context = array()) { + mollom_action_comment($comments, 'unpublish'); +} + +/** + * Action callback to report to mollom and delete. + */ +function mollom_delete_comment($comments, $context = array()) { + mollom_action_comment($comments, 'delete'); +} + +/** + * Perform action and send to Mollom as Spam + */ +function mollom_action_comment($comments, $op) { + $cids = array(); + $nids = array(); + foreach ($comments as $comment) { + $cids[] = $comment->cid; + $nids[$comment->nid] = TRUE; + } + + mollom_data_report_multiple('comment', $cids, 'spam'); + mollom_data_delete_multiple('comment', $cids); + + if ($op == "unpublish") { + db_update("comment") + ->fields(array("status" => COMMENT_NOT_PUBLISHED)) + ->condition("cid",$cids) + ->execute(); + + foreach ($nids as $nid => $val) { + _comment_update_node_statistics($nid); + } + } + else if ($op == 'delete') { + comment_delete_multiple($cids); + } +} + +/** + * @} End of "name mollom_action". + */ \ No newline at end of file