diff --git a/mollom.module b/mollom.module index 2960ab3..cc231e9 100644 --- a/mollom.module +++ b/mollom.module @@ -666,7 +666,7 @@ function mollom_data_delete_form_submit($form, &$form_state) { $id = $data['postId']; if (!empty($form_state['values']['mollom']['feedback'])) { - if (mollom_data_report($entity, $id, $form_state['values']['mollom']['feedback'])) { + if (mollom_data_report($entity, $id, $form_state['values']['mollom']['feedback'], 'moderate', 'mollom_data_delete_form_submit')) { drupal_set_message(t('The content was successfully reported as inappropriate.')); } } @@ -682,9 +682,17 @@ function mollom_data_delete_form_submit($form, &$form_state) { * The entity type to send feedback for. * @param $id * The entity id to send feedback for. + * @param $feedback + * The feedback reason for reporting content. + * @param $type + * The type of feedback, one of 'moderate' or 'flag'. + * @param $source + * An optional single word string identifier for the user interface source. + * This is tracked along with the feedback to provide a more complete picture + * of how feedback is used and submitted on the site. */ -function mollom_data_report($entity, $id, $feedback) { - return mollom_data_report_multiple($entity, array($id), $feedback); +function mollom_data_report($entity, $id, $feedback, $type = 'moderate', $source = 'mollom_data_report') { + return mollom_data_report_multiple($entity, array($id), $feedback, $type, $source); } /** @@ -694,15 +702,23 @@ function mollom_data_report($entity, $id, $feedback) { * The entity type to send feedback for. * @param $ids * An array of entity ids to send feedback for. + * @param $feedback + * The feedback reason for reporting content. + * @param $type + * The type of feedback, one of 'moderate' or 'flag'. + * @param $source + * An optional single word string identifier for the user interface source. + * This is tracked along with the feedback to provide a more complete picture + * of how feedback is used and submitted on the site. */ -function mollom_data_report_multiple($entity, array $ids, $feedback) { +function mollom_data_report_multiple($entity, array $ids, $feedback, $type = 'moderate', $source = 'mollom_data_report_multiple') { $return = TRUE; foreach ($ids as $id) { // Load the Mollom session data. $data = mollom_data_load($entity, $id); // Send feedback, if we have session data. if (!empty($data->contentId) || !empty($data->captchaId)) { - $result = _mollom_send_feedback($data, $feedback, 'moderate', 'mollom_data_report_multiple'); + $result = _mollom_send_feedback($data, $feedback, $type, $source); $return = $return && $result; } } @@ -3951,3 +3967,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', 'moderate', "mollom_action_comment_$op"); + 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". + */