// 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;
}
}