| 1 |
<?php |
| 2 |
/** |
| 3 |
* Elementor Render Helper Class. |
| 4 |
* |
| 5 |
* This class contains render helper logics. |
| 6 |
* |
| 7 |
* @package RadiusTheme\SB |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace RadiusTheme\SB\Elementor\Helper; |
| 11 |
|
| 12 |
use Elementor\Plugin; |
| 13 |
use RadiusTheme\SB\Helpers\Fns; |
| 14 |
use RadiusTheme\SB\Helpers\BuilderFns; |
| 15 |
|
| 16 |
// Do not allow directly accessing this file. |
| 17 |
if ( ! defined( 'ABSPATH' ) ) { |
| 18 |
exit( 'This script cannot be accessed directly.' ); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* BuilderFns class |
| 23 |
*/ |
| 24 |
class RenderHelpers { |
| 25 |
/** |
| 26 |
* Get data. |
| 27 |
* |
| 28 |
* @param array|string $haystack The array or string to search for the value. |
| 29 |
* @param string $needle The key to look for in the array or the string itself. |
| 30 |
* @param mixed $default The default value to return if the key is not. |
| 31 |
* |
| 32 |
* @return mixed |
| 33 |
*/ |
| 34 |
public static function get_data( $haystack, $needle, $default = null ) { |
| 35 |
if ( is_array( $haystack ) && ! empty( $haystack[ $needle ] ) ) { |
| 36 |
return $haystack[ $needle ]; |
| 37 |
} elseif ( is_string( $haystack ) && ! empty( $haystack ) ) { |
| 38 |
return $haystack; |
| 39 |
} else { |
| 40 |
return $default; |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Builds an array with field values. |
| 46 |
* |
| 47 |
* @param array $meta Field values. |
| 48 |
* @param string $template Template name. |
| 49 |
* @param array $raw_settings Raw settings. |
| 50 |
* |
| 51 |
* @return array |
| 52 |
*/ |
| 53 |
public static function meta_dataset( array $meta, $template = '', $raw_settings = [] ) { |
| 54 |
$c_image_size = self::get_data( $meta, 'image_custom_dimension', [] ); |
| 55 |
$c_image_size['crop'] = self::get_data( $meta, 'image_crop', [] ); |
| 56 |
|
| 57 |
if ( ( ! empty( $_GET['displayview'] ) && 'list' === $_GET['displayview'] ) || ( empty( $_GET['displayview'] ) && ( ! empty( $meta['view_mode'] ) && 'list' === $meta['view_mode'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 58 |
$meta['cols'] = self::get_data( $meta, 'list_cols', 1 ); |
| 59 |
$meta['cols_tablet'] = self::get_data( $meta, 'list_cols_tablet', $meta['cols'] ); |
| 60 |
$meta['cols_mobile'] = self::get_data( $meta, 'list_cols_mobile', $meta['cols'] ); |
| 61 |
} |
| 62 |
|
| 63 |
$data = apply_filters( |
| 64 |
'rtsb/elementor/render/meta_dataset', |
| 65 |
[ |
| 66 |
// Layout. |
| 67 |
'widget' => 'custom', |
| 68 |
'template' => self::get_data( $template, '', '' ), |
| 69 |
'raw_settings' => $raw_settings, |
| 70 |
'layout' => self::get_data( $meta, 'layout', 'layout1' ), |
| 71 |
'grid_layout' => self::get_data( $raw_settings, 'layout', 'grid-layout1' ), |
| 72 |
'list_layout' => self::get_data( $raw_settings, 'list_layout', 'list-layout1' ), |
| 73 |
'd_cols' => self::get_data( $meta, 'cols', 0 ), |
| 74 |
't_cols' => self::get_data( $meta, 'cols_tablet', 2 ), |
| 75 |
'm_cols' => self::get_data( $meta, 'cols_mobile', 1 ), |
| 76 |
'grid_type' => self::get_data( $meta, 'grid_style', 'even' ), |
| 77 |
|
| 78 |
// Query. |
| 79 |
'post_in' => self::get_data( $meta, 'include_posts', [] ), |
| 80 |
'post_not_in' => self::get_data( $meta, 'exclude_posts', [] ), |
| 81 |
'limit' => ( empty( $meta['posts_limit'] ) || '-1' === $meta['posts_limit'] ) ? 10000000 : $meta['posts_limit'], |
| 82 |
'offset' => self::get_data( $meta, 'posts_offset', 0 ), |
| 83 |
'order_by' => self::get_data( $meta, 'posts_order_by', 'date' ), |
| 84 |
'order' => self::get_data( $meta, 'posts_order', 'DESC' ), |
| 85 |
'author_in' => self::get_data( $meta, 'filter_author', [] ), |
| 86 |
'display_by' => self::get_data( $meta, 'products_filter', 'date' ), |
| 87 |
'categories' => self::get_data( $meta, 'filter_categories', [] ), |
| 88 |
'tags' => self::get_data( $meta, 'filter_tags', [] ), |
| 89 |
'attributes' => self::get_data( $meta, 'filter_attributes', [] ), |
| 90 |
'relation' => self::get_data( $meta, 'tax_relation', 'OR' ), |
| 91 |
'category_source' => self::get_data( $meta, 'select_source', 'product_cat' ), |
| 92 |
'category_term' => self::get_data( $meta, 'select_cat' ), |
| 93 |
'display_cat_by' => self::get_data( $meta, 'display_cat_by' ), |
| 94 |
'include_cats' => self::get_data( $meta, 'include_cats', [] ), |
| 95 |
'exclude_cats' => self::get_data( $meta, 'exclude_cats', [] ), |
| 96 |
'select_parent_cat' => self::get_data( $meta, 'select_parent_cat' ), |
| 97 |
'select_cats' => self::get_data( $meta, 'select_cats', [] ), |
| 98 |
'select_cat_ids' => self::get_data( $meta, 'include_cat_ids', '' ), |
| 99 |
'cats_limit' => ( empty( $meta['cats_limit'] ) || '-1' === $meta['cats_limit'] ) ? 10000000 : $meta['cats_limit'], |
| 100 |
'show_empty' => ! empty( $meta['show_empty'] ), |
| 101 |
'show_uncategorized' => ! empty( $meta['show_uncategorized'] ), |
| 102 |
'show_subcats' => ! empty( $meta['show_subcats'] ), |
| 103 |
'show_top_level_cats' => ! empty( $meta['show_top_level_cats'] ), |
| 104 |
'cats_order_by' => self::get_data( $meta, 'cats_order_by', 'name' ), |
| 105 |
'cats_order' => self::get_data( $meta, 'cats_order', 'DESC' ), |
| 106 |
'rtsb_order' => self::get_data( $meta, 'rtsb_order', 'ASC' ), |
| 107 |
'rtsb_orderby' => self::get_data( $meta, 'rtsb_orderby', 'menu_order' ), |
| 108 |
|
| 109 |
// Pagination. |
| 110 |
'pagination' => ! empty( $meta['show_pagination'] ), |
| 111 |
'posts_loading_type' => self::get_data( $meta, 'pagination_type', 'pagination' ), |
| 112 |
'posts_per_page' => self::get_data( $meta, 'pagination_per_page', '' ), |
| 113 |
|
| 114 |
// Image. |
| 115 |
'f_img' => ! empty( $meta['show_featured_image'] ), |
| 116 |
'gallery_img' => ! empty( $meta['show_product_gallery'] ), |
| 117 |
'c_img' => ! empty( $meta['show_cat_image'] ), |
| 118 |
'hover_img' => ! empty( $meta['show_hover_image'] ), |
| 119 |
'f_img_size' => self::get_data( $meta, 'image', 'medium' ), |
| 120 |
'custom_img_size' => ! empty( $c_image_size ) && is_array( $c_image_size ) ? $c_image_size : [], |
| 121 |
'default_img_id' => ! empty( $meta['default_preview_image']['id'] ) ? $meta['default_preview_image']['id'] : null, |
| 122 |
'show_overlay' => ! empty( $meta['show_overlay'] ), |
| 123 |
'hover_animation' => self::get_data( $meta, 'image_hover_animation', 'none' ), |
| 124 |
'show_custom_image' => ! empty( $meta['show_custom_image'] ), |
| 125 |
'custom_image' => ! empty( $meta['custom_image']['id'] ) ? $meta['custom_image']['id'] : null, |
| 126 |
|
| 127 |
// Visibility. |
| 128 |
'visibility' => ! empty( self::content_visibility( $meta ) ) ? self::content_visibility( $meta ) : [], |
| 129 |
|
| 130 |
// Action Buttons. |
| 131 |
'btn_preset' => self::get_data( $meta, 'action_btn_preset', 'preset1' ), |
| 132 |
'btn_position' => self::get_data( $meta, 'action_btn_position', 'above' ), |
| 133 |
'tooltip_position' => self::get_data( $meta, 'action_btn_tooltip_position', 'top' ), |
| 134 |
|
| 135 |
// Product Title. |
| 136 |
'title_tag' => self::get_data( $meta, 'title_tag', 'h3' ), |
| 137 |
'title_hover' => ! empty( $meta['title_hover'] ), |
| 138 |
'title_limit' => self::get_data( $meta, 'title_limit', 'default' ), |
| 139 |
'title_limit_custom' => self::get_data( $meta, 'title_limit_custom' ), |
| 140 |
'show_custom_title' => ! empty( $meta['show_custom_title'] ), |
| 141 |
'cat_custom_title' => self::get_data( $meta, 'custom_title', '' ), |
| 142 |
|
| 143 |
// Variation Swatches. |
| 144 |
'swatch_position' => self::get_data( $meta, 'swatch_position', 'top' ), |
| 145 |
'swatch_type' => self::get_data( $meta, 'swatch_type', 'circle' ), |
| 146 |
|
| 147 |
// Short Description. |
| 148 |
'show_custom_excerpt' => ! empty( $meta['show_custom_description'] ), |
| 149 |
'cat_custom_excerpt' => self::get_data( $meta, 'custom_description', '' ), |
| 150 |
'cat_excerpt_position' => self::get_data( $meta, 'excerpt_position', 'below' ), |
| 151 |
'excerpt_limit' => self::get_data( $meta, 'excerpt_limit', 'default' ), |
| 152 |
'excerpt_limit_custom' => self::get_data( $meta, 'excerpt_limit_custom', 200 ), |
| 153 |
|
| 154 |
// Count. |
| 155 |
'count_position' => self::get_data( $meta, 'count_display_type', 'flex' ), |
| 156 |
'before_count' => self::get_data( $meta, 'before_count', '' ), |
| 157 |
'after_count' => self::get_data( $meta, 'after_count', '' ), |
| 158 |
|
| 159 |
// Add to cart. |
| 160 |
'show_cart_icon' => ! empty( $meta['show_cart_icon'] ), |
| 161 |
'show_cart_text' => ! empty( $meta['show_cart_text'] ), |
| 162 |
'add_to_cart_icon' => self::get_data( $meta, 'add_to_cart_icon', [] ), |
| 163 |
'add_to_cart_success_icon' => self::get_data( $meta, 'add_to_cart_success_icon', [] ), |
| 164 |
'add_to_cart_text' => self::get_data( $meta, 'add_to_cart_text', esc_html__( 'Add to Cart', 'shopbuilder' ) ), |
| 165 |
'add_to_cart_success_text' => self::get_data( $meta, 'add_to_cart_success_text', '' ), |
| 166 |
'add_to_cart_alignment' => self::get_data( $meta, 'cart_icon_alignment', 'left' ), |
| 167 |
|
| 168 |
// Action Button Icons. |
| 169 |
'quick_view_icon' => self::get_data( $meta, 'quick_view_icon', [] ), |
| 170 |
'comparison_icon' => self::get_data( $meta, 'comparison_icon', [] ), |
| 171 |
'comparison_icon_added' => self::get_data( $meta, 'comparison_icon_added', [] ), |
| 172 |
'wishlist_icon' => self::get_data( $meta, 'wishlist_icon', [] ), |
| 173 |
'wishlist_icon_added' => self::get_data( $meta, 'wishlist_icon_added', [] ), |
| 174 |
|
| 175 |
// Badges. |
| 176 |
'sale_badge_type' => self::get_data( $meta, 'sale_badges_type', 'percentage' ), |
| 177 |
'sale_badge_text' => self::get_data( $meta, 'sale_badges_text', esc_html__( 'Sale', 'shopbuilder' ) ), |
| 178 |
'custom_badge_text' => self::get_data( $meta, 'custom_badge_text', esc_html__( 'Sale', 'shopbuilder' ) ), |
| 179 |
'out_of_stock_badge_text' => self::get_data( $meta, 'stock_badges_text', esc_html__( 'Out of Stock', 'shopbuilder' ) ), |
| 180 |
'badge_position' => self::get_data( $meta, 'badges_position', 'top' ), |
| 181 |
'badge_alignment' => self::get_data( $meta, 'badges_alignment', 'left' ), |
| 182 |
'badge_preset' => self::get_data( $meta, 'custom_badge_preset', 'preset-1' ), |
| 183 |
'enable_badges_module' => self::get_data( $meta, 'enable_badges_module', '' ), |
| 184 |
|
| 185 |
// Link. |
| 186 |
'image_link' => ! empty( $meta['image_link'] ), |
| 187 |
'title_link' => ! empty( $meta['title_link'] ), |
| 188 |
'hover_btn_text' => self::get_data( $meta, 'hover_btn_text', esc_html__( 'See Details', 'shopbuilder' ) ), |
| 189 |
'show_hover_btn_icon' => ! empty( $meta['show_hover_btn_icon'] ), |
| 190 |
'hover_btn_icon' => self::get_data( $meta, 'hover_btn_icon', [] ), |
| 191 |
'custom_link' => self::get_data( $meta, 'custom_link' ), |
| 192 |
|
| 193 |
// Slider. |
| 194 |
'd_group' => self::get_data( $meta, 'cols_group', 1 ), |
| 195 |
't_group' => self::get_data( $meta, 'cols_group_tablet', 1 ), |
| 196 |
'm_group' => self::get_data( $meta, 'cols_group_mobile', 1 ), |
| 197 |
'auto_play' => ! empty( $meta['slide_autoplay'] ), |
| 198 |
'stop_on_hover' => ! empty( $meta['pause_hover'] ), |
| 199 |
'slider_nav' => ! empty( $meta['slider_nav'] ), |
| 200 |
'slider_dot' => ! empty( $meta['slider_pagi'] ), |
| 201 |
'slider_dynamic_dot' => ! empty( $meta['slider_dynamic_pagi'] ), |
| 202 |
'loop' => ! empty( $meta['slider_loop'] ), |
| 203 |
'lazy_load' => ! empty( $meta['slider_lazy_load'] ), |
| 204 |
'auto_height' => ! empty( $meta['slider_auto_height'] ), |
| 205 |
'speed' => self::get_data( $meta, 'slide_speed', 2000 ), |
| 206 |
'space_between' => isset( $meta['grid_gap']['size'] ) && strlen( $meta['grid_gap']['size'] ) ? $meta['grid_gap']['size'] : 30, |
| 207 |
'auto_play_timeout' => self::get_data( $meta, 'autoplay_timeout', 5000 ), |
| 208 |
'nav_position' => self::get_data( $meta, 'slider_nav_position', 'top' ), |
| 209 |
'left_arrow_icon' => self::get_data( $meta, 'slider_left_arrow_icon', [] ), |
| 210 |
'right_arrow_icon' => self::get_data( $meta, 'slider_right_arrow_icon', [] ), |
| 211 |
], |
| 212 |
$meta |
| 213 |
); |
| 214 |
|
| 215 |
if ( ! empty( $meta['active_cat_slider'] ) ) { |
| 216 |
$data['active_cat_slider'] = true; |
| 217 |
} |
| 218 |
|
| 219 |
if ( ! empty( $meta['cols_widescreen'] ) ) { |
| 220 |
$data['w_cols'] = $meta['cols_widescreen']; |
| 221 |
} |
| 222 |
|
| 223 |
if ( ! empty( $meta['cols_laptop'] ) ) { |
| 224 |
$data['l_cols'] = $meta['cols_laptop']; |
| 225 |
} |
| 226 |
|
| 227 |
if ( ! empty( $meta['cols_tablet_extra'] ) ) { |
| 228 |
$data['te_cols'] = $meta['cols_tablet_extra']; |
| 229 |
} |
| 230 |
|
| 231 |
if ( ! empty( $meta['cols_mobile_extra'] ) ) { |
| 232 |
$data['me_cols'] = $meta['cols_mobile_extra']; |
| 233 |
} |
| 234 |
|
| 235 |
$queried_obj = get_queried_object(); |
| 236 |
|
| 237 |
if ( is_shop() || is_product_taxonomy() ) { |
| 238 |
$data['posts_per_page'] = self::get_products_per_page(); |
| 239 |
$data['order_by'] = self::get_data( $data, 'rtsb_orderby', $data['order_by'] ); |
| 240 |
$data['order'] = self::get_data( $data, 'rtsb_order', $data['order'] ); |
| 241 |
} |
| 242 |
|
| 243 |
if ( ! is_shop() && is_product_taxonomy() ) { |
| 244 |
if ( ! empty( $queried_obj->taxonomy ) ) { |
| 245 |
$data['queried_tax'] = esc_html( $queried_obj->taxonomy ); |
| 246 |
} |
| 247 |
|
| 248 |
if ( ! empty( $queried_obj->term_id ) ) { |
| 249 |
$data['queried_term'] = esc_html( $queried_obj->term_id ); |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
return apply_filters( 'rtsb/elementor/render/meta_dataset_final', $data, $meta, $raw_settings ); |
| 254 |
} |
| 255 |
|
| 256 |
/** |
| 257 |
* Builds an array with field values. |
| 258 |
* |
| 259 |
* @param array $meta Field values. |
| 260 |
* @param string $template Template name. |
| 261 |
* |
| 262 |
* @return array |
| 263 |
*/ |
| 264 |
public static function archive_meta_dataset( array $meta, $template = '' ) { |
| 265 |
$data = apply_filters( |
| 266 |
'rtsb/elementor/render/archive_meta_dataset', |
| 267 |
[ |
| 268 |
// Layout. |
| 269 |
'widget' => 'default', |
| 270 |
'template' => self::get_data( $template, '', '' ), |
| 271 |
'view_mode' => self::get_data( $meta, 'view_mode', 'grid' ), |
| 272 |
'show_flash_sale' => ! empty( $meta['show_flash_sale'] ), |
| 273 |
'wishlist_button' => ! empty( $meta['wishlist_button'] ), |
| 274 |
'comparison_button' => ! empty( $meta['comparison_button'] ), |
| 275 |
'quick_view_button' => ! empty( $meta['quick_view_button'] ), |
| 276 |
'show_rating' => ! empty( $meta['show_rating'] ), |
| 277 |
'show_pagination' => ! empty( $meta['show_pagination'] ), |
| 278 |
'cart_icon' => self::get_data( $meta, 'cart_icon', [] ), |
| 279 |
'wishlist_icon' => self::get_data( $meta, 'wishlist_icon', [] ), |
| 280 |
'wishlist_icon_added' => self::get_data( $meta, 'wishlist_icon_added', [] ), |
| 281 |
'comparison_icon' => self::get_data( $meta, 'comparison_icon', [] ), |
| 282 |
'comparison_icon_added' => self::get_data( $meta, 'comparison_icon_added', [] ), |
| 283 |
'quick_view_icon' => self::get_data( $meta, 'quick_view_icon', [] ), |
| 284 |
'prev_icon' => self::get_data( $meta, 'prev_icon', [] ), |
| 285 |
'next_icon' => self::get_data( $meta, 'next_icon', [] ), |
| 286 |
'posts_per_page' => self::get_products_per_page(), |
| 287 |
'rtsb_order' => self::get_data( $meta, 'rtsb_order', 'ASC' ), |
| 288 |
'rtsb_orderby' => self::get_data( $meta, 'rtsb_orderby', 'menu_order' ), |
| 289 |
'tooltip_position' => self::get_data( $meta, 'action_btn_tooltip_position', 'top' ), |
| 290 |
], |
| 291 |
$meta |
| 292 |
); |
| 293 |
|
| 294 |
$queried_obj = get_queried_object(); |
| 295 |
|
| 296 |
if ( ! is_shop() && BuilderFns::is_archive() ) { |
| 297 |
if ( ! empty( $queried_obj->taxonomy ) ) { |
| 298 |
$data['queried_tax'] = esc_html( $queried_obj->taxonomy ); |
| 299 |
} |
| 300 |
|
| 301 |
if ( ! empty( $queried_obj->term_id ) ) { |
| 302 |
$data['queried_term'] = esc_html( $queried_obj->term_id ); |
| 303 |
} |
| 304 |
} |
| 305 |
|
| 306 |
return apply_filters( 'rtsb/elementor/render/archive_meta_dataset_final', $data, $meta ); |
| 307 |
} |
| 308 |
|
| 309 |
/** |
| 310 |
* Setting up content visibility |
| 311 |
* |
| 312 |
* @param array $settings Elementor settings. |
| 313 |
* |
| 314 |
* @return array |
| 315 |
*/ |
| 316 |
public static function content_visibility( $settings ) { |
| 317 |
$visibility = []; |
| 318 |
|
| 319 |
if ( ! empty( $settings['show_title'] ) ) { |
| 320 |
$visibility[] = 'title'; |
| 321 |
} |
| 322 |
|
| 323 |
if ( ! empty( $settings['show_short_desc'] ) ) { |
| 324 |
$visibility[] = 'excerpt'; |
| 325 |
} |
| 326 |
|
| 327 |
if ( ! empty( $settings['show_price'] ) ) { |
| 328 |
$visibility[] = 'price'; |
| 329 |
} |
| 330 |
|
| 331 |
if ( ! empty( $settings['show_rating'] ) ) { |
| 332 |
$visibility[] = 'rating'; |
| 333 |
} |
| 334 |
|
| 335 |
if ( ! empty( $settings['show_badges'] ) ) { |
| 336 |
$visibility[] = 'badges'; |
| 337 |
} |
| 338 |
|
| 339 |
if ( ! empty( $settings['show_categories'] ) ) { |
| 340 |
$visibility[] = 'categories'; |
| 341 |
} |
| 342 |
|
| 343 |
if ( ! empty( $settings['single_category'] ) ) { |
| 344 |
$visibility[] = 'single-cat'; |
| 345 |
} |
| 346 |
|
| 347 |
if ( ! empty( $settings['show_swatches'] ) ) { |
| 348 |
$visibility[] = 'swatches'; |
| 349 |
} |
| 350 |
|
| 351 |
if ( ! empty( $settings['show_vs_clear_btn'] ) ) { |
| 352 |
$visibility[] = 'clear-btn'; |
| 353 |
} |
| 354 |
|
| 355 |
if ( ! empty( $settings['show_count'] ) ) { |
| 356 |
$visibility[] = 'count'; |
| 357 |
} |
| 358 |
|
| 359 |
if ( ! empty( $settings['show_wishlist'] ) ) { |
| 360 |
$visibility[] = 'wishlist'; |
| 361 |
} |
| 362 |
|
| 363 |
if ( ! empty( $settings['show_compare'] ) ) { |
| 364 |
$visibility[] = 'compare'; |
| 365 |
} |
| 366 |
|
| 367 |
if ( ! empty( $settings['show_quick_view'] ) ) { |
| 368 |
$visibility[] = 'quick_view'; |
| 369 |
} |
| 370 |
|
| 371 |
if ( ! empty( $settings['show_add_to_cart'] ) ) { |
| 372 |
$visibility[] = 'add_to_cart'; |
| 373 |
} |
| 374 |
|
| 375 |
return $visibility; |
| 376 |
} |
| 377 |
|
| 378 |
/** |
| 379 |
* Set Default Layout. |
| 380 |
* |
| 381 |
* @param string $layout Layout. |
| 382 |
* |
| 383 |
* @return string |
| 384 |
*/ |
| 385 |
public static function set_default_layout( $layout ) { |
| 386 |
$is_list = preg_match( '/list/', $layout ); |
| 387 |
$is_cat_single = preg_match( '/category-single/', $layout ); |
| 388 |
$is_cat = preg_match( '/category/', $layout ); |
| 389 |
$is_carousel = preg_match( '/slider/', $layout ); |
| 390 |
$default = 'grid-layout1'; |
| 391 |
|
| 392 |
if ( $is_list ) { |
| 393 |
$default = 'list-layout1'; |
| 394 |
} elseif ( $is_cat_single ) { |
| 395 |
$default = 'category-single-layout1'; |
| 396 |
} elseif ( $is_cat ) { |
| 397 |
$default = 'category-layout1'; |
| 398 |
} elseif ( $is_carousel ) { |
| 399 |
$default = 'slider-layout1'; |
| 400 |
} |
| 401 |
|
| 402 |
return $default; |
| 403 |
} |
| 404 |
|
| 405 |
/** |
| 406 |
* Default layout columns. |
| 407 |
* |
| 408 |
* @param int $layout Layout. |
| 409 |
* |
| 410 |
* @return int |
| 411 |
*/ |
| 412 |
public static function default_columns( $layout ) { |
| 413 |
switch ( $layout ) { |
| 414 |
case 'rtsb-post-grid-layout1': |
| 415 |
case 'rtsb-post-grid-layout2': |
| 416 |
case 'rtsb-post-grid-layout3': |
| 417 |
case 'rtsb-team-layout1': |
| 418 |
case 'rtsb-team-layout2': |
| 419 |
case 'rtsb-testimonial-layout2': |
| 420 |
case 'grid-layout2': |
| 421 |
case 'slider-layout2': |
| 422 |
$columns = 3; |
| 423 |
break; |
| 424 |
case 'rtsb-post-list-layout1': |
| 425 |
case 'rtsb-post-list-layout2': |
| 426 |
case 'list-layout1': |
| 427 |
case 'list-layout2': |
| 428 |
case 'list-layout3': |
| 429 |
case 'list-layout7': |
| 430 |
case 'list-layout5': |
| 431 |
$columns = 1; |
| 432 |
break; |
| 433 |
case 'rtsb-team-layout4': |
| 434 |
case 'rtsb-testimonial-layout1': |
| 435 |
case 'rtsb-testimonial-layout3': |
| 436 |
case 'rtsb-testimonial-layout4': |
| 437 |
case 'rtsb-testimonial-layout5': |
| 438 |
case 'list-layout4': |
| 439 |
case 'list-layout6': |
| 440 |
case 'slider-layout5': |
| 441 |
case 'slider-layout8': |
| 442 |
$columns = 2; |
| 443 |
break; |
| 444 |
case 'rtsb-logo-layout1': |
| 445 |
case 'rtsb-logo-layout2': |
| 446 |
case 'grid-layout6': |
| 447 |
case 'grid-layout9': |
| 448 |
$columns = 5; |
| 449 |
break; |
| 450 |
|
| 451 |
case 'category-layout1': |
| 452 |
$columns = 6; |
| 453 |
break; |
| 454 |
|
| 455 |
default: |
| 456 |
$columns = 4; |
| 457 |
break; |
| 458 |
} |
| 459 |
|
| 460 |
return apply_filters( 'rtsb/element/general/default_columns', $columns, $layout ); |
| 461 |
} |
| 462 |
|
| 463 |
/** |
| 464 |
* Pagination JSON data. |
| 465 |
* |
| 466 |
* @param array $metas Data set. |
| 467 |
* @param string $template Template name. |
| 468 |
* |
| 469 |
* @return string |
| 470 |
*/ |
| 471 |
public static function pagination_data( $metas, $template ) { |
| 472 |
$el_data = self::meta_dataset( $metas, $template ); |
| 473 |
|
| 474 |
return esc_js( wp_json_encode( $el_data, JSON_UNESCAPED_UNICODE ) ); |
| 475 |
} |
| 476 |
|
| 477 |
/** |
| 478 |
* Container classes |
| 479 |
* |
| 480 |
* @param array $metas Meta data. |
| 481 |
* @param array $settings Settings array. |
| 482 |
* @param string $custom_class Custom class. |
| 483 |
* |
| 484 |
* @return mixed|null |
| 485 |
*/ |
| 486 |
public static function prepare_container_classes( $metas = [], $settings = [], $custom_class = '' ) { |
| 487 |
$classes = 'rtsb-elementor-container products rtsb-pos-r '; |
| 488 |
$classes .= $custom_class; |
| 489 |
|
| 490 |
$raw_layout = esc_html( $metas['layout'] ); |
| 491 |
$layout = self::filter_layout( $raw_layout ); |
| 492 |
$is_cat = preg_match( '/category/', $layout ); |
| 493 |
$cart_txt_class = ''; |
| 494 |
|
| 495 |
$animation = $metas['hover_animation']; |
| 496 |
|
| 497 |
if ( ! $is_cat ) { |
| 498 |
$cart_txt_class = $metas['show_cart_text'] ? ' has-cart-text' : ' no-cart-text'; |
| 499 |
$animation .= ' gallery-hover-' . ( ! empty( $settings['gallery_hover_animation'] ) ? $settings['gallery_hover_animation'] : 'fade' ); |
| 500 |
} |
| 501 |
|
| 502 |
$badge_class = [ |
| 503 |
'position' => $metas['badge_position'], |
| 504 |
'alignment' => $metas['badge_alignment'], |
| 505 |
]; |
| 506 |
|
| 507 |
if ( ! in_array( 'clear-btn', $metas['visibility'], true ) ) { |
| 508 |
$classes .= ' no-clear-btn'; |
| 509 |
} |
| 510 |
|
| 511 |
$classes .= ! empty( $metas['pagination'] ) ? ' rtsb-has-pagination' : ' rtsb-no-pagination'; |
| 512 |
$classes .= ' badge-' . esc_attr( $badge_class['position'] ) . ' badge-' . esc_attr( $badge_class['alignment'] ) . esc_attr( $cart_txt_class ) . ' img-hover-' . esc_attr( $animation ) . ' excerpt-' . esc_attr( $metas['cat_excerpt_position'] ); |
| 513 |
|
| 514 |
if ( $metas['show_overlay'] ) { |
| 515 |
$classes .= ' has-overlay'; |
| 516 |
} |
| 517 |
|
| 518 |
if ( in_array( 'single-cat', $metas['visibility'], true ) ) { |
| 519 |
$classes .= ' show-single-cat'; |
| 520 |
} |
| 521 |
|
| 522 |
if ( ! $is_cat ) { |
| 523 |
$action_btn_classes = [ |
| 524 |
'show_compare_text' => 'has-compare-text', |
| 525 |
'show_quick_view_text' => 'has-quick-view-text', |
| 526 |
'show_wishlist_text' => 'has-wishlist-text', |
| 527 |
'show_compare_icon' => 'no-compare-icon', |
| 528 |
'show_quick_view_icon' => 'no-quick-view-icon', |
| 529 |
'show_wishlist_icon' => 'no-wishlist-icon', |
| 530 |
'show_quick_checkout_icon' => 'no-quick_checkout-icon', |
| 531 |
]; |
| 532 |
|
| 533 |
foreach ( $action_btn_classes as $setting_key => $class ) { |
| 534 |
if ( strpos( $setting_key, 'icon' ) !== false ) { |
| 535 |
$classes .= empty( $settings[ $setting_key ] ) ? ' ' . $class : ''; |
| 536 |
} else { |
| 537 |
$classes .= ! empty( $settings[ $setting_key ] ) ? ' ' . $class : ''; |
| 538 |
} |
| 539 |
} |
| 540 |
|
| 541 |
if ( rtsb()->has_pro() && ! empty( $settings['custom_ordering'] ) ) { |
| 542 |
$classes .= ' has-custom-ordering'; |
| 543 |
} |
| 544 |
} |
| 545 |
if ( rtsb()->has_pro() && ! empty( $settings['slider_slide_animation'] ) ) { |
| 546 |
$classes .= ' has-slide-animation'; |
| 547 |
} |
| 548 |
|
| 549 |
return apply_filters( 'rtsb/product/container/class', $classes, $settings ); |
| 550 |
} |
| 551 |
|
| 552 |
/** |
| 553 |
* Function to filter and validate the layout against allowed patterns. |
| 554 |
* |
| 555 |
* @param string $layout The layout string to be filtered. |
| 556 |
* @param string $template The template to be checked. |
| 557 |
* |
| 558 |
* @return string |
| 559 |
*/ |
| 560 |
public static function filter_layout( $layout, $template = '' ) { |
| 561 |
$allowed_patterns = apply_filters( 'rtsb/elementor/custom_layout', [ 'grid', 'list', 'slider', 'category', 'toyup', 'zilly', 'rtsb' ] ); |
| 562 |
$layout_part = explode( '-', $layout ); |
| 563 |
$default = 'grid-layout1'; |
| 564 |
|
| 565 |
if ( empty( $layout_part[0] ) ) { |
| 566 |
return $default; |
| 567 |
} |
| 568 |
|
| 569 |
if ( in_array( $layout_part[0], $allowed_patterns, true ) ) { |
| 570 |
return $layout; |
| 571 |
} else { |
| 572 |
if ( ! empty( $template ) ) { |
| 573 |
$grid = preg_match( '/grid/', $template ); |
| 574 |
$list = preg_match( '/list/', $template ); |
| 575 |
$slider = preg_match( '/slider/', $template ); |
| 576 |
$category = preg_match( '/category/', $template ); |
| 577 |
|
| 578 |
if ( $grid ) { |
| 579 |
return $default; |
| 580 |
} elseif ( $list ) { |
| 581 |
return 'list-layout1'; |
| 582 |
} elseif ( $slider ) { |
| 583 |
return 'slider-layout1'; |
| 584 |
} elseif ( $category ) { |
| 585 |
return 'category-layout1'; |
| 586 |
} else { |
| 587 |
return $default; |
| 588 |
} |
| 589 |
} else { |
| 590 |
return $default; |
| 591 |
} |
| 592 |
} |
| 593 |
} |
| 594 |
|
| 595 |
/** |
| 596 |
* Row classes |
| 597 |
* |
| 598 |
* @param array $settings Settings array. |
| 599 |
* |
| 600 |
* @return mixed|null |
| 601 |
*/ |
| 602 |
public static function prepare_row_classes( $settings = [] ) { |
| 603 |
$masonry_class = null; |
| 604 |
$classes = 'rtsb-row rtsb-content-loader element-loading'; |
| 605 |
$loader_class = ' rtsb-pre-loader'; |
| 606 |
|
| 607 |
$raw_layout = esc_html( $settings['layout'] ); |
| 608 |
$layout = self::filter_layout( $raw_layout ); |
| 609 |
$grid_type = $settings['grid_type']; |
| 610 |
$is_carousel = preg_match( '/slider/', $layout ); |
| 611 |
|
| 612 |
if ( preg_match( '/category/', $layout ) && ! empty( $settings['active_cat_slider'] ) ) { |
| 613 |
$classes .= ' rtsb-slider-layout'; |
| 614 |
} |
| 615 |
|
| 616 |
if ( 'equal' === $grid_type ) { |
| 617 |
$masonry_class = ' rtsb-equal'; |
| 618 |
} elseif ( 'masonry' === $grid_type ) { |
| 619 |
$masonry_class = ' rtsb-masonry'; |
| 620 |
} else { |
| 621 |
$masonry_class = ' rtsb-even'; |
| 622 |
} |
| 623 |
|
| 624 |
if ( ! rtsb()->has_pro() || $is_carousel ) { |
| 625 |
$masonry_class = ' rtsb-even'; |
| 626 |
} |
| 627 |
|
| 628 |
if ( $is_carousel && ! empty( $settings['raw_settings']['always_show_nav'] ) ) { |
| 629 |
$classes .= ' always-show-nav'; |
| 630 |
} |
| 631 |
|
| 632 |
if ( ! empty( $settings['raw_settings']['inner_slider_always_show_nav'] ) ) { |
| 633 |
$classes .= ' inner-slider-always-show-nav'; |
| 634 |
} |
| 635 |
if ( empty( $settings['raw_settings']['cols_mobile'] ) ) { |
| 636 |
$classes .= ' rtsb-mobile-flex-row'; |
| 637 |
} |
| 638 |
|
| 639 |
$classes .= ' rtsb-' . $layout . $masonry_class . $loader_class; |
| 640 |
|
| 641 |
return apply_filters( 'rtsb/elementor/row/classes', $classes, $settings ); |
| 642 |
} |
| 643 |
|
| 644 |
/** |
| 645 |
* Prepare pagination attributes. |
| 646 |
* |
| 647 |
* @param string $layout The layout type. |
| 648 |
* @param bool $has_filters Whether the widget has filters. |
| 649 |
* @param string $template The template name. |
| 650 |
* @param array $settings The widget settings. |
| 651 |
* @param bool $ajax Whether to enable AJAX pagination. |
| 652 |
* |
| 653 |
* @return string |
| 654 |
*/ |
| 655 |
public static function prepare_pagination_attr( $layout, $has_filters, $template, $settings, $ajax ) { |
| 656 |
$is_cat = preg_match( '/category/', $layout ); |
| 657 |
$is_carousel = preg_match( '/slider/', $layout ); |
| 658 |
|
| 659 |
if ( $is_carousel ) { |
| 660 |
return $has_filters ? self::pagination_data( $settings, $template ) : ''; |
| 661 |
} elseif ( $is_cat ) { |
| 662 |
return ''; |
| 663 |
} else { |
| 664 |
$ajax_pagination = ! empty( $settings['show_pagination'] ) && 'pagination' !== $settings['pagination_type']; |
| 665 |
$page = Fns::product_filters_has_ajax( apply_filters( 'rtsb/builder/set/current/page/type', '' ) ); |
| 666 |
$condition = rtsb()->has_pro() && $ajax && ( $ajax_pagination || $has_filters || $page ); |
| 667 |
|
| 668 |
return $condition ? self::pagination_data( $settings, $template ) : ''; |
| 669 |
} |
| 670 |
} |
| 671 |
|
| 672 |
/** |
| 673 |
* Archive JSON data. |
| 674 |
* |
| 675 |
* @param array $metas Data set. |
| 676 |
* @param string $template Template name. |
| 677 |
* |
| 678 |
* @return string |
| 679 |
*/ |
| 680 |
public static function archive_data( $metas, $template ) { |
| 681 |
$el_data = self::archive_meta_dataset( $metas, $template ); |
| 682 |
|
| 683 |
return ' data-rtsb-ajax=\'' . esc_js( wp_json_encode( $el_data ) ) . '\''; |
| 684 |
} |
| 685 |
|
| 686 |
/** |
| 687 |
* Slider options. |
| 688 |
* |
| 689 |
* @param array $meta Meta values. |
| 690 |
* @param array $settings Raw Settings. |
| 691 |
* |
| 692 |
* @return array |
| 693 |
*/ |
| 694 |
public static function slider_data( array $meta, $settings = [] ) { |
| 695 |
$has_dots = $meta['slider_dot'] ? ' has-dot' : ' no-dot'; |
| 696 |
$has_dots .= $meta['slider_nav'] ? ' has-nav' : ' no-nav'; |
| 697 |
$has_dynamic_dots = $meta['slider_dynamic_dot'] ? true : false; |
| 698 |
$d_col = 0 === $meta['d_cols'] ? self::default_columns( $meta['layout'] ) : $meta['d_cols']; |
| 699 |
$t_col = 0 === $meta['t_cols'] ? 2 : $meta['t_cols']; |
| 700 |
$m_col = 0 === $meta['m_cols'] ? 1 : $meta['m_cols']; |
| 701 |
|
| 702 |
if ( Plugin::$instance->breakpoints->has_custom_breakpoints() ) { |
| 703 |
// Widescreen. |
| 704 |
$w_col = self::get_data( $settings, 'cols_widescreen' ); |
| 705 |
$w_col = 0 === $w_col ? self::default_columns( $meta['layout'] ) : $w_col; |
| 706 |
$w_group = self::get_data( $settings, 'cols_group_widescreen', 1 ); |
| 707 |
|
| 708 |
// Laptop. |
| 709 |
$l_col = self::get_data( $settings, 'cols_laptop' ); |
| 710 |
$l_col = 0 === $l_col ? self::default_columns( $meta['layout'] ) : $l_col; |
| 711 |
$l_group = self::get_data( $settings, 'cols_group_laptop', 1 ); |
| 712 |
|
| 713 |
// Tablet Landscape. |
| 714 |
$te_col = self::get_data( $settings, 'cols_tablet_extra' ); |
| 715 |
$te_col = 0 === $te_col ? 3 : $te_col; |
| 716 |
$te_group = self::get_data( $settings, 'cols_group_tablet_extra', 1 ); |
| 717 |
|
| 718 |
// Mobile Landscape. |
| 719 |
$me_col = self::get_data( $settings, 'cols_mobile_extra' ); |
| 720 |
$me_col = 0 === $me_col ? 2 : $me_col; |
| 721 |
$me_group = self::get_data( $settings, 'cols_group_mobile_extra', 1 ); |
| 722 |
|
| 723 |
$el_breakpoints = Fns::get_elementor_breakpoints(); |
| 724 |
|
| 725 |
foreach ( $el_breakpoints as $key => $value ) { |
| 726 |
if ( isset( $value['is_enabled'] ) && ! $value['is_enabled'] ) { |
| 727 |
unset( $el_breakpoints[ $key ] ); |
| 728 |
} |
| 729 |
} |
| 730 |
|
| 731 |
$breakpoints = [ |
| 732 |
0 => [ |
| 733 |
'slidesPerView' => absint( $m_col ), |
| 734 |
'slidesPerGroup' => absint( $meta['m_group'] ), |
| 735 |
'pagination' => [ |
| 736 |
'dynamicBullets' => $has_dynamic_dots, |
| 737 |
], |
| 738 |
], |
| 739 |
]; |
| 740 |
|
| 741 |
$desktop = [ |
| 742 |
'desktop' => [ |
| 743 |
'label' => 'Desktop', |
| 744 |
'value' => 1920, |
| 745 |
'is_enabled' => 1, |
| 746 |
], |
| 747 |
]; |
| 748 |
|
| 749 |
if ( ! empty( $el_breakpoints['laptop'] ) && $el_breakpoints['laptop']['is_enabled'] ) { |
| 750 |
$widescreen_position = array_search( 'widescreen', array_keys( $el_breakpoints ), true ); |
| 751 |
$el_breakpoints = array_merge( |
| 752 |
array_slice( $el_breakpoints, 0, $widescreen_position ), |
| 753 |
$desktop, |
| 754 |
array_slice( $el_breakpoints, $widescreen_position ) |
| 755 |
); |
| 756 |
} else { |
| 757 |
$desktop['desktop']['value'] = 1366; |
| 758 |
$el_breakpoints['desktop'] = $desktop['desktop']; |
| 759 |
} |
| 760 |
|
| 761 |
foreach ( $el_breakpoints as $el_breakpoint => $value ) { |
| 762 |
$breakpoint_value = ! empty( $value['value'] ) ? $value['value'] : $value['default_value']; |
| 763 |
$dynamic_bullets = $has_dynamic_dots; |
| 764 |
$slides_per_view = $d_col; |
| 765 |
$slides_per_group = $meta['d_group']; |
| 766 |
|
| 767 |
switch ( $el_breakpoint ) { |
| 768 |
case 'widescreen': |
| 769 |
$slides_per_view = $w_col; |
| 770 |
$slides_per_group = $w_group; |
| 771 |
|
| 772 |
break; |
| 773 |
|
| 774 |
case 'laptop': |
| 775 |
$slides_per_view = $l_col; |
| 776 |
$slides_per_group = $l_group; |
| 777 |
|
| 778 |
break; |
| 779 |
|
| 780 |
case 'tablet_extra': |
| 781 |
$slides_per_view = $l_col; |
| 782 |
$slides_per_group = $l_group; |
| 783 |
|
| 784 |
if ( empty( $el_breakpoints['laptop'] ) ) { |
| 785 |
$slides_per_view = $d_col; |
| 786 |
$slides_per_group = $meta['d_group']; |
| 787 |
} |
| 788 |
|
| 789 |
break; |
| 790 |
|
| 791 |
case 'tablet': |
| 792 |
$slides_per_view = $te_col; |
| 793 |
$slides_per_group = $te_group; |
| 794 |
|
| 795 |
if ( empty( $el_breakpoints['laptop'] ) && empty( $el_breakpoints['tablet_extra'] ) ) { |
| 796 |
$slides_per_view = $d_col; |
| 797 |
$slides_per_group = $meta['d_group']; |
| 798 |
} elseif ( empty( $el_breakpoints['laptop'] ) && ! empty( $el_breakpoints['tablet_extra'] ) ) { |
| 799 |
$slides_per_view = $te_col; |
| 800 |
$slides_per_group = $te_group; |
| 801 |
} elseif ( ! empty( $el_breakpoints['laptop'] ) && empty( $el_breakpoints['tablet_extra'] ) ) { |
| 802 |
$slides_per_view = $l_col; |
| 803 |
$slides_per_group = $l_group; |
| 804 |
} |
| 805 |
|
| 806 |
break; |
| 807 |
|
| 808 |
case 'mobile_extra': |
| 809 |
$slides_per_view = $t_col; |
| 810 |
$slides_per_group = $meta['t_group']; |
| 811 |
$dynamic_bullets = $has_dynamic_dots; |
| 812 |
|
| 813 |
break; |
| 814 |
|
| 815 |
case 'mobile': |
| 816 |
$slides_per_view = $t_col; |
| 817 |
$slides_per_group = $meta['t_group']; |
| 818 |
$dynamic_bullets = $has_dynamic_dots; |
| 819 |
|
| 820 |
if ( ! empty( $el_breakpoints['mobile_extra'] ) ) { |
| 821 |
$slides_per_view = $me_col; |
| 822 |
$slides_per_group = $me_group; |
| 823 |
} |
| 824 |
|
| 825 |
break; |
| 826 |
} |
| 827 |
|
| 828 |
if ( $value['is_enabled'] ) { |
| 829 |
$br = 'widescreen' !== $el_breakpoint ? $breakpoint_value + 1 : $breakpoint_value; |
| 830 |
|
| 831 |
$breakpoints[ absint( $br ) ] = [ |
| 832 |
'slidesPerView' => absint( $slides_per_view ), |
| 833 |
'slidesPerGroup' => absint( $slides_per_group ), |
| 834 |
'pagination' => [ |
| 835 |
'dynamicBullets' => $dynamic_bullets, |
| 836 |
], |
| 837 |
]; |
| 838 |
} |
| 839 |
} |
| 840 |
} else { |
| 841 |
$breakpoints = [ |
| 842 |
0 => [ |
| 843 |
'slidesPerView' => absint( $m_col ), |
| 844 |
'slidesPerGroup' => absint( $meta['m_group'] ), |
| 845 |
'pagination' => [ |
| 846 |
'dynamicBullets' => $has_dynamic_dots, |
| 847 |
], |
| 848 |
], |
| 849 |
768 => [ |
| 850 |
'slidesPerView' => absint( $t_col ), |
| 851 |
'slidesPerGroup' => absint( $meta['t_group'] ), |
| 852 |
'pagination' => [ |
| 853 |
'dynamicBullets' => $has_dynamic_dots, |
| 854 |
], |
| 855 |
], |
| 856 |
1025 => [ |
| 857 |
'slidesPerView' => absint( $d_col ), |
| 858 |
'slidesPerGroup' => absint( $meta['d_group'] ), |
| 859 |
'pagination' => [ |
| 860 |
'dynamicBullets' => $has_dynamic_dots, |
| 861 |
], |
| 862 |
], |
| 863 |
]; |
| 864 |
} |
| 865 |
|
| 866 |
$slider_options = [ |
| 867 |
'slidesPerView' => absint( $d_col ), |
| 868 |
'slidesPerGroup' => absint( $meta['d_group'] ), |
| 869 |
'speed' => absint( $meta['speed'] ), |
| 870 |
'loop' => $meta['loop'], |
| 871 |
'autoHeight' => $meta['auto_height'], |
| 872 |
'preloadImages' => ! $meta['lazy_load'], |
| 873 |
'lazy' => $meta['lazy_load'], |
| 874 |
'breakpoints' => $breakpoints, |
| 875 |
]; |
| 876 |
|
| 877 |
if ( ! empty( $meta['raw_settings']['slider_slide_animation'] ) ) { |
| 878 |
$slider_options['watchSlidesProgress'] = true; |
| 879 |
} |
| 880 |
if ( $meta['auto_play'] ) { |
| 881 |
$slider_options['autoplay'] = [ |
| 882 |
'delay' => absint( $meta['auto_play_timeout'] ), |
| 883 |
'pauseOnMouseEnter' => $meta['stop_on_hover'], |
| 884 |
'disableOnInteraction' => false, |
| 885 |
]; |
| 886 |
} |
| 887 |
|
| 888 |
$slider_options = apply_filters( 'rtsb/elementor/render/slider_dataset', $slider_options, $meta ); |
| 889 |
$carouselClass = 'rtsb-carousel-slider slider-loading rtsb-pos-s ' . $meta['nav_position'] . '-nav' . $has_dots; |
| 890 |
|
| 891 |
return [ |
| 892 |
'data' => esc_js( wp_json_encode( $slider_options ) ), |
| 893 |
'class' => $carouselClass, |
| 894 |
]; |
| 895 |
} |
| 896 |
|
| 897 |
/** |
| 898 |
* Preloader. |
| 899 |
* |
| 900 |
* @param string $layout Layout. |
| 901 |
* |
| 902 |
* @return string |
| 903 |
*/ |
| 904 |
public static function pre_loader( $layout ) { |
| 905 |
$loader_class = ''; |
| 906 |
|
| 907 |
$is_carousel = preg_match( '/slider/', $layout ); |
| 908 |
|
| 909 |
if ( $is_carousel ) { |
| 910 |
$loader_class = ' full-op'; |
| 911 |
} |
| 912 |
|
| 913 |
return '<div class="rtsb-elements-loading rtsb-ball-clip-rotate"><div></div></div>'; |
| 914 |
} |
| 915 |
|
| 916 |
/** |
| 917 |
* Badge class. |
| 918 |
* |
| 919 |
* @param string $preset Badge preset. |
| 920 |
* |
| 921 |
* @return string|null |
| 922 |
*/ |
| 923 |
public static function badge_class( $preset ) { |
| 924 |
switch ( $preset ) { |
| 925 |
case 'preset-default': |
| 926 |
$class = 'default-badge'; |
| 927 |
break; |
| 928 |
case 'preset2': |
| 929 |
$class = 'fill angle-right'; |
| 930 |
break; |
| 931 |
case 'preset3': |
| 932 |
$class = 'outline'; |
| 933 |
break; |
| 934 |
|
| 935 |
case 'preset4': |
| 936 |
$class = 'outline angle-right'; |
| 937 |
break; |
| 938 |
|
| 939 |
default: |
| 940 |
$class = 'fill'; |
| 941 |
break; |
| 942 |
} |
| 943 |
|
| 944 |
return $class; |
| 945 |
} |
| 946 |
|
| 947 |
/** |
| 948 |
* Registers required scripts. |
| 949 |
* |
| 950 |
* @param array $scripts Scripts to register. |
| 951 |
* |
| 952 |
* @return void |
| 953 |
*/ |
| 954 |
public static function register_scripts( $scripts ) { |
| 955 |
$caro = false; |
| 956 |
$masonry = false; |
| 957 |
$script = []; |
| 958 |
|
| 959 |
$script[] = 'jquery'; |
| 960 |
|
| 961 |
foreach ( $scripts as $sc => $value ) { |
| 962 |
if ( ! empty( $sc ) ) { |
| 963 |
if ( 'isCarousel' === $sc ) { |
| 964 |
$caro = $value; |
| 965 |
} |
| 966 |
|
| 967 |
if ( 'isMasonry' === $sc ) { |
| 968 |
$masonry = $value; |
| 969 |
} |
| 970 |
} |
| 971 |
} |
| 972 |
|
| 973 |
if ( count( $scripts ) ) { |
| 974 |
/** |
| 975 |
* Scripts. |
| 976 |
*/ |
| 977 |
if ( $caro ) { |
| 978 |
$script[] = 'swiper'; |
| 979 |
} |
| 980 |
|
| 981 |
if ( $masonry ) { |
| 982 |
$script[] = 'masonry'; |
| 983 |
} |
| 984 |
|
| 985 |
$script[] = 'rtsb-imagesloaded'; |
| 986 |
$script[] = 'rtsb-public'; |
| 987 |
|
| 988 |
foreach ( $script as $sc ) { |
| 989 |
wp_enqueue_script( $sc ); |
| 990 |
} |
| 991 |
} |
| 992 |
} |
| 993 |
|
| 994 |
/** |
| 995 |
* Check if a wrapper is needed based on the current theme. |
| 996 |
* |
| 997 |
* @return bool |
| 998 |
*/ |
| 999 |
public static function is_wrapper_needed() { |
| 1000 |
$theme_list = apply_filters( |
| 1001 |
'rtsb/products/inner/wrapper/basedon/themes', |
| 1002 |
[ |
| 1003 |
'twentytwentyone', |
| 1004 |
'twentytwentytwo', |
| 1005 |
'twentytwentythree', |
| 1006 |
'storefront', |
| 1007 |
'hello-elementor', |
| 1008 |
'astra', |
| 1009 |
], |
| 1010 |
rtsb()->current_theme |
| 1011 |
); |
| 1012 |
|
| 1013 |
if ( in_array( rtsb()->current_theme, $theme_list, true ) ) { |
| 1014 |
return true; |
| 1015 |
} |
| 1016 |
|
| 1017 |
return false; |
| 1018 |
} |
| 1019 |
|
| 1020 |
/** |
| 1021 |
* Get the number of products per page based on WooCommerce settings. |
| 1022 |
* |
| 1023 |
* @return int |
| 1024 |
*/ |
| 1025 |
public static function get_products_per_page() { |
| 1026 |
$products_row = absint( get_option( 'woocommerce_catalog_rows', 4 ) ); |
| 1027 |
$products_col = absint( get_option( 'woocommerce_catalog_columns', 4 ) ); |
| 1028 |
$products_per_page = apply_filters( 'rtsb/elementor/archive/products_per_page', $products_row * $products_col ); |
| 1029 |
|
| 1030 |
return ! empty( $products_per_page ) ? $products_per_page : 12; |
| 1031 |
} |
| 1032 |
} |
| 1033 |
|