From 501bc5212c8e89465f5f1fd77a1008fb19132ab8 Mon Sep 17 00:00:00 2001 From: svfcode Date: Wed, 12 Mar 2025 16:21:57 +0300 Subject: [PATCH 1/3] Upd. Settings. Using level for banners from cloud. --- cleantalk.php | 14 ++++++++++++++ lib/Cleantalk/ApbctWP/AdminNotices.php | 6 +++--- lib/Cleantalk/Common/API.php | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/cleantalk.php b/cleantalk.php index 3c9b56642..367c0a297 100644 --- a/cleantalk.php +++ b/cleantalk.php @@ -2713,6 +2713,20 @@ function ct_account_status_check($api_key = null, $process_errors = true) $apbct->data['notice_trial'] = TT::getArrayValueAsInt($result, 'trial', 0); $apbct->data['notice_review'] = TT::getArrayValueAsInt($result, 'show_review', 0); + $notice_banners = API::getNoticeBanners($api_key); + + if (isset($notice_banners['operation_status'], $notice_banners['banners']) && $notice_banners['operation_status'] === 'SUCCESS') { + if (isset($notice_banners['banners']['TRIAL'], $notice_banners['banners']['TRIAL']['level'])) { + $apbct->data['notice_trial_level'] = strtolower($notice_banners['banners']['TRIAL']['level']); + } + if (isset($notice_banners['banners']['RENEW'], $notice_banners['banners']['RENEW']['level'])) { + $apbct->data['notice_renew_level'] = strtolower($notice_banners['banners']['RENEW']['level']); + } + if (isset($notice_banners['banners']['REVIEW'], $notice_banners['banners']['REVIEW']['level'])) { + $apbct->data['notice_review_level'] = strtolower($notice_banners['banners']['REVIEW']['level']); + } + } + // Other $apbct->data['service_id'] = TT::getArrayValueAsInt($result, 'service_id', 0); $apbct->data['user_id'] = TT::getArrayValueAsInt($result, 'user_id', 0); diff --git a/lib/Cleantalk/ApbctWP/AdminNotices.php b/lib/Cleantalk/ApbctWP/AdminNotices.php index 4c01c7e44..3c60bb247 100644 --- a/lib/Cleantalk/ApbctWP/AdminNotices.php +++ b/lib/Cleantalk/ApbctWP/AdminNotices.php @@ -210,7 +210,7 @@ public function notice_trial() // phpcs:ignore PSR1.Methods.CamelCapsMethodName. $this->apbct->data['wl_brandname'] ); - $banner_data->level = 'error'; + $banner_data->level = isset($this->apbct->data['notice_trial_level']) ? $this->apbct->data['notice_trial_level'] : 'error'; $banner_data->is_dismissible = ! $this->is_cleantalk_page; $banner = new ApbctUniversalBanner($banner_data); @@ -245,7 +245,7 @@ public function notice_renew() // phpcs:ignore PSR1.Methods.CamelCapsMethodName. $this->apbct->data['wl_brandname'] ); - $banner_data->level = 'error'; + $banner_data->level = isset($this->apbct->data['notice_renew_level']) ? $this->apbct->data['notice_renew_level'] : 'error'; $banner_data->is_dismissible = ! $this->is_cleantalk_page; $banner = new ApbctUniversalBanner($banner_data); @@ -285,7 +285,7 @@ public function notice_review() // phpcs:ignore PSR1.Methods.CamelCapsMethodName . ''; $banner_data->additional_text = $support_link . '  ' . $close_link; - $banner_data->level = 'success'; + $banner_data->level = isset($this->apbct->data['notice_review_level']) ? $this->apbct->data['notice_review_level'] : 'success'; $banner = new ApbctUniversalBanner($banner_data); $banner->echoBannerBody(); diff --git a/lib/Cleantalk/Common/API.php b/lib/Cleantalk/Common/API.php index 2b74d2751..ee3ae7a25 100644 --- a/lib/Cleantalk/Common/API.php +++ b/lib/Cleantalk/Common/API.php @@ -168,6 +168,24 @@ public static function methodNoticePaidTill( return static::sendRequest($request); } + /** + * Wrapper for notice_banners API method. + * Gets notice banners. + * + * @param string $api_key + * + * @return array|bool|mixed + */ + public static function getNoticeBanners($api_key) + { + $request = array( + 'method_name' => 'notice_banners', + 'auth_key' => $api_key, + ); + + return static::sendRequest($request); + } + /** * Wrapper for ip_info API method. * Gets IP country. From 82b35376f71329ac3841f14734c28a5d5def5d63 Mon Sep 17 00:00:00 2001 From: svfcode Date: Thu, 13 Mar 2025 08:34:12 +0300 Subject: [PATCH 2/3] fix psalm --- cleantalk.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cleantalk.php b/cleantalk.php index 367c0a297..1f5021453 100644 --- a/cleantalk.php +++ b/cleantalk.php @@ -2716,13 +2716,13 @@ function ct_account_status_check($api_key = null, $process_errors = true) $notice_banners = API::getNoticeBanners($api_key); if (isset($notice_banners['operation_status'], $notice_banners['banners']) && $notice_banners['operation_status'] === 'SUCCESS') { - if (isset($notice_banners['banners']['TRIAL'], $notice_banners['banners']['TRIAL']['level'])) { + if (isset($notice_banners['banners']['TRIAL']['level'])) { $apbct->data['notice_trial_level'] = strtolower($notice_banners['banners']['TRIAL']['level']); } - if (isset($notice_banners['banners']['RENEW'], $notice_banners['banners']['RENEW']['level'])) { + if (isset($notice_banners['banners']['RENEW']['level'])) { $apbct->data['notice_renew_level'] = strtolower($notice_banners['banners']['RENEW']['level']); } - if (isset($notice_banners['banners']['REVIEW'], $notice_banners['banners']['REVIEW']['level'])) { + if (isset($notice_banners['banners']['REVIEW']['level'])) { $apbct->data['notice_review_level'] = strtolower($notice_banners['banners']['REVIEW']['level']); } } From 89845e9f885f82b3fdb90e43ac85379c509b2560 Mon Sep 17 00:00:00 2001 From: svfcode Date: Mon, 17 Mar 2025 09:04:22 +0300 Subject: [PATCH 3/3] upd flow to make addition req only if show_notice is true --- cleantalk.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/cleantalk.php b/cleantalk.php index 1f5021453..b6b6ea7cd 100644 --- a/cleantalk.php +++ b/cleantalk.php @@ -2713,17 +2713,19 @@ function ct_account_status_check($api_key = null, $process_errors = true) $apbct->data['notice_trial'] = TT::getArrayValueAsInt($result, 'trial', 0); $apbct->data['notice_review'] = TT::getArrayValueAsInt($result, 'show_review', 0); - $notice_banners = API::getNoticeBanners($api_key); + if ($apbct->data['notice_show']) { + $notice_banners = API::getNoticeBanners($api_key); - if (isset($notice_banners['operation_status'], $notice_banners['banners']) && $notice_banners['operation_status'] === 'SUCCESS') { - if (isset($notice_banners['banners']['TRIAL']['level'])) { - $apbct->data['notice_trial_level'] = strtolower($notice_banners['banners']['TRIAL']['level']); - } - if (isset($notice_banners['banners']['RENEW']['level'])) { - $apbct->data['notice_renew_level'] = strtolower($notice_banners['banners']['RENEW']['level']); - } - if (isset($notice_banners['banners']['REVIEW']['level'])) { - $apbct->data['notice_review_level'] = strtolower($notice_banners['banners']['REVIEW']['level']); + if (isset($notice_banners['operation_status'], $notice_banners['banners']) && $notice_banners['operation_status'] === 'SUCCESS') { + if (isset($notice_banners['banners']['TRIAL']['level'])) { + $apbct->data['notice_trial_level'] = strtolower($notice_banners['banners']['TRIAL']['level']); + } + if (isset($notice_banners['banners']['RENEW']['level'])) { + $apbct->data['notice_renew_level'] = strtolower($notice_banners['banners']['RENEW']['level']); + } + if (isset($notice_banners['banners']['REVIEW']['level'])) { + $apbct->data['notice_review_level'] = strtolower($notice_banners['banners']['REVIEW']['level']); + } } }