]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Declaring some more static functions properly
authorMikael Nordfeldth <mmn@hethane.se>
Mon, 9 Sep 2013 21:08:43 +0000 (23:08 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Mon, 9 Sep 2013 21:28:20 +0000 (23:28 +0200)
As a bonus I added type declaration on Profile_block::exists and
Subscription::exists respectively.

classes/Profile.php
classes/Profile_block.php
classes/Subscription.php
classes/User.php
lib/apiauthaction.php

index fe8e11641989603e1067b5b8fe44380fff9e3d7d..bc0f6922e83119d258ccbf085d0059e02d9a2768 100644 (file)
@@ -1366,15 +1366,8 @@ class Profile extends Managed_DataObject
 
     function hasBlocked($other)
     {
-        $block = Profile_block::get($this->id, $other->id);
-
-        if (empty($block)) {
-            $result = false;
-        } else {
-            $result = true;
-        }
-
-        return $result;
+        $block = Profile_block::exists($this, $other);
+        return !empty($block);
     }
 
     function getAtomFeed()
index d9b5cbba87445944b6ee83052a7c11b1ef88fada..b30e3b244e8ebdf9f6b1c487c949f77ecabb89e4 100644 (file)
@@ -54,9 +54,9 @@ class Profile_block extends Managed_DataObject
         );
     }
 
-    function get($blocker, $blocked)
+    static function exists(Profile $blocker, Profile $blocked)
     {
-        return Profile_block::pkeyGet(array('blocker' => $blocker,
-                                            'blocked' => $blocked));
-     }
+        return Profile_block::pkeyGet(array('blocker' => $blocker->id,
+                                            'blocked' => $blocked->id));
+    }
 }
index 0c0c6489dedf7bd1b8b5851f953205f6a94590e0..3f1819a8414360a085ad90048f0cadea68653a93 100644 (file)
@@ -185,7 +185,7 @@ class Subscription extends Managed_DataObject
      * Cancel a subscription
      *
      */
-    function cancel(Profile $subscriber, Profile $other)
+    static function cancel(Profile $subscriber, Profile $other)
     {
         if (!self::exists($subscriber, $other)) {
             // TRANS: Exception thrown when trying to unsibscribe without a subscription.
@@ -230,7 +230,7 @@ class Subscription extends Managed_DataObject
         return;
     }
 
-    function exists($subscriber, $other)
+    static function exists(Profile $subscriber, Profile $other)
     {
         $sub = Subscription::pkeyGet(array('subscriber' => $subscriber->id,
                                            'subscribed' => $other->id));
index e8e06a2d40b9d00f17f512bb980343dbad2e0d38..7a56e0f12ee217881e57338ac46e3208d9a55c43 100644 (file)
@@ -632,11 +632,11 @@ class User extends Managed_DataObject
         return true;
     }
 
-    function unblock($other)
+    function unblock(Profile $other)
     {
         // Get the block record
 
-        $block = Profile_block::get($this->id, $other->id);
+        $block = Profile_block::exists($this->getProfile(), $other);
 
         if (!$block) {
             return false;
index 3edcda4cb774656afe53f9dcd416c9984dc8ced2..499c50248032eee1e677a7a3cb8fe3028d7626ef 100644 (file)
@@ -104,7 +104,11 @@ class ApiAuthAction extends ApiAction
         }
 
         // NOTE: Make sure we're scoped properly based on the auths!
-        $this->scoped = $this->auth_user->getProfile();
+        if (isset($this->auth_user) && !empty($this->auth_user)) {
+            $this->scoped = $this->auth_user->getProfile();
+        } else {
+            $this->scoped = null;
+        }
 
         // Reject API calls with the wrong access level