]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Type-aware comparison is necessary for Notice is_local/scope
authorMikael Nordfeldth <mmn@hethane.se>
Tue, 13 Oct 2015 22:27:51 +0000 (00:27 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Tue, 13 Oct 2015 22:42:15 +0000 (00:42 +0200)
classes/Notice.php
classes/User_group.php
lib/imqueuehandler.php
plugins/FacebookBridge/lib/facebookqueuehandler.php
plugins/GeoURL/GeoURLPlugin.php
plugins/Linkback/LinkbackPlugin.php
plugins/Realtime/RealtimePlugin.php
plugins/Share/SharePlugin.php

index 47ada7f9580ef7fb513bcbd35d9163147fb38a60..71c3690a0c24529eab934f5c3f0730230603032e 100644 (file)
@@ -997,15 +997,13 @@ class Notice extends Managed_DataObject
     }
 
     static public function figureOutScope(Profile $actor, array $groups, $scope=null) {
-        if (is_null($scope)) {
-            $scope = self::defaultScope();
-        }
+        $scope = is_null($scope) ? self::defaultScope() : intval($scope);
 
         // For private streams
         try {
             $user = $actor->getUser();
             // FIXME: We can't do bit comparison with == (Legacy StatusNet thing. Let's keep it for now.)
-            if ($user->private_stream && ($scope == Notice::PUBLIC_SCOPE || $scope == Notice::SITE_SCOPE)) {
+            if ($user->private_stream && ($scope === Notice::PUBLIC_SCOPE || $scope === Notice::SITE_SCOPE)) {
                 $scope |= Notice::FOLLOWER_SCOPE;
             }
         } catch (NoSuchUserException $e) {
@@ -2489,8 +2487,13 @@ class Notice extends Managed_DataObject
 
     public function isLocal()
     {
-        return ($this->is_local == Notice::LOCAL_PUBLIC ||
-                $this->is_local == Notice::LOCAL_NONPUBLIC);
+        $is_local = intval($this->is_local);
+        return ($is_local === self::LOCAL_PUBLIC || $is_local === self::LOCAL_NONPUBLIC);
+    }
+
+    public function getScope()
+    {
+        return intval($this->scope);
     }
 
     public function isRepeat()
@@ -2683,13 +2686,9 @@ class Notice extends Managed_DataObject
 
     protected function _inScope($profile)
     {
-        if (!is_null($this->scope)) {
-            $scope = $this->scope;
-        } else {
-            $scope = self::defaultScope();
-        }
+        $scope = is_null($this->scope) ? self::defaultScope() : $this->getScope();
 
-        if ($scope == 0 && !$this->getProfile()->isPrivateStream()) { // Not scoping, so it is public.
+        if ($scope === 0 && !$this->getProfile()->isPrivateStream()) { // Not scoping, so it is public.
             return !$this->isHiddenSpam($profile);
         }
 
index df54b7987c7d7228ca507cd9b842a159b095005a..01437ace39a6b2aa88506990fc5171c5107d9ab7 100644 (file)
@@ -818,7 +818,7 @@ class User_group extends Managed_DataObject
     function isPrivate()
     {
         return ($this->join_policy == self::JOIN_POLICY_MODERATE &&
-                $this->force_scope == 1);
+                intval($this->force_scope) === 1);
     }
 
     public function isLocal()
index 9c35890c62c47d9bae54903c7b321b687e7f49c8..2df25ac9f4fb36b522d7a2df8a4e52374e29ce23 100644 (file)
@@ -38,8 +38,7 @@ class ImQueueHandler extends QueueHandler
     function handle($notice)
     {
         $this->plugin->broadcastNotice($notice);
-        if ($notice->is_local == Notice::LOCAL_PUBLIC ||
-            $notice->is_local == Notice::LOCAL_NONPUBLIC) {
+        if ($notice->isLocal()) {
             $this->plugin->publicNotice($notice);
         }
         return true;
index 1e82ff01b1845f43b956dbd0bc4415defa3da1ac..2d2df343d9153097797c959006fca03d843bb2f6 100644 (file)
@@ -40,22 +40,9 @@ class FacebookQueueHandler extends QueueHandler
 
     function handle($notice)
     {
-        if ($this->_isLocal($notice)) {
+        if ($notice->isLocal()) {
             return Facebookclient::facebookBroadcastNotice($notice);
         }
         return true;
     }
-
-    /**
-     * Determine whether the notice was locally created
-     *
-     * @param Notice $notice the notice
-     *
-     * @return boolean locality
-     */
-    function _isLocal($notice)
-    {
-        return ($notice->is_local == Notice::LOCAL_PUBLIC ||
-                $notice->is_local == Notice::LOCAL_NONPUBLIC);
-    }
 }
index a8e2546c4f846b05b1eb22b97f98c1a0fab7cee9..0e779a4fe8b33ade89ab1619013cba7e837ed7c6 100644 (file)
@@ -96,7 +96,7 @@ class GeoURLPlugin extends Plugin
      */
     function onHandleQueuedNotice(&$notice)
     {
-        if ($notice->is_local == 1) {
+        if (intval($notice->is_local) === Notice::LOCAL_PUBLIC) {
 
             $request = HTTPClient::start();
 
index a710abd7bf8c8c5f80c59b16db87143323638d67..0bbd55d43a6c515d55dc77568df4adbad68c0c01 100644 (file)
@@ -60,7 +60,7 @@ class LinkbackPlugin extends Plugin
 
     function onHandleQueuedNotice($notice)
     {
-        if ($notice->is_local == 1) {
+        if (intval($notice->is_local) === Notice::LOCAL_PUBLIC) {
             // Try to avoid actually mucking with the
             // notice content
             $c = $notice->content;
index d41f8eca425e57367999a0e2b05809ab9cee06ac..fbfb0aae306d3460878557e2004e1be6f0b902f5 100644 (file)
@@ -173,8 +173,9 @@ class RealtimePlugin extends Plugin
 
         // Add to the public timeline
 
-        if ($notice->is_local == Notice::LOCAL_PUBLIC ||
-            ($notice->is_local == Notice::REMOTE && !common_config('public', 'localonly'))) {
+        $is_local = intval($notice->is_local);
+        if ($is_local === Notice::LOCAL_PUBLIC ||
+                ($is_local === Notice::REMOTE && !common_config('public', 'localonly'))) {
             $paths[] = array('public', null, null);
         }
 
index d62ec8259273bf90e5df64dba6514ad99dc033cf..5b5d374abe372f79923c1f13b60102c5b7166ea1 100644 (file)
@@ -231,8 +231,9 @@ class SharePlugin extends ActivityVerbHandlerPlugin
     public function onEndShowNoticeOptionItems($nli)
     {
         // FIXME: Use bitmasks (but be aware that PUBLIC_SCOPE is 0!)
-        if ($nli->notice->scope == Notice::PUBLIC_SCOPE ||
-                $nli->notice->scope == Notice::SITE_SCOPE) {
+        // Also: AHHH, $scope and $scoped are scarily similar looking.
+        $scope = $nli->notice->getScope();
+        if ($scope === Notice::PUBLIC_SCOPE || $scope === Notice::SITE_SCOPE) {
             $scoped = Profile::current();
             if ($scoped instanceof Profile &&
                     $scoped->getID() !== $nli->notice->getProfile()->getID()) {