From 6536db9cc85bd515318cb423b5a1f38d7a520e1f Mon Sep 17 00:00:00 2001 From: eug-L Date: Tue, 23 Jul 2024 15:57:07 +0800 Subject: [PATCH 1/2] fix undefined variable `$showPages` --- tawk_to/src/core/TawktoGenerator.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tawk_to/src/core/TawktoGenerator.php b/tawk_to/src/core/TawktoGenerator.php index 1f40be5..2d0dfde 100644 --- a/tawk_to/src/core/TawktoGenerator.php +++ b/tawk_to/src/core/TawktoGenerator.php @@ -92,7 +92,9 @@ private function shouldDisplayWidget($options = null) // prepare visibility $currentUrl = $base_url.$_SERVER["REQUEST_URI"]; if ($options->always_display == false) { - if (UrlPatternMatcher::match($currentUrl, $showPages)) { + $show_pages = json_decode($options->show_oncustom); + + if (UrlPatternMatcher::match($currentUrl, $show_pages)) { $show = true; } From 952654615ce44c000f171bf1d927d2a586722f8a Mon Sep 17 00:00:00 2001 From: eug-L Date: Tue, 23 Jul 2024 16:35:12 +0800 Subject: [PATCH 2/2] fix empty custom show/hide url excludes home route "/" --- tawk_to/src/core/TawktoGenerator.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tawk_to/src/core/TawktoGenerator.php b/tawk_to/src/core/TawktoGenerator.php index 2d0dfde..a9c2345 100644 --- a/tawk_to/src/core/TawktoGenerator.php +++ b/tawk_to/src/core/TawktoGenerator.php @@ -597,12 +597,18 @@ public function setOptions($options) switch ($column) { case 'hide_oncustom': case 'show_oncustom': - // replace newlines and returns with comma, and convert to array for saving + // split by newlines, then remove empty lines $value = urldecode($value); - $value = str_ireplace(["\r\n", "\r", "\n"], ',', $value); - $value = explode(",", $value); - $value = (empty($value) || !$value) ? array() : $value; - $jsonOpts[$column] = json_encode($value); + $value = str_ireplace("\r", "\n", $value); + $value = explode("\n", $value); + $non_empty_values = array(); + foreach ($value as $str) { + $trimmed = trim($str); + if ($trimmed !== '') { + $non_empty_values[] = $trimmed; + } + } + $jsonOpts[$column] = json_encode($non_empty_values); break; case 'show_onfrontpage':