' . __('We Use Cookies to Improve Your Experience', 'an-cookie-consent') . '' . __('This website uses cookies to ensure it works properly, enhance your experience, and analyze traffic. By continuing, you agree to the use of all cookies. You can also choose to allow only necessary cookies or manage your preferences. More details in ', 'an-cookie-consent') . '[cookie_policy_page_link][/cookies_content]' . '[accept_cookies title="' . __('Accept All', 'an-cookie-consent') . '" class="an-button-cookie"]' . '[reject_cookies title="' . __('Reject All', 'an-cookie-consent') . '" class="an-button-cookie"]'; return apply_filters( 'an_cookie_consent_default_content', $default_content ); } function an_admin_enqueue() { global $an_functions; if ($an_functions->is_an_admin_page()) { $an_js_ver = date("ymd-Gis", filemtime( ADVANCED_NOTIFICATIONS_ROOT_PATH . 'addons/cookie-consent/assets/js/an-cookie-consent-admin.js' )); wp_register_script( 'admin-an-cookie-consent-js', ADVANCED_NOTIFICATIONS_URL_PATH . 'addons/cookie-consent/assets/js/an-cookie-consent-admin.js', array(), $an_js_ver ); wp_enqueue_script( 'admin-an-cookie-consent-js' ); wp_localize_script( 'admin-an-cookie-consent-js', 'an_cookie_consent_default_content', array( 'content' => $this->an_get_default_cookie_consent_content() ) ); } } function an_enqueue_blocker() { $consent_categories_localize = $this->an_cookie_consent_categories(); if (!empty($consent_categories_localize) && is_array($consent_categories_localize)) { $an_js_ver = date("ymd-Gis", filemtime( ADVANCED_NOTIFICATIONS_ROOT_PATH . 'addons/cookie-consent/assets/js/an-cookie-consent-blocker.js' )); wp_register_script( 'an-cookie-consent-blocker', ADVANCED_NOTIFICATIONS_URL_PATH . 'addons/cookie-consent/assets/js/an-cookie-consent-blocker.js', array(), $an_js_ver, false ); wp_localize_script( 'an-cookie-consent-blocker', 'an_cookie_consent_categories', $consent_categories_localize ); wp_localize_script( 'an-cookie-consent-blocker', 'an_cookie_consent_settings', array( 'regulation' => esc_attr(eis_get_option('an_settings', 'cookie_consent_regulations')) ) ); wp_enqueue_script( 'an-cookie-consent-blocker' ); } } function an_enqueue() { $an_css_ver = date("ymd-Gis", filemtime(ADVANCED_NOTIFICATIONS_ROOT_PATH . 'addons/cookie-consent/assets/css/an-cookie-consent.css')); wp_register_style( 'an-cookie-consent-style', ADVANCED_NOTIFICATIONS_URL_PATH . 'addons/cookie-consent/assets/css/an-cookie-consent.css', false, $an_css_ver ); wp_enqueue_style( 'an-cookie-consent-style' ); if (is_rtl()) { $an_css_ver = date("ymd-Gis", filemtime(ADVANCED_NOTIFICATIONS_ROOT_PATH . 'addons/cookie-consent/assets/css/an-cookie-consent-rtl.css')); wp_register_style( 'an-cookie-consent-style-rtl', ADVANCED_NOTIFICATIONS_URL_PATH . 'addons/cookie-consent/assets/css/an-cookie-consent-rtl.css', false, $an_css_ver ); wp_enqueue_style( 'an-cookie-consent-style-rtl' ); } $an_js_ver = date("ymd-Gis", filemtime( ADVANCED_NOTIFICATIONS_ROOT_PATH . 'addons/cookie-consent/assets/js/an-cookie-consent.js' )); wp_register_script( 'an-cookie-consent-js', ADVANCED_NOTIFICATIONS_URL_PATH . 'addons/cookie-consent/assets/js/an-cookie-consent.js', array( 'jquery' ), $an_js_ver, false ); wp_enqueue_script( 'an-cookie-consent-js' ); } function generateHash($content) { $hash = 0; $length = strlen($content); if ($length === 0) { return strval($hash); } for ($i = 0; $i < $length; $i++) { $char = ord($content[$i]); $hash = (($hash << 5) - $hash) + $char; $hash = $hash & 0xFFFFFFFF; // Convert to 32-bit integer // Handle sign bit for 32-bit integer if ($hash > 0x7FFFFFFF) { $hash = $hash - 0x100000000; } } return strval(abs($hash)); } function is_cookie_consent_all_allow() { if (isset($_COOKIE['an_cookie_preferences'])) { $cookie_value = $_COOKIE['an_cookie_preferences']; $cookie_value = stripslashes($cookie_value); $cookie_value = json_decode($cookie_value, true); if (isset($cookie_value['status'])) { if ($cookie_value['status'] === 'accept') { return true; } else { return false; } } } $regulation = eis_get_option('an_settings', 'cookie_consent_regulations'); if ($regulation === 'opt-out') { return true; // חיובי } return false; } function get_consent_category_status($category_name) { if ($category_name == 'necessary') { return true; } if (isset($_COOKIE['an_cookie_preferences'])) { $cookie_value = $_COOKIE['an_cookie_preferences']; $cookie_value = stripslashes($cookie_value); $cookie_value = json_decode($cookie_value, true); if (isset($cookie_value[$category_name])) { if ($cookie_value[$category_name]) { return true; } else { return false; } } } $regulation = eis_get_option('an_settings', 'cookie_consent_regulations'); if ($regulation === 'opt-out') { return true; // חיובי } else { return false; } } public function register_header_callback() { if (!$this->is_cookie_consent_all_allow()) { header_register_callback(array($this, 'filter_cookies')); } } public function filter_cookies() { $headers = headers_list(); $cookie_names = $this->extract_cookie_names($headers); $cookies_to_remove = $this->should_remove_cookies($cookie_names); if (empty($cookies_to_remove)) { return; } header_remove(); foreach ($headers as $header) { if (stripos($header, 'Set-Cookie:') === 0) { $cookie_name = $this->get_cookie_name_from_header($header); if (in_array($cookie_name, $cookies_to_remove)) { continue; } } header($header); } } private function extract_cookie_names($headers) { $cookie_names = array(); foreach ($headers as $header) { if (stripos($header, 'Set-Cookie:') === 0) { $cookie_name = $this->get_cookie_name_from_header($header); if ($cookie_name) { $cookie_names[] = $cookie_name; } } } return $cookie_names; } private function get_cookie_name_from_header($header) { if (preg_match('/Set-Cookie:\s*([^=]+)=/i', $header, $matches)) { return trim($matches[1]); } return null; } protected function should_remove_cookies($cookie_names) { $cookies_to_remove = array(); $cookie_categories = $this->an_cookie_consent_categories(); if (empty($cookie_categories) || !is_array($cookie_categories)) { return $cookies_to_remove; } $cookie_hashes = array(); foreach ($cookie_names as $cookie_name) { $hash = $this->generateHash($cookie_name); $cookie_hashes[$hash] = $cookie_name; } foreach ($cookie_categories as $category_name => $ids) { if (!$this->an_is_block_category($category_name)) { continue; } if (is_array($ids)) { foreach ($ids as $cookie_id) { if (isset($cookie_hashes[$cookie_id])) { $cookies_to_remove[] = $cookie_hashes[$cookie_id]; } } } } return array_unique($cookies_to_remove); } function an_is_block_category($category_name) { $category_status = $this->get_consent_category_status($category_name); if (!$category_status) { return true; } else { return false; } } function an_cookie_consent_categories() { $consent_data = get_option('an_cookie_consent_data'); if (!empty($consent_data) && is_array($consent_data)) { $an_consent_categories = array(); foreach ($consent_data as $type_group) { if (!is_array($type_group)) continue; foreach ($type_group as $id => $item) { if (!empty($item['admin_category'])) { $category = $item['admin_category']; $an_consent_categories[$category][] = $id; } elseif (!empty($item['category'])) { $category = $item['category']; $an_consent_categories[$category][] = $id; } } } unset($an_consent_categories['necessary']); return $an_consent_categories; } } function is_suspicious_script($scriptContent) { if (empty($scriptContent)) return false; // Convert to lower case for case-insensitive matching $content = strtolower($scriptContent); // Define suspicious patterns $patterns = [ '/document\.cookie/', // direct cookie access '/localstorage\.setitem/', // localStorage '/sessionstorage\.setitem/', // sessionStorage '/indexeddb\.open/', // IndexedDB usage '/fetch\s*\(/', // fetch API '/xmlhttprequest/', // AJAX '/navigator\.sendbeacon/', // sendBeacon '/new\s+image\s*\(\)\.src/', // tracking pixel '/dataLayer\.push/', // GTM '/gtag\s*\(/', // Google Analytics '/fbq\s*\(/', // Facebook Pixel '/mixpanel/', // Mixpanel '/clarity/', // Microsoft Clarity '/analytics\./', // Generic analytics '/eval\s*\(/', // eval usage '/Function\s*\(/', // dynamic Function '/function\s*\(/', // dynamic Function '/function/', // dynamic Function ]; // Score suspicious hits $score = 0; foreach ($patterns as $pattern) { if (preg_match($pattern, $content)) { $score++; } } // Threshold: 2 or more matches = suspicious return $score >= 1; } function an_cookies_content_html($type,$content,$class=null) { $class = $class ? ' ' . esc_html($class) : ''; switch ($type) { case 'cookies_content': $content = $content ? wp_kses_post($content) : ''; return '
' . $content . '
'; case 'cookie_policy_page_link': if ($content == 'default') { $page_id = get_option('wp_page_for_privacy_policy'); } else { $page_id = is_page($content) ? $content : false; } if ($page_id) { $privacy_page = get_post($page_id); $page_title = $privacy_page->post_title; $page_url = get_permalink($privacy_page->ID); return '' . $page_title . ''; } else { return ''; } case 'accept_cookies': return ''; case 'reject_cookies': return ''; } // Allow Pro version to handle manage_cookies $filtered_content = apply_filters('an_cookies_content_html', $content, $type, $class); if ($filtered_content !== $content) { return $filtered_content; } return $content; } function an_cookies_shortcode( $atts=array(), $content =null, $shortcode='' ) { $defaults = array(); switch ($shortcode) { case 'cookies_content': $defaults = array( 'class' => '', ); break; case 'cookie_policy_page_link': $defaults = array( 'page_id' => 'default', 'class' => '', ); break; case 'accept_cookies': $defaults = array( 'title' => __('Accept All', 'an-cookie-consent'), 'class' => '', ); break; case 'reject_cookies': $defaults = array( 'title' => __('Reject All', 'an-cookie-consent'), 'class' => '', ); break; } $atts = shortcode_atts($defaults, $atts, $shortcode); switch ($shortcode) { case 'cookies_content': return $this->an_cookies_content_html('cookies_content', do_shortcode($content), $atts['class']); case 'cookie_policy_page_link': return $this->an_cookies_content_html('cookie_policy_page_link', $atts['page_id'], $atts['class']); case 'accept_cookies': return $this->an_cookies_content_html('accept_cookies', $atts['title'], $atts['class']); case 'reject_cookies': return $this->an_cookies_content_html('reject_cookies', $atts['title'], $atts['class']); } // Allow Pro version to handle manage_cookies shortcode $filtered_result = apply_filters('an_cookies_shortcode', '', $shortcode, $atts, $content); if (!empty($filtered_result)) { return $filtered_result; } return ''; } function an_cookie_consent_content($an_content,$notification) { if ($notification['type'] == 'cookie-consent') { if ($notification['cookie_consent_content_builder_type'] == 'default') { $cookies_content = '
' . $notification['cookie_consent_content_title'] . '
'; $cookies_content .= '
' . do_shortcode($notification['cookie_consent_content_body']) . '
'; $an_content = $this->an_cookies_content_html('cookies_content', $cookies_content, 'an-cookies-content-default'); $an_content .= $this->an_cookies_content_html('accept_cookies', $notification['an_accept_cookies_button_text'], 'an-button-cookie'); $an_content .= $this->an_cookies_content_html('reject_cookies', $notification['an_reject_cookies_button_text'], 'an-button-cookie'); // Allow Pro version to add manage_cookies button $an_content = apply_filters('an_cookie_consent_content_buttons', $an_content, $notification); } elseif ($notification['cookie_consent_content_builder_type'] == 'editor') { $an_content = $notification['content'] ? do_shortcode(wp_kses_post($notification['content'])) : ''; } } return $an_content; } function an_load_consent_categories($type='') { if ($type == 'script') { $file_path = ADVANCED_NOTIFICATIONS_ROOT_PATH . 'addons/cookie-consent/assets/json/script-categories.json'; } elseif ($type == 'cookie') { $file_path = ADVANCED_NOTIFICATIONS_ROOT_PATH . 'addons/cookie-consent/assets/json/cookie-categories.json'; } elseif ($type == 'iframe') { $file_path = ADVANCED_NOTIFICATIONS_ROOT_PATH . 'addons/cookie-consent/assets/json/iframe-categories.json'; } if (file_exists($file_path)) { $json = file_get_contents($file_path); $categories = json_decode($json, true); if (is_array($categories)) { return $categories; } } return []; } function an_extract_multiple_json_vars($js_code) { $results = []; preg_match_all('/var\s+(\w+)\s*=\s*(\{.*?\})\s*;/s', $js_code, $matches, PREG_SET_ORDER); foreach ($matches as $match) { $var_name = $match[1]; $json_candidate = str_replace('\/', '/', $match[2]); $data = json_decode($json_candidate, true); if (json_last_error() === JSON_ERROR_NONE) { $results[$var_name] = $data; } } if (empty($results)) { $json_candidate = str_replace('\/', '/', $js_code); $data = json_decode($json_candidate, true); if (json_last_error() === JSON_ERROR_NONE) { $results['__plain_json__'] = $data; } } return $results; } function an_classify_script_from_json($script_src_or_inline) { $src = trim($script_src_or_inline); $lower = strtolower($src); if ($this->an_extract_multiple_json_vars($lower)) { return 'necessary'; } $categories = $this->an_load_consent_categories('script'); if (empty($categories)) { return 'other'; } foreach ($categories as $category => $patterns) { foreach ($patterns as $pattern) { if (strpos($lower, strtolower($pattern)) !== false) { return $category; } } } return 'other'; } function an_classify_cookie_from_json($cookie_name, $cookie_value = '') { $name = strtolower(trim($cookie_name)); $value = strtolower(trim($cookie_value)); $categories = $this->an_load_consent_categories('cookie'); if (empty($categories)) { return 'other'; } foreach ($categories as $category => $patterns) { foreach ($patterns as $pattern) { $pattern = strtolower($pattern); if (strpos($name, $pattern) !== false || strpos($value, $pattern) !== false) { return $category; } } } return 'other'; } function an_classify_iframe_from_json( $iframe_src ) { // Normalize inputs $src = strtolower( trim( $iframe_src ) ); $categories = $this->an_load_consent_categories('iframe'); if ( empty( $categories ) ) { return 'other'; } // 1) Exact or contains match on src first (most reliable) foreach ( $categories as $category => $patterns ) { foreach ( $patterns as $pattern ) { $pattern = strtolower( $pattern ); if ( $pattern === $src || ( $src !== '' && strpos( $src, $pattern ) !== false ) ) { return $category; } } } // 2) Heuristic: if src contains known video/audio/map keywords -> functional $heuristic_keywords = array( 'youtube', 'vimeo', 'maps', 'spotify', 'soundcloud', 'calendly', 'docs.google' ); foreach ( $heuristic_keywords as $kw ) { if ( $src !== '' && strpos( $src, $kw ) !== false ) { return 'functional'; } } // 3) Default fallback return 'other'; } function an_pre_register_cookie_consent_notification($notification,$args) { // cookie consent $notification['cookie_consent_content_builder_type'] = (isset($args['cookie_consent_content_builder_type'])) ? $args['cookie_consent_content_builder_type'] : 'default'; $notification['cookie_consent_content_title'] = (isset($args['cookie_consent_content_title'])) ? $args['cookie_consent_content_title'] : null; $notification['cookie_consent_content_body'] = (isset($args['cookie_consent_content_body_eis_html'])) ? $args['cookie_consent_content_body_eis_html'] : ''; $notification['cookie_consent_policy_page'] = (isset($args['cookie_consent_policy_page'])) ? $args['cookie_consent_policy_page'] : 'default'; $notification['an_accept_cookies_button_text'] = (isset($args['an_accept_cookies_button_text'])) ? $args['an_accept_cookies_button_text'] : ''; $notification['an_reject_cookies_button_text'] = (isset($args['an_reject_cookies_button_text'])) ? $args['an_reject_cookies_button_text'] : ''; $notification['an_manage_cookies_button_text'] = (isset($args['an_manage_cookies_button_text'])) ? $args['an_manage_cookies_button_text'] : ''; $notification['an_manage_cookies_settings'] = (isset($args['an_manage_cookies_settings'])) ? $args['an_manage_cookies_settings'] : ''; $notification['manage_preferences_content_title'] = (isset($args['manage_preferences_content_title'])) ? $args['manage_preferences_content_title'] : ''; $notification['manage_preferences_content_body'] = (isset($args['manage_preferences_content_body_eis_html'])) ? $args['manage_preferences_content_body_eis_html'] : ''; $notification['manage_preferences_necessary_title'] = (isset($args['manage_preferences_necessary_title'])) ? $args['manage_preferences_necessary_title'] : ''; $notification['manage_preferences_necessary_text'] = (isset($args['manage_preferences_necessary_text'])) ? $args['manage_preferences_necessary_text'] : ''; $notification['manage_preferences_functional_title'] = (isset($args['manage_preferences_functional_title'])) ? $args['manage_preferences_functional_title'] : ''; $notification['manage_preferences_functional_text'] = (isset($args['manage_preferences_functional_text'])) ? $args['manage_preferences_functional_text'] : ''; $notification['manage_preferences_analytics_title'] = (isset($args['manage_preferences_analytics_title'])) ? $args['manage_preferences_analytics_title'] : ''; $notification['manage_preferences_analytics_text'] = (isset($args['manage_preferences_analytics_text'])) ? $args['manage_preferences_analytics_text'] : ''; $notification['manage_preferences_marketing_title'] = (isset($args['manage_preferences_marketing_title'])) ? $args['manage_preferences_marketing_title'] : ''; $notification['manage_preferences_marketing_text'] = (isset($args['manage_preferences_marketing_text'])) ? $args['manage_preferences_marketing_text'] : ''; $notification['manage_preferences_accept_cookies_button_text'] = (isset($args['manage_preferences_accept_cookies_button_text'])) ? $args['manage_preferences_accept_cookies_button_text'] : ''; $notification['manage_preferences_save_cookies_button_text'] = (isset($args['manage_preferences_save_cookies_button_text'])) ? $args['manage_preferences_save_cookies_button_text'] : ''; return $notification; } function cookie_consent_content_builder_type() { $cookie_consent_content_builder_type = array( 'default' => __('Default', 'an-cookie-consent'), 'editor' => __('Editor', 'an-cookie-consent'), 'elementor_eis_disabled' => __('Elementor', 'an-cookie-consent') . ' - ' . __('PRO', 'an-cookie-consent'), ); return apply_filters('an_cookie_consent_content_builder_type', $cookie_consent_content_builder_type); } } $an_cookie_consent = new AdvancedNotificationsCookieConsent();