| @@ -93,8 +93,9 @@ | ||
| 93 | 93 | $view_mode = isset( $_GET['displayview'] ) ? sanitize_text_field( wp_unslash( $_GET['displayview'] ) ) : $view_mode; // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 94 | 94 | $tooltip_attr = 'list' == $view_mode && ! empty( $metas['tooltip_position_list'] ) ? esc_attr( $metas['tooltip_position_list'] ) : $metas['tooltip_position']; |
| 95 | 95 | $has_pro = rtsb()->has_pro(); |
| 96 | 96 | $has_filters = $has_pro && ! empty( $settings['tax_filter'] ); |
| 97 | + $grid_style = $settings['grid_style'] ?? 'even'; | |
| 97 | 98 | |
| 98 | 99 | // Set default layout. |
| 99 | 100 | if ( ! $has_pro && ! in_array( $layout, array_keys( Fns::free_layouts() ), true ) ) { |
| 100 | 101 | $layout = RenderHelpers::set_default_layout( $layout ); |
| @@ -99,8 +100,13 @@ | ||
| 99 | 100 | if ( ! $has_pro && ! in_array( $layout, array_keys( Fns::free_layouts() ), true ) ) { |
| 100 | 101 | $layout = RenderHelpers::set_default_layout( $layout ); |
| 101 | 102 | } |
| 102 | 103 | |
| 104 | + if ( $has_pro && 'masonry' === $grid_style ) { | |
| 105 | + $style_attr .= '; --rtsb-masonry-columns: ' . esc_attr( RenderHelpers::default_columns( $layout ) ); | |
| 106 | + $style_attr .= '; --rtsb-masonry-list-columns: ' . esc_attr( RenderHelpers::default_columns( $layout ) ); | |
| 107 | + } | |
| 108 | + | |
| 103 | 109 | // Container classes. |
| 104 | 110 | $container_classes = RenderHelpers::prepare_container_classes( $metas, $settings, $class ); |
| 105 | 111 | |
| 106 | 112 | // Pagination attributes. |
| @@ -141,8 +147,9 @@ | ||
| 141 | 147 | $script_generator = []; |
| 142 | 148 | $script_generator['layout'] = $layout_id; |
| 143 | 149 | $script_generator['rand'] = absint( $rand ); |
| 144 | 150 | $script_generator['isCarousel'] = preg_match( '/slider/', $layout ); |
| 151 | + $script_generator['isMasonry'] = $has_pro && 'masonry' === $grid_style; | |
| 145 | 152 | |
| 146 | 153 | // Register scripts in the wp_footer action. |
| 147 | 154 | add_action( |
| 148 | 155 | 'wp_footer', |
| @@ -188,9 +195,8 @@ | ||
| 188 | 195 | $this->html = ! empty( $settings['show_filter'] ) ? $hook_html . $start_wrapper : $start_wrapper; |
| 189 | 196 | |
| 190 | 197 | if ( $is_carousel ) { |
| 191 | 198 | $slider_data = RenderHelpers::slider_data( $settings, $raw_settings ); |
| 192 | - | |
| 193 | 199 | // Adding slider render attributes. |
| 194 | 200 | $this->add_attribute( |
| 195 | 201 | 'rtsb_slider_attr_' . $rand, |
| 196 | 202 | [ |
| @@ -240,11 +246,17 @@ | ||
| 240 | 246 | } |
| 241 | 247 | |
| 242 | 248 | $i = 0; |
| 243 | 249 | |
| 244 | - foreach ( $products as $product ) { | |
| 250 | + global $product; | |
| 251 | + $isGlobalProduct = false; | |
| 252 | + if ( $product instanceof WC_Product ) { | |
| 253 | + $isGlobalProduct = $product; | |
| 254 | + } | |
| 255 | + | |
| 256 | + foreach ( $products as $_product ) { | |
| 245 | 257 | $i++; |
| 246 | - $GLOBALS['product'] = $product; | |
| 258 | + $GLOBALS['product'] = $_product; | |
| 247 | 259 | $layout = RenderHelpers::filter_layout( esc_html( $settings['layout'] ), $template ); |
| 248 | 260 | |
| 249 | 261 | /** |
| 250 | 262 | * Before product template render hook. |
| @@ -251,9 +263,9 @@ | ||
| 251 | 263 | */ |
| 252 | 264 | do_action( 'rtsb_before_product_template_render' ); |
| 253 | 265 | |
| 254 | 266 | // Loop arg. |
| 255 | - $arg = $this->arg_dataset( $settings, $product, $settings['lazy_load'], $i ); | |
| 267 | + $arg = $this->arg_dataset( $settings, $_product, $settings['lazy_load'], $i ); | |
| 256 | 268 | |
| 257 | 269 | // Get template. |
| 258 | 270 | $html .= Fns::load_template( $template . $layout, $arg, true ); |
| 259 | 271 | |
| @@ -263,9 +275,11 @@ | ||
| 263 | 275 | do_action( 'rtsb_after_product_template_render' ); |
| 264 | 276 | |
| 265 | 277 | unset( $GLOBALS['product'] ); |
| 266 | 278 | } |
| 267 | - | |
| 279 | + if ( $isGlobalProduct ) { | |
| 280 | + $GLOBALS['product'] = $isGlobalProduct; | |
| 281 | + } | |
| 268 | 282 | return $html; |
| 269 | 283 | } |
| 270 | 284 | |
| 271 | 285 | /** |
| @@ -798,9 +812,13 @@ | ||
| 798 | 812 | $arg['image_link'] = $meta['image_link']; |
| 799 | 813 | $arg['grid'] .= 'rtsb-col-grid '; |
| 800 | 814 | |
| 801 | 815 | if ( ! $fullwidth ) { |
| 802 | - $arg['class'] .= ' even-grid-item '; | |
| 816 | + if ( 'masonry' === $meta['grid_type'] ) { | |
| 817 | + $arg['class'] .= 'masonry-grid-item '; | |
| 818 | + } else { | |
| 819 | + $arg['class'] .= 'even-grid-item '; | |
| 820 | + } | |
| 803 | 821 | } |
| 804 | 822 | |
| 805 | 823 | if ( ! empty( $meta['active_cat_slider'] ) ) { |
| 806 | 824 | $arg['class'] .= ' rtsb-slide-item swiper-slide animated rtFadeIn '; |
| @@ -907,10 +925,15 @@ | ||
| 907 | 925 | $is_list = preg_match( '/list/', $layout ); |
| 908 | 926 | $is_carousel = preg_match( '/slider/', $layout ); |
| 909 | 927 | |
| 910 | 928 | if ( ! $is_carousel ) { |
| 911 | - $arg['grid'] .= 'rtsb-col-grid '; | |
| 912 | - $arg['class'] .= ' even-grid-item '; | |
| 929 | + $arg['grid'] .= 'rtsb-col-grid '; | |
| 930 | + | |
| 931 | + if ( 'masonry' === $meta['grid_type'] ) { | |
| 932 | + $arg['class'] .= 'masonry-grid-item '; | |
| 933 | + } else { | |
| 934 | + $arg['class'] .= 'even-grid-item '; | |
| 935 | + } | |
| 913 | 936 | } else { |
| 914 | 937 | $arg['grid'] .= 'rtsb-col-grid rtsb-col-full rtsb-slide-item swiper-slide '; |
| 915 | 938 | } |
| 916 | 939 | |
| @@ -1389,8 +1412,46 @@ | ||
| 1389 | 1412 | return $this; |
| 1390 | 1413 | } |
| 1391 | 1414 | |
| 1392 | 1415 | /** |
| 1416 | + * Add link render attributes. | |
| 1417 | + * | |
| 1418 | + * @param array|string $element The HTML element. | |
| 1419 | + * @param array $url_control Array of link settings. | |
| 1420 | + * @param bool $overwrite Optional. Whether to overwrite existing | |
| 1421 | + * attribute. Default is false, not to overwrite. | |
| 1422 | + * | |
| 1423 | + * @return Render | |
| 1424 | + */ | |
| 1425 | + public function add_link_attributes( $element, array $url_control, $overwrite = false ) { | |
| 1426 | + $attributes = []; | |
| 1427 | + | |
| 1428 | + if ( ! empty( $url_control['url'] ) ) { | |
| 1429 | + $allowed_protocols = array_merge( wp_allowed_protocols(), [ 'skype', 'viber' ] ); | |
| 1430 | + | |
| 1431 | + $attributes['href'] = esc_url( $url_control['url'], $allowed_protocols ); | |
| 1432 | + } | |
| 1433 | + | |
| 1434 | + if ( ! empty( $url_control['is_external'] ) ) { | |
| 1435 | + $attributes['target'] = '_blank'; | |
| 1436 | + } | |
| 1437 | + | |
| 1438 | + if ( ! empty( $url_control['nofollow'] ) ) { | |
| 1439 | + $attributes['rel'] = 'nofollow'; | |
| 1440 | + } | |
| 1441 | + | |
| 1442 | + if ( ! empty( $url_control['custom_attributes'] ) ) { | |
| 1443 | + $attributes = array_merge( $attributes, Utils::parse_custom_attributes( $url_control['custom_attributes'] ) ); | |
| 1444 | + } | |
| 1445 | + | |
| 1446 | + if ( $attributes ) { | |
| 1447 | + $this->add_attribute( $element, $attributes, null, $overwrite ); | |
| 1448 | + } | |
| 1449 | + | |
| 1450 | + return $this; | |
| 1451 | + } | |
| 1452 | + | |
| 1453 | + /** | |
| 1393 | 1454 | * Get render attribute string. |
| 1394 | 1455 | * |
| 1395 | 1456 | * @param string $element The element. |
| 1396 | 1457 | * |
| @@ -1401,6 +1462,27 @@ | ||
| 1401 | 1462 | return ''; |
| 1402 | 1463 | } |
| 1403 | 1464 | |
| 1404 | 1465 | return Utils::render_html_attributes( $this->attributes[ $element ] ); |
| 1466 | + } | |
| 1467 | + | |
| 1468 | + /** | |
| 1469 | + * Function to render link attributes. | |
| 1470 | + * | |
| 1471 | + * @param string $id Element ID. | |
| 1472 | + * @param array $control_name Control name. | |
| 1473 | + * @param string $class_name Class name. | |
| 1474 | + * | |
| 1475 | + * @return string | |
| 1476 | + */ | |
| 1477 | + public function render_link_attributes( $id, $control_name, $class_name = 'logo-img-link' ) { | |
| 1478 | + $this->add_attribute( $id, 'class', $class_name ); | |
| 1479 | + | |
| 1480 | + if ( ! empty( $control_name['url'] ) ) { | |
| 1481 | + $this->add_link_attributes( $id, $control_name ); | |
| 1482 | + } else { | |
| 1483 | + $this->add_attribute( $id, 'role', 'button' ); | |
| 1484 | + } | |
| 1485 | + | |
| 1486 | + return $this->get_attribute_string( $id ); | |
| 1405 | 1487 | } |
| 1406 | 1488 | } |