From 79c40bc73b41147fbc98eb03c590f9d4383c32d1 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Wed, 14 Oct 2015 00:27:51 +0200 Subject: [PATCH] Type-aware comparison is necessary for Notice is_local/scope --- classes/Notice.php | 23 +++++++++---------- classes/User_group.php | 2 +- lib/imqueuehandler.php | 3 +-- .../lib/facebookqueuehandler.php | 15 +----------- plugins/GeoURL/GeoURLPlugin.php | 2 +- plugins/Linkback/LinkbackPlugin.php | 2 +- plugins/Realtime/RealtimePlugin.php | 5 ++-- plugins/Share/SharePlugin.php | 5 ++-- 8 files changed, 22 insertions(+), 35 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index 47ada7f958..71c3690a0c 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -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); } diff --git a/classes/User_group.php b/classes/User_group.php index df54b7987c..01437ace39 100644 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -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() diff --git a/lib/imqueuehandler.php b/lib/imqueuehandler.php index 9c35890c62..2df25ac9f4 100644 --- a/lib/imqueuehandler.php +++ b/lib/imqueuehandler.php @@ -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; diff --git a/plugins/FacebookBridge/lib/facebookqueuehandler.php b/plugins/FacebookBridge/lib/facebookqueuehandler.php index 1e82ff01b1..2d2df343d9 100644 --- a/plugins/FacebookBridge/lib/facebookqueuehandler.php +++ b/plugins/FacebookBridge/lib/facebookqueuehandler.php @@ -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); - } } diff --git a/plugins/GeoURL/GeoURLPlugin.php b/plugins/GeoURL/GeoURLPlugin.php index a8e2546c4f..0e779a4fe8 100644 --- a/plugins/GeoURL/GeoURLPlugin.php +++ b/plugins/GeoURL/GeoURLPlugin.php @@ -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(); diff --git a/plugins/Linkback/LinkbackPlugin.php b/plugins/Linkback/LinkbackPlugin.php index a710abd7bf..0bbd55d43a 100644 --- a/plugins/Linkback/LinkbackPlugin.php +++ b/plugins/Linkback/LinkbackPlugin.php @@ -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; diff --git a/plugins/Realtime/RealtimePlugin.php b/plugins/Realtime/RealtimePlugin.php index d41f8eca42..fbfb0aae30 100644 --- a/plugins/Realtime/RealtimePlugin.php +++ b/plugins/Realtime/RealtimePlugin.php @@ -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); } diff --git a/plugins/Share/SharePlugin.php b/plugins/Share/SharePlugin.php index d62ec82592..5b5d374abe 100644 --- a/plugins/Share/SharePlugin.php +++ b/plugins/Share/SharePlugin.php @@ -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()) { -- 2.39.5