PluginProbe
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 4.7.5
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v4.7.5
4.7.4 4.7.5 4.7.3 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 All 95 releases
cookiebot / src / settings / pages / Support_Page.php

Support_Page.php in Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode 4.7.5, at src/settings/pages/Support_Page.php

328 lines 11.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace cybot\cookiebot\settings\pages;
4
5 use cybot\cookiebot\addons\controller\addons\Base_Cookiebot_Addon;
6 use cybot\cookiebot\addons\Cookiebot_Addons;
7 use cybot\cookiebot\lib\Consent_API_Helper;
8 use cybot\cookiebot\lib\Cookiebot_Frame;
9 use cybot\cookiebot\lib\Cookiebot_Javascript_Helper;
10 use cybot\cookiebot\lib\Settings_Service_Interface;
11 use cybot\cookiebot\lib\Cookiebot_WP;
12 use cybot\cookiebot\shortcode\Cookiebot_Declaration_Shortcode;
13 use InvalidArgumentException;
14 use Exception;
15 use function cybot\cookiebot\lib\asset_url;
16 use function cybot\cookiebot\lib\include_view;
17
18 class Support_Page implements Settings_Page_Interface {
19
20
21 const ADMIN_SLUG = 'cookiebot_support';
22
23 public function menu() {
24 add_submenu_page(
25 'cookiebot',
26 __( 'Cookiebot Support', 'cookiebot' ),
27 __( 'Support', 'cookiebot' ),
28 'manage_options',
29 self::ADMIN_SLUG,
30 array( $this, 'display' ),
31 20
32 );
33 }
34
35 /**
36 * @throws InvalidArgumentException
37 */
38 public function display() {
39 $scripts = array(
40 array( 'cookiebot-support-page-js', 'js/backend/support-page.js' ),
41 );
42
43 foreach ( $scripts as $script ) {
44 wp_enqueue_script(
45 $script[0],
46 asset_url( $script[1] ),
47 null,
48 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION,
49 true
50 );
51 }
52
53 $style_sheets = array(
54 array( 'cookiebot-support-css', 'css/backend/support_page.css' ),
55 );
56
57 foreach ( $style_sheets as $style ) {
58 wp_enqueue_style(
59 $style[0],
60 asset_url( $style[1] ),
61 null,
62 Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION
63 );
64 }
65
66 $debug_output = $this->prepare_debug_data();
67 include_view( Cookiebot_Frame::get_view_path() . 'support-page.php', array( 'debug_output' => $debug_output ) );
68 }
69
70 private function get_ignored_scripts() {
71 $ignored_scripts = get_option( 'cookiebot-ignore-scripts' );
72
73 $ignored_scripts = array_map(
74 function ( $ignore_tag ) {
75 return trim( $ignore_tag );
76 },
77 explode( PHP_EOL, $ignored_scripts )
78 );
79
80 $ignored_scripts = apply_filters( 'cybot_cookiebot_ignore_scripts', $ignored_scripts );
81
82 return implode( ', ', $ignored_scripts );
83 }
84
85 /**
86 * @throws InvalidArgumentException
87 */
88 public function prepare_debug_data() {
89 global $wpdb;
90
91 $cookiebot_javascript_helper = new Cookiebot_Javascript_Helper();
92
93 $debug_output = '';
94 // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
95 $debug_output .= '##### Debug Information for ' . get_site_url() . ' generated at ' . date( 'c' ) . " #####\n\n";
96 $debug_output .= 'WordPress Version: ' . get_bloginfo( 'version' ) . "\n";
97 $debug_output .= 'WordPress Language: ' . get_bloginfo( 'language' ) . "\n";
98 $debug_output .= 'PHP Version: ' . phpversion() . "\n";
99 $debug_output .= 'MySQL Version: ' . $wpdb->db_version() . "\n";
100 $debug_output .= "\n--- Cookiebot Information ---\n";
101 $debug_output .= 'Plugin Version: ' . Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION . "\n";
102 $debug_output .= 'Settings ID: ' . Cookiebot_WP::get_cbid() . "\n";
103 $debug_output .= 'Blocking mode: ' . get_option( 'cookiebot-cookie-blocking-mode' ) . "\n";
104 if ( Cookiebot_Frame::is_cb_frame_type() !== false ) {
105 $debug_output .= 'Language: ' . get_option( 'cookiebot-language' ) . "\n";
106 $debug_output .= 'Frontend Language: ' . $this->print_option_enabled( 'cookiebot-front-language' ) . "\n";
107 }
108 $debug_output .= 'IAB: ' . $this->print_option_enabled( 'cookiebot-iab' ) . "\n";
109 if ( Cookiebot_Frame::is_cb_frame_type() !== false ) {
110 $debug_output .= 'TCF version: ' . $this->print_tcf_version() . "\n";
111 $debug_output .= 'TCF tag: ' . $cookiebot_javascript_helper->include_publisher_restrictions_js( true ) . "\n";
112 $debug_output .= 'Multiple banners: ' . $this->print_option_enabled( 'cookiebot-multiple-config' ) . "\n";
113 $debug_output .= $this->print_multiple_configuration_banners();
114 $debug_output .= 'Add async/defer to banner tag: ' . $this->print_option_if_not_empty( 'cookiebot-script-tag-uc-attribute' ) . "\n";
115 $debug_output .= 'Add async/defer to declaration tag: ' . $this->print_option_if_not_empty( 'cookiebot-script-tag-cd-attribute' ) . "\n";
116 }
117 $debug_output .= 'Auto update: ' . $this->print_option_enabled( 'cookiebot-autoupdate' ) . "\n";
118 $debug_output .= 'Show banner on site: ' . $this->print_option_active( 'cookiebot-banner-enabled' ) . "\n";
119 $debug_output .= 'Hide Cookie Popup: ' . $this->print_option_active( 'cookiebot-nooutput' ) . "\n";
120 $debug_output .= 'Enable Cookiebot on front end while logged in: ' . $this->print_option_active( 'cookiebot-output-logged-in' ) . "\n";
121 if ( Cookiebot_Frame::is_cb_frame_type() !== false ) {
122 $debug_output .= 'List of ignored javascript files: ' . $this->get_ignored_scripts() . "\n";
123 $debug_output .= 'Banner tag: ' . "\n" . $cookiebot_javascript_helper->include_cookiebot_js( true ) . "\n";
124 $debug_output .= 'Declaration tag: ' . Cookiebot_Declaration_Shortcode::show_declaration() . "\n";
125 } else {
126 $debug_output .= 'Banner tag: ' . "\n" . $cookiebot_javascript_helper->include_uc_cmp_js( true ) . "\n\n";
127 }
128
129 if ( get_option( 'cookiebot-gtm' ) !== false ) {
130 $debug_output .= 'GTM tag: ' . $cookiebot_javascript_helper->include_google_tag_manager_js( true ) . "\n";
131 }
132
133 if ( get_option( 'cookiebot-gcm' ) === '1' ) {
134 $debug_output .= 'GCM tag: ' . $cookiebot_javascript_helper->include_google_consent_mode_js( true ) . "\n";
135 }
136
137 if ( is_multisite() ) {
138 $debug_output .= $this->print_multisite_network_settings();
139 }
140
141 $debug_output .= $this->print_wp_consent_level_api_mapping();
142 $debug_output .= $this->print_activated_addons();
143 $debug_output .= $this->print_activated_plugins();
144
145 $debug_output .= "\n##### Debug Information END #####";
146
147 return $debug_output;
148 }
149
150 /**
151 * Print the value of the option if it's not empty.
152 *
153 * @param string $option_name Name of the option to print.
154 *
155 * @return string
156 */
157 private function print_option_if_not_empty( $option_name, $is_multisite = false ) {
158 $option_value = $is_multisite ? get_site_option( $option_name ) : get_option( $option_name );
159 return $option_value !== '' ? $option_value : 'None';
160 }
161
162 /**
163 * Print "Enabled" or "Not enabled" depending on the option value. Option value should be "1" or "0".
164 *
165 * @param string $option_name Name of the option to check.
166 * @param bool $is_multisite Is multisite option.
167 *
168 * @return string
169 */
170 private function print_option_enabled( $option_name, $is_multisite = false ) {
171 return $this->print_option_active( $option_name, $is_multisite, 'Enabled', 'Not enabled' );
172 }
173
174 /**
175 * Print "Yes" or "No" depending on the option value. Option value should be "1" or "0". If <b>$active_text</b> or
176 * <b>$disabled_text</b> is set, it will be used instead of default values "Yes" or "No".
177 *
178 * @param string $option_name Name of the option to check.
179 * @param bool $is_multisite Is multisite option.
180 * @param string $active_text (Optional) Text to print if option is active. Default is "Yes".
181 * @param string $disabled_text (Optional) Text to print if option is disabled. Default is "No".
182 *
183 * @return string
184 */
185 private function print_option_active( $option_name, $is_multisite = false, $active_text = 'Yes', $disabled_text = 'No' ) {
186 if ( $is_multisite ) {
187 return get_site_option( $option_name ) === '1' ? $active_text : $disabled_text;
188 }
189 return get_option( $option_name ) === '1' ? $active_text : $disabled_text;
190 }
191
192 /**
193 * Render debug information about WP Consent Level API mapping.
194 *
195 * @return string
196 */
197 private function print_wp_consent_level_api_mapping() {
198 $output = '';
199
200 $consent_api_helper = new Consent_API_Helper();
201
202 if ( $consent_api_helper->is_wp_consent_api_active() ) {
203 $output .= "\n--- WP Consent API Mapping ---\n";
204 $map = $consent_api_helper->get_wp_consent_api_mapping();
205 if ( Cookiebot_Frame::is_cb_frame_type() !== false ) {
206 $output .= 'F = Functional, N = Necessary, P = Preferences, M = Marketing, S = Statistics, SA = Statistics Anonymous' . "\n";
207 foreach ( $map as $key => $value ) {
208 $output .= strtoupper( str_replace( ';', ', ', $key ) ) . ' => ';
209 $output .= 'F=1, ';
210 $output .= 'P=' . $value['preferences'] . ', ';
211 $output .= 'M=' . $value['marketing'] . ', ';
212 $output .= 'S=' . $value['statistics'] . ', ';
213 $output .= 'SA=' . $value['statistics-anonymous'] . "\n";
214 }
215 } else {
216 foreach ( $map as $key => $value ) {
217 $output .= $key . ' => ' . $value . "\n";
218 }
219 }
220 }
221
222 return $output;
223 }
224
225 private function print_multiple_configuration_banners() {
226 $secondary_id = get_option( 'cookiebot-second-banner-id' );
227 $secondary_regions = get_option( 'cookiebot-second-banner-regions' );
228 $banners = get_option( 'cookiebot-multiple-banners' );
229 $output = '';
230
231 if ( ! empty( $banners ) ) {
232 $counter = 1;
233 $output .= "\n--- Multiple Configuration Banners ---\n";
234 if ( ! empty( $secondary_id ) ) {
235 $output .= '-Banner: ' . $counter . " -\n";
236 $output .= 'Id: ' . $secondary_id . " \n";
237 $output .= 'Regions: ' . $secondary_regions . " \n\n";
238 ++$counter;
239 }
240 foreach ( $banners as $banner ) {
241 $output .= '-Banner: ' . $counter . " -\n";
242 $output .= 'Id: ' . $banner['group'] . " \n";
243 $output .= 'Regions: ' . $banner['region'] . " \n\n";
244 ++$counter;
245 }
246 }
247
248 return $output;
249 }
250
251 private function print_tcf_version() {
252 $version = get_option( 'cookiebot-tcf-version' );
253 return ( empty( $version ) || $version === 'IAB' ) ? '2.0' : $version;
254 }
255
256 /**
257 * Print information about activated cookiebot addons.
258 *
259 * @return string
260 */
261 private function print_activated_addons() {
262 $output = '';
263
264 if ( Cookiebot_Frame::is_cb_frame_type() === false ) {
265 return $output;
266 }
267
268 try {
269 $cookiebot_addons = new Cookiebot_Addons();
270 /** @var Settings_Service_Interface $settings_service */
271 $settings_service = $cookiebot_addons->container->get( 'Settings_Service_Interface' );
272 $addons = $settings_service->get_active_addons();
273 $output .= "\n--- Activated Cookiebot Addons ---\n";
274 /** @var Base_Cookiebot_Addon $addon */
275 foreach ( $addons as $addon ) {
276 $output .= $addon::ADDON_NAME . ' (' . implode( ', ', $addon->get_cookie_types() ) . ")\n";
277 }
278 } catch ( Exception $exception ) {
279 $output .= PHP_EOL . '--- Cookiebot Addons could not be activated ---' . PHP_EOL;
280 $output .= $exception->getMessage() . PHP_EOL;
281 }
282
283 return $output;
284 }
285
286 /**
287 * Print information about activated plugins
288 *
289 * @return string
290 */
291 private function print_activated_plugins() {
292 if ( ! function_exists( 'get_plugins' ) ) {
293 include_once ABSPATH . 'wp-admin/includes/plugin.php';
294 }
295
296 $plugins = get_plugins();
297 $active_plugins = get_option( 'active_plugins' );
298
299 $output = "\n--- Activated Plugins ---\n";
300
301 foreach ( $active_plugins as $plugin_key ) {
302 if ( $plugin_key !== 'cookiebot/cookiebot.php' ) {
303 $output .= $plugins[ $plugin_key ]['Name'] . ' (Version: ' . $plugins[ $plugin_key ]['Version'] . ")\n";
304 }
305 }
306
307 return $output;
308 }
309
310 /**
311 * Print information about activated plugins
312 *
313 * @return string
314 */
315 private function print_multisite_network_settings() {
316 $output = "\n--- Cookiebot Multisite Information ---\n";
317 $output .= 'Cookiebot Network ID: ' . $this->print_option_if_not_empty( 'cookiebot-cbid', true ) . "\n";
318 $output .= 'Network Blocking mode: ' . get_site_option( 'cookiebot-cookie-blocking-mode' ) . "\n";
319 $output .= 'Network Add async/defer to banner tag: ' . $this->print_option_if_not_empty( 'cookiebot-script-tag-uc-attribute', true ) . "\n";
320 $output .= 'Network Add async/defer to declaration tag: ' . $this->print_option_if_not_empty( 'cookiebot-script-tag-cd-attribute', true ) . "\n";
321 $output .= 'Network Auto update: ' . $this->print_option_enabled( 'cookiebot-autoupdate', true ) . "\n";
322 $output .= 'Network Hide Cookie Popup: ' . $this->print_option_enabled( 'cookiebot-nooutput', true ) . "\n";
323 $output .= 'Network Disable Cookiebot in WP Admin: ' . $this->print_option_active( 'cookiebot-nooutput-admin', true ) . "\n";
324
325 return $output;
326 }
327 }
328