? flag_abuse-reset.patch
? flag_abuse-reset_2.patch
Index: flag_abuse.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag_abuse/flag_abuse.module,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 flag_abuse.module
--- flag_abuse.module	12 May 2009 00:35:49 -0000	1.1.2.1
+++ flag_abuse.module	4 Nov 2009 15:33:18 -0000
@@ -39,14 +39,21 @@ function flag_abuse_perm() {
 function flag_abuse_preprocess_flag(&$vars) {
   global $user;
   
-  // permmission check instead of a role
+  // permission check
   if (user_access('reset abuse flags', $user)) {
-    // is this one of our abuse flags
-    // @todo: should be dynamic
+    // is this one of our abuse flags?
     if (in_array($vars['flag']->name, array('abuse_node', 'abuse_comment', 'abuse_user'))) {
-      $vars['action'] = 'reset';
-      $vars['link_text'] = t('Reset flags');
-      $vars['link_title'] = t('Remove all flags on this content');
+      // is this content even flagged?
+      $flag = flag_get_flag($vars['flag']->name);
+      $count = flag_get_counts($vars['flag']->content_type, $vars['content_id']);
+      if (!empty($count) && $count[$vars['flag']->name] > 0) {
+        // seems there should be a better way to do this...
+        $vars['link_href'] = str_replace('unflag', 'reset', $vars['link_href']);
+        
+        // I added the count in here as I thought it would be more useful.
+        $vars['link_text'] = $flag->get_label('reset_short') .'('. $count[$vars['flag']->name] .')';
+        $vars['link_title'] = $flag->get_label('reset_long');
+      }
     }
   }
 }
@@ -54,23 +61,27 @@ function flag_abuse_preprocess_flag(&$va
 /**
  * Implementation of hook_flag().
  *
- * If a user with appropriate permission/role flags this content from our view
+ * If a user with appropriate permissions flags this content from our view
  * we want to remove all flags. http://drupal.org/node/327901#comment-1085685
  *
+ * Note that since this runs _after_ the actual flagging has already happened,
+ * we must somehow veryify that this is a reset and not a flag/unflag. This
+ * would be possible if http://drupal.org/node/571100 goes in.
+ *
  * @todo: When $flag->access() goes in, use this to limit access to a flag that
  * an administrator has already acted upon. http://drupal.org/node/322034
  */
 function flag_abuse_flag($event, $flag, $content_id, $account) {
-  // permmission check instead of a role
-  if (user_access('reset abuse flags', $account)) {
-    // is this one of our abuse flags
-    // @todo: should be dynamic
-    if (in_array($flag->name, array('abuse_node', 'abuse_comment', 'abuse_user'))) {
-      // remove all flag on this content
-      $query = db_query("SELECT uid FROM {flag_content} WHERE fid = %d", $flag->fid);
-      while ($result = db_fetch_object($query)) {
-        // Supposed to pass in a full $account here, let's see if we can fake it
-        $flag->flag('unflag', $content_id, $result, TRUE);
+  if ($event == 'reset') {
+    // permission check, name check
+    if (user_access('reset abuse flags', $account) && in_array($flag->name, array('abuse_node', 'abuse_comment', 'abuse_user'))) {
+      // make sure there are flags to be reset
+      $count = flag_get_counts($flag->content_type, $content_id);
+      if (!empty($count) && $count[$flag->name] > 0) {
+        // remove all flags on this content
+        db_query('DELETE FROM {flag_content} WHERE content_id = %d', $content_id);
+        // reset the count
+        db_query('UPDATE {flag_counts} SET count = 0 WHERE content_id = %d', $content_id);
       }
     }
   }
@@ -102,4 +113,17 @@ function flag_abuse_popups() {
     ),
   );
   return $popups;
-}
\ No newline at end of file
+}
+
+/**
+ * Implementation of hook_flag_options_alter().
+ */
+function flag_abuse_flag_options_alter($flag, &$options) {
+  $options['events'][] = 'reset';
+  $options += array(
+    'reset_short' => 'Reset flags',
+    'reset_long' => 'Reset all flags on this '. $flag->content_type,
+    'reset_message' => 'Flags reset.',
+  );
+  $options['roles'] += array('reset' => array(DRUPAL_AUTHENTICATED_RID));
+}
Index: includes/flag_abuse.flag_default.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag_abuse/includes/flag_abuse.flag_default.inc,v
retrieving revision 1.1
diff -u -p -r1.1 flag_abuse.flag_default.inc
--- includes/flag_abuse.flag_default.inc	19 Mar 2009 22:11:19 -0000	1.1
+++ includes/flag_abuse.flag_default.inc	4 Nov 2009 15:33:18 -0000
@@ -10,12 +10,16 @@ function _flag_abuse_abuse_node_flags(&$
       0 => '2',
     ),
     'global' => FALSE,
+    'events' => array('flag', 'unflag', 'reset'),
     'flag_short' => 'Flag as offensive',
     'flag_long' => 'Flag this content as offensive.',
     'flag_confirmation' => 'Are you sure you want to flag this content as offensive?',
     'unflag_short' => 'Flag as non-offensive',
     'unflag_long' => 'Flag this content as non-offensive.',
     'unflag_confirmation' => 'Are you sure you want to flag this content as non-offensive?',
+    'reset_short' => 'Reset flags',
+    'reset_long' => 'Reset all flags on this content',
+    'reset_confirmation' => 'Are you sure you want to reset all flags on this content?',
     'types' => array('story'),
     'status' => FALSE,
     'show_on_teaser' => FALSE,
@@ -40,6 +44,9 @@ function _flag_abuse_abuse_comment_flags
     'unflag_short' => 'Flag as non-offensive',
     'unflag_long' => 'Flag this content as non-offensive.',
     'unflag_confirmation' => 'Are you sure you want to flag this content as non-offensive?',
+    'reset_short' => 'Reset flags',
+    'reset_long' => 'Reset all flags on this commnet',
+    'reset_confirmation' => 'Are you sure you want to reset all flags on this comment?',
     'types' => array('story'),
     'status' => FALSE,
     'show_on_teaser' => FALSE,
@@ -64,6 +71,9 @@ function _flag_abuse_abuse_user_flags(&$
     'unflag_short' => 'Remove Report',
     'unflag_long' => 'Remove your report about this user.',
     'unflag_confirmation' => 'Are you sure you want to remove your report of this user?',
+    'reset_short' => 'Reset flags',
+    'reset_long' => 'Reset all flags on this user',
+    'reset_confirmation' => 'Are you sure you want to reset all flags on this user?',
     'status' => FALSE,
     'show_on_teaser' => FALSE,
     'link_type' => 'confirm',
