Index: flag.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag.module,v
retrieving revision 1.11.2.70
diff -u -r1.11.2.70 flag.module
--- flag.module	17 Mar 2009 02:07:34 -0000	1.11.2.70
+++ flag.module	17 Mar 2009 03:59:48 -0000
@@ -516,18 +516,22 @@
  */
 function flag_flag($action, $flag, $content_id, $account) {
   if (module_exists('trigger')) {
-
     $flag_action = $flag->get_flag_action($content_id);
     $flag_action->action = $action;
     $context = (array)$flag_action;
-    $aids = _trigger_get_hook_aids($action, $action);
-    foreach ($aids as $aid => $action_info) {
+    // Generic "all flags" actions.
+    foreach (_trigger_get_hook_aids($action, $action) as $aid => $action_info) {
       // The 'if ($aid)' is a safeguard against http://drupal.org/node/271460#comment-886564
       if ($aid) {
         actions_do($aid, $flag, $context);
       }
     }
-
+    // Actions specifically for this flag.
+    foreach (_trigger_get_hook_aids($action . '_' . $flag->name, $action) as $aid => $action_info) {
+      if ($aid) {
+        actions_do($aid, $flag, $context);
+      }
+    }
   }
 
   if (module_exists('rules')) {
Index: includes/flag.actions.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/includes/Attic/flag.actions.inc,v
retrieving revision 1.1.4.2
diff -u -r1.1.4.2 flag.actions.inc
--- includes/flag.actions.inc	17 Mar 2009 02:07:34 -0000	1.1.4.2
+++ includes/flag.actions.inc	17 Mar 2009 03:59:48 -0000
@@ -10,16 +10,224 @@
  * Implementation of hook_hook_info().
  */
 function flag_hook_info() {
-  return array(
+  $hooks = array(
     'flag' => array(
       'flag' => array(
         'flag' => array(
-          'runs when' => t('Content has been flagged'),
+          'runs when' => t('Content has been flagged with any flag'),
         ),
         'unflag' => array(
-          'runs when' => t('Content has been unflagged')
+          'runs when' => t('Content has been unflagged with any flag')
         ),
       ),
     ),
   );
+
+  foreach (flag_get_flags() as $flag) {
+    $hooks['flag']['flag']['flag_'. $flag->name]['runs when'] = t('A %type has been flagged with %name', array('%type' => $flag->content_type, '%name' => $flag->name));
+    $hooks['flag']['flag']['unflag_'. $flag->name]['runs when'] = t('A %type has been unflagged with %name', array('%type' => $flag->content_type, '%name' => $flag->name));
+  }
+
+  return $hooks;
+}
+
+/**
+ * Implementation of hook_action_info().
+ */
+function flag_action_info() {
+  return array(
+    'flag_node_action' => array(
+      'type' => 'node',
+      'description' => t('Flag (or unflag) a node'),
+      'configurable' => TRUE,
+      'hooks' => array(
+        'node' => array('view', 'presave', 'insert', 'update', 'delete', 'view'),
+        'comment' => array('insert', 'update', 'delete', 'view'),
+      ),
+    ),
+    'flag_comment_action' => array(
+      'type' => 'comment',
+      'description' => t('Flag (or unflag) a comment'),
+      'configurable' => TRUE,
+      'hooks' => array(
+        'comment' => array('insert', 'update', 'delete', 'view'),
+      ),
+    ),
+    'flag_user_action' => array(
+      'type' => 'user',
+      'description' => t('Flag (or unflag) a user'),
+      'configurable' => TRUE,
+      'hooks' => array(
+        'user' => array('insert', 'update', 'delete', 'login', 'logout', 'view'),
+      ),
+    ),
+  );
+}
+
+/**
+ * Implementation of hook_action_info_alter().
+ *
+ * Enable Flag actions on Node and Comment hooks without trigger_unlock.module.
+ */
+function flag_action_info_alter(&$actions) {
+  $node_flags = flag_get_flags('node');
+  $comment_flags = flag_get_flags('comment');
+  $user_flags = flag_get_flags('user');
+
+  foreach ($actions as $name => $action) {
+    if (strpos($name, 'node') === 0) {
+      $actions[$name]['hooks']['flag'] = array('flag', 'unflag');
+      foreach ($node_flags as $flag) {
+        $actions[$name]['hooks']['flag'][] = 'flag_' . $flag->name;
+        $actions[$name]['hooks']['flag'][] = 'unflag_' . $flag->name;
+      }
+    }
+    if (strpos($name, 'comment') === 0) {
+      $actions[$name]['hooks']['flag'] = array('flag', 'unflag');
+      foreach ($comment_flags as $flag) {
+        $actions[$name]['hooks']['flag'][] = 'flag_' . $flag->name;
+        $actions[$name]['hooks']['flag'][] = 'unflag_' . $flag->name;
+      }
+    }
+    if (strpos($name, 'user') === 0) {
+      $actions[$name]['hooks']['flag'] = array('flag', 'unflag');
+      foreach ($user_flags as $flag) {
+        $actions[$name]['hooks']['flag'][] = 'flag_' . $flag->name;
+        $actions[$name]['hooks']['flag'][] = 'unflag_' . $flag->name;
+      }
+    }
+  }
+}
+
+/**
+ * Implementation of a Drupal action. Flags a node.
+ *
+ * Note the first parameter is "object" because it may be a comment or a node.
+ */
+function flag_node_action(&$object, $context = array()) {
+  if ($flag = flag_get_flag($context['flag'])) {
+    $flag->flag($context['flag_action'], $object->nid);
+  }
+}
+
+/**
+ * Implementation of a Drupal action. Flags a node.
+ */
+function flag_node_action_form($context = array()) {
+  return flag_action_form($context, 'node');
+}
+
+/**
+ * Submit function for the Flag node action form.
+ */
+function flag_node_action_submit($form, $form_state) {
+  return flag_action_submit($form, $form_state);
+}
+
+/**
+ * Implementation of a Drupal action. Flags a comment.
+ */
+function flag_comment_action(&$comment, $context = array()) {
+  if ($flag = flag_get_flag($context['flag'])) {
+    $flag->flag($context['flag_action'], $comment->cid);
+  }
+}
+
+/**
+ * Form for configuring the Flag comment action.
+ */
+function flag_comment_action_form($context) {
+  return flag_action_form($context, 'comment');
+}
+
+/**
+ * Submit function for the Flag comment action form.
+ */
+function flag_comment_action_submit($form, $form_state) {
+  return flag_action_submit($form, $form_state);
+}
+
+
+/**
+ * Implementation of a Drupal action. Flags a comment.
+ */
+function flag_user_action(&$account, $context = array()) {
+  if ($flag = flag_get_flag($context['flag'])) {
+    $flag->flag($context['flag_action'], $account->uid);
+  }
+}
+
+/**
+ * Form for configuring the Flag comment action.
+ */
+function flag_user_action_form($context) {
+  return flag_action_form($context, 'user');
+}
+
+/**
+ * Submit function for the Flag comment action form.
+ */
+function flag_user_action_submit($form, $form_state) {
+  return flag_action_submit($form, $form_state);
+}
+
+/**
+ * Generic form for configuring Flag actions.
+ *
+ * @param $context
+ *   The current action context.
+ * @param $content_type
+ *   The content type applicable to this action, such as "node" or "comment".
+ */
+function flag_action_form($context, $content_type) {
+  $form = array();
+
+  $flags = flag_get_flags($content_type);
+  $options = drupal_map_assoc(array_keys($flags));
+
+  $form['flag'] = array(
+    '#title' => t('Flag'),
+    '#type' => 'radios',
+    '#options' => $options,
+    '#required' => TRUE,
+    '#description' => t('When this action is fired, which flag should be flagged (or unflagged)?'),
+    '#default_value' => isset($context['flag']) ? $context['flag'] : reset($options),
+  );
+
+  $form['flag_action'] = array(
+    '#title' => t('Flag operation'),
+    '#type' => 'radios',
+    '#options' => array('flag' => t('Flag'), 'unflag' => t('Unflag')),
+    '#description' => t('When this action is fired, which operation should be performed on the flag?'),
+    '#default_value' => isset($context['flag_action']) ? $context['flag_action'] : 'flag',
+  );
+
+  if (empty($options)) {
+    $error = t('There are no available %type flags. Before you can create an action of this type, you need to <a href="!url">create a %type flag</a>.', array('%type' => $content_type, '!url' => url('admin/build/flags/add')));
+    $form['flag']['#type'] = 'item';
+    $form['flag']['#children'] = $error;
+    $form['flag']['#element_validate'][] = 'flag_action_validate_flag';
+    $form['flag']['#flag_error'] = $error;
+  }
+
+  return $form;
+}
+
+/**
+ * Generic validation handler for validating Flag action configuration.
+ */
+function flag_action_validate_flag($element) {
+  if (isset($element['#flag_error'])) {
+    form_error($element, $element['#flag_error']);
+  }
+}
+
+/**
+ * Generic submission handler for saving Flag action configuration.
+ */
+function flag_action_submit($form, $form_state) {
+  return array(
+    'flag' => $form_state['values']['flag'],
+    'flag_action' => $form_state['values']['flag_action'],
+  );
 }
