| @@ -1,6 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace EverCompare\Frontend; |
| 3 | + | |
| 4 | +defined( 'ABSPATH' ) || exit; | |
| 3 | 5 | /** |
| 4 | 6 | * Button handlers class |
| 5 | 7 | */ |
| 6 | 8 | class Manage_Compare { |
| @@ -124,15 +126,8 @@ | ||
| 124 | 126 | if( ever_compare_get_option( 'open_popup', 'ever_compare_settings_tabs', 'on' ) === 'on' ){ |
| 125 | 127 | add_action( 'wp_footer', [ $this, 'pop_up_html' ] ); |
| 126 | 128 | } |
| 127 | 129 | |
| 128 | - /** | |
| 129 | - * Manage maximum product added message | |
| 130 | - */ | |
| 131 | - if( isset( $_COOKIE[ 'ever_compare_max_limit' ] ) && $_COOKIE[ 'ever_compare_max_limit' ] == 'yes' ) { | |
| 132 | - setcookie( 'ever_compare_max_limit', 'no', 0, COOKIEPATH, COOKIE_DOMAIN, false, false ); | |
| 133 | - $this->reached_max_limit = true; | |
| 134 | - } | |
| 135 | 130 | |
| 136 | 131 | |
| 137 | 132 | } |
| 138 | 133 | |
| @@ -169,9 +164,9 @@ | ||
| 169 | 164 | * [pop_up_html] |
| 170 | 165 | * @return [void] |
| 171 | 166 | */ |
| 172 | 167 | public function pop_up_html(){ |
| 173 | - echo '<div class="htcompare-popup"><div class="htcompare-popup-content-area"><span class="htcompare-popup-close"> </span>'.do_shortcode( '[evercompare_table]' ).'</div></div>'; | |
| 168 | + echo '<div class="htcompare-popup"><div class="htcompare-popup-content-area"><button type="button" class="htcompare-popup-close" aria-label="' . esc_attr__( 'Close compare popup', 'ever-compare' ) . '"> </button><div class="htcompare-table" data-ajax-load="true"></div></div></div>'; | |
| 174 | 169 | } |
| 175 | 170 | |
| 176 | 171 | /** |
| 177 | 172 | * [reached_max_limit_message] |
| @@ -199,12 +194,12 @@ | ||
| 199 | 194 | } |
| 200 | 195 | |
| 201 | 196 | $ids = $this->get_compared_products(); |
| 202 | 197 | |
| 203 | - if ( isset( $_GET['evcompare'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 198 | + if ( ! empty( $_GET['evcompare'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 204 | 199 | $query_perametter_ids = sanitize_text_field( wp_unslash($_GET['evcompare']) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 205 | 200 | if( !empty( $query_perametter_ids ) ){ |
| 206 | - $ids = explode( ',', $query_perametter_ids ); | |
| 201 | + $ids = array_filter( array_map( 'absint', explode( ',', $query_perametter_ids ) ) ); | |
| 207 | 202 | } |
| 208 | 203 | } |
| 209 | 204 | |
| 210 | 205 | $buttonText = ever_compare_get_option( 'shareable_link_button_text','ever_compare_table_settings_tabs','Copy shareable link' ) ? ever_compare_get_option( 'shareable_link_button_text','ever_compare_table_settings_tabs','Copy shareable link' ) : esc_html__( 'Copy shareable link', 'ever-compare' ); |
| @@ -236,9 +231,8 @@ | ||
| 236 | 231 | $products = $this->get_compared_products(); |
| 237 | 232 | |
| 238 | 233 | // Reached Maximum Limit |
| 239 | 234 | if( $this->reached_max_limit() ) { |
| 240 | - setcookie( 'ever_compare_max_limit', 'yes', 0, COOKIEPATH, COOKIE_DOMAIN, false, false ); | |
| 241 | 235 | $this->compare_json_response(); |
| 242 | 236 | } |
| 243 | 237 | |
| 244 | 238 | $products[] = $id; |
| @@ -288,8 +282,10 @@ | ||
| 288 | 282 | $this->reached_max_limit = false; |
| 289 | 283 | } |
| 290 | 284 | } |
| 291 | 285 | |
| 286 | + $products = array_values( $products ); | |
| 287 | + | |
| 292 | 288 | if ( empty( $products ) ) { |
| 293 | 289 | setcookie( $cookie_name, false, 0, COOKIEPATH, COOKIE_DOMAIN, false, false ); |
| 294 | 290 | $_COOKIE[$cookie_name] = false; |
| 295 | 291 | } else { |
| @@ -336,12 +332,12 @@ | ||
| 336 | 332 | $ids = $this->get_compared_products(); |
| 337 | 333 | |
| 338 | 334 | // For shareable link |
| 339 | 335 | $shareable_link = ever_compare_get_option('enable_shareable_link','ever_compare_table_settings_tabs','off'); |
| 340 | - if ( ( $shareable_link === 'on' ) && isset( $_GET['evcompare'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 336 | + if ( ( $shareable_link === 'on' ) && ! empty( $_GET['evcompare'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 341 | 337 | $query_perametter_ids = sanitize_text_field( wp_unslash($_GET['evcompare']) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 342 | 338 | if( !empty( $query_perametter_ids ) ){ |
| 343 | - $ids = explode( ',', $query_perametter_ids ); | |
| 339 | + $ids = array_filter( array_map( 'absint', explode( ',', $query_perametter_ids ) ) ); | |
| 344 | 340 | } |
| 345 | 341 | } |
| 346 | 342 | |
| 347 | 343 | if ( empty( $ids ) ) { |
| @@ -418,9 +414,9 @@ | ||
| 418 | 414 | ); |
| 419 | 415 | |
| 420 | 416 | $default_show = array( |
| 421 | 417 | 'title' => esc_html__( 'title', 'ever-compare' ), |
| 422 | - 'ratting' => esc_html__( 'ratting', 'ever-compare' ), | |
| 418 | + 'ratting' => esc_html__( 'Rating', 'ever-compare' ), | |
| 423 | 419 | 'price' => esc_html__( 'price', 'ever-compare' ), |
| 424 | 420 | 'add_to_cart' => esc_html__( 'add_to_cart', 'ever-compare' ), |
| 425 | 421 | 'description' => esc_html__( 'description', 'ever-compare' ), |
| 426 | 422 | 'availability' => esc_html__( 'availability', 'ever-compare' ), |
| @@ -472,9 +468,10 @@ | ||
| 472 | 468 | switch ( $type ) { |
| 473 | 469 | case 'primary': |
| 474 | 470 | ?> |
| 475 | 471 | <div class="htcompare-primary-content-area"> |
| 476 | - <a href="#" class="htcompare-remove" data-product_title="<?php echo esc_attr( $product['title'] ); ?>" data-product_id="<?php echo esc_attr( $product['id'] ); ?>"> </a> | |
| 472 | + <?php /* translators: %s: product title */ ?> | |
| 473 | + <a href="#" class="htcompare-remove" data-product_title="<?php echo esc_attr( $product['title'] ); ?>" data-product_id="<?php echo esc_attr( $product['id'] ); ?>" aria-label="<?php echo esc_attr( sprintf( __( 'Remove %s from compare', 'ever-compare' ), $product['title'] ) ); ?>"> </a> | |
| 477 | 474 | <a href="<?php echo esc_url(get_permalink( $product['id'] )); ?>" class="htcompare-product-image"> |
| 478 | 475 | <?php echo wp_kses_post($product['primary']['image']); ?> |
| 479 | 476 | </a> |
| 480 | 477 | </div> |
| @@ -604,9 +601,9 @@ | ||
| 604 | 601 | * @return [array] product id list |
| 605 | 602 | */ |
| 606 | 603 | public function is_product_in_compare( $id ) { |
| 607 | 604 | $list = $this->get_compared_products(); |
| 608 | - return in_array( strval($id), $list, true ); | |
| 605 | + return in_array( absint($id), $list, true ); | |
| 609 | 606 | } |
| 610 | 607 | |
| 611 | 608 | /** |
| 612 | 609 | * [get_compared_products] |
| @@ -614,9 +611,12 @@ | ||
| 614 | 611 | */ |
| 615 | 612 | public function get_compared_products() { |
| 616 | 613 | $cookie_name = $this->get_cookie_name(); |
| 617 | 614 | if(!empty( $_COOKIE[ $cookie_name ] )) { |
| 618 | - return json_decode( sanitize_text_field(wp_unslash( $_COOKIE[ $cookie_name ] )), true ); | |
| 615 | + $decoded = json_decode( sanitize_text_field(wp_unslash( $_COOKIE[ $cookie_name ] )), true ); | |
| 616 | + if ( is_array( $decoded ) ) { | |
| 617 | + return array_filter( array_map( 'absint', $decoded ) ); | |
| 618 | + } | |
| 619 | 619 | } |
| 620 | 620 | return []; |
| 621 | 621 | } |
| 622 | 622 | |