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
Dashboard_Page.php
287 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 | |
| 23 | // Add constant for WP_DEBUG |
| 24 | if ( ! defined( 'WP_DEBUG' ) ) { |
| 25 | define( 'WP_DEBUG', false ); |
| 26 | } |
| 27 | |
| 28 | class Dashboard_Page implements Settings_Page_Interface { |
| 29 | |
| 30 | |
| 31 | const ICON = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAiIGhlaWdodD0iNDAiIHZpZXdCb3g9IjAgMCA0MCA0MCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGcgY2xpcC1wYXRoPSJ1cmwoI2NsaXAwXzY0ODFfMzE4MTUpIj4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik01Ljg2MTYgNS44MDUyVjE5LjgxMTRDNS44NjE2IDI3LjUzNjMgMTIuMjAzOSAzMy44MTc2IDIwLjAwMzkgMzMuODE3NkMyNy44MDM4IDMzLjgxNzYgMzQuMTQ2MiAyNy41MzYzIDM0LjE0NjIgMTkuODExNFY1LjgwNTJINS44NjE2Wk0yMCAzOS42MjI4QzguOTc2MzggMzkuNjIwNyAwIDMwLjczNzEgMCAxOS44MTE0VjBINDBWMTkuODExNEM0MCAzMC43Mjk0IDMxLjAzMTQgMzkuNjIwNyAyMCAzOS42MjI4Wk0yMi42ODk0IDI2Ljk0ODZMMjIuNjg4OCAyNi45NDk5SDE1LjkyTDE1LjkzMTIgMjYuOTI2Nkw5Ljk4OTIxIDE2LjU4MjFIMTYuNzY1N0wxOS4wMTA2IDIwLjQ5MDJMMjMuNzEyMiAxMC42NjMxSDMwLjQ4ODhMMjIuNzAzNSAyNi45MTkyTDIyLjcyMDQgMjYuOTQ4NkgyMi42ODk0WiIgZmlsbD0iYmxhY2siLz4KPC9nPgo8ZGVmcz4KPGNsaXBQYXRoIGlkPSJjbGlwMF82NDgxXzMxODE1Ij4KPHJlY3Qgd2lkdGg9IjQwIiBoZWlnaHQ9IjQwIiBmaWxsPSJ3aGl0ZSIvPgo8L2NsaXBQYXRoPgo8L2RlZnM+Cjwvc3ZnPgo='; |
| 32 | |
| 33 | const ADMIN_SLUG = 'cookiebot'; |
| 34 | |
| 35 | public function menu() { |
| 36 | add_menu_page( |
| 37 | 'Cookiebot', |
| 38 | __( 'Cookiebot', 'cookiebot' ), |
| 39 | 'manage_options', |
| 40 | self::ADMIN_SLUG, |
| 41 | array( $this, 'display' ), |
| 42 | self::ICON |
| 43 | ); |
| 44 | |
| 45 | if ( Cookiebot_Frame::is_cb_frame_type() !== 'empty' ) { |
| 46 | add_submenu_page( |
| 47 | 'cookiebot', |
| 48 | __( 'Cookiebot Dashboard', 'cookiebot' ), |
| 49 | __( 'Dashboard', 'cookiebot' ), |
| 50 | 'manage_options', |
| 51 | self::ADMIN_SLUG, |
| 52 | array( $this, 'display' ), |
| 53 | 1 |
| 54 | ); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @throws InvalidArgumentException |
| 60 | */ |
| 61 | public function display() { |
| 62 | // Get all necessary data upfront |
| 63 | $cbid = Cookiebot_WP::get_cbid(); |
| 64 | $auth_token = Cookiebot_WP::get_auth_token(); |
| 65 | $user_data = Cookiebot_WP::get_user_data(); |
| 66 | $scan_status = Cookiebot_WP::get_scan_status(); |
| 67 | $scan_id = get_option( 'cookiebot-scan-id' ); |
| 68 | $banner_enabled = Cookiebot_WP::get_banner_enabled(); |
| 69 | $auto_blocking_mode = Cookiebot_WP::get_auto_blocking_mode(); |
| 70 | $gcm_enabled = Cookiebot_WP::get_gcm_enabled(); |
| 71 | $subscription = Cookiebot_WP::get_subscription_type(); |
| 72 | $legal_framework = Cookiebot_WP::get_legal_framwework(); |
| 73 | $is_authenticated = ! empty( Cookiebot_WP::get_auth_token() ); |
| 74 | $is_cb_user = Cookiebot_Frame::is_cb_frame_type(); |
| 75 | |
| 76 | // Get user data and check if they were onboarded via signup |
| 77 | $was_onboarded = Cookiebot_WP::was_onboarded_via_signup(); |
| 78 | $user_email = isset( $user_data['email'] ) ? $user_data['email'] : ''; |
| 79 | |
| 80 | // Prepare variables for the template |
| 81 | $template_args = array( |
| 82 | 'cbid' => $cbid, |
| 83 | 'user_data' => $user_data, |
| 84 | 'scan_status' => $scan_status, |
| 85 | 'scan_id' => $scan_id, |
| 86 | 'cb_wp' => CYBOT_COOKIEBOT_PLUGIN_URL . 'assets/img/cb-wp.png', |
| 87 | 'europe_icon' => CYBOT_COOKIEBOT_PLUGIN_URL . 'assets/img/europe.png', |
| 88 | 'usa_icon' => CYBOT_COOKIEBOT_PLUGIN_URL . 'assets/img/usa.png', |
| 89 | 'check_icon' => CYBOT_COOKIEBOT_PLUGIN_URL . 'assets/img/icons/check.svg', |
| 90 | 'link_icon' => CYBOT_COOKIEBOT_PLUGIN_URL . 'assets/img/icons/link.svg', |
| 91 | 'banner_enabled' => $banner_enabled, |
| 92 | 'auto_blocking_mode' => $auto_blocking_mode, |
| 93 | 'gcm_enabled' => $gcm_enabled, |
| 94 | 'preview_link' => Cookiebot_WP::get_preview_link(), |
| 95 | 'subscription' => $subscription, |
| 96 | 'legal_framework' => $legal_framework, |
| 97 | 'customize_banner_link' => 'https://admin.usercentrics.eu/#/v3/appearance/layout?settingsId=' . $cbid, |
| 98 | 'cookiebot_admin_link' => 'https://admin.cookiebot.com', |
| 99 | 'uc_admin_link' => 'https://admin.usercentrics.eu', |
| 100 | 'configure_banner_link' => 'https://support.usercentrics.com/hc/en-us/articles/18225055002908-WordPress-Plugin-FAQ', |
| 101 | 'has_user_data' => ! empty( $user_data ), |
| 102 | 'has_cbid' => ! empty( $cbid ), |
| 103 | 'is_authenticated' => ! empty( Cookiebot_WP::get_auth_token() ), |
| 104 | 'was_onboarded' => $was_onboarded, |
| 105 | 'user_email' => $user_email, |
| 106 | ); |
| 107 | |
| 108 | wp_enqueue_script( |
| 109 | 'cookiebot-amplitude-js', |
| 110 | CYBOT_COOKIEBOT_PLUGIN_URL . 'assets/js/backend/amplitude.js', |
| 111 | array( 'jquery' ), |
| 112 | Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION, |
| 113 | true |
| 114 | ); |
| 115 | |
| 116 | wp_localize_script( |
| 117 | 'cookiebot-amplitude-js', |
| 118 | 'cookiebot_amplitude', |
| 119 | array() |
| 120 | ); |
| 121 | |
| 122 | if ( ! $is_authenticated && ! empty( $cbid ) && ! empty( $user_data ) && ! empty( $was_onboarded ) ) { |
| 123 | wp_enqueue_style( |
| 124 | 'cookiebot-dashboard-css', |
| 125 | CYBOT_COOKIEBOT_PLUGIN_URL . 'assets/css/backend/dashboard.css', |
| 126 | array(), |
| 127 | Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION |
| 128 | ); |
| 129 | |
| 130 | wp_enqueue_script( |
| 131 | 'cookiebot-account-static-js', |
| 132 | CYBOT_COOKIEBOT_PLUGIN_URL . 'assets/js/backend/account-static.js', |
| 133 | array( 'jquery' ), |
| 134 | Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION, |
| 135 | true |
| 136 | ); |
| 137 | |
| 138 | wp_localize_script( |
| 139 | 'cookiebot-account-static-js', |
| 140 | 'cookiebot_account', |
| 141 | array( |
| 142 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 143 | 'nonce' => wp_create_nonce( 'cookiebot-account' ), |
| 144 | 'cbid' => $cbid, |
| 145 | 'scan_id' => $scan_id, |
| 146 | 'has_user_data' => ! empty( $user_data ), |
| 147 | 'has_cbid' => ! empty( $cbid ), |
| 148 | 'was_onboarded' => $was_onboarded, |
| 149 | 'debug' => defined( 'WP_DEBUG' ) && WP_DEBUG, |
| 150 | 'auth_expired_flow' => true, |
| 151 | ) |
| 152 | ); |
| 153 | |
| 154 | require_once CYBOT_COOKIEBOT_PLUGIN_DIR . 'src/view/admin/common/dashboard-page-session-expired.php'; |
| 155 | return; |
| 156 | } |
| 157 | |
| 158 | // Check if the trial has expired |
| 159 | if ( Cookiebot_WP::is_trial_expired() && ! Cookiebot_WP::has_upgraded() ) { |
| 160 | wp_enqueue_style( |
| 161 | 'cookiebot-dashboard-css', |
| 162 | CYBOT_COOKIEBOT_PLUGIN_URL . 'assets/css/backend/dashboard.css', |
| 163 | array(), |
| 164 | Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION |
| 165 | ); |
| 166 | |
| 167 | wp_enqueue_script( |
| 168 | 'cookiebot-account-js', |
| 169 | CYBOT_COOKIEBOT_PLUGIN_URL . 'assets/js/backend/account.js', |
| 170 | array( 'jquery' ), |
| 171 | Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION, |
| 172 | true |
| 173 | ); |
| 174 | |
| 175 | wp_localize_script( |
| 176 | 'cookiebot-account-js', |
| 177 | 'cookiebot_account', |
| 178 | array( |
| 179 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 180 | 'nonce' => wp_create_nonce( 'cookiebot-account' ), |
| 181 | 'cbid' => $cbid, |
| 182 | 'scan_id' => $scan_id, |
| 183 | 'has_user_data' => ! empty( $user_data ), |
| 184 | 'has_cbid' => ! empty( $cbid ), |
| 185 | 'was_onboarded' => $was_onboarded, |
| 186 | 'debug' => defined( 'WP_DEBUG' ) && WP_DEBUG, |
| 187 | ) |
| 188 | ); |
| 189 | |
| 190 | require_once CYBOT_COOKIEBOT_PLUGIN_DIR . 'src/view/admin/common/dashboard-trial-expired.php'; |
| 191 | return; |
| 192 | } |
| 193 | |
| 194 | // Redirect CB users to previous dashboard page |
| 195 | if ( ( ! empty( $cbid ) && $is_cb_user ) || ( ! empty( $cbid ) && empty( $user_data ) ) ) { |
| 196 | wp_enqueue_style( |
| 197 | 'cookiebot-dashboard-backup-css', |
| 198 | CYBOT_COOKIEBOT_PLUGIN_URL . 'assets/css/backend/dashboard-old.css', |
| 199 | array(), |
| 200 | Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION |
| 201 | ); |
| 202 | |
| 203 | wp_enqueue_script( |
| 204 | 'cookiebot-account-js', |
| 205 | CYBOT_COOKIEBOT_PLUGIN_URL . 'assets/js/backend/account.js', |
| 206 | array( 'jquery' ), |
| 207 | Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION, |
| 208 | true |
| 209 | ); |
| 210 | |
| 211 | wp_localize_script( |
| 212 | 'cookiebot-account-js', |
| 213 | 'cookiebot_account', |
| 214 | array( |
| 215 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 216 | 'nonce' => wp_create_nonce( 'cookiebot-account' ), |
| 217 | 'cbid' => $cbid, |
| 218 | 'scan_id' => $scan_id, |
| 219 | 'has_user_data' => ! empty( $user_data ), |
| 220 | 'has_cbid' => ! empty( $cbid ), |
| 221 | 'was_onboarded' => $was_onboarded, |
| 222 | 'debug' => defined( 'WP_DEBUG' ) && WP_DEBUG, |
| 223 | ) |
| 224 | ); |
| 225 | |
| 226 | require_once CYBOT_COOKIEBOT_PLUGIN_DIR . 'src/view/admin/common/dashboard-page-old.php'; |
| 227 | return; |
| 228 | } |
| 229 | |
| 230 | wp_enqueue_style( |
| 231 | 'cookiebot-dashboard-css', |
| 232 | CYBOT_COOKIEBOT_PLUGIN_URL . 'assets/css/backend/dashboard.css', |
| 233 | array(), |
| 234 | Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION |
| 235 | ); |
| 236 | |
| 237 | wp_enqueue_script( |
| 238 | 'cookiebot-dashboard-js', |
| 239 | CYBOT_COOKIEBOT_PLUGIN_URL . 'assets/js/backend/dashboard.js', |
| 240 | array( 'jquery' ), |
| 241 | Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION, |
| 242 | true |
| 243 | ); |
| 244 | |
| 245 | wp_localize_script( |
| 246 | 'cookiebot-dashboard-js', |
| 247 | 'cookiebot_dashboard', |
| 248 | array( |
| 249 | 'cbid' => $cbid, |
| 250 | 'user_data' => $user_data, |
| 251 | ) |
| 252 | ); |
| 253 | |
| 254 | wp_enqueue_script( |
| 255 | 'cookiebot-account-js', |
| 256 | CYBOT_COOKIEBOT_PLUGIN_URL . 'assets/js/backend/account.js', |
| 257 | array( 'jquery' ), |
| 258 | Cookiebot_WP::COOKIEBOT_PLUGIN_VERSION, |
| 259 | true |
| 260 | ); |
| 261 | |
| 262 | wp_localize_script( |
| 263 | 'cookiebot-account-js', |
| 264 | 'cookiebot_account', |
| 265 | array( |
| 266 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 267 | 'nonce' => wp_create_nonce( 'cookiebot-account' ), |
| 268 | 'cbid' => $cbid, |
| 269 | 'scan_id' => $scan_id, |
| 270 | 'has_user_data' => ! empty( $user_data ), |
| 271 | 'has_cbid' => ! empty( $cbid ), |
| 272 | 'was_onboarded' => $was_onboarded, |
| 273 | 'is_authenticated' => ! empty( Cookiebot_WP::get_auth_token() ), |
| 274 | 'messages' => array( |
| 275 | 'success_create' => __( 'Account created successfully!', 'cookiebot' ), |
| 276 | 'error_create' => __( 'Failed to create account.', 'cookiebot' ), |
| 277 | 'success_verify' => __( 'CBID verified successfully!', 'cookiebot' ), |
| 278 | 'error_verify' => __( 'Invalid CBID.', 'cookiebot' ), |
| 279 | ), |
| 280 | 'debug' => defined( 'WP_DEBUG' ) && WP_DEBUG, |
| 281 | ) |
| 282 | ); |
| 283 | |
| 284 | require_once CYBOT_COOKIEBOT_PLUGIN_DIR . 'src/view/admin/common/dashboard-page.php'; |
| 285 | } |
| 286 | } |
| 287 |