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