From cadfef63c417e0c75994da58d8f95a9993803d20 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Wed, 6 Dec 2017 14:57:06 -0500 Subject: [PATCH 1/3] Update false evaluations === false and !== false to is_null where appropriate. --- boot.php | 2 +- include/nav.php | 2 +- include/network.php | 2 ++ src/Content/Feature.php | 8 +++++--- src/Network/FKOAuthDataStore.php | 2 +- src/Worker/OnePoll.php | 2 +- view/theme/vier/theme.php | 4 ++-- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/boot.php b/boot.php index eda8a4037d..c6f7b1e20d 100644 --- a/boot.php +++ b/boot.php @@ -742,7 +742,7 @@ function run_update_function($x) // delete the config entry to try again. $t = Config::get('database', 'update_' . $x); - if ($t !== false) { + if (!is_null($t)) { return false; } Config::set('database', 'update_' . $x, time()); diff --git a/include/nav.php b/include/nav.php index f2bf161f9e..58ec150e7a 100644 --- a/include/nav.php +++ b/include/nav.php @@ -209,7 +209,7 @@ function nav_info(App $a) // Provide a banner/logo/whatever $banner = Config::get('system', 'banner'); - if ($banner === false) { + if (is_null($banner)) { $banner = 'logoFriendica'; } diff --git a/include/network.php b/include/network.php index 52e3409573..06649554b0 100644 --- a/include/network.php +++ b/include/network.php @@ -126,6 +126,7 @@ function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = array()) if (x($opts, 'timeout')) { @curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']); } else { + // if Config::get returns null, intval will be 0 which will also evaluate to false $curl_time = intval(Config::get('system', 'curl_timeout')); @curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60)); } @@ -302,6 +303,7 @@ function post_url($url, $params, $headers = null, &$redirects = 0, $timeout = 0) if (intval($timeout)) { curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); } else { + // if Config::get returns null, intval will be 0 which will also evaluate to false $curl_time = intval(Config::get('system', 'curl_timeout')); curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60)); } diff --git a/src/Content/Feature.php b/src/Content/Feature.php index 864c07a0d8..f17b649eef 100644 --- a/src/Content/Feature.php +++ b/src/Content/Feature.php @@ -23,13 +23,15 @@ class Feature { $x = Config::get('feature_lock', $feature, false); - if ($x === false) { + if (is_null($x)) { $x = PConfig::get($uid, 'feature', $feature, false); } - if ($x === false) { + + if (is_null($x)) { $x = Config::get('feature', $feature, false); } - if ($x === false) { + + if (is_null($x)) { $x = self::getDefault($feature); } diff --git a/src/Network/FKOAuthDataStore.php b/src/Network/FKOAuthDataStore.php index 126f140bdf..d7fa145189 100644 --- a/src/Network/FKOAuthDataStore.php +++ b/src/Network/FKOAuthDataStore.php @@ -171,7 +171,7 @@ class FKOAuthDataStore extends OAuthDataStore dba::delete('tokens', array('id' => $token->key)); - if (!is_null($ret) && $uverifier !== false) { + if (!is_null($ret) && !is_null($uverifier)) { Config::delete("oauth", $verifier); } diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index c1fb5350c3..c3528b623e 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -92,7 +92,7 @@ Class OnePoll if ($contact['subhub']) { $poll_interval = Config::get('system', 'pushpoll_frequency'); - $contact['priority'] = (($poll_interval !== false) ? intval($poll_interval) : 3); + $contact['priority'] = ((!is_null($poll_interval)) ? intval($poll_interval) : 3); $hub_update = false; if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 day")) { diff --git a/view/theme/vier/theme.php b/view/theme/vier/theme.php index a8654f743b..0f81200890 100644 --- a/view/theme/vier/theme.php +++ b/view/theme/vier/theme.php @@ -110,13 +110,13 @@ EOT; function get_vier_config($key, $default = false, $admin = false) { if (local_user() && !$admin) { $result = PConfig::get(local_user(), "vier", $key); - if ($result !== false) { + if (!is_null($result)) { return $result; } } $result = Config::get("vier", $key); - if ($result !== false) { + if (!is_null($result)) { return $result; } From 3e5a518591fb73b28bf5f8e0fac44e8440ae3c40 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Wed, 6 Dec 2017 15:18:45 -0500 Subject: [PATCH 2/3] Undo changes to Feature the evaluations were correct before. --- src/Content/Feature.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Content/Feature.php b/src/Content/Feature.php index f17b649eef..c98a53c544 100644 --- a/src/Content/Feature.php +++ b/src/Content/Feature.php @@ -23,15 +23,15 @@ class Feature { $x = Config::get('feature_lock', $feature, false); - if (is_null($x)) { + if ($x === false) { $x = PConfig::get($uid, 'feature', $feature, false); } - if (is_null($x)) { + if ($x === false) { $x = Config::get('feature', $feature, false); } - if (is_null($x)) { + if ($x === false) { $x = self::getDefault($feature); } From 71911a69898a9b42192406ff4b8c2b58f07b2e1a Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Wed, 6 Dec 2017 15:25:36 -0500 Subject: [PATCH 3/3] Use default value use the default value parameter correctly! --- include/network.php | 10 ++++------ src/Worker/OnePoll.php | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/network.php b/include/network.php index 06649554b0..45f5d4e79a 100644 --- a/include/network.php +++ b/include/network.php @@ -126,9 +126,8 @@ function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = array()) if (x($opts, 'timeout')) { @curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']); } else { - // if Config::get returns null, intval will be 0 which will also evaluate to false - $curl_time = intval(Config::get('system', 'curl_timeout')); - @curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60)); + $curl_time = Config::get('system', 'curl_timeout', 60); + @curl_setopt($ch, CURLOPT_TIMEOUT, intval($curl_time)); } // by default we will allow self-signed certs @@ -303,9 +302,8 @@ function post_url($url, $params, $headers = null, &$redirects = 0, $timeout = 0) if (intval($timeout)) { curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); } else { - // if Config::get returns null, intval will be 0 which will also evaluate to false - $curl_time = intval(Config::get('system', 'curl_timeout')); - curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60)); + $curl_time = Config::get('system', 'curl_timeout', 60); + curl_setopt($ch, CURLOPT_TIMEOUT, intval($curl_time)); } if (defined('LIGHTTPD')) { diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index c3528b623e..1190c77f5f 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -91,8 +91,8 @@ Class OnePoll $t = $contact['last-update']; if ($contact['subhub']) { - $poll_interval = Config::get('system', 'pushpoll_frequency'); - $contact['priority'] = ((!is_null($poll_interval)) ? intval($poll_interval) : 3); + $poll_interval = Config::get('system', 'pushpoll_frequency', 3); + $contact['priority'] = intval($poll_interval); $hub_update = false; if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 day")) {