#963312: filter to zero nodes if no friends found. 6.x-3.0-rc1
authorDave Cohen
Sun, 14 Nov 2010 01:07:33 +0000 (01:07 +0000)
committerDave Cohen
Sun, 14 Nov 2010 01:07:33 +0000 (01:07 +0000)
fb_views/fb_views_handler_filter_friends.inc

index 2bde355..602af2a 100644 (file)
@@ -11,21 +11,17 @@ class fb_views_handler_filter_friends extends views_handler_filter_boolean_opera
   }
 
   function query() {
-    $fb_app = $GLOBALS['_fb_app']; // Set on Canvas and Connect pages.
-
-    $uid = $GLOBALS['user']->uid;
-
-    if ($fb_app && $uid) {
-      $fbu = fb_get_fbu($uid, $fb_app);
-
-      if ($fbu) {
-        $friends = fb_get_friends($fbu, $fb_app);
-
-        if (is_array($friends) && count($friends)) {
-          $this->ensure_my_table();
-          $this->query->add_where(0, $this->table_alias . '.fbu IN (%s)', implode(',', $friends));
-        }
-      }
+    // We can't learn friends if user is not logged in.
+    $fbu = fb_facebook_user();
+    if ($fbu) {
+      $friends = fb_get_friends($fbu);
+    }
+    if (!$fbu || !count($friends)) {
+      // Hide all content
+      $friends = array(0);
     }
+
+    $this->ensure_my_table();
+    $this->query->add_where(0, $this->table_alias . '.fbu IN (%s)', implode(',', $friends));
   }
 }