true, 'lastUpdate' => gmdate( 'Y-m-d' ), ] ); exit; } /** * add embed code to page * * @since 1.0.0 * */ public static function add_embed_code() { if ( is_admin() ) { return; } $code = AS_CM_Controllers_Options::get_option_embed_code(); $local_options = AS_CM_Controllers_Options::get_option_local_banner(); if ( empty( $code ) ) { if ( empty( $local_options['enabled'] ) ) { return; } // Render local fallback container; assets are enqueued in enqueue_local_assets() echo "\r\n
\r\n"; return; } $code = apply_filters( AS_CM_Manager::$action . '_embed_code', $code ); $allowed_html = array( 'script' => array( 'type' => true, 'src' => true, 'id' => true, 'async' => true, 'defer' => true, 'charset' => true, 'crossorigin' => true, ), ); echo "\r\n" . wp_kses( $code, $allowed_html ) . "\r\n"; } /** * Output blocking runtime inline at the very top of so it * executes before any third-party script can load or set cookies. * * Hooked at wp_head priority -1000 to guarantee earliest execution. * * @since 2.2.1 */ public static function output_blocking_runtime() { if ( is_admin() ) { return; } $code = AS_CM_Controllers_Options::get_option_embed_code(); $local_options = AS_CM_Controllers_Options::get_option_local_banner(); if ( ! empty( $code ) || empty( $local_options['enabled'] ) ) { return; } $categories = [ [ 'key' => 'required', 'locked' => true, 'default' => true ], [ 'key' => 'statistics', 'locked' => false, 'default' => false ], [ 'key' => 'statistics-anonymous', 'locked' => false, 'default' => false ], [ 'key' => 'marketing', 'locked' => false, 'default' => false ], [ 'key' => 'unclassified', 'locked' => false, 'default' => false ], ]; if ( isset( $local_options['cookie_categories'] ) && is_array( $local_options['cookie_categories'] ) ) { $available = isset( $local_options['cookie_categories']['availableCategories'] ) && is_array( $local_options['cookie_categories']['availableCategories'] ) ? $local_options['cookie_categories']['availableCategories'] : []; $states = isset( $local_options['cookie_categories']['categoryStates'] ) && is_array( $local_options['cookie_categories']['categoryStates'] ) ? $local_options['cookie_categories']['categoryStates'] : []; if ( ! empty( $available ) ) { $categories = []; foreach ( $available as $cat_key ) { $state = isset( $states[ $cat_key ] ) ? $states[ $cat_key ] : []; $visible = array_key_exists( 'visible', $state ) ? (bool) $state['visible'] : true; if ( ! $visible ) { continue; } $categories[] = [ 'key' => $cat_key, 'locked' => ! empty( $state['locked'] ), 'default' => ! empty( $state['activated'] ), ]; } } if ( empty( $categories ) ) { $categories = [ [ 'key' => 'required', 'locked' => true, 'default' => true ], ]; } } $consent_cookie_name = 'as_cm_consent'; $blocking_config = [ 'categories' => $categories, 'consentCookieName' => $consent_cookie_name, ]; if ( class_exists( 'AS_CM_Controllers_Scan' ) ) { $blocking_data = AS_CM_Controllers_Scan::get_blocking_data(); $blocking_config['blocking'] = [ 'services' => $blocking_data['services'], 'cookies' => $blocking_data['cookies'], 'hosts' => $blocking_data['hosts'], 'reloadOnChange' => true, 'defaultCategory' => 'unclassified', 'debug' => defined( 'WP_DEBUG' ) && WP_DEBUG, ]; } // --- Google Consent Mode v2: set defaults before any Google script --- $gcm_enabled = isset( $local_options['features']['google_consent_mode']['enabled'] ) && ! empty( $local_options['features']['google_consent_mode']['enabled'] ); if ( $gcm_enabled ) { $gcm_default = isset( $local_options['features']['google_consent_mode']['default_consent'] ) && 'granted' === $local_options['features']['google_consent_mode']['default_consent'] ? 'granted' : 'denied'; $stats_state = $gcm_default; $marketing_state = $gcm_default; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated $consent_raw = isset( $_COOKIE[ $consent_cookie_name ] ) ? sanitize_text_field( wp_unslash( $_COOKIE[ $consent_cookie_name ] ) ) : ''; if ( $consent_raw ) { $consent_data = json_decode( $consent_raw, true ); if ( is_array( $consent_data ) && isset( $consent_data['consent'] ) && is_array( $consent_data['consent'] ) ) { $stats_state = ! empty( $consent_data['consent']['statistics'] ) ? 'granted' : 'denied'; $marketing_state = ! empty( $consent_data['consent']['marketing'] ) ? 'granted' : 'denied'; } } echo "\n" . '' . "\n"; } // --- Blocking config --- echo '' . "\n"; // --- Blocking runtime (inline for guaranteed early execution) --- $js_path = AS_CM_Manager::$path . 'assets/public/js/blocking-runtime.js'; if ( ! file_exists( $js_path ) ) { return; } // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents $js_content = file_get_contents( $js_path ); if ( $js_content ) { if ( function_exists( 'wp_print_inline_script_tag' ) ) { wp_print_inline_script_tag( $js_content, array( 'id' => 'ascm-blocking-runtime' ) ); } else { // Fallback for WordPress < 5.7 echo '' . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } } /** * Enqueue assets for local fallback banner if no embed code is configured */ public static function enqueue_local_assets() { if ( is_admin() ) { return; } $code = AS_CM_Controllers_Options::get_option_embed_code(); $local_options = AS_CM_Controllers_Options::get_option_local_banner(); $defaults = AS_CM_Controllers_Options::get_local_banner_defaults(); if ( ! empty( $code ) || empty( $local_options['enabled'] ) ) { return; } $plugin_url = AS_CM_Manager::$url; $version = AS_CM_Manager::$version . '-' . time(); wp_enqueue_script( AS_CM_Helpers_General::prepare_name( 'local-banner-script', false ), $plugin_url . '/assets/public/js/local-banner.js', [], $version, true ); // blocking-runtime.js is now output inline at wp_head priority -1000 // via output_blocking_runtime() for guaranteed early execution. $default_config = [ 'position' => 'popup', 'layout' => 'classic', 'theme' => 'theme1', 'texts' => [ 'welcome_title' => __( 'Notice on data processing', 'adsimple-cookie-manager-for-wp' ), 'welcome_message' => __( "If you want to use our website without restrictions, please click «Accept all». Data processing from third parties that we have classified as not necessary can be {necessary-cookies}rejected{/necessary-cookies}. You can change your {cookie-settings}Privacy Settings{/cookie-settings} at any time.", 'adsimple-cookie-manager-for-wp' ), 'allow' => __( 'Accept all', 'adsimple-cookie-manager-for-wp' ), 'necessary_cookies_only' => __( 'Necessary only', 'adsimple-cookie-manager-for-wp' ), 'allow_selected' => __( 'Save selection', 'adsimple-cookie-manager-for-wp' ), 'title' => __( 'Settings', 'adsimple-cookie-manager-for-wp' ), 'message' => __( 'Below you have the option to set your own preferences.', 'adsimple-cookie-manager-for-wp' ), 'policy' => __( 'Privacy settings', 'adsimple-cookie-manager-for-wp' ), 'close' => __( 'Close', 'adsimple-cookie-manager-for-wp' ), ], 'categories' => [ ['key' => 'required', 'label' => __( 'Necessary', 'adsimple-cookie-manager-for-wp' ), 'locked' => true, 'default' => true], ['key' => 'statistics', 'label' => __( 'Statistics', 'adsimple-cookie-manager-for-wp' ), 'locked' => false, 'default' => false], ['key' => 'statistics-anonymous', 'label' => __( 'Statistics (anonymous)', 'adsimple-cookie-manager-for-wp' ), 'locked' => false, 'default' => false], ['key' => 'marketing', 'label' => __( 'Marketing', 'adsimple-cookie-manager-for-wp' ), 'locked' => false, 'default' => false], ['key' => 'unclassified', 'label' => __( 'Unclassified', 'adsimple-cookie-manager-for-wp' ), 'locked' => false, 'default' => false], ], 'links' => [ 'privacy' => '', 'privacyLabel' => __( 'Privacy policy', 'adsimple-cookie-manager-for-wp' ), 'imprint' => '', 'imprintLabel' => __( 'Legal notice', 'adsimple-cookie-manager-for-wp' ), ], 'settings_button' => [ 'label' => __( 'Privacy settings', 'adsimple-cookie-manager-for-wp' ), 'iconColor' => '', 'iconBackground' => '', 'iconDesktopShow' => '1', 'offsetSettingsTabPosition' => 1, ], 'consentCookieName' => 'as_cm_consent', 'consentTtlDays' => 180, 'popup_effects' => [ 'popup_shadow' => '1', 'popup_overlay_color' => '', 'popup_overlay_opacity' => 50, ], 'custom_colors_enabled' => false, 'custom_colors' => isset( $defaults['custom_colors'] ) && is_array( $defaults['custom_colors'] ) ? $defaults['custom_colors'] : [ 'popupText' => '#333333', 'popupLink' => '#57ca85', 'popupLinkHover' => '#57ca85', 'popup' => '#ffffff', 'button' => '#57ca85', 'buttonHover' => '#57ca85', 'buttonText' => '#ffffff', 'buttonTextHover' => '#ffffff', 'buttonBorder' => '#57ca85', 'buttonBorderHover' => '#57ca85', 'necessaryCookiesOnlyButton' => '#fcb100', 'necessaryCookiesOnlyButtonHover' => '#fcb100', 'necessaryCookiesOnlyButtonText' => '#ffffff', 'necessaryCookiesOnlyButtonTextHover'=> '#ffffff', 'necessaryCookiesOnlyButtonBorder' => '#fcb100', 'necessaryCookiesOnlyButtonBorderHover' => '#fcb100', 'popupElements' => '#57ca85', 'checkboxColor' => '#ffffff', ], 'cssVariables' => AS_CM_Controllers_Options::get_option_local_banner_css_variables(), ]; $links = isset( $local_options['links'] ) && is_array( $local_options['links'] ) ? $local_options['links'] : []; $privacy_page_id = isset( $links['privacy_page_id'] ) ? absint( $links['privacy_page_id'] ) : 0; $imprint_page_id = isset( $links['imprint_page_id'] ) ? absint( $links['imprint_page_id'] ) : 0; if ( $privacy_page_id > 0 ) { $privacy_url = get_permalink( $privacy_page_id ); if ( $privacy_url ) { $default_config['links']['privacy'] = $privacy_url; } if ( empty( $links['privacy_label'] ) ) { $default_config['links']['privacyLabel'] = get_the_title( $privacy_page_id ); } } if ( $imprint_page_id > 0 ) { $imprint_url = get_permalink( $imprint_page_id ); if ( $imprint_url ) { $default_config['links']['imprint'] = $imprint_url; } if ( empty( $links['imprint_label'] ) ) { $default_config['links']['imprintLabel'] = get_the_title( $imprint_page_id ); } } if ( isset( $links['privacy'] ) && empty( $default_config['links']['privacy'] ) ) { $default_config['links']['privacy'] = $links['privacy']; } if ( isset( $links['privacy_label'] ) && $links['privacy_label'] !== '' ) { $default_config['links']['privacyLabel'] = $links['privacy_label']; } if ( isset( $links['imprint'] ) && empty( $default_config['links']['imprint'] ) ) { $default_config['links']['imprint'] = $links['imprint']; } if ( isset( $links['imprint_label'] ) && $links['imprint_label'] !== '' ) { $default_config['links']['imprintLabel'] = $links['imprint_label']; } $allowed_positions = [ 'bottom', 'bottom-left', 'top', 'bottom-right', 'top-push', 'popup' ]; if ( isset( $local_options['position'] ) && in_array( $local_options['position'], $allowed_positions, true ) ) { $default_config['position'] = $local_options['position']; } if ( isset( $local_options['layout'] ) && in_array( $local_options['layout'], [ 'classic', 'block', 'wire' ], true ) ) { $default_config['layout'] = $local_options['layout']; } $layout_choice = isset( $default_config['layout'] ) ? $default_config['layout'] : 'classic'; $layout_style = 'wire' === $layout_choice ? 'edgeless' : 'classic'; $style_base_handle = AS_CM_Helpers_General::prepare_name( 'consent-base-style', false ); $style_layout_handle = AS_CM_Helpers_General::prepare_name( 'consent-layout-style', false ); $style_anim_handle = AS_CM_Helpers_General::prepare_name( 'consent-animation-style', false ); $style_media_handle = AS_CM_Helpers_General::prepare_name( 'consent-media-style', false ); $style_theme_handle = AS_CM_Helpers_General::prepare_name( 'consent-theme-style', false ); $style_main_handle = AS_CM_Helpers_General::prepare_name( 'consent-main-style', false ); $local_style_handle = AS_CM_Helpers_General::prepare_name( 'local-banner-style', false ); wp_enqueue_style( $style_base_handle, $plugin_url . '/assets/public/css/consent/base.css', [], $version ); wp_enqueue_style( $style_layout_handle, $plugin_url . '/assets/public/css/consent/layout.css', [ $style_base_handle ], $version ); wp_enqueue_style( $style_anim_handle, $plugin_url . '/assets/public/css/consent/animation.css', [ $style_layout_handle ], $version ); wp_enqueue_style( $style_media_handle, $plugin_url . '/assets/public/css/consent/media.css', [ $style_anim_handle ], $version ); $theme_file = 'edgeless' === $layout_style ? '/assets/public/css/consent/edgeless.css' : '/assets/public/css/consent/classic.css'; wp_enqueue_style( $style_theme_handle, $plugin_url . $theme_file, [ $style_media_handle ], $version ); wp_enqueue_style( $style_main_handle, $plugin_url . '/assets/public/css/consent/cookieconsent.css', [ $style_theme_handle ], $version ); wp_enqueue_style( $local_style_handle, $plugin_url . '/assets/public/css/local-banner.css', [ $style_main_handle ], $version ); $default_config['layout_style'] = $layout_style; if ( ! empty( $local_options['theme'] ) ) { $default_config['theme'] = sanitize_text_field( $local_options['theme'] ); } if ( ! empty( $local_options['consent_ttl_days'] ) ) { $ttl = absint( $local_options['consent_ttl_days'] ); if ( $ttl < 1 ) { $ttl = 1; } if ( $ttl > 730 ) { $ttl = 730; } $default_config['consentTtlDays'] = $ttl; } if ( isset( $local_options['texts'] ) && is_array( $local_options['texts'] ) ) { foreach ( $local_options['texts'] as $key => $value ) { if ( $value === '' ) { continue; } $default_config['texts'][ $key ] = $value; } } if ( isset( $local_options['settings_button'] ) && is_array( $local_options['settings_button'] ) ) { $settings_button = wp_parse_args( $local_options['settings_button'], $default_config['settings_button'] ); $settings_button['label'] = isset( $settings_button['label'] ) ? $settings_button['label'] : $default_config['settings_button']['label']; $settings_button['iconColor'] = isset( $settings_button['iconColor'] ) ? $settings_button['iconColor'] : $default_config['settings_button']['iconColor']; $settings_button['iconBackground'] = isset( $settings_button['iconBackground'] ) ? $settings_button['iconBackground'] : $default_config['settings_button']['iconBackground']; $settings_button['iconDesktopShow'] = isset( $settings_button['iconDesktopShow'] ) && '0' === (string) $settings_button['iconDesktopShow'] ? '0' : '1'; $settings_button['offsetSettingsTabPosition'] = isset( $settings_button['offsetSettingsTabPosition'] ) ? min( 90, max( 0, absint( $settings_button['offsetSettingsTabPosition'] ) ) ) : $default_config['settings_button']['offsetSettingsTabPosition']; $default_config['settings_button'] = $settings_button; } if ( isset( $local_options['popup_effects'] ) && is_array( $local_options['popup_effects'] ) ) { $default_config['popup_effects'] = wp_parse_args( $local_options['popup_effects'], $default_config['popup_effects'] ); $default_config['popup_effects']['popup_shadow'] = isset( $default_config['popup_effects']['popup_shadow'] ) && '0' === (string) $default_config['popup_effects']['popup_shadow'] ? '0' : '1'; $default_config['popup_effects']['popup_overlay_opacity'] = isset( $default_config['popup_effects']['popup_overlay_opacity'] ) ? min( 100, max( 0, absint( $default_config['popup_effects']['popup_overlay_opacity'] ) ) ) : $default_config['popup_effects']['popup_overlay_opacity']; } if ( ! empty( $local_options['custom_colors_enabled'] ) ) { $default_config['custom_colors_enabled'] = true; } if ( isset( $local_options['custom_colors'] ) && is_array( $local_options['custom_colors'] ) ) { $filtered_custom_colors = []; foreach ( $local_options['custom_colors'] as $key => $value ) { if ( is_string( $value ) && '' === trim( $value ) ) { continue; } $filtered_custom_colors[ $key ] = $value; } if ( ! empty( $filtered_custom_colors ) ) { $default_config['custom_colors'] = array_replace( $default_config['custom_colors'], $filtered_custom_colors ); } } if ( isset( $local_options['cookie_categories'] ) && is_array( $local_options['cookie_categories'] ) ) { $labels = [ 'required' => __( 'Necessary', 'adsimple-cookie-manager-for-wp' ), 'statistics' => __( 'Statistics', 'adsimple-cookie-manager-for-wp' ), 'statistics-anonymous' => __( 'Statistics (anonymous)', 'adsimple-cookie-manager-for-wp' ), 'marketing' => __( 'Marketing', 'adsimple-cookie-manager-for-wp' ), 'unclassified' => __( 'Unclassified', 'adsimple-cookie-manager-for-wp' ), 'preferences' => __( 'Preferences', 'adsimple-cookie-manager-for-wp' ), ]; $available_categories = isset( $local_options['cookie_categories']['availableCategories'] ) && is_array( $local_options['cookie_categories']['availableCategories'] ) ? $local_options['cookie_categories']['availableCategories'] : []; $states = isset( $local_options['cookie_categories']['categoryStates'] ) && is_array( $local_options['cookie_categories']['categoryStates'] ) ? $local_options['cookie_categories']['categoryStates'] : []; $default_config['categories'] = []; foreach ( $available_categories as $category_key ) { $state = isset( $states[ $category_key ] ) ? $states[ $category_key ] : []; $visible = array_key_exists( 'visible', $state ) ? (bool) $state['visible'] : true; if ( ! $visible ) { continue; } $label = isset( $labels[ $category_key ] ) ? $labels[ $category_key ] : ucwords( str_replace( '-', ' ', $category_key ) ); $default_config['categories'][] = [ 'key' => $category_key, 'label' => $label, 'locked' => ! empty( $state['locked'] ), 'default' => ! empty( $state['activated'] ), ]; } if ( empty( $default_config['categories'] ) ) { $default_config['categories'] = [ [ 'key' => 'required', 'label' => __( 'Necessary', 'adsimple-cookie-manager-for-wp' ), 'locked' => true, 'default' => true ], ]; } } if ( class_exists( 'AS_CM_Controllers_Scan' ) ) { $blocking_data = AS_CM_Controllers_Scan::get_blocking_data(); $default_config['blocking'] = [ 'services' => $blocking_data['services'], 'cookies' => $blocking_data['cookies'], 'hosts' => $blocking_data['hosts'], 'reloadOnChange' => true, 'defaultCategory' => 'unclassified', 'debug' => defined( 'WP_DEBUG' ) && WP_DEBUG, ]; } if ( isset( $local_options['features']['google_consent_mode'] ) && ! empty( $local_options['features']['google_consent_mode']['enabled'] ) ) { $default_config['googleConsentMode'] = [ 'enabled' => true, 'defaultConsent' => isset( $local_options['features']['google_consent_mode']['default_consent'] ) && 'granted' === $local_options['features']['google_consent_mode']['default_consent'] ? 'granted' : 'denied', ]; } if ( isset( $local_options['features']['gpc_support'] ) && ! empty( $local_options['features']['gpc_support']['enabled'] ) ) { $default_config['gpcSupport'] = [ 'enabled' => true, 'autoReject' => ! empty( $local_options['features']['gpc_support']['auto_reject'] ), 'hideBanner' => ! empty( $local_options['features']['gpc_support']['hide_banner'] ), ]; } wp_localize_script( AS_CM_Helpers_General::prepare_name( 'local-banner-script', false ), 'ascmLocalConfig', $default_config ); } /** * Inject the scan content script when page is loaded in scan iframe * * When the page is loaded with ?as_cm_scan_job=JOB_ID parameter, * we inject the content script that collects cookies, scripts, etc. * and sends them back to the parent window via postMessage. * * @since 2.1.6 */ public static function maybe_inject_scan_script() { // Check if scan job parameter is present // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( empty( $_GET['as_cm_scan_job'] ) ) { return; } // Verify user has permission (check referer is from admin) $referer = wp_get_referer(); if ( ! $referer || strpos( $referer, admin_url() ) === false ) { // Also check if it's a same-origin request (iframe from admin) $http_referer = isset( $_SERVER['HTTP_REFERER'] ) ? esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : ''; if ( ! $http_referer || strpos( $http_referer, admin_url() ) === false ) { return; } } // phpcs:ignore WordPress.Security.NonceVerification.Recommended $job_id = sanitize_text_field( wp_unslash( $_GET['as_cm_scan_job'] ) ); if ( empty( $job_id ) ) { return; } // Get the admin origin for postMessage $admin_origin = admin_url(); $parsed = wp_parse_url( $admin_origin ); $origin = ( isset( $parsed['scheme'] ) ? $parsed['scheme'] : 'http' ) . '://' . ( isset( $parsed['host'] ) ? $parsed['host'] : 'localhost' ); if ( isset( $parsed['port'] ) ) { $origin .= ':' . $parsed['port']; } // Get site host for filtering internal resources $site_host = wp_parse_url( home_url(), PHP_URL_HOST ); // Output the content script ?>