Dashboard_Page.php
3 years ago
Debug_Page.php
3 years ago
Gtm_Page.php
3 years ago
Iab_Page.php
4 years ago
Legislations_Page.php
4 years ago
Multiple_Page.php
3 years ago
Settings_Page.php
3 years ago
Settings_Page_Interface.php
3 years ago
Support_Page.php
3 years ago
Debug_Page.php
169 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_Javascript_Helper; |
| 9 | use cybot\cookiebot\lib\Settings_Service_Interface; |
| 10 | use cybot\cookiebot\lib\Cookiebot_WP; |
| 11 | use cybot\cookiebot\shortcode\Cookiebot_Declaration_Shortcode; |
| 12 | use InvalidArgumentException; |
| 13 | use RuntimeException; |
| 14 | use function cybot\cookiebot\lib\asset_url; |
| 15 | use function cybot\cookiebot\lib\include_view; |
| 16 | use Exception; |
| 17 | |
| 18 | class Debug_Page implements Settings_Page_Interface { |
| 19 | |
| 20 | const ADMIN_SLUG = 'cookiebot_debug'; |
| 21 | |
| 22 | public function menu() { |
| 23 | add_submenu_page( |
| 24 | 'cookiebot', |
| 25 | __( 'Debug info', 'cookiebot' ), |
| 26 | __( 'Debug info', 'cookiebot' ), |
| 27 | 'manage_options', |
| 28 | self::ADMIN_SLUG, |
| 29 | array( $this, 'display' ), |
| 30 | 25 |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * @throws InvalidArgumentException |
| 36 | */ |
| 37 | public function display() { |
| 38 | wp_enqueue_script( |
| 39 | 'cookiebot-debug-page-js', |
| 40 | asset_url( 'js/backend/debug-page.js' ), |
| 41 | null, |
| 42 | Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION, |
| 43 | true |
| 44 | ); |
| 45 | |
| 46 | $style_sheets = [ |
| 47 | [ 'cookiebot-debug-css' , 'css/backend/debug_info.css' ] |
| 48 | ]; |
| 49 | |
| 50 | foreach ($style_sheets as $style ){ |
| 51 | wp_enqueue_style( |
| 52 | $style[0], |
| 53 | asset_url($style[1]), |
| 54 | null, |
| 55 | Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION |
| 56 | ); |
| 57 | } |
| 58 | |
| 59 | $debug_output = $this->prepare_debug_data(); |
| 60 | |
| 61 | include_view( 'admin/settings/debug-page.php', array( 'debug_output' => $debug_output ) ); |
| 62 | } |
| 63 | |
| 64 | private function get_ignored_scripts() { |
| 65 | $ignored_scripts = get_option( 'cookiebot-ignore-scripts' ); |
| 66 | |
| 67 | $ignored_scripts = array_map( |
| 68 | function( $ignore_tag ) { |
| 69 | return trim( $ignore_tag ); |
| 70 | }, |
| 71 | explode( PHP_EOL, $ignored_scripts ) |
| 72 | ); |
| 73 | |
| 74 | $ignored_scripts = apply_filters( 'cybot_cookiebot_ignore_scripts', $ignored_scripts ); |
| 75 | |
| 76 | return implode( ', ', $ignored_scripts ); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * @throws InvalidArgumentException |
| 81 | */ |
| 82 | private function prepare_debug_data() { |
| 83 | global $wpdb; |
| 84 | |
| 85 | $cookiebot_javascript_helper = new Cookiebot_Javascript_Helper(); |
| 86 | $consent_api_helper = new Consent_API_Helper(); |
| 87 | |
| 88 | if ( ! function_exists( 'get_plugins' ) ) { |
| 89 | include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 90 | } |
| 91 | |
| 92 | $plugins = get_plugins(); |
| 93 | $active_plugins = get_option( 'active_plugins' ); |
| 94 | |
| 95 | $debug_output = ''; |
| 96 | // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date |
| 97 | $debug_output .= '##### Debug Information for ' . get_site_url() . ' generated at ' . date( 'c' ) . " #####\n\n"; |
| 98 | $debug_output .= 'WordPress Version: ' . get_bloginfo( 'version' ) . "\n"; |
| 99 | $debug_output .= 'WordPress Language: ' . get_bloginfo( 'language' ) . "\n"; |
| 100 | $debug_output .= 'PHP Version: ' . phpversion() . "\n"; |
| 101 | $debug_output .= 'MySQL Version: ' . $wpdb->db_version() . "\n"; |
| 102 | $debug_output .= "\n--- Cookiebot Information ---\n"; |
| 103 | $debug_output .= 'Plugin Version: ' . Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION . "\n"; |
| 104 | $debug_output .= 'Cookiebot ID: ' . Cookiebot_WP::get_cbid() . "\n"; |
| 105 | $debug_output .= 'Blocking mode: ' . get_option( 'cookiebot-cookie-blocking-mode' ) . "\n"; |
| 106 | $debug_output .= 'Language: ' . get_option( 'cookiebot-language' ) . "\n"; |
| 107 | $debug_output .= 'IAB: ' . ( get_option( 'cookiebot-iab' ) === '1' ? 'Enabled' : 'Not enabled' ) . "\n"; |
| 108 | $debug_output .= 'CCPA banner for visitors from California: ' . ( get_option( 'cookiebot-ccpa' ) === '1' ? 'Enabled' : 'Not enabled' ) . "\n"; |
| 109 | $debug_output .= 'CCPA domain group id: ' . get_option( 'cookiebot-ccpa-domain-group-id' ) . "\n"; |
| 110 | $debug_output .= 'Add async/defer to banner tag: ' . ( get_option( 'cookiebot-script-tag-uc-attribute' ) !== '' ? get_option( 'cookiebot-script-tag-uc-attribute' ) : 'None' ) . "\n"; |
| 111 | $debug_output .= 'Add async/defer to declaration tag: ' . ( get_option( 'cookiebot-script-tag-cd-attribute' ) !== '' ? get_option( 'cookiebot-script-tag-cd-attribute' ) : 'None' ) . "\n"; |
| 112 | $debug_output .= 'Auto update: ' . ( get_option( 'cookiebot-autoupdate' ) === '1' ? 'Enabled' : 'Not enabled' ) . "\n"; |
| 113 | $debug_output .= 'Hide Cookie Popup: ' . ( get_option( 'cookiebot-nooutput' ) === '1' ? 'Yes' : 'No' ) . "\n"; |
| 114 | $debug_output .= 'Disable Cookiebot in WP Admin: ' . ( get_option( 'cookiebot-nooutput-admin' ) === '1' ? 'Yes' : 'No' ) . "\n"; |
| 115 | $debug_output .= 'Enable Cookiebot on front end while logged in: ' . ( get_option( 'cookiebot-output-logged-in' ) === '1' ? 'Yes' : 'No' ) . "\n"; |
| 116 | $debug_output .= 'List of ignored javascript files: ' . $this->get_ignored_scripts() . "\n"; |
| 117 | $debug_output .= 'Banner tag: ' . $cookiebot_javascript_helper->include_cookiebot_js( true ) . "\n"; |
| 118 | $debug_output .= 'Declaration tag: ' . Cookiebot_Declaration_Shortcode::show_declaration() . "\n"; |
| 119 | |
| 120 | if ( get_option( 'cookiebot-gtm' ) !== false ) { |
| 121 | $debug_output .= 'GTM tag: ' . $cookiebot_javascript_helper->include_google_tag_manager_js( true ) . "\n"; |
| 122 | } |
| 123 | |
| 124 | if ( get_option( 'cookiebot-gcm' ) !== false ) { |
| 125 | $debug_output .= 'GCM tag: ' . $cookiebot_javascript_helper->include_google_consent_mode_js( true ) . "\n"; |
| 126 | } |
| 127 | |
| 128 | if ( $consent_api_helper->is_wp_consent_api_active() ) { |
| 129 | $debug_output .= "\n--- WP Consent Level API Mapping ---\n"; |
| 130 | $debug_output .= 'F = Functional, N = Necessary, P = Preferences, M = Marketing, S = Statistics, SA = Statistics Anonymous' . "\n"; |
| 131 | $m = $consent_api_helper->get_wp_consent_api_mapping(); |
| 132 | foreach ( $m as $k => $v ) { |
| 133 | $debug_output .= strtoupper( str_replace( ';', ', ', $k ) ) . ' => '; |
| 134 | $debug_output .= 'F=1, '; |
| 135 | $debug_output .= 'P=' . $v['preferences'] . ', '; |
| 136 | $debug_output .= 'M=' . $v['marketing'] . ', '; |
| 137 | $debug_output .= 'S=' . $v['statistics'] . ', '; |
| 138 | $debug_output .= 'SA=' . $v['statistics-anonymous'] . "\n"; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | try { |
| 143 | $cookiebot_addons = new Cookiebot_Addons(); |
| 144 | /** @var Settings_Service_Interface $settings_service */ |
| 145 | $settings_service = $cookiebot_addons->container->get( 'Settings_Service_Interface' ); |
| 146 | $addons = $settings_service->get_active_addons(); |
| 147 | $debug_output .= "\n--- Activated Cookiebot Addons ---\n"; |
| 148 | /** @var Base_Cookiebot_Addon $addon */ |
| 149 | foreach ( $addons as $addon ) { |
| 150 | $debug_output .= $addon::ADDON_NAME . ' (' . implode( ', ', $addon->get_cookie_types() ) . ")\n"; |
| 151 | } |
| 152 | } catch ( Exception $exception ) { |
| 153 | $debug_output .= PHP_EOL . '--- Cookiebot Addons could not be activated ---' . PHP_EOL; |
| 154 | $debug_output .= $exception->getMessage() . PHP_EOL; |
| 155 | } |
| 156 | |
| 157 | $debug_output .= "\n--- Activated Plugins ---\n"; |
| 158 | foreach ( $active_plugins as $p ) { |
| 159 | if ( $p !== 'cookiebot/cookiebot.php' ) { |
| 160 | $debug_output .= $plugins[ $p ]['Name'] . ' (Version: ' . $plugins[ $p ]['Version'] . ")\n"; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | $debug_output .= "\n##### Debug Information END #####"; |
| 165 | |
| 166 | return $debug_output; |
| 167 | } |
| 168 | } |
| 169 |