' . __('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 '
'; 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 = ''; $cookies_content .= '