gging_on' => false, 'notify_animate_hide' => true, 'notify_animate_show' => false, 'notify_div_id' => '#cookie-law-info-bar', 'notify_position_horizontal' => 'right', // left | right 'notify_position_vertical' => 'bottom', // 'top' = header | 'bottom' = footer 'notify_message' => addslashes( '
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
[cookie_settings margin="0px 5px 0px 0px"][cookie_accept_all]
' ), 'scroll_close' => false, 'scroll_close_reload' => false, 'accept_close_reload' => false, 'reject_close_reload' => false, 'showagain_background' => '#fff', 'showagain_border' => '#000', 'showagain_text' => addslashes( 'Manage consent' ), 'showagain_div_id' => '#cookie-law-info-again', 'showagain_tab' => true, 'showagain_x_position' => '100px', 'text' => '#333333', 'use_colour_picker' => true, 'show_once_yn' => false, // this is a new feature so default = switched off 'show_once' => '10000', // 8 seconds 'is_GMT_on' => true, 'as_popup' => false, // version 1.7.1 onwards this option is merged with `cookie_bar_as` 'popup_overlay' => true, 'bar_heading_text' => '', 'cookie_bar_as' => 'banner', 'popup_showagain_position' => 'bottom-right', // bottom-right | bottom-left | top-right | top-left 'widget_position' => 'left', // left | right ); $settings_v0_9 = apply_filters( 'wt_cli_plugin_settings', $settings_v0_9 ); return $key != '' ? $settings_v0_9[ $key ] : $settings_v0_9; } /** Returns JSON object containing the settings for the main script REFACTOR / DEBUG: may need to use addslashes( ... ) else breaks JSON */ public static function get_json_settings() { $settings = self::get_settings(); // DEBUG hex: // preg_match('/^#[a-f0-9]{6}|#[a-f0-9]{3}$/i', $hex) // DEBUG json_encode - issues across different versions of PHP! // $str = json_encode( $slim_settings, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP ); // Slim down JSON objects to the bare bones: $slim_settings = array( 'animate_speed_hide' => $settings['animate_speed_hide'], 'animate_speed_show' => $settings['animate_speed_show'], 'background' => $settings['background'], 'border' => $settings['border'], 'border_on' => false, // $settings['border_on'], 'button_1_button_colour' => $settings['button_1_button_colour'], 'button_1_button_hover' => ( self::su_hex_shift( $settings['button_1_button_colour'], 'down', 20 ) ), 'button_1_link_colour' => $settings['button_1_link_colour'], 'button_1_as_button' => $settings['button_1_as_button'], 'button_1_new_win' => $settings['button_1_new_win'], 'button_2_button_colour' => $settings['button_2_button_colour'], 'button_2_button_hover' => ( self::su_hex_shift( $settings['button_2_button_colour'], 'down', 20 ) ), 'button_2_link_colour' => $settings['button_2_link_colour'], 'button_2_as_button' => $settings['button_2_as_button'], 'button_2_hidebar' => $settings['button_2_hidebar'], 'button_3_button_colour' => $settings['button_3_button_colour'], 'button_3_button_hover' => ( self::su_hex_shift( $settings['button_3_button_colour'], 'down', 20 ) ), 'button_3_link_colour' => $settings['button_3_link_colour'], 'button_3_as_button' => $settings['button_3_as_button'], 'button_3_new_win' => $settings['button_3_new_win'], 'button_4_button_colour' => $settings['button_4_button_colour'], 'button_4_button_hover' => ( self::su_hex_shift( $settings['button_4_button_colour'], 'down', 20 ) ), 'button_4_link_colour' => $settings['button_4_link_colour'], 'button_4_as_button' => $settings['button_4_as_button'], 'button_7_button_colour' => $settings['button_7_button_colour'], 'button_7_button_hover' => ( self::su_hex_shift( $settings['button_7_button_colour'], 'down', 20 ) ), 'button_7_link_colour' => $settings['button_7_link_colour'], 'button_7_as_button' => $settings['button_7_as_button'], 'button_7_new_win' => $settings['button_7_new_win'], 'font_family' => $settings['font_family'], 'header_fix' => $settings['header_fix'], 'notify_animate_hide' => $settings['notify_animate_hide'], 'notify_animate_show' => $settings['notify_animate_show'], 'notify_div_id' => $settings['notify_div_id'], 'notify_position_horizontal' => $settings['notify_position_horizontal'], 'notify_position_vertical' => $settings['notify_position_vertical'], 'scroll_close' => $settings['scroll_close'], 'scroll_close_reload' => $settings['scroll_close_reload'], 'accept_close_reload' => $settings['accept_close_reload'], 'reject_close_reload' => $settings['reject_close_reload'], 'showagain_tab' => $settings['showagain_tab'], 'showagain_background' => $settings['showagain_background'], 'showagain_border' => $settings['showagain_border'], 'showagain_div_id' => $settings['showagain_div_id'], 'showagain_x_position' => $settings['showagain_x_position'], 'text' => $settings['text'], 'show_once_yn' => $settings['show_once_yn'], 'show_once' => $settings['show_once'], 'logging_on' => $settings['logging_on'], 'as_popup' => $settings['as_popup'], 'popup_overlay' => $settings['popup_overlay'], 'bar_heading_text' => $settings['bar_heading_text'], 'cookie_bar_as' => $settings['cookie_bar_as'], 'popup_showagain_position' => $settings['popup_showagain_position'], 'widget_position' => $settings['widget_position'], ); // $str = json_encode( $slim_settings ); /* DEBUG: if ( $str == null | $str == '') { $str = 'error: json is empty'; } */ return $slim_settings; } /** Returns sanitised content based on field-specific rules defined here Used for both read AND write operations */ public static function sanitise_settings( $key, $value ) { $ret = null; switch ( $key ) { // Convert all boolean values from text to bool: case 'is_on': case 'is_reject_on': case 'is_eu_on': case 'logging_on': case 'border_on': case 'notify_animate_show': case 'notify_animate_hide': case 'showagain_tab': case 'use_colour_picker': case 'button_1_new_win': case 'button_1_as_button': case 'button_2_new_win': case 'button_2_as_button': case 'button_2_hidebar': case 'button_3_new_win': case 'button_3_as_button': case 'button_4_new_win': case 'button_4_as_button': case 'button_7_new_win': case 'button_7_as_button': case 'scroll_close': case 'scroll_close_reload': case 'accept_close_reload': case 'reject_close_reload': case 'show_once_yn': case 'header_fix': case 'is_GMT_on': case 'as_popup': case 'popup_overlay': case 'thirdparty_on_field': case 'third_party_default_state': case 'ccpa_enabled': case 'button_6_as_link': case 'ccpa_region_based': case 'ccpa_enable_bar': if ( $value == 'true' || $value === true ) { $ret = true; } elseif ( $value == 'false' || $value === false ) { $ret = false; } else { // Unexpected value returned from radio button, go fix the HTML. // Failover = assign null. $ret = 'fffffff'; } break; // Any hex colour e.g. '#f00', '#FE01ab' '#ff0000' but not 'f00' or 'ff0000': case 'background': case 'text': case 'border': case 'showagain_background': case 'showagain_border': case 'button_1_link_colour': case 'button_1_button_colour': case 'button_2_link_colour': case 'button_2_button_colour': case 'button_3_link_colour': case 'button_3_button_colour': case 'button_4_link_colour': case 'button_4_button_colour': case 'button_7_link_colour': case 'button_7_button_colour': if ( preg_match( '/^#[a-f0-9]{6}|#[a-f0-9]{3}$/i', $value ) ) { // Was: '/^#([0-9a-fA-F]{1,2}){3}$/i' which allowed e.g. '#00dd' (error) $ret = $value; } else { // Failover = assign '#000' (black) $ret = '#000'; } break; // Allow some HTML, but no JavaScript. Note that deliberately NOT stripping out line breaks here, that's done when sending JavaScript parameter elsewhere: case 'notify_message': case 'bar_heading_text': case 'ccpa_content': case 'ccpa_gdpr_content': case 'gdpr_content': $ret = wp_kses( $value, self::allowed_html(), self::allowed_protocols() ); break; // URLs only: case 'button_1_url': case 'button_2_url': case 'button_3_url': case 'button_4_url': case 'button_7_url': $ret = esc_url( $value ); break; // Basic sanitisation for all the rest: default: $ret = self::wt_cli_clean( $value ); break; } if ( ( 'is_eu_on' === $key || 'logging_on' == $key ) && 'fffffff' === $ret ) { $ret = false; } return $ret; } public static function wt_cli_clean( $var ) { if ( is_array( $var ) ) { return array_map( 'self::wt_cli_clean', $var ); } else { return is_scalar( $var ) ? sanitize_text_field( $var ) : $var; } } public static function get_non_necessary_cookie_ids() { global $wpdb; $args = array( 'post_type' => CLI_POST_TYPE, 'posts_per_page' => -1, 'suppress_filters' => false, 'meta_query' => array( array( 'key' => '_cli_cookie_sensitivity', 'value' => 'non-necessary', ), ), ); $posts = get_posts( $args ); if ( ! $posts ) { return; } $cookie_slugs = array(); if ( $posts ) { foreach ( $posts as $post ) { $cookie_slugs[] = get_post_meta( $post->ID, '_cli_cookie_slugid', true ); } } return $cookie_slugs; } /** * Color shift a hex value by a specific percentage factor * By http://www.phpkode.com/source/s/shortcodes-ultimate/shortcodes-ultimate/lib/color.php * Adapted by Richard Ashby; amended error handling to use failovers not messages, so app continues * * @param string $supplied_hex Any valid hex value. Short forms e.g. #333 accepted. * @param string $shift_method How to shift the value e.g( +,up,lighter,>) * @param integer $percentage Percentage in range of [0-100] to shift provided hex value by * @return string shifted hex value * @version 1.0 2008-03-28 */ public static function su_hex_shift( $supplied_hex, $shift_method, $percentage = 50 ) { $shifted_hex_value = null; $valid_shift_option = false; $current_set = 1; $RGB_values = array(); $valid_shift_up_args = array( 'up', '+', 'lighter', '>' ); $valid_shift_down_args = array( 'down', '-', 'darker', '<' ); $shift_method = strtolower( trim( $shift_method ) ); // Check Factor if ( ! is_numeric( $percentage ) || ( $percentage = (int) $percentage ) < 0 || $percentage > 100 ) { // trigger_error( "Invalid factor", E_USER_ERROR ); return $supplied_hex; } // Check shift method foreach ( array( $valid_shift_down_args, $valid_shift_up_args ) as $options ) { foreach ( $options as $method ) { if ( $method == $shift_method ) { $valid_shift_option = ! $valid_shift_option; $shift_method = ( $current_set === 1 ) ? '+' : '-'; break 2; } } ++$current_set; } if ( ! $valid_shift_option ) { // trigger_error( "Invalid shift method", E_USER_ERROR ); return $supplied_hex; } // Check Hex string switch ( strlen( $supplied_hex = ( str_replace( '#', '', trim( $supplied_hex ) ) ) ) ) { case 3: if ( preg_match( '/^([0-9a-f])([0-9a-f])([0-9a-f])/i', $supplied_hex ) ) { $supplied_hex = preg_replace( '/^([0-9a-f])([0-9a-f])([0-9a-f])/i', '\\1\\1\\2\\2\\3\\3', $supplied_hex ); } else { // trigger_error( "Invalid hex color value", E_USER_ERROR ); return $supplied_hex; } break; case 6: if ( ! preg_match( '/^[0-9a-f]{2}[0-9a-f]{2}[0-9a-f]{2}$/i', $supplied_hex ) ) { // trigger_error( "Invalid hex color value", E_USER_ERROR ); return $supplied_hex; } break; default: // trigger_error( "Invalid hex color length", E_USER_ERROR ); return $supplied_hex; } // Start shifting $RGB_values['R'] = hexdec( $supplied_hex[0] . $supplied_hex[1] ); $RGB_values['G'] = hexdec( $supplied_hex[2] . $supplied_hex[3] ); $RGB_values['B'] = hexdec( $supplied_hex[4] . $supplied_hex[5] ); foreach ( $RGB_values as $c => $v ) { switch ( $shift_method ) { case '-': $amount = round( ( ( 255 - $v ) / 100 ) * $percentage ) + $v; break; case '+': $amount = $v - round( ( $v / 100 ) * $percentage ); break; default: // trigger_error( "Oops. Unexpected shift method", E_USER_ERROR ); return $supplied_hex; } $shifted_hex_value .= $current_value = ( strlen( $decimal_to_hex = dechex( $amount ) ) < 2 ) ? '0' . $decimal_to_hex : $decimal_to_hex; } return '#' . $shifted_hex_value; } /** Returns list of HTML tags allowed in HTML fields for use in declaration of wp_kset field validation. Deliberately allows class and ID declarations to assist with custom CSS styling. To customise further, see the excellent article at: http://ottopress.com/2010/wp-quickie-kses/ */ public static function allowed_html() { $allowed_html = array( // Allowed: ... // Not allowed: ... 'a' => array( 'href' => array(), 'id' => array(), 'class' => array(), 'title' => array(), 'target' => array(), 'rel' => array(), 'style' => array(), ), 'b' => array(), 'br' => array( 'id' => array(), 'class' => array(), 'style' => array(), ), 'div' => array( 'id' => array(), 'class' => array(), 'style' => array(), ), 'em' => array( 'id' => array(), 'class' => array(), 'style' => array(), ), 'i' => array(), 'img' => array( 'src' => array(), 'id' => array(), 'class' => array(), 'alt' => array(), 'style' => array(), ), 'p' => array( 'id' => array(), 'class' => array(), 'style' => array(), ), 'span' => array( 'id' => array(), 'class' => array(), 'style' => array(), ), 'strong' => array( 'id' => array(), 'class' => array(), 'style' => array(), ), 'label' => array( 'id' => array(), 'class' => array(), 'style' => array(), ), ); $html5_tags = array( 'article', 'section', 'aside', 'details', 'figcaption', 'figure', 'footer', 'header', 'main', 'mark', 'nav', 'summary', 'time' ); foreach ( $html5_tags as $html5_tag ) { $allowed_html[ $html5_tag ] = array( 'id' => array(), 'class' => array(), 'style' => array(), ); } return $allowed_html; } /** Returns list of allowed protocols, for use in declaration of wp_kset field validation. N.B. JavaScript is specifically disallowed for security reasons. Don't even trust your own database, as you don't know if another plugin has written to your settings. */ public static function allowed_protocols() { // Additional options: 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet' return array( 'http', 'https' ); } /** * Check if GTM is active **/ public static function cli_is_active_GTM() { if ( in_array( 'duracelltomi-google-tag-manager/duracelltomi-google-tag-manager-for-wordpress.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { return true; } } /* * * Patch script while updating versions */ public static function cli_patches() { $options = self::get_settings(); // ========bar as widget=========@since 1.7.1 if ( $options['cookie_bar_as'] == 'banner' && $options['as_popup'] == true ) { $options['cookie_bar_as'] = 'popup'; $options['as_popup'] = false; $options['popup_showagain_position'] = $options['notify_position_vertical'] . '-' . $options['notify_position_horizontal']; update_option( CLI_SETTINGS_FIELD, $options ); } // ========reject button missing issue=========@since 1.6.7 $message_bar_text = $options['notify_message']; // user turned on the reject button with his previous settings if ( isset( $options['is_reject_on'] ) && $options['is_reject_on'] == true ) { if ( strpos( $message_bar_text, 'cookie_reject' ) === false ) { $pattern = get_shortcode_regex(); if ( preg_match_all( '/' . $pattern . '/s', $message_bar_text, $matches ) ) { $shortcode_arr = $matches[0]; foreach ( $shortcode_arr as $shrtcode ) { if ( strpos( $shrtcode, 'cookie_button' ) !== false ) { $options['notify_message'] = str_replace( $shrtcode, $shrtcode . ' [cookie_reject]', $message_bar_text ); $options['is_reject_on'] = false; update_option( CLI_SETTINGS_FIELD, $options ); break; } } } } else { $options['is_reject_on'] = false; update_option( CLI_SETTINGS_FIELD, $options ); } } // ---------reject button missing issue------------ // bar heading text issue @since 1.6.7 $bar_version = '1.6.6'; $bar_heading_version = get_option( 'cli_heading_version' ); if ( $bar_heading_version != $bar_version ) { if ( isset( $options['bar_heading_text'] ) && $options['bar_heading_text'] == 'This website uses cookies' ) { $options['bar_heading_text'] = ''; update_option( CLI_SETTINGS_FIELD, $options ); update_option( 'cli_heading_version', $bar_version ); } } } /** * Check whether JS blocking is active or not * * @since 1.8.9 * @return bool */ public static function wt_cli_is_js_blocking_active() { $js_blocking_enabled = false; $js_option = self::get_js_option(); if ( $js_option === true && ! self::is_divi_enabled() ) { $js_blocking_enabled = true; } return apply_filters( 'wt_cli_enable_js_blocking', $js_blocking_enabled ); } /** * JS blocker will be disabled by default for existing customer * * @since 1.8.9 * @return bool */ public static function check_for_upgrade() { $plugin_settings = get_option( CLI_SETTINGS_FIELD ); if ( $plugin_settings === false ) { $transient_value = get_transient( '_wt_cli_first_time_activation' ); if ( $transient_value === false ) { set_transient( '_wt_cli_first_time_activation', true, 30 ); } return true; } return false; } public static function maybe_first_time_install() { $maybe_first_time = false; $activation_transient = wp_validate_boolean( get_transient( '_wt_cli_first_time_activation' ) ); if ( $activation_transient === true ) { $maybe_first_time = true; } return $maybe_first_time; } /** * Return js options * * @since 1.8.9 * @return bool,string */ public static function get_js_option() { $js_option = false; $js_option = get_option( 'cookielawinfo_js_blocking' ); if ( isset( $js_option ) && $js_option === 'yes' ) { return true; } return false; } /** * Check whether DIVI builder is active or not * * @since 2.0.4 * @return bool */ public static function is_divi_enabled() { return isset( $_GET['et_fb'] ) ? true : false; } }