Index: flag_actions.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag_actions.module,v
retrieving revision 1.1.2.12.2.1
diff -u -r1.1.2.12.2.1 flag_actions.module
--- flag_actions.module	14 Sep 2009 11:58:03 -0000	1.1.2.12.2.1
+++ flag_actions.module	19 Sep 2009 01:23:58 -0000
@@ -125,15 +125,19 @@
  *
  * @param $fid
  *   The flag object ID.
+ * @param $event
+ *   The flag event, such as "flag" or "unflag".
  * @param $threshold
  *   The flagging threshold at which this action will be executed.
+ * @param $repeat_threshold
+ *   The number of additional flaggings after which the action will be repeated.
  * @param $callback
  *   The action callback to be executed.
  * @param $parameters
  *   The action parameters.
  */
-function flag_actions_insert_action($fid, $event, $threshold, $callback, $parameters) {
-  db_query("INSERT INTO {flag_actions} (fid, event, threshold, callback, parameters) VALUES (%d, '%s', %d, '%s', '%s')", $fid, $event, $threshold, $callback, serialize($parameters));
+function flag_actions_insert_action($fid, $event, $threshold, $repeat_threshold, $callback, $parameters) {
+  db_query("INSERT INTO {flag_actions} (fid, event, threshold, repeat_threshold, callback, parameters) VALUES (%d, '%s', %d, %d, '%s', '%s')", $fid, $event, $threshold, $repeat_threshold, $callback, serialize($parameters));
   return db_last_insert_id('flag_actions', 'aid');
 }
 
@@ -142,13 +146,17 @@
  *
  * @param $aid
  *   The flag action ID to update.
+ * @param $event
+ *   The flag event, such as "flag" or "unflag".
  * @param $threshold
  *   The flagging threshold at which this action will be executed.
+ * @param $repeat_threshold
+ *   The number of additional flaggings after which the action will be repeated.
  * @param $parameters
  *   The action parameters.
  */
-function flag_actions_update_action($aid, $event, $threshold, $parameters) {
-  return db_query("UPDATE {flag_actions} SET event = '%s', threshold = %d, parameters = '%s' WHERE aid = %d", $event, $threshold, serialize($parameters), $aid);
+function flag_actions_update_action($aid, $event, $threshold, $repeat_threshold, $parameters) {
+  return db_query("UPDATE {flag_actions} SET event = '%s', threshold = %d, repeat_threshold = %d, parameters = '%s' WHERE aid = %d", $event, $threshold, $repeat_threshold, serialize($parameters), $aid);
 }
 
 /**
@@ -176,10 +184,15 @@
   $relevant_objects = $flag->get_relevant_action_objects($content_id);
   $node_changed = FALSE;
   foreach ($actions as $aid => $action) {
-    $threshold = ($action->event == $event) &&
-                (($action->event == 'flag'   && $count == $action->threshold) ||
-                 ($action->event == 'unflag' && $count == $action->threshold - 1));
-    if ($threshold && !$action->missing) {
+    if ($action->event == 'flag') {
+      $at_threshold = ($count == $action->threshold);
+      $repeat = ($count > $action->threshold) && (($count - $action->threshold) % $action->repeat_threshold == 0);
+    }
+    elseif ($action->event == 'unflag') {
+      $at_threshold = ($count == $action->threshold - 1);
+      $repeat = ($count < $action->threshold - 1) && (($count - $action->threshold - 1) % $action->repeat_threshold == 0);
+    }
+    if (($at_threshold || $repeat) && $action->event == $event && !$action->missing) {
       $context = $action->parameters;
       $context['callback'] = $action->callback;
       // We're setting 'hook' to something, to prevent PHP warnings by actions
@@ -239,9 +252,30 @@
   foreach ($actions as $action) {
     $flag = flag_get_flag($action->flag);
 
+    // Build a sample string representing repeating actions.
+    if ($action->repeat_threshold) {
+      $repeat_count = 3;
+      $repeat_subtract = ($action->event == 'flag') ? 1 : -1;
+      $repeat_samples = array();
+      for ($n = 1; $n < $repeat_count + 2; $n++) {
+        $sample = $action->threshold + (($n * $action->repeat_threshold) * $repeat_subtract);
+        if ($sample > 0) {
+          $repeat_samples[] = $sample;
+        }
+      }
+      if (count($repeat_samples) > $repeat_count) {
+        $repeat_samples[$repeat_count] = '&hellip;';
+      }
+      $repeat_string = implode(', ', $repeat_samples);
+    }
+    else {
+      $repeat_string = '-';
+    }
+
     $row = array();
     $row[] = $flag->get_title();
-    $row[] = ($action->event == 'flag' ? '≥ ' : '< ') . $action->threshold;
+    $row[] = ($action->event == 'flag' ? '&ge; ' : '&lt; ') . $action->threshold;
+    $row[] = $repeat_string;
     $row[] = empty($action->missing) ? $action->description : '<div class="error">' . $action->description . '</div>';
     $row[] = l(t('edit'), 'admin/build/flags/actions/configure/'. $action->aid);
     $row[] = l(t('delete'), 'admin/build/flags/actions/delete/'. $action->aid);
@@ -255,6 +289,7 @@
   $header = array(
     t('Flag'),
     t('Threshold'),
+    t('Repeats'),
     t('Action'),
     array('data' => t('Operations'), 'colspan' => 2),
   );
@@ -379,6 +414,7 @@
     $action->parameters = array();
     $action->event = 'flag';
     $action->threshold = 10;
+    $action->repeat_threshold = 0;
     drupal_set_title(t('Add "@action" action to the @title flag', array('@action' => $action->description, '@title' => $flag->get_title())));
   }
 
@@ -421,6 +457,13 @@
     '#required' => TRUE,
   );
 
+  $form['flag']['repeat_threshold'] = array(
+    '#type' => 'textfield',
+    '#size' => 6,
+    '#maxlength' => 6,
+    '#default_value' => $action->repeat_threshold,
+  );
+
   $action_form = $callback .'_form';
   if (function_exists($action_form)) {
     $edit = $action->parameters;
@@ -454,22 +497,23 @@
     return;
   }
 
-  $aid        = $form_state['values']['flag']['aid'];
-  $flag       = $form_state['values']['flag']['flag'];
-  $event      = $form_state['values']['flag']['event'];
-  $threshold  = $form_state['values']['flag']['threshold'];
-  $callback   = $form_state['values']['flag']['callback'];
+  $aid              = $form_state['values']['flag']['aid'];
+  $flag             = $form_state['values']['flag']['flag'];
+  $event            = $form_state['values']['flag']['event'];
+  $threshold        = $form_state['values']['flag']['threshold'];
+  $repeat_threshold = $form_state['values']['flag']['repeat_threshold'];
+  $callback         = $form_state['values']['flag']['callback'];
 
   $parameters = $form_state['values'];
   unset($parameters['flag']);
 
   if (empty($aid)) {
-    $aid = flag_actions_insert_action($flag->fid, $event, $threshold, $callback, $parameters);
+    $aid = flag_actions_insert_action($flag->fid, $event, $threshold, $repeat_threshold, $callback, $parameters);
     $form_state['values']['flag']['aid'] = $aid;
     $form_state['values']['flag']['is_new'] = TRUE;
   }
   else {
-    flag_actions_update_action($aid, $event, $threshold, $parameters);
+    flag_actions_update_action($aid, $event, $threshold, $repeat_threshold, $parameters);
   }
 
   $action = flag_actions_get_action($aid);
@@ -481,16 +525,19 @@
 function theme_flag_actions_flag_form($form) {
   $event = drupal_render($form['event']);
   $threshold = drupal_render($form['threshold']);
+  $repeat_threshold = drupal_render($form['repeat_threshold']);
   $action = $form['#action']->description;
 
   $output  = '';
   $output .= '<div class="container-inline">';
   $output .= t('Perform action when content !event !threshold flags', array('!event' => $event, '!threshold' => $threshold));
   $output .= '</div>';
+  $output .= '<div class="container-inline">';
+  $output .= t('Repeat this action every !repeat_threshold additional flags after the threshold is reached', array('!repeat_threshold' => $repeat_threshold));
+  $output .= '</div>';
 
   $element = array(
     '#title' => t('Flagging threshold'),
-    '#description' => t('Set the event for which this action should be executed.'),
     '#required' => TRUE,
   );
 
Index: flag_actions.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag_actions.install,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 flag_actions.install
--- flag_actions.install	30 Sep 2008 03:08:49 -0000	1.1.2.2
+++ flag_actions.install	19 Sep 2009 01:23:57 -0000
@@ -47,7 +47,15 @@
       'threshold' => array(
         'type' => 'int',
         'size' => 'small',
-        'not null' => FALSE,
+        'not null' => TRUE,
+        'default' => 0,
+        'disp-width' => '5',
+      ),
+      'repeat_threshold' => array(
+        'type' => 'int',
+        'size' => 'small',
+        'not null' => TRUE,
+        'default' => 0,
         'disp-width' => '5',
       ),
       'callback' => array(
@@ -67,3 +75,34 @@
 
   return $schema;
 }
+
+/**
+ * Add a "repeat_threshold" value to all existing Flag actions.
+ */
+function flag_actions_update_6200() {
+  $ret = array();
+
+  // Add the new repeat_threshold column.
+  if (!db_column_exists('flag_actions', 'repeat_threshold')) {
+    $column = array(
+      'type' => 'int',
+      'size' => 'small',
+      'not null' => TRUE,
+      'default' => 0,
+      'disp-width' => '5',
+    );
+    db_add_field($ret, 'flag_actions', 'repeat_threshold', $column);
+  }
+
+  // Update the normal threshold column to default to 0.
+  $column = array(
+    'type' => 'int',
+    'size' => 'small',
+    'not null' => TRUE,
+    'default' => 0,
+    'disp-width' => '5',
+  );
+  db_change_field($ret, 'flag_actions', 'threshold', 'threshold', $column);
+
+  return $ret;
+}
