Index: flag.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag/Attic/flag.inc,v
retrieving revision 1.1.2.30.2.8
diff -u -r1.1.2.30.2.8 flag.inc
--- flag.inc	28 Sep 2009 02:05:06 -0000	1.1.2.30.2.8
+++ flag.inc	28 Sep 2009 03:31:04 -0000
@@ -462,11 +462,27 @@
    * @param $account
    *   Optional. The account for which the actions will be compared against.
    *   If left empty, the current user will be used.
-   *
-   * @abstract
    */
   function access_multiple($content_ids, $account = NULL) {
-    return array();
+    $account = isset($account) ? $account : $GLOBALS['user'];
+    $access = array();
+
+    // First check basic user access for this action.
+    foreach ($content_ids as $content_id => $action) {
+      $access[$content_id] = $this->user_access($content_ids[$content_id], $account);
+    }
+
+    // Merge in module-defined access.
+    foreach (module_implements('flag_access_multiple') as $module) {
+      $module_access = module_invoke($module, 'flag_access_multiple', $this, $content_ids, $account);
+      foreach ($module_access as $content_id => $content_access) {
+        if (isset($content_access)) {
+          $access[$content_id] = $content_access;
+        }
+      }
+    }
+
+    return $access;
   }
 
   /**
@@ -1006,27 +1025,18 @@
   }
 
   function access_multiple($content_ids, $account = NULL) {
-    if (!isset($account)) {
-      $account = $GLOBALS['user'];
-    }
+    $access = parent::access_multiple($content_ids, $account);
 
-    $passed = array();
-    $nids  = implode(',', array_map('intval', array_keys($content_ids)));
+    // Ensure that only flaggable node types are granted access. This avoids a
+    // node_load() on every type, usually done by applies_to_content_id().
+    $nids = implode(',', array_map('intval', array_keys($content_ids)));
     $placeholders = implode(',', array_fill(0, sizeof($this->types), "'%s'"));
-    $result = db_query("SELECT nid FROM {node} WHERE nid IN ($nids) AND type in ($placeholders)", $this->types);
+    $result = db_query("SELECT nid as content_id FROM {node} WHERE nid IN ($nids) AND type NOT IN ($placeholders)", $this->types);
     while ($row = db_fetch_object($result)) {
-      // First check basic user access for this action.
-      $passed[$row->nid] = $this->user_access($content_ids[$row->nid], $account);
-
-      // Allow other modules to modify access.
-      $access_array = module_invoke_all('flag_access_multiple', $this, $content_ids, $account);
-      foreach ($access_array as $access) {
-        if (isset($access)) {
-          $passed[$row->nid] = $access;
-        }
-      }
+      $access[$row->content_id] = FALSE;
     }
-    return $passed;
+
+    return $access;
   }
 
   function get_content_id($node) {
@@ -1165,27 +1176,19 @@
   }
 
   function access_multiple($content_ids, $account = NULL) {
-    if (!isset($account)) {
-      $account = $GLOBALS['user'];
-    }
+    $account = isset($account) ? $account : $GLOBALS['user'];
+    $access = parent::access_multiple($content_ids, $account);
 
-    $passed = array();
+    // Ensurele node types are granted access. This avoids a
+    // node_load() on every type, usually done by applies_to_content_id().
     $content_ids  = implode(',', array_map('intval', array_keys($content_ids)));
     $placeholders = implode(',', array_fill(0, sizeof($this->types), "'%s'"));
-    $result = db_query("SELECT cid FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid WHERE cid IN ($content_ids) and n.type IN ($placeholders)", $this->types);
+    $result = db_query("SELECT cid as content_id FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid WHERE cid IN ($content_ids) and n.type NOT IN ($placeholders)", $this->types);
     while ($row = db_fetch_object($result)) {
-      // First check basic user access for this action.
-      $passed[$row->cid] = $this->user_access($content_ids[$row->cid], $account);
-
-      // Allow other modules to modify access.
-      $access_array = module_invoke_all('flag_access_multiple', $this, $content_ids, $account);
-      foreach ($access_array as $access) {
-        if (isset($access)) {
-          $passed[$row->cid] = $access;
-        }
-      }
+      $access[$row->content_id] = FALSE;
     }
-    return $passed;
+
+    return $access;
   }
 
   function get_content_id($comment) {
@@ -1326,36 +1330,20 @@
   }
 
   function access_multiple($content_ids, $account = NULL) {
-    if (!isset($account)) {
-      $account = $GLOBALS['user'];
-    }
-
-    // This user flag doesn't currently support subtypes so all users are
-    // applicable for flagging.
-    $passed = array();
-    foreach (array_keys($content_ids) as $uid) {
-      // First check basic user access for this action.
-      $passed[$uid] = $this->user_access($content_ids[$uid], $account);
-
-      // Exclude anonymous.
-      if ($uid == 0) {
-        $passed[$uid] = FALSE;
-      }
+    $account = isset($account) ? $account : $GLOBALS['user'];
+    $access = parent::access_multiple($content_ids, $account);
 
-      // Prevent users from flagging themselves.
-      if ($this->access_uid == 'others' && $uid == $account->uid) {
-        $passed[$uid] = FALSE;
-      }
+    // Exclude anonymous.
+    if (array_key_exists(0, $access)) {
+      $access[0] = FALSE;
+    }
 
-      // Allow other modules to modify access.
-      $access_array = module_invoke_all('flag_access_multiple', $this, $content_ids, $account);
-      foreach ($access_array as $access) {
-        if (isset($access)) {
-          $passed[$uid] = $access;
-        }
-      }
+    // Prevent users from flagging themselves.
+    if ($this->access_uid == 'others' && array_key_exists($account->uid, $access)) {
+      $access[$account->uid] = FALSE;
     }
-    return $passed;
+
+    return $access;
   }
 
   function get_content_id($user) {
@@ -1447,4 +1435,3 @@
     ? url($path, NULL, $fragment, $absolute)
     : url($path, array('absolute' => TRUE, 'fragment' => $fragment));
 }
-
