Index: flag.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag.inc,v
retrieving revision 1.1.2.12
diff -u -F^[^a-z]*function -r1.1.2.12 flag.inc
--- flag.inc	10 Sep 2008 20:34:28 -0000	1.1.2.12
+++ flag.inc	11 Sep 2008 22:50:38 -0000
@@ -475,6 +475,12 @@   function get_flag_action($content_id) 
   }
 
   /**
+   * @defgroup actions Actions integration
+   * @{
+   * Methods that can be overridden to support Actions.
+   */
+
+  /**
    * Returns an array of all actions that are executable with this flag.
    */
   function get_valid_actions() {
@@ -488,6 +494,27 @@   function get_valid_actions() {
   }
 
   /**
+   * Returns objects the action may possibly need. This method should return at
+   * least the 'primary' object the action operates on.
+   *
+   * This method is needed because get_valid_actions() returns actions that
+   * don't necessarily operate on an object of a type this flag manages. For
+   * example, flagging a comment may trigger an 'Unpublish post' action on a
+   * node; So the comment flag needs to tell the action about some node.
+   *
+   * Derived classes must implement this.
+   *
+   * @abstract
+   */
+  function get_relevant_action_objects($content_id) {
+    return array();
+  }
+
+  /**
+   * @} End of "defgroup actions".
+   */
+
+  /**
    * @defgroup views Views 2 integration
    * @{
    * Methods that can be overridden to support the Views module.
@@ -697,6 +724,12 @@   function get_valid_actions() {
     return $actions;
   }
 
+  function get_relevant_action_objects($content_id) {
+    return array(
+      'node' => $this->load_content($content_id),
+    );
+  }
+
   function get_views_info() {
     return array(
       'views table' => 'node',
@@ -787,6 +820,14 @@   function get_flag_action($content_id) 
     return $flag_action;
   }
 
+  function get_relevant_action_objects($content_id) {
+    $comment = $this->load_content($content_id);
+    return array(
+      'comment' => $comment,
+      'node' => node_load($comment->nid),
+    );
+  }
+
   function get_views_info() {
     return array(
       'views table' => 'comments',
@@ -880,6 +921,12 @@   function get_flag_action($content_id) 
     return $flag_action;
   }
 
+  function get_relevant_action_objects($content_id) {
+    return array(
+      'user' => $this->load_content($content_id),
+    );
+  }
+
   function get_views_info() {
     return array(
       'views table' => 'users',
Index: flag_actions.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag_actions.module,v
retrieving revision 1.1.2.4
diff -u -F^[^a-z]*function -r1.1.2.4 flag_actions.module
--- flag_actions.module	10 Sep 2008 23:18:59 -0000	1.1.2.4
+++ flag_actions.module	11 Sep 2008 22:50:39 -0000
@@ -80,12 +80,13 @@ function flag_actions_get_actions($flag_
   // Retrieve the list of user-defined flag actions.
   if (!isset($flag_actions) || $reset) {
     $flag_actions = array();
-    $result = db_query("SELECT a.*, f.name as flag, f.content_type as type FROM {flag_actions} a INNER JOIN flags f ON a.fid = f.fid");
+    $result = db_query("SELECT a.*, f.name as flag FROM {flag_actions} a INNER JOIN flags f ON a.fid = f.fid");
     while ($action = db_fetch_object($result)) {
       $action->parameters = unserialize($action->parameters);
       $action->description = $actions[$action->callback]['description'];
       $action->configurable = $actions[$action->callback]['configurable'];
       $action->behavior = isset($actions[$action->callback]['behavior']) ? $actions[$action->callback]['behavior'] : array();
+      $action->type = $actions[$action->callback]['type'];
 
       $flag_actions[$action->aid] = $action;
     }
@@ -149,24 +150,45 @@ function flag_actions_delete_action($aid
  */
 function flag_actions_do($event, $flag, $content_id, $account) {
   $actions = flag_actions_get_actions($flag->name);
+  if (!$actions) {
+    return;
+  }
 
   $flag_action = $flag->get_flag_action($content_id);
   $flag_action->action = $event;
   $flag_action->count = $count = $flag->get_count($content_id);
-  $object = $flag->load_content($content_id);
+  $relevant_objects = $flag->get_relevant_action_objects($content_id);
   $node_changed = FALSE;
   foreach ($actions as $aid => $action) {
     if (($action->event == $event && $action->event == 'flag' && $count == $action->threshold) || ($action->event == $event && $action->event == 'unflag' && $count == $action->threshold - 1)) {
       $context = $action->parameters;
       $context['callback'] = $action->callback;
+      // We're setting 'hook' to something, to prevent PHP warnings by actions
+      // who read it. Maybe we should set it to nodeapi/comment/user, depending
+      // on the flag, because these three are among the only hooks some actions
+      // in system.module "know" to work with.
       $context['hook'] = 'flag';
       $context['type'] = $action->type;
       $context['account'] = $account;
       $context['flag'] = $flag;
       $context['flag-action'] = $flag_action;
-      $context[$action->type] = &$object;
+      // We add to the $context all the objects we know about:
+      $context = array_merge($relevant_objects, $context);
       $callback = $action->callback;
-      $callback($object, $context);
+
+      if (isset($relevant_objects[$action->type])) {
+        $callback($relevant_objects[$action->type], $context);
+      }
+      else {
+        // What object shall we send as last resort? Let's send a node, or
+        // the flag's object.
+        if (isset($relevant_objects['node'])) {
+          $callback($relevant_objects['node'], $context);
+        }
+        else {
+          $callback($relevant_objects[$flag->content_type], $context);
+        }
+      }
 
       if (is_array($action->behavior) && in_array('changes_node_property', $action->behavior)) {
         $node_changed = TRUE;
@@ -174,7 +196,7 @@ function flag_actions_do($event, $flag, 
     }
   }
   if ($node_changed) {
-    node_save_action($object);
+    node_save_action($relevant_objects['node']);
   }
 }
 
