' . __( 'Make sure your website complies with the latest cookie consent laws', 'cookie-notice' ) . '
' . __( 'Run compliance check to learn if your website complies with the lastes consent record storage and cookie blocking requirements.', 'cookie-notice' ) . '
' . __( "We're sorry to see you go. Could you please tell us what happened?", 'cookie-notice' ) . '
';
foreach ( array(
'1' => __( "I couldn't figure out how to make it work.", 'cookie-notice' ),
'2' => __( 'I found another plugin to use for the same task.', 'cookie-notice' ),
'3' => __( 'The Cookie Compliance banner is too big.', 'cookie-notice' ),
'4' => __( 'The Cookie Compliance consent choices (Silver, Gold, Platinum) are confusing.', 'cookie-notice' ),
'5' => __( 'The Cookie Compliance default settings are too strict.', 'cookie-notice' ),
'6' => __( 'The web application user interface is not clear to me.', 'cookie-notice' ),
'7' => __( "Support isn't timely.", 'cookie-notice' ),
'8' => __( 'Other', 'cookie-notice' )
) as $option => $text ) {
echo '
';
}
echo '
';
}
/**
* Send data about deactivation of the plugin.
*
* @return void
*/
public function deactivate_plugin() {
// check permissions
if ( ! current_user_can( 'install_plugins' ) || wp_verify_nonce( $_POST['nonce'], 'cn-deactivate-plugin' ) === false )
return;
if ( isset( $_POST['option_id'] ) ) {
$option_id = (int) $_POST['option_id'];
$other = esc_html( $_POST['other'] );
// avoid fake submissions
if ( $option_id == 8 && $other == '' )
wp_send_json_success();
wp_remote_post(
'https://hu-manity.co/wp-json/api/v1/forms/', array(
'timeout' => 15,
'blocking' => true,
'headers' => array(),
'body' => array(
'id' => 1,
'option' => $option_id,
'other' => $other,
'referrer' => get_site_url()
)
)
);
wp_send_json_success();
}
wp_send_json_error();
}
/**
* Get allowed script blocking HTML.
*
* @return array
*/
public function get_allowed_html() {
return apply_filters(
'cn_refuse_code_allowed_html',
array_merge(
wp_kses_allowed_html( 'post' ),
array(
'script' => array(
'type' => array(),
'src' => array(),
'charset' => array(),
'async' => array()
),
'noscript' => array(),
'style' => array(
'type' => array()
),
'iframe' => array(
'src' => array(),
'height' => array(),
'width' => array(),
'frameborder' => array(),
'allowfullscreen' => array()
)
)
)
);
}
/**
* Helper: convert hex color to rgb color.
*
* @param type $color
* @return array
*/
public function hex2rgb( $color ) {
if ( $color[0] == '#' )
$color = substr( $color, 1 );
if ( strlen( $color ) == 6 )
list( $r, $g, $b ) = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] );
elseif ( strlen( $color ) == 3 )
list( $r, $g, $b ) = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] );
else
return false;
$r = hexdec( $r );
$g = hexdec( $g );
$b = hexdec( $b );
return array( $r, $g, $b );
}
/**
* Helper: Convert undersocores to CamelCase/
*
* @param type $string
* @param bool $capitalize_first_char
* @return string
*/
public function underscores_to_camelcase( $string, $capitalize_first_char = false ) {
$str = str_replace( ' ', '', ucwords( str_replace( '_', ' ', $string ) ) );
if ( ! $capitalize_first_char ) {
$str[0] = strtolower( $str[0] );
}
return $str;
}
/**
* Check legacy parameters that were yes/no strings.
*
* @param array $options
* @param array $params
* @return array
*/
public function check_legacy_params( $options, $params ) {
foreach ( $params as $param ) {
if ( array_key_exists( $param, $options ) && ! is_bool( $options[$param] ) )
$options[$param] = $options[$param] === 'yes';
}
return $options;
}
/**
* Merge multidimensional associative arrays.
* Works only with strings, integers and arrays as keys. Values can be any type but they have to have same type to be kept in the final array.
* Every array should have the same type of elements. Only keys from $defaults array will be kept in the final array unless $siblings are not empty.
* $siblings examples: array( '=>', 'only_first_level', 'first_level=>second_level', 'first_key=>next_key=>sibling' ) and so on.
* Single '=>' means that all siblings of the highest level will be kept in the final array.
*
* @param array $default Array with defaults values
* @param array $array Array to merge
* @param boolean|array $siblings Whether to allow "string" siblings to copy from $array if they do not exist in $defaults, false otherwise
* @return array Merged arrays
*/
public function multi_array_merge( $defaults, $array, $siblings = false ) {
// make a copy for better performance and to prevent $default override in foreach
$copy = $defaults;
// prepare siblings for recursive deeper level
$new_siblings = array();
// allow siblings?
if ( ! empty( $siblings ) && is_array( $siblings ) ) {
foreach ( $siblings as $sibling ) {
// highest level siblings
if ( $sibling === '=>' ) {
// copy all non-existent string siblings
foreach( $array as $key => $value ) {
if ( is_string( $key ) && ! array_key_exists( $key, $defaults ) ) {
$defaults[$key] = null;
}
}
// sublevel siblings
} else {
// explode siblings
$ex = explode( '=>', $sibling );
// copy all non-existent siblings
foreach ( array_keys( $array[$ex[0]] ) as $key ) {
if ( ! array_key_exists( $key, $defaults[$ex[0]] ) )
$defaults[$ex[0]][$key] = null;
}
// more than one sibling child?
if ( count( $ex ) > 1 )
$new_siblings[$ex[0]] = array( substr_replace( $sibling, '', 0, strlen( $ex[0] . '=>' ) ) );
// no more sibling children
else
$new_siblings[$ex[0]] = false;
}
}
}
// loop through first array
foreach ( $defaults as $key => $value ) {
// integer key?
if ( is_int( $key ) ) {
$copy = array_unique( array_merge( $defaults, $array ), SORT_REGULAR );
break;
// string key?
} elseif ( is_string( $key ) && isset( $array[$key] ) ) {
// string, boolean, integer or null values?
if ( ( is_string( $value ) && is_string( $array[$key] ) ) || ( is_bool( $value ) && is_bool( $array[$key] ) ) || ( is_int( $value ) && is_int( $array[$key] ) ) || is_null( $value ) )
$copy[$key] = $array[$key];
// arrays
elseif ( is_array( $value ) && isset( $array[$key] ) && is_array( $array[$key] ) ) {
if ( empty( $value ) )
$copy[$key] = $array[$key];
else
$copy[$key] = $this->multi_array_merge( $defaults[$key], $array[$key], ( isset( $new_siblings[$key] ) ? $new_siblings[$key] : false ) );
}
}
}
return $copy;
}
/**
* Get plugin mode
*
* @return type
*/
public function get_status() {
return $this->status; // notice, active, pending etc.
}
/**
* Indicate if current page is the Cookie Policy page
*
* @return bool
*/
public function is_cookie_policy_page() {
$see_more = $this->options['general']['see_more_opt'];
if ( $see_more['link_type'] !== 'page' )
return false;
$cp_id = $see_more['id'];
$cp_slug = get_post_field( 'post_name', $cp_id );
$current_page = sanitize_post( $GLOBALS['wp_the_query']->get_queried_object() );
return $current_page->post_name === $cp_slug;
}
}
/**
* Initialize Cookie Notice.
*/
function Cookie_Notice() {
static $instance;
// first call to instance() initializes the plugin
if ( $instance === null || ! ( $instance instanceof Cookie_Notice ) )
$instance = Cookie_Notice::instance();
return $instance;
}
$cookie_notice = Cookie_Notice();