PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 4.5.11
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v4.5.11
4.7.2 4.7.1 trunk 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 3.0.0 3.0.1 3.1.0 3.10.0 3.10.1 3.11.1 3.11.2 3.11.3 3.2.0 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.5 3.6.6 3.7.0 3.7.1 3.8.0 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.2.0 4.2.1 4.2.10 4.2.11 4.2.12 4.2.13 4.2.14 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.3.10 4.3.11 4.3.12 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.7.1 4.3.8 4.3.9 4.3.9.1 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.10 4.5.11 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 4.5.9 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.7.0
cookiebot / src / settings / pages / Dashboard_Page.php
cookiebot / src / settings / pages Last commit date
Additional_Page.php 1 year ago Dashboard_Page.php 11 months ago Embeddings_Page.php 1 year ago Gcm_Page.php 1 year ago General_Page.php 11 months ago Gtm_Page.php 1 year ago Iab_Page.php 1 year ago Multiple_Page.php 1 year ago Settings_Page.php 1 year ago Settings_Page_Interface.php 1 year ago Support_Page.php 1 year ago
Dashboard_Page.php
288 lines
1 <?php
2
3 namespace cybot\cookiebot\settings\pages;
4
5 use cybot\cookiebot\lib\Cookiebot_Frame;
6 use cybot\cookiebot\lib\Cookiebot_WP;
7 use InvalidArgumentException;
8 use function cybot\cookiebot\lib\include_view;
9
10 // Import WordPress functions from global namespace
11 use function \add_menu_page;
12 use function \add_submenu_page;
13 use function \do_action;
14 use function \wp_enqueue_style;
15 use function \wp_enqueue_script;
16 use function \wp_localize_script;
17 use function \admin_url;
18 use function \wp_create_nonce;
19 use function \__;
20 use function \defined;
21 use function \constant;
22 use function cybot\cookiebot\lib\asset_url;
23
24 // Add constant for WP_DEBUG
25 if ( ! defined( 'WP_DEBUG' ) ) {
26 define( 'WP_DEBUG', false );
27 }
28
29 class Dashboard_Page implements Settings_Page_Interface {
30
31
32 const ICON = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAiIGhlaWdodD0iNDAiIHZpZXdCb3g9IjAgMCA0MCA0MCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGcgY2xpcC1wYXRoPSJ1cmwoI2NsaXAwXzY0ODFfMzE4MTUpIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik01Ljg2MTYgNS44MDUyVjE5LjgxMTRDNS44NjE2IDI3LjUzNjMgMTIuMjAzOSAzMy44MTc2IDIwLjAwMzkgMzMuODE3NkMyNy44MDM4IDMzLjgxNzYgMzQuMTQ2MiAyNy41MzYzIDM0LjE0NjIgMTkuODExNFY1LjgwNTJINS44NjE2Wk0yMCAzOS42MjI4QzguOTc2MzggMzkuNjIwNyAwIDMwLjczNzEgMCAxOS44MTE0VjBINDBWMTkuODExNEM0MCAzMC43Mjk0IDMxLjAzMTQgMzkuNjIwNyAyMCAzOS42MjI4Wk0yMi42ODk0IDI2Ljk0ODZMMjIuNjg4OCAyNi45NDk5SDE1LjkyTDE1LjkzMTIgMjYuOTI2Nkw5Ljk4OTIxIDE2LjU4MjFIMTYuNzY1N0wxOS4wMTA2IDIwLjQ5MDJMMjMuNzEyMiAxMC42NjMxSDMwLjQ4ODhMMjIuNzAzNSAyNi45MTkyTDIyLjcyMDQgMjYuOTQ4NkgyMi42ODk0WiIgZmlsbD0iYmxhY2siLz4KPC9nPgo8ZGVmcz4KPGNsaXBQYXRoIGlkPSJjbGlwMF82NDgxXzMxODE1Ij4KPHJlY3Qgd2lkdGg9IjQwIiBoZWlnaHQ9IjQwIiBmaWxsPSJ3aGl0ZSIvPgo8L2NsaXBQYXRoPgo8L2RlZnM+Cjwvc3ZnPgo=';
33
34 const ADMIN_SLUG = 'cookiebot';
35
36 public function menu() {
37 add_menu_page(
38 'Cookiebot',
39 __( 'Cookiebot', 'cookiebot' ),
40 'manage_options',
41 self::ADMIN_SLUG,
42 array( $this, 'display' ),
43 self::ICON
44 );
45
46 if ( Cookiebot_Frame::is_cb_frame_type() !== 'empty' ) {
47 add_submenu_page(
48 'cookiebot',
49 __( 'Cookiebot Dashboard', 'cookiebot' ),
50 __( 'Dashboard', 'cookiebot' ),
51 'manage_options',
52 self::ADMIN_SLUG,
53 array( $this, 'display' ),
54 1
55 );
56 }
57 }
58
59 /**
60 * @throws InvalidArgumentException
61 */
62 public function display() {
63 // Get all necessary data upfront
64 $cbid = Cookiebot_WP::get_cbid();
65 $auth_token = Cookiebot_WP::get_auth_token();
66 $user_data = Cookiebot_WP::get_user_data();
67 $scan_status = Cookiebot_WP::get_scan_status();
68 $scan_id = get_option( 'cookiebot-scan-id' );
69 $banner_enabled = Cookiebot_WP::get_banner_enabled();
70 $auto_blocking_mode = Cookiebot_WP::get_auto_blocking_mode();
71 $gcm_enabled = Cookiebot_WP::get_gcm_enabled();
72 $subscription = Cookiebot_WP::get_subscription_type();
73 $legal_framework = Cookiebot_WP::get_legal_framwework();
74 $is_authenticated = ! empty( Cookiebot_WP::get_auth_token() );
75 $is_cb_user = Cookiebot_Frame::is_cb_frame_type();
76
77 // Get user data and check if they were onboarded via signup
78 $was_onboarded = Cookiebot_WP::was_onboarded_via_signup();
79 $user_email = isset( $user_data['email'] ) ? $user_data['email'] : '';
80
81 // Prepare variables for the template
82 $template_args = array(
83 'cbid' => $cbid,
84 'user_data' => $user_data,
85 'scan_status' => $scan_status,
86 'scan_id' => $scan_id,
87 'cb_wp' => asset_url( 'img/cb-wp.png' ),
88 'europe_icon' => asset_url( 'img/europe.png' ),
89 'usa_icon' => asset_url( 'img/usa.png' ),
90 'check_icon' => asset_url( 'img/icons/check.svg' ),
91 'link_icon' => asset_url( 'img/icons/link.svg' ),
92 'banner_enabled' => $banner_enabled,
93 'auto_blocking_mode' => $auto_blocking_mode,
94 'gcm_enabled' => $gcm_enabled,
95 'preview_link' => Cookiebot_WP::get_preview_link(),
96 'subscription' => $subscription,
97 'legal_framework' => $legal_framework,
98 'customize_banner_link' => 'https://admin.usercentrics.eu/#/v3/appearance/layout?settingsId=' . $cbid,
99 'cookiebot_admin_link' => 'https://admin.cookiebot.com',
100 'uc_admin_link' => 'https://admin.usercentrics.eu',
101 'configure_banner_link' => 'https://support.usercentrics.com/hc/en-us/articles/18225055002908-WordPress-Plugin-FAQ',
102 'has_user_data' => ! empty( $user_data ),
103 'has_cbid' => ! empty( $cbid ),
104 'is_authenticated' => ! empty( Cookiebot_WP::get_auth_token() ),
105 'was_onboarded' => $was_onboarded,
106 'user_email' => $user_email,
107 );
108
109 wp_enqueue_script(
110 'cookiebot-amplitude-js',
111 asset_url( 'js/backend/amplitude.js' ),
112 array( 'jquery' ),
113 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION,
114 true
115 );
116
117 wp_localize_script(
118 'cookiebot-amplitude-js',
119 'cookiebot_amplitude',
120 array()
121 );
122
123 if ( ! $is_authenticated && ! empty( $cbid ) && ! empty( $user_data ) && ! empty( $was_onboarded ) ) {
124 wp_enqueue_style(
125 'cookiebot-dashboard-css',
126 asset_url( 'css/backend/dashboard.css' ),
127 array(),
128 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION
129 );
130
131 wp_enqueue_script(
132 'cookiebot-account-static-js',
133 asset_url( 'js/backend/account-static.js' ),
134 array( 'jquery' ),
135 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION,
136 true
137 );
138
139 wp_localize_script(
140 'cookiebot-account-static-js',
141 'cookiebot_account',
142 array(
143 'ajax_url' => admin_url( 'admin-ajax.php' ),
144 'nonce' => wp_create_nonce( 'cookiebot-account' ),
145 'cbid' => $cbid,
146 'scan_id' => $scan_id,
147 'has_user_data' => ! empty( $user_data ),
148 'has_cbid' => ! empty( $cbid ),
149 'was_onboarded' => $was_onboarded,
150 'debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
151 'auth_expired_flow' => true,
152 )
153 );
154
155 require_once CYBOT_COOKIEBOT_PLUGIN_DIR . 'src/view/admin/common/dashboard-page-session-expired.php';
156 return;
157 }
158
159 // Check if the trial has expired
160 if ( Cookiebot_WP::is_trial_expired() && ! Cookiebot_WP::has_upgraded() ) {
161 wp_enqueue_style(
162 'cookiebot-dashboard-css',
163 asset_url( 'css/backend/dashboard.css' ),
164 array(),
165 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION
166 );
167
168 wp_enqueue_script(
169 'cookiebot-account-js',
170 asset_url( 'js/backend/account.js' ),
171 array( 'jquery' ),
172 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION,
173 true
174 );
175
176 wp_localize_script(
177 'cookiebot-account-js',
178 'cookiebot_account',
179 array(
180 'ajax_url' => admin_url( 'admin-ajax.php' ),
181 'nonce' => wp_create_nonce( 'cookiebot-account' ),
182 'cbid' => $cbid,
183 'scan_id' => $scan_id,
184 'has_user_data' => ! empty( $user_data ),
185 'has_cbid' => ! empty( $cbid ),
186 'was_onboarded' => $was_onboarded,
187 'debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
188 )
189 );
190
191 require_once CYBOT_COOKIEBOT_PLUGIN_DIR . 'src/view/admin/common/dashboard-trial-expired.php';
192 return;
193 }
194
195 // Redirect CB users to previous dashboard page
196 if ( ( ! empty( $cbid ) && $is_cb_user ) || ( ! empty( $cbid ) && empty( $user_data ) ) ) {
197 wp_enqueue_style(
198 'cookiebot-dashboard-backup-css',
199 asset_url( 'css/backend/dashboard-old.css' ),
200 array(),
201 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION
202 );
203
204 wp_enqueue_script(
205 'cookiebot-account-js',
206 asset_url( 'js/backend/account.js' ),
207 array( 'jquery' ),
208 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION,
209 true
210 );
211
212 wp_localize_script(
213 'cookiebot-account-js',
214 'cookiebot_account',
215 array(
216 'ajax_url' => admin_url( 'admin-ajax.php' ),
217 'nonce' => wp_create_nonce( 'cookiebot-account' ),
218 'cbid' => $cbid,
219 'scan_id' => $scan_id,
220 'has_user_data' => ! empty( $user_data ),
221 'has_cbid' => ! empty( $cbid ),
222 'was_onboarded' => $was_onboarded,
223 'debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
224 )
225 );
226
227 require_once CYBOT_COOKIEBOT_PLUGIN_DIR . 'src/view/admin/common/dashboard-page-old.php';
228 return;
229 }
230
231 wp_enqueue_style(
232 'cookiebot-dashboard-css',
233 asset_url( 'css/backend/dashboard.css' ),
234 array(),
235 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION
236 );
237
238 wp_enqueue_script(
239 'cookiebot-dashboard-js',
240 asset_url( 'js/backend/dashboard.js' ),
241 array( 'jquery' ),
242 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION,
243 true
244 );
245
246 wp_localize_script(
247 'cookiebot-dashboard-js',
248 'cookiebot_dashboard',
249 array(
250 'cbid' => $cbid,
251 'user_data' => $user_data,
252 )
253 );
254
255 wp_enqueue_script(
256 'cookiebot-account-js',
257 asset_url( 'js/backend/account.js' ),
258 array( 'jquery' ),
259 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION,
260 true
261 );
262
263 wp_localize_script(
264 'cookiebot-account-js',
265 'cookiebot_account',
266 array(
267 'ajax_url' => admin_url( 'admin-ajax.php' ),
268 'nonce' => wp_create_nonce( 'cookiebot-account' ),
269 'cbid' => $cbid,
270 'scan_id' => $scan_id,
271 'has_user_data' => ! empty( $user_data ),
272 'has_cbid' => ! empty( $cbid ),
273 'was_onboarded' => $was_onboarded,
274 'is_authenticated' => ! empty( Cookiebot_WP::get_auth_token() ),
275 'messages' => array(
276 'success_create' => __( 'Account created successfully!', 'cookiebot' ),
277 'error_create' => __( 'Failed to create account.', 'cookiebot' ),
278 'success_verify' => __( 'CBID verified successfully!', 'cookiebot' ),
279 'error_verify' => __( 'Invalid CBID.', 'cookiebot' ),
280 ),
281 'debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
282 )
283 );
284
285 require_once CYBOT_COOKIEBOT_PLUGIN_DIR . 'src/view/admin/common/dashboard-page.php';
286 }
287 }
288