PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 1.1.0
ShopBuilder – WooCommerce Builder For Elementor v1.1.0
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Helpers / Fns.php

Fns.php in ShopBuilder – WooCommerce Builder For Elementor 1.1.0, at app/Helpers/Fns.php

2,001 lines 64.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Fns Helpers class
4 *
5 * @package RadiusTheme\SB
6 */
7
8 namespace RadiusTheme\SB\Helpers;
9
10 // Do not allow directly accessing this file.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit( 'This script cannot be accessed directly.' );
13 }
14
15 use Elementor\Icons_Manager;
16 use RadiusTheme\SB\Models\ReSizer;
17 use RadiusTheme\SB\Models\DataModel;
18 use RadiusTheme\SB\Models\ModuleList;
19 use RadiusTheme\SB\Models\Settings;
20 use WC_Product;
21
22 /**
23 * Fns class
24 */
25 class Fns {
26 /**
27 * @param $plugin_slug
28 * @return bool
29 */
30 public static function check_plugin_installed( $plugin_slug ): bool {
31 $installed_plugins = get_plugins();
32 return array_key_exists( $plugin_slug, $installed_plugins ) || in_array( $plugin_slug, $installed_plugins, true );
33 }
34
35 /**
36 * @param $plugin_slug
37 * @return bool
38 */
39 public static function check_plugin_active( $plugin_slug ): bool {
40 if ( is_plugin_active( $plugin_slug ) ) {
41 return true;
42 }
43 return false;
44 }
45
46 /**
47 * @return bool
48 */
49 public static function check_is_block_theme(): bool {
50 global $wp_version;
51 return version_compare( $wp_version, '5.9', '>=' ) && function_exists( 'wp_is_block_theme' ) && wp_is_block_theme();
52 }
53
54 /**
55 * Verify nonce.
56 *
57 * @return bool
58 */
59 public static function verify_nonce() {
60 $nonce = isset( $_REQUEST[ rtsb()->nonceId ] ) ? $_REQUEST[ rtsb()->nonceId ] : null;
61 $nonceText = rtsb()->nonceText;
62 if ( wp_verify_nonce( $nonce, $nonceText ) ) {
63 return true;
64 }
65
66 return false;
67 }
68
69 /**
70 * @param string $template_name Template name.
71 * @param string $template_path Template path. (default: '').
72 * @param string $plugin_path Plugin path. (default: ''). fallback file from plugin
73 *
74 * @return mixed|void
75 */
76 public static function locate_template( $template_name, $template_path = '', $plugin_path = '' ) {
77 $template_name = $template_name . '.php';
78 if ( ! $template_path ) {
79 $template_path = rtsb()->get_template_path();
80 }
81 if ( ! $plugin_path ) {
82 $plugin_path = RTSB_ABSPATH . 'templates/';
83 }
84
85 $template_rtsb_path = trailingslashit( $template_path ) . $template_name;
86 $template_path = '/' . $template_name;
87 $plugin_path = $plugin_path . $template_name;
88
89 $located = locate_template(
90 apply_filters(
91 'rtsb/core/locate_template_files',
92 [
93 $template_rtsb_path, // Search in <theme>/shopbuilder/.
94 $template_path, // Search in <theme>/.
95 ]
96 )
97 );
98
99 if ( ! $located && file_exists( $plugin_path ) ) {
100 return apply_filters( 'rtsb/core/locate_template', $plugin_path, $template_name );
101 }
102
103 /**
104 * APPLY_FILTERS: rtsb/core/locate_template
105 *
106 * Filter the location of the templates.
107 *
108 * @param string $located Template found
109 * @param string $path Template path
110 *
111 * @return string
112 */
113 return apply_filters( 'rtsb/core/locate_template', $located, $template_name );
114 }
115
116 /**
117 * Template Content
118 *
119 * @param string $template_name Template name.
120 * @param array $args Arguments. (default: array).
121 * @param bool $return Whether to return or print the template.
122 * @param string $template_path Template path. (default: '').
123 * @param string $plugin_path Fallback path from where file will load if fail to load from template. (default: '').
124 *
125 * @return false|string|void
126 */
127 public static function load_template( $template_name, array $args = null, $return = false, $template_path = '', $plugin_path = '' ) {
128 $located = self::locate_template( $template_name, $template_path, $plugin_path );
129
130 if ( ! file_exists( $located ) ) {
131 // translators: %s template.
132 self::doing_it_wrong( __FUNCTION__, sprintf( __( '%s does not exist.', 'shopbuilder' ), '<code>' . $located . '</code>' ), '1.0' );
133
134 return;
135 }
136
137 if ( ! empty( $args ) && is_array( $args ) ) {
138 $atts = $args;
139 extract( $args ); // @codingStandardsIgnoreLine
140 }
141
142 // Allow 3rd party plugin filter template file from their plugin.
143 $located = apply_filters( 'rtsb/core/get_template', $located, $template_name, $args );
144
145 if ( $return ) {
146 ob_start();
147 }
148
149 do_action( 'rtsb/core/before_template_part', $template_name, $located, $args );
150 include $located;
151 do_action( 'rtsb/core/after_template_part', $template_name, $located, $args );
152
153 if ( $return ) {
154 return ob_get_clean();
155 }
156 }
157
158 /**
159 * Verify nonce.
160 *
161 * @return string
162 */
163 public static function is_woocommerce() {
164 return is_woocommerce() || is_cart() || is_checkout() || is_account_page();
165 }
166
167 /**
168 * Page builder
169 *
170 * @param int $post_id post id.
171 *
172 * @return string
173 */
174 public static function page_edit_with( $post_id ) {
175 if ( ! $post_id ) {
176 return '';
177 }
178
179 $edit_with = get_post_meta( $post_id, '_elementor_edit_mode', true );
180
181 if ( 'builder' === $edit_with ) {
182 $edit_by = 'elementor';
183 } else {
184 $edit_by = 'gutenberg';
185 }
186
187 return $edit_by;
188 }
189
190 /**
191 * Returns default expiration for wishlist cookie
192 *
193 * @return int Number of seconds the cookie should last.
194 */
195 public static function get_cookie_expiration() {
196 return intval( apply_filters( 'rtsb/cookie_expiration', 60 * 60 * 24 * 30 ) );
197 }
198
199 /**
200 * Create a cookie.
201 *
202 * @param string $name Cookie name.
203 * @param mixed $value Cookie value.
204 * @param int $time Cookie expiration time.
205 * @param bool $secure Whether cookie should be available to secured connection only.
206 * @param bool $httponly Whether cookie should be available to HTTP request only (no js handling).
207 *
208 * @return bool
209 * @since 1.0.0
210 */
211 public static function setcookie( $name, $value = [], $time = null, $secure = false, $httponly = false ) {
212
213 if ( ! apply_filters( 'rtsb/set_cookie', true ) || empty( $name ) ) {
214 return false;
215 }
216
217 $time = ! empty( $time ) ? $time : time() + self::get_cookie_expiration();
218
219 $value = wp_json_encode( stripslashes_deep( $value ) );
220 $expiration = apply_filters( 'rtsb/cookie_expiration_time', $time ); // Default 30 days.
221
222 $_COOKIE[ $name ] = $value;
223 wc_setcookie( $name, $value, $expiration, $secure, $httponly );
224
225 return true;
226 }
227
228 /**
229 * Retrieve the value of a cookie.
230 *
231 * @param string $name Cookie name.
232 *
233 * @return mixed
234 * @since 1.0.0
235 */
236 public static function getcookie( $name ) {
237 if ( isset( $_COOKIE[ $name ] ) ) {
238 return json_decode( sanitize_text_field( wp_unslash( $_COOKIE[ $name ] ) ), true );
239 }
240
241 return [];
242 }
243
244 /**
245 * Woocommerce Last product id return
246 */
247 public static function get_prepared_product_id() {
248
249 if ( is_singular( 'product' ) ) {
250 return get_the_ID();
251 }
252 // Return the Builder Template id.
253
254 if ( get_post_type( get_the_ID() ) == BuilderFns::$post_type_tb ) {
255 $product_id = get_post_meta( get_the_ID(), BuilderFns::$product_template_meta, true );
256 if ( $product_id ) {
257 return $product_id;
258 }
259 }
260
261 global $wpdb;
262 $cache_key = 'rtsb_prepared_product_id';
263 $_post_id = get_transient( $cache_key );
264 if ( false === $_post_id || 'publish' !== get_post_status( $_post_id ) ) {
265 delete_transient( $cache_key );
266 $_post_id = $wpdb->get_var(
267 $wpdb->prepare( "SELECT MAX(ID) FROM {$wpdb->prefix}posts WHERE post_type = %s AND post_status = %s", 'product', 'publish' )
268 );
269 set_transient( $cache_key, $_post_id, 12 * HOUR_IN_SECONDS );
270 }
271
272 return $_post_id;
273 }
274
275 /**
276 * Get the product function.
277 *
278 * @return object
279 */
280 public static function get_product() {
281 global $post, $product;
282 if ( is_singular( 'product' ) && $product instanceof WC_Product ) {
283 return $product;
284 }
285 return wc_get_product( self::get_prepared_product_id() );
286 }
287
288 /**
289 * Error function
290 *
291 * @param [type] $function function name.
292 * @param [type] $message message.
293 * @param [type] $version version.
294 *
295 * @return void
296 */
297 public static function doing_it_wrong( $function, $message, $version ) {
298 $message .= ' Backtrace: ' . wp_debug_backtrace_summary();
299 _doing_it_wrong( $function, $message, $version );
300 }
301
302 /**
303 * @return array
304 */
305 public static function get_pages() {
306 $pages = [];
307 $rawPages = get_pages();
308 if ( ! empty( $rawPages ) ) {
309 foreach ( $rawPages as $page ) {
310 $pages[ $page->ID ] = $page->post_title;
311 }
312 }
313
314 return $pages;
315 }
316
317 public static function get_section_items( $section_id ) {
318 if ( ! $section_id ) {
319 return [];
320 }
321
322 return DataModel::source()->get_option( $section_id, [] );
323 }
324
325 public static function get_options( $section_id, $item_id ) {
326 if ( ! $section_id || ! $item_id ) {
327 return [];
328 }
329 $sections = self::get_section_items( $section_id );
330
331 return isset( $sections[ $item_id ] ) ? $sections[ $item_id ] : [];
332 }
333
334 /**
335 * @param string $section_id
336 * @param string $item_id
337 * @param string $option_id
338 * @param null $default EXCEPT multi_checkbox you can provide default value if given option does not set any value
339 * @param null $type checkbox, multi_checkbox, number
340 *
341 * @return bool|int|mixed|null
342 */
343 public static function get_option( $section_id, $item_id, $option_id, $default = null, $type = null ) {
344 $options = self::get_options( $section_id, $item_id );
345
346 if ( $type === 'checkbox' ) {
347 if ( isset( $options[ $option_id ] ) ) {
348 return $options[ $option_id ] === 'on';
349 }
350
351 return $default;
352 } elseif ( $type === 'multi_checkbox' ) {
353 return isset( $options[ $option_id ] ) && is_array( $options[ $option_id ] ) && in_array( $default, $options[ $option_id ] );
354 } elseif ( $type === 'number' ) {
355 return isset( $options[ $option_id ] ) ? absint( $options[ $option_id ] ) : absint( $default );
356 }
357
358 return isset( $options[ $option_id ] ) && ! empty( $options[ $option_id ] ) ? $options[ $option_id ] : $default;
359 }
360
361
362 /**
363 * Create a page and store the ID in an option.
364 *
365 * @param mixed $slug Slug for the new page.
366 * @param array $options ['section_id', 'item_id', 'option_id']Option name to store the page's ID.
367 * @param string $page_title (default: '') Title for the new page.
368 * @param string $page_content (default: '') Content for the new page.
369 * @param int $post_parent (default: 0) Parent for the new page.
370 * @param string $post_status (default: publish) The post status of the new page.
371 *
372 * @return int page ID.
373 */
374 public static function create_page( $slug, $options = '', $page_title = '', $page_content = '', $post_parent = 0, $post_status = 'publish' ) {
375 global $wpdb;
376
377 $option_value = 0;
378 if ( ! empty( $options ) ) {
379 if ( is_array( $options ) ) {
380 $options = wp_parse_args(
381 $options,
382 [
383 'section_id' => '',
384 'item_id' => '',
385 'option_id' => '',
386 ]
387 );
388 $option_value = self::get_option( $options['section_id'], $options['item_id'], $options['option_id'], 0, 'number' );
389 } else {
390 $option_value = absint( get_option( $options ) );
391 }
392 }
393
394 if ( $option_value > 0 ) {
395 $page_object = get_post( $option_value );
396
397 if ( $page_object && 'page' === $page_object->post_type && ! in_array(
398 $page_object->post_status,
399 [
400 'pending',
401 'trash',
402 'future',
403 'auto-draft',
404 ],
405 true
406 ) ) {
407 // Valid page is already in place.
408 return $page_object->ID;
409 }
410 }
411
412 if ( strlen( $page_content ) > 0 ) {
413 // Search for an existing page with the specified page content (typically a shortcode).
414 $shortcode = str_replace( [ '<!-- wp:shortcode -->', '<!-- /wp:shortcode -->' ], '', $page_content );
415 $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$shortcode}%" ) );
416 } else {
417 // Search for an existing page with the specified page slug.
418 $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug ) );
419 }
420
421 $valid_page_found = apply_filters( 'rtsb/core/create_page_id', $valid_page_found, $slug, $page_content, $options );
422
423 if ( $valid_page_found ) {
424 if ( is_array( $options ) ) {
425 if ( ! empty( $options['section_id'] ) && $options['item_id'] && $options['option_id'] ) {
426 $section_items = DataModel::source()->get_option( $options['section_id'], [] );
427 $section_items[ $options['item_id'] ][ $options['option_id'] ] = $valid_page_found;
428 DataModel::source()->set_option( $options['section_id'], $section_items );
429 }
430 } else {
431 if ( $options ) {
432 update_option( $options, $valid_page_found );
433 }
434 }
435
436 return $valid_page_found;
437 }
438
439 // Search for a matching valid trashed page.
440 if ( strlen( $page_content ) > 0 ) {
441 // Search for an existing page with the specified page content (typically a shortcode).
442 $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
443 } else {
444 // Search for an existing page with the specified page slug.
445 $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) );
446 }
447
448 if ( $trashed_page_found ) {
449 $page_id = $trashed_page_found;
450 $page_data = [
451 'ID' => $page_id,
452 'post_status' => $post_status,
453 ];
454 wp_update_post( $page_data );
455 } else {
456 $page_data = [
457 'post_status' => $post_status,
458 'post_type' => 'page',
459 'post_author' => 1,
460 'post_name' => $slug,
461 'post_title' => $page_title,
462 'post_content' => $page_content,
463 'post_parent' => $post_parent,
464 'comment_status' => 'closed',
465 ];
466 $page_id = wp_insert_post( $page_data );
467
468 do_action( 'rtsb/core/page_created', $page_id, $page_data );
469 }
470
471 if ( is_array( $options ) ) {
472 if ( ! empty( $options['section_id'] ) && $options['item_id'] && $options['option_id'] ) {
473 $section_items = DataModel::source()->get_option( $options['section_id'], [] );
474 $section_items[ $options['item_id'] ][ $options['option_id'] ] = $page_id;
475 DataModel::source()->set_option( $options['section_id'], $section_items );
476 }
477 } else {
478 if ( $options ) {
479 update_option( $options, $page_id );
480 }
481 }
482
483 return $page_id;
484 }
485
486 // TODO:: Need to remove if not used.
487 public static function get_kses_array() {
488 return [
489 'a' => [
490 'class' => [],
491 'href' => [],
492 'rel' => [],
493 'title' => [],
494 ],
495 'abbr' => [
496 'title' => [],
497 ],
498 'b' => [],
499 'blockquote' => [
500 'cite' => [],
501 ],
502 'cite' => [
503 'title' => [],
504 ],
505 'code' => [],
506 'del' => [
507 'datetime' => [],
508 'title' => [],
509 ],
510 'dd' => [],
511 'div' => [
512 'class' => [],
513 'title' => [],
514 'style' => [],
515 ],
516 'dl' => [],
517 'dt' => [],
518 'em' => [],
519 'h1' => [
520 'class' => [],
521 ],
522 'h2' => [
523 'class' => [],
524 ],
525 'h3' => [
526 'class' => [],
527 ],
528 'h4' => [
529 'class' => [],
530 ],
531 'h5' => [
532 'class' => [],
533 ],
534 'h6' => [
535 'class' => [],
536 ],
537 'i' => [
538 'class' => [],
539 ],
540 'img' => [
541 'alt' => [],
542 'class' => [],
543 'height' => [],
544 'src' => [],
545 'width' => [],
546 ],
547 'li' => [
548 'class' => [],
549 ],
550 'ol' => [
551 'class' => [],
552 ],
553 'p' => [
554 'class' => [],
555 ],
556 'q' => [
557 'cite' => [],
558 'title' => [],
559 ],
560 'span' => [
561 'class' => [],
562 'title' => [],
563 'style' => [],
564 ],
565 'iframe' => [
566 'width' => [],
567 'height' => [],
568 'scrolling' => [],
569 'frameborder' => [],
570 'allow' => [],
571 'src' => [],
572 ],
573 'strike' => [],
574 'br' => [],
575 'strong' => [],
576 'data-wow-duration' => [],
577 'data-wow-delay' => [],
578 'data-wallpaper-options' => [],
579 'data-stellar-background-ratio' => [],
580 'ul' => [
581 'class' => [],
582 ],
583 ];
584 }
585
586 // TODO:: Need to remove if not used.
587 public static function kses( $raw, $allowDanger = false ) {
588
589 if ( function_exists( 'wp_kses' ) && ! $allowDanger ) { // WP is here
590 return wp_kses( $raw, self::get_kses_array() );
591 } else {
592 return $raw;
593 }
594 }
595
596 /*
597 * Escape output of wishlist icon
598 *
599 * @param string $data Data to escape.
600 * @return string Escaped data
601 */
602 public static function print_icon( $data ) {
603 /**
604 * APPLY_FILTERS: rtsb/core/allowed_icon_html
605 *
606 * Filter the allowed HTML for the icons.
607 *
608 * @param array $allowed_icon_html Allowed HTML
609 *
610 * @return array
611 */
612 $allowed_icon_html = apply_filters(
613 'rtsb/core/allowed_icon_html',
614 [
615 'i' => [
616 'class' => true,
617 ],
618 'img' => [
619 'src' => true,
620 'alt' => true,
621 'width' => true,
622 'height' => true,
623 ],
624 'svg' => [
625 'class' => true,
626 'aria-hidden' => true,
627 'aria-labelledby' => true,
628 'role' => true,
629 'xmlns' => true,
630 'width' => true,
631 'height' => true,
632 'viewbox' => true,
633 'stroke' => true,
634 'fill' => true,
635 ],
636 'g' => [
637 'fill' => true,
638 ],
639 'title' => [
640 'title' => true,
641 ],
642 'path' => [
643 'd' => true,
644 'fill' => true,
645 'stroke-width' => true,
646 'stroke-linecap' => true,
647 'stroke-linejoin' => true,
648 ],
649 ]
650 );
651
652 echo wp_kses( $data, $allowed_icon_html );
653 }
654
655 /**
656 * Prints HTMl.
657 *
658 * @param string $html HTML.
659 * @param bool $allHtml All HTML.
660 *
661 * @return void
662 */
663 public static function print_html( $html, $allHtml = false ) {
664 if ( $allHtml ) {
665 echo stripslashes_deep( $html ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
666 } else {
667 echo wp_kses_post( stripslashes_deep( $html ) );
668 }
669 }
670
671 /**
672 * Allowed HTML for wp_kses.
673 *
674 * @param string $level Tag level.
675 *
676 * @return mixed
677 */
678 public static function allowedHtml( $level = 'basic' ) {
679 $allowed_html = [];
680 // TODO:: Need Optimize.
681 switch ( $level ) {
682 case 'basic':
683 $allowed_html = [
684 'b' => [
685 'class' => [],
686 'id' => [],
687 ],
688 'i' => [
689 'class' => [],
690 'id' => [],
691 ],
692 'u' => [
693 'class' => [],
694 'id' => [],
695 ],
696 'br' => [
697 'class' => [],
698 'id' => [],
699 ],
700 'em' => [
701 'class' => [],
702 'id' => [],
703 ],
704 'span' => [
705 'class' => [],
706 'id' => [],
707 ],
708 'strong' => [
709 'class' => [],
710 'id' => [],
711 ],
712 'hr' => [
713 'class' => [],
714 'id' => [],
715 ],
716 'div' => [
717 'class' => [],
718 'id' => [],
719 ],
720 'a' => [
721 'href' => [],
722 'title' => [],
723 'class' => [],
724 'id' => [],
725 'target' => [],
726 ],
727 ];
728 break;
729
730 case 'advanced':
731 $allowed_html = [
732 'b' => [
733 'class' => [],
734 'id' => [],
735 ],
736 'i' => [
737 'class' => [],
738 'id' => [],
739 ],
740 'u' => [
741 'class' => [],
742 'id' => [],
743 ],
744 'br' => [
745 'class' => [],
746 'id' => [],
747 ],
748 'em' => [
749 'class' => [],
750 'id' => [],
751 ],
752 'span' => [
753 'class' => [],
754 'id' => [],
755 ],
756 'strong' => [
757 'class' => [],
758 'id' => [],
759 ],
760 'hr' => [
761 'class' => [],
762 'id' => [],
763 ],
764 'a' => [
765 'href' => [],
766 'title' => [],
767 'class' => [],
768 'id' => [],
769 'target' => [],
770 ],
771 'input' => [
772 'type' => [],
773 'name' => [],
774 'class' => [],
775 'value' => [],
776 ],
777 ];
778 break;
779
780 case 'image':
781 $allowed_html = [
782 'img' => [
783 'src' => [],
784 'data-src' => [],
785 'alt' => [],
786 'height' => [],
787 'width' => [],
788 'class' => [],
789 'id' => [],
790 'style' => [],
791 'srcset' => [],
792 'loading' => [],
793 'sizes' => [],
794 ],
795 'div' => [
796 'class' => [],
797 ],
798 ];
799 break;
800
801 case 'anchor':
802 $allowed_html = [
803 'a' => [
804 'href' => [],
805 'title' => [],
806 'class' => [],
807 'id' => [],
808 'style' => [],
809 ],
810 ];
811 break;
812
813 default:
814 // code...
815 break;
816 }
817
818 return $allowed_html;
819 }
820
821 /**
822 * Definition for wp_kses.
823 *
824 * @param string $string String to check.
825 * @param string $level Tag level.
826 *
827 * @return string|void
828 */
829 // TODO:: Need to remove if not used.
830 public static function htmlKses( $string, $level ) {
831 if ( empty( $string ) ) {
832 return;
833 }
834
835 return wp_kses( $string, self::allowedHtml( $level ) );
836 }
837
838 /**
839 * Insert Some array element
840 *
841 * @param [type] $key The elements will insert nearby this key.
842 * @param [type] $main_array Original array.
843 * @param [type] $insert_array some element will insert in original array.
844 * @param boolean $is_after array insert position base on the key.
845 *
846 * @return array
847 */
848 public static function insert_controls( $key, $main_array, $insert_array, $is_after = false ) {
849 $index = array_search( $key, array_keys( $main_array ), true );
850 if ( 'integer' === gettype( $index ) ) {
851 if ( $is_after ) {
852 $index ++;
853 }
854 $main_array = array_merge(
855 array_slice( $main_array, 0, $index ),
856 $insert_array,
857 array_slice( $main_array, $index )
858 );
859 }
860
861 return $main_array;
862 }
863
864 /**
865 * Image Sizes
866 *
867 * @return array
868 */
869 public static function get_image_sizes() {
870 global $_wp_additional_image_sizes;
871
872 $sizes = [];
873
874 foreach ( get_intermediate_image_sizes() as $_size ) {
875 if ( in_array( $_size, [ 'thumbnail', 'medium', 'large' ], true ) ) {
876 $sizes[ $_size ]['width'] = get_option( "{$_size}_size_w" );
877 $sizes[ $_size ]['height'] = get_option( "{$_size}_size_h" );
878 $sizes[ $_size ]['crop'] = (bool) get_option( "{$_size}_crop" );
879 } elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
880 $sizes[ $_size ] = [
881 'width' => $_wp_additional_image_sizes[ $_size ]['width'],
882 'height' => $_wp_additional_image_sizes[ $_size ]['height'],
883 'crop' => $_wp_additional_image_sizes[ $_size ]['crop'],
884 ];
885 }
886 }
887
888 $imgSize = [];
889
890 foreach ( $sizes as $key => $img ) {
891 $imgSize[ $key ] = ucfirst( $key ) . " ({$img['width']}*{$img['height']})";
892 }
893
894 $imgSize['full'] = esc_html__( 'Full size', 'shopbuilder' );
895 $imgSize['rtsb_custom'] = esc_html__( 'Custom image size', 'shopbuilder' );
896
897 return $imgSize;
898 }
899
900 /**
901 * Free Layouts
902 *
903 * @return array
904 */
905 public static function free_layouts() {
906 $layouts = [
907 'grid-layout1' => esc_html__( 'Grid Layout 1', 'shopbuilder' ),
908 'grid-layout2' => esc_html__( 'Grid Layout 2', 'shopbuilder' ),
909 'list-layout1' => esc_html__( 'List Layout 1', 'shopbuilder' ),
910 'list-layout2' => esc_html__( 'List Layout 2', 'shopbuilder' ),
911 'slider-layout1' => esc_html__( 'Slider Layout 1', 'shopbuilder' ),
912 'slider-layout2' => esc_html__( 'Slider Layout 2', 'shopbuilder' ),
913 'category-single-layout1' => esc_html__( 'Category Single Layout 1', 'shopbuilder' ),
914 'category-layout1' => esc_html__( 'Category Layout 1', 'shopbuilder' ),
915 'category-layout2' => esc_html__( 'Category Layout 2', 'shopbuilder' ),
916 'category-layout3' => esc_html__( 'Category Layout 2', 'shopbuilder' ),
917 ];
918
919 return apply_filters( 'rtsb/elements/elementor/free_layouts', $layouts );
920 }
921
922 /**
923 * Get all terms by taxonomy
924 *
925 * @param string $taxonomy Taxonomy name.
926 *
927 * @return array
928 */
929 public static function get_all_terms( $taxonomy ) {
930 $terms = [];
931
932 if ( empty( $taxonomy ) ) {
933 return $terms;
934 }
935
936 $termList = get_terms( [ $taxonomy ], [ 'hide_empty' => 0 ] );
937
938 if ( is_array( $termList ) && ! empty( $termList ) && empty( $termList['errors'] ) ) {
939 foreach ( $termList as $term ) {
940 $terms[ $term->term_id ] = esc_html( $term->name );
941 }
942 }
943
944 return $terms;
945 }
946
947 /**
948 * Get all terms by attributes
949 *
950 * @return array
951 */
952 public static function get_all_attributes() {
953 $terms = [];
954 $termList = [];
955
956 $attributes = wc_get_attribute_taxonomies();
957
958 if ( $attributes ) {
959 foreach ( $attributes as $tax ) {
960 if ( taxonomy_exists( wc_attribute_taxonomy_name( $tax->attribute_name ) ) ) {
961 $termList[ $tax->attribute_name ] = get_terms( wc_attribute_taxonomy_name( $tax->attribute_name ), 'orderby=name&hide_empty=0' );
962 }
963 }
964 }
965
966 if ( ! empty( $termList ) && empty( $termList['errors'] ) && is_array( $termList ) ) {
967 foreach ( $termList as $name => $atts ) {
968 foreach ( $atts as $term ) {
969 $terms[ $term->term_id ] = esc_html( ucwords( str_replace( '-', ' ', $name ) ) . ' - ' . $term->name );
970 }
971 }
972 }
973
974 return $terms;
975 }
976
977 /**
978 * Get User list
979 *
980 * @return array
981 */
982 public static function get_users() {
983 $users = [];
984 $u = get_users();
985
986 if ( ! empty( $u ) ) {
987 foreach ( $u as $user ) {
988 $users[ $user->ID ] = $user->display_name;
989 }
990 }
991
992 return $users;
993 }
994
995 /**
996 * Get products list.
997 *
998 * @return array
999 */
1000 public static function get_products_list() {
1001 $products = [];
1002 // TODO:: Need To replace with $wpdb.
1003 $query = get_posts(
1004 [
1005 'post_type' => 'product',
1006 'post_status' => 'publish',
1007 'posts_per_page' => - 1,
1008 'orderby' => 'title',
1009 'order' => 'ASC',
1010 ]
1011 );
1012
1013 if ( ! empty( $query ) && is_array( $query ) ) {
1014 foreach ( $query as $product ) {
1015 $products[ $product->ID ] = $product->post_title;
1016 }
1017 }
1018
1019 return $products;
1020 }
1021
1022 /**
1023 * Get Taxonomy List.
1024 *
1025 * @return array
1026 */
1027 public static function get_tax_list() {
1028 return [
1029 'product_cat' => esc_html__( 'Product Category', 'shopbuilder' ),
1030 // 'product_tag' => esc_html__( 'Product Tag', 'shopbuilder' ), // Pro.
1031 // 'product_attr' => esc_html__( 'Product Attr', 'shopbuilder' ), // Pro.
1032 ];
1033 }
1034
1035 /**
1036 * Get Category Query List.
1037 *
1038 * @return array
1039 */
1040 public static function get_cat_list() {
1041 return [
1042 'all' => esc_html__( 'All Categories', 'shopbuilder' ),
1043 'specific_parent' => esc_html__( 'Sub-Categories by Parent', 'shopbuilder' ),
1044 'cat_ids' => esc_html__( 'Select by ID', 'shopbuilder' ),
1045 'selection' => esc_html__( 'Manual Selection', 'shopbuilder' ),
1046 ];
1047 }
1048
1049 /**
1050 * Get Term List.
1051 *
1052 * @param string $taxonomy Taxonomy.
1053 * @param bool $first_term First term.
1054 * @param bool $only_parents Only parent terms.
1055 * @param bool $return_slug Return with slug.
1056 *
1057 * @return int|array
1058 */
1059 public static function get_terms( $taxonomy, $first_term = false, $only_parents = false, $return_slug = false ) {
1060 // TODO:: Return Slug always true for all settings.
1061 $term_list = [];
1062 $args = [
1063 'taxonomy' => $taxonomy,
1064 'hide_empty' => false,
1065 ];
1066
1067 if ( $only_parents ) {
1068 $args['parent'] = 0;
1069 }
1070
1071 $terms = get_terms( $args );
1072
1073 if ( empty( $terms ) ) {
1074 return [ esc_html__( 'Nothing found', 'shopbuilder' ) ];
1075 }
1076
1077 foreach ( $terms as $term ) {
1078 if ( $return_slug ) {
1079 $term_list[ $term->slug ] = $term->name;
1080 } else {
1081 $term_list[ $term->term_id ] = $term->name;
1082 }
1083 }
1084
1085 if ( $first_term ) {
1086 return array_keys( $term_list )[0];
1087 } else {
1088 return $term_list;
1089 }
1090 }
1091
1092 /**
1093 * Get product rating.
1094 *
1095 * @return string|void
1096 */
1097 public static function get_product_rating_html() {
1098 global $product;
1099
1100 $html = '';
1101 $rating_count = $product->get_rating_count();
1102 $average = $product->get_average_rating();
1103
1104 if ( empty( wc_get_rating_html( $average, $rating_count ) ) ) {
1105 return $html;
1106 }
1107
1108 $html .= '<div class="product-rating">';
1109 $html .= wc_get_rating_html( $average, $rating_count );
1110 // TODO:: Disable Rating Count option need to apply.
1111 $html .= ! empty( $html ) ? '<span class="count">(' . $average . ')</span>' : '';
1112 $html .= '</div>';
1113
1114 self::print_html( $html, true );
1115 }
1116
1117 /**
1118 * Text truncation.
1119 *
1120 * @param string $text_to_truncate Text.
1121 * @param int $limit Limit.
1122 * @param string $after After text.
1123 *
1124 * @return string
1125 */
1126 public static function text_truncation( $text_to_truncate, $limit, $after = '&#8230;' ) {
1127 if ( empty( $limit ) ) {
1128 return $text_to_truncate;
1129 }
1130
1131 $limit ++;
1132
1133 $text = '';
1134
1135 if ( mb_strlen( $text_to_truncate ) > $limit ) {
1136 $subex = mb_substr( wp_strip_all_tags( $text_to_truncate ), 0, $limit );
1137 $exwords = explode( ' ', $subex );
1138 $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
1139
1140 if ( $excut < 0 ) {
1141 $text .= mb_substr( $subex, 0, $excut ) . $after;
1142 } else {
1143 $text .= $subex . $after;
1144 }
1145 } else {
1146 $text .= $text_to_truncate;
1147 }
1148
1149 return $text;
1150 }
1151
1152 /**
1153 * Promo Badge HTML
1154 *
1155 * @param string $text Text.
1156 * @param string $class Class.
1157 *
1158 * @return void
1159 */
1160 public static function get_badge_html( $text, $class = 'fill' ) {
1161
1162 ob_start();
1163 ?>
1164
1165 <ul class="rtsb-promotion-list">
1166 <li class="rtsb-promotion-list-item">
1167 <span class="rtsb-tag-<?php echo ! empty( $class ) ? esc_attr( $class ) : ''; ?>"><?php echo esc_html( $text ); ?></span>
1168 </li>
1169 </ul>
1170
1171 <?php
1172 self::print_html( ob_get_clean() );
1173 }
1174
1175 /**
1176 * Categories HTML
1177 *
1178 * @param int $id Product ID.
1179 * @param string $class Custom class.
1180 *
1181 * @return void|string
1182 */
1183 public static function get_categories_list( $id, $class = 'rtsb-category-outline' ) {
1184 if ( empty( $id ) ) {
1185 return '';
1186 }
1187
1188 ob_start();
1189 ?>
1190
1191 <ul class="rtsb-category-list <?php echo esc_attr( $class ); ?>">
1192 <?php
1193 self::print_html(
1194 wc_get_product_category_list(
1195 $id,
1196 '</li><li class="rtsb-category-list-item">',
1197 '<li class="rtsb-category-list-item">',
1198 '</li>'
1199 )
1200 );
1201 ?>
1202 </ul>
1203
1204 <?php
1205 self::print_html( ob_get_clean() );
1206 }
1207
1208
1209 /**
1210 * Get Featured Image HTML.
1211 *
1212 * @param string $type Image type.
1213 * @param int $post_id Post ID.
1214 * @param string $f_img_size Image size.
1215 * @param null $default_img_id Default image ID.
1216 * @param array $custom_img_size Custom image size.
1217 * @param bool $lazy Lazy load check.
1218 * @param bool $hover Hover image.
1219 *
1220 * @return string|null
1221 */
1222 public static function get_product_image_html( $type = 'product', $post_id = null, $f_img_size = 'medium', $default_img_id = null, $custom_img_size = [], $lazy = false, $hover = false ) {
1223 $img_html = null;
1224 $attachment_id = null;
1225 $c_size = false;
1226 $hover_class = '';
1227 $post_title = '';
1228
1229 if ( 'rtsb_custom' === $f_img_size ) {
1230 $f_img_size = 'full';
1231 $c_size = true;
1232 }
1233
1234 if ( $hover ) {
1235 $a_id = $post_id;
1236 $hover_class = ' rtsb-img-hover';
1237 } else {
1238 if ( 'product' === $type ) {
1239 $a_id = get_post_thumbnail_id( $post_id );
1240 $post_title = get_the_title( $post_id );
1241 } elseif ( 'category' === $type ) {
1242 $a_id = get_term_meta( $post_id, 'thumbnail_id', true );
1243 $post_title = get_term( $post_id )->name;
1244 } else {
1245 $a_id = $default_img_id;
1246 }
1247 }
1248
1249 $img_alt = trim( wp_strip_all_tags( get_post_meta( $a_id, '_wp_attachment_image_alt', true ) ) );
1250 $alt_tag = ! empty( $img_alt ) ? $img_alt : wp_strip_all_tags( $post_title );
1251 $lazy_class = $lazy ? ' swiper-lazy' : '';
1252 $attr = [
1253 'class' => 'img-responsive rtsb-product-image' . $lazy_class . $hover_class,
1254 'alt' => $alt_tag,
1255 ];
1256
1257 if ( $a_id ) {
1258 $img_html = wp_get_attachment_image( $a_id, $f_img_size, false, $attr );
1259 $attachment_id = $a_id;
1260 }
1261
1262 if ( ! $img_html && $default_img_id ) {
1263 $img_html = wp_get_attachment_image( $default_img_id, $f_img_size, false, $attr );
1264 $attachment_id = $default_img_id;
1265 }
1266
1267 if ( $img_html && $c_size ) {
1268 preg_match( '@src="([^"]+)"@', $img_html, $match );
1269 $img_src = array_pop( $match );
1270 $w = ! empty( $custom_img_size['width'] ) ? absint( $custom_img_size['width'] ) : null;
1271 $h = ! empty( $custom_img_size['height'] ) ? absint( $custom_img_size['height'] ) : null;
1272 $c = ! empty( $custom_img_size['crop'] ) && 'soft' === $custom_img_size['crop'] ? false : true;
1273
1274 if ( $w && $h ) {
1275 $image = self::image_resize( $img_src, $w, $h, $c, false );
1276
1277 if ( ! empty( $image ) ) {
1278 [ $src, $width, $height ] = $image;
1279
1280 $hwstring = image_hwstring( $width, $height );
1281 $attachment = get_post( $attachment_id );
1282 $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $f_img_size );
1283
1284 if ( $lazy ) {
1285 $attr['data-src'] = $src;
1286 } else {
1287 $attr['src'] = $src;
1288 }
1289
1290 $attr = array_map( 'esc_attr', $attr );
1291 $img_html = rtrim( "<img $hwstring" );
1292
1293 foreach ( $attr as $name => $value ) {
1294 $img_html .= " $name=" . '"' . $value . '"';
1295 }
1296
1297 $img_html .= ' />';
1298 }
1299 }
1300 }
1301
1302 if ( ! $img_html ) {
1303 $hwstring = image_hwstring( 160, 160 );
1304 $attr = isset( $attr['src'] ) ? apply_filters( 'wp_get_attachment_image_attributes', $attr, false, $f_img_size ) : [];
1305 $attr['class'] = 'default-img';
1306 $attr['src'] = esc_url( rtsb()->get_assets_uri( 'images/demo.png' ) );
1307 $attr['alt'] = esc_html__( 'Default Image', 'shopbuilder' );
1308 $img_html = rtrim( "<img $hwstring" );
1309
1310 foreach ( $attr as $name => $value ) {
1311 $img_html .= " $name=" . '"' . $value . '"';
1312 }
1313
1314 $img_html .= ' />';
1315 }
1316
1317 if ( $lazy ) {
1318 $img_html = $img_html . '<div class="swiper-lazy-preloader swiper-lazy-preloader"></div>';
1319 }
1320
1321 return $img_html;
1322 }
1323
1324 /**
1325 * Call the Image resize model for resize function
1326 *
1327 * @param string $url URL.
1328 * @param int $width Width.
1329 * @param int $height Height.
1330 * @param string $crop Crop.
1331 * @param bool|true $single Single.
1332 * @param bool|false $upscale Upscale.
1333 *
1334 * @return array|bool|string
1335 */
1336 public static function image_resize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
1337 $rtResize = new ReSizer();
1338
1339 return $rtResize->process( $url, $width, $height, $crop, $single, $upscale );
1340 }
1341
1342 /**
1343 * Get Product Image
1344 *
1345 * @param string $f_image Featured Image.
1346 * @param string $h_image Hover Image.
1347 *
1348 * @return void
1349 */
1350 public static function get_product_image( $f_image, $h_image = null ) {
1351 echo wp_kses( $f_image, self::allowedHtml( 'image' ) );
1352
1353 if ( ! empty( $h_image ) ) {
1354 echo wp_kses( $h_image, self::allowedHtml( 'image' ) );
1355 }
1356 }
1357
1358 /**
1359 * Post Custom Field value.
1360 *
1361 * @param int $post_id Post id.
1362 * @param string $field_key Custom Field Key.
1363 * @param string $field_fallback FallBack text.
1364 *
1365 * @return string|void
1366 */
1367 public static function get_post_custom_field_value( $post_id, $field_key = '', $field_fallback = '' ) {
1368 if ( ! $post_id || ! $field_key ) {
1369 return;
1370 }
1371 $field_value = get_post_meta( $post_id, $field_key, true );
1372 if ( empty( $field_value ) ) {
1373 $field_value = ! empty( $field_fallback ) ? $field_fallback : $field_value;
1374 }
1375 $field_value = apply_filters( 'rtsb/get_post_custom_field_value/' . $field_key, $field_value, $field_key );
1376
1377 return sprintf( '<span class="rtsb-woo-custom-field">%s</span>', $field_value );
1378 }
1379
1380 /**
1381 * Elementor Icon
1382 *
1383 * @param array $control Elementor Control array.
1384 * @param string $class Custom class.
1385 * @param string $builder Builder name.
1386 *
1387 * @return string
1388 */
1389 public static function icons_manager( $control, $class = '', $builder = 'elementor' ): string {
1390 $attributes = [
1391 'aria-hidden' => 'true',
1392 ];
1393
1394 if ( ! empty( $class ) ) {
1395 $attributes['class'] = esc_attr( $class );
1396 }
1397
1398 ob_start();
1399
1400 if ( defined( 'ELEMENTOR_VERSION' ) && ! empty( $control ) && 'elementor' === $builder ) {
1401 Icons_Manager::render_icon( $control, $attributes );
1402 }
1403
1404 return ob_get_clean();
1405 }
1406
1407 /**
1408 * Get sale badge
1409 *
1410 * @param string $type Badge type.
1411 * @param string $text Badge text.
1412 * @param string $out_of_stock_text Out of stock text.
1413 *
1414 * @return string
1415 */
1416 public static function get_sale_badge( $type, $text, $out_of_stock_text ) {
1417 global $product;
1418
1419 if ( ! $product->is_in_stock() ) {
1420 return $out_of_stock_text;
1421 }
1422
1423 if ( ! $product->is_on_sale() ) {
1424 return '';
1425 }
1426
1427 $badge_text = '';
1428 $percentage = null;
1429 $max_percentage = '';
1430
1431 if ( $product->is_type( 'simple' ) ) {
1432 $max_percentage = ( ( $product->get_regular_price() - $product->get_sale_price() ) / $product->get_regular_price() ) * 100;
1433 } elseif ( $product->is_type( 'variable' ) ) {
1434 $max_percentage = 0;
1435
1436 foreach ( $product->get_children() as $child_id ) {
1437
1438 $variation = wc_get_product( $child_id );
1439
1440 $price = $variation->get_regular_price();
1441 $sale = $variation->get_sale_price();
1442
1443 if ( 0 !== $price && ! empty( $sale ) ) {
1444 $percentage = ( $price - $sale ) / $price * 100;
1445 }
1446
1447 if ( $percentage > $max_percentage ) {
1448 $max_percentage = $percentage;
1449 }
1450 }
1451 }
1452
1453 if ( $max_percentage > 0 ) {
1454 $badge_text = '-' . round( $max_percentage ) . '%';
1455 }
1456
1457 if ( 'text' === $type ) {
1458 $badge_text = $text;
1459 }
1460
1461 return $badge_text;
1462 }
1463
1464 /**
1465 * Pagination
1466 *
1467 * @param string $pages Pages.
1468 * @param integer $range Range.
1469 * @param boolean $ajax Ajax.
1470 *
1471 * @return string
1472 */
1473 public static function custom_pagination( $pages = '', $range = 4, $ajax = false ) {
1474 $html = null;
1475 $showitems = ( $range * 2 ) + 1;
1476
1477 global $paged;
1478
1479 if ( is_front_page() ) {
1480 $paged = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1;
1481 } else {
1482 $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
1483 }
1484
1485 if ( empty( $paged ) ) {
1486 $paged = 1;
1487 }
1488
1489 if ( $pages == '' ) {
1490 global $wp_query;
1491 $pages = $wp_query->max_num_pages;
1492
1493 if ( ! $pages ) {
1494 $pages = 1;
1495 }
1496 }
1497
1498 $ajaxClass = null;
1499 $dataAttr = null;
1500
1501 if ( $ajax ) {
1502 $ajaxClass = ' rtsb-ajax';
1503 $dataAttr = "data-paged='1'";
1504 }
1505
1506 if ( 1 != $pages ) {
1507 $html .= '<div class="rtsb-pagination' . $ajaxClass . '" ' . $dataAttr . '>';
1508 $html .= '<ul class="pagination-list">';
1509
1510 if ( $paged > 2 && $paged > $range + 1 && $showitems < $pages ) {
1511 $html .= "<li><a data-paged='1' href='" . get_pagenum_link( 1 ) . "' aria-label='First'>&laquo;</a></li>";
1512 }
1513
1514 if ( $paged > 1 && $showitems < $pages ) {
1515 $p = $paged - 1;
1516 $html .= "<li><a data-paged='{$p}' href='" . get_pagenum_link( $p ) . "' aria-label='Previous'>&lsaquo;</a></li>";
1517 }
1518
1519 for ( $i = 1; $i <= $pages; $i ++ ) {
1520 if ( 1 != $pages && ( ! ( $i >= $paged + $range + 1 || $i <= $paged - $range - 1 ) || $pages <= $showitems ) ) {
1521 $html .= ( $paged == $i ) ? '<li class="active"><span>' . $i . '</span></li>' : "<li><a data-paged='{$i}' href='" . get_pagenum_link( $i ) . "'>" . $i . '</a></li>';
1522 }
1523 }
1524
1525 if ( $paged < $pages && $showitems < $pages ) {
1526 $p = $paged + 1;
1527 $html .= "<li><a data-paged='{$p}' href=\"" . get_pagenum_link( $paged + 1 ) . "\" aria-label='Next'>&rsaquo;</a></li>";
1528 }
1529
1530 if ( $paged < $pages - 1 && $paged + $range - 1 < $pages && $showitems < $pages ) {
1531 $html .= "<li><a data-paged='{$pages}' href='" . get_pagenum_link( $pages ) . "' aria-label='Last'>&raquo;</a></li>";
1532 }
1533
1534 $html .= '</ul>';
1535 $html .= '</div>';
1536 }
1537
1538 return $html;
1539 }
1540
1541 /**
1542 * Action Buttons HTMl
1543 *
1544 * @param array $items Items.
1545 * @param array $ajax_cart Ajax cart HTML.
1546 * @param string $preset Button preset.
1547 * @param array $position Position.
1548 *
1549 * @return void|string
1550 */
1551 public static function get_formatted_action_buttons( $items, $ajax_cart = '', $preset = 'preset1', $position = 'above' ) {
1552 if ( empty( $items ) ) {
1553 return;
1554 }
1555
1556 $html = '';
1557 $class = '';
1558
1559 if ( 'after' === $position ) {
1560 $class .= 'after-content';
1561 }
1562
1563 if ( 'preset2' === $preset ) {
1564 $class .= ' rtsb-action-buttons-vertical vertical-delay-effect';
1565 } elseif ( 'preset4' === $preset ) {
1566 $class .= 'rtsb-action-buttons-vertical rtsb-action-buttons-vertical-left vertical-delay-effect';
1567 } elseif ( 'preset5' === $preset ) {
1568 $class .= ' action-buttons-outline horizontal-floating-btn';
1569 } else {
1570 $class .= ' rtsb-action-buttons-cart-box-width-auto horizontal-floating-btn';
1571 }
1572
1573 if ( 'preset3' === $preset ) {
1574 $html .= '<div class="rtsb-action-buttons top-part">';
1575 $html .= '<ul class="rtsb-action-button-list">';
1576 $html .= self::get_action_button_by_type( $items, 'wishlist' );
1577 $html .= self::get_action_button_by_type( $items, 'compare' );
1578 $html .= self::get_action_button_by_type( $items, 'quick_view' );
1579 $html .= '</ul>';
1580 $html .= '</div>';
1581
1582 $html .= '<div class="rtsb-action-buttons bottom-part">';
1583 $html .= '<ul class="rtsb-action-button-list">';
1584 $html .= self::get_action_button_by_type( $items, 'add_to_cart', $ajax_cart );
1585 } else {
1586 $html .= '<div class="rtsb-action-buttons ' . esc_attr( $class ) . '">';
1587 $html .= '<ul class="rtsb-action-button-list">';
1588 $html .= self::get_action_button_by_type( $items, 'add_to_cart', $ajax_cart );
1589 $html .= self::get_action_button_by_type( $items, 'wishlist' );
1590 $html .= self::get_action_button_by_type( $items, 'compare' );
1591 $html .= self::get_action_button_by_type( $items, 'quick_view' );
1592 }
1593
1594 $html .= '</ul>';
1595 $html .= '</div>';
1596
1597 return apply_filters( 'rtsb/elements/elementor/get_formatted_action_buttons', $html );
1598 }
1599
1600 /**
1601 * Get Action Button HTML
1602 *
1603 * @param array $items Items.
1604 * @param string $type Button type.
1605 * @param string $cart_html Ajax cart HTML.
1606 * @param string $wrapper Wrapper tag.
1607 *
1608 * @return void|string
1609 */
1610 public static function get_action_button_by_type( $items, $type, $cart_html = '', $wrapper = 'li' ) {
1611 if ( ! in_array( $type, $items, true ) ) {
1612 return;
1613 }
1614
1615 $html = '';
1616 $class = 'rtsb-action-button-item';
1617
1618 if ( 'add_to_cart' === $type ) {
1619 $class .= ' rtsb-cart' . ( empty( $cart_html ) ? esc_attr( ' no-cart-button' ) : '' );
1620 } else {
1621 $class .= ' rtsb-' . esc_attr( str_replace( '_', '-', $type ) );
1622 }
1623
1624 $html .= '<' . esc_attr( $wrapper ) . ' class="' . esc_attr( $class ) . '">';
1625
1626 if ( ( 'add_to_cart' === $type ) && ( ! empty( $cart_html ) ) ) {
1627 $html .= $cart_html;
1628 } else {
1629 $html .= shortcode_exists( 'rtsb_' . $type . '_button' ) ? do_shortcode( '[rtsb_' . $type . '_button]' ) : null;
1630 }
1631
1632 $html .= '</' . esc_attr( $wrapper ) . '>';
1633
1634 return apply_filters( 'rtsb/elements/elementor/get_action_button_by_type', $html );
1635 }
1636
1637 /**
1638 * Social Share Platforms.
1639 *
1640 * @return mixed|null
1641 */
1642 public static function social_share_platforms_list() {
1643 return apply_filters(
1644 'rtsb/settings/social_share/platforms',
1645 [
1646 [
1647 'value' => 'facebook',
1648 'label' => esc_html__( 'Facebook', 'shopbuilder' ),
1649 ],
1650 [
1651 'value' => 'twitter',
1652 'label' => esc_html__( 'Twitter', 'shopbuilder' ),
1653 ],
1654 [
1655 'value' => 'linkedin',
1656 'label' => esc_html__( 'Linkedin', 'shopbuilder' ),
1657 ],
1658 [
1659 'value' => 'pinterest',
1660 'label' => esc_html__( 'Pinterest', 'shopbuilder' ),
1661 ],
1662 [
1663 'value' => 'skype',
1664 'label' => esc_html__( 'Skype', 'shopbuilder' ),
1665 ],
1666 [
1667 'value' => 'whatsapp',
1668 'label' => esc_html__( 'Whatsapp', 'shopbuilder' ),
1669 ],
1670 [
1671 'value' => 'reddit',
1672 'label' => esc_html__( 'Reddit', 'shopbuilder' ),
1673 ],
1674 [
1675 'value' => 'telegram',
1676 'label' => esc_html__( 'Telegram', 'shopbuilder' ),
1677 ],
1678 ]
1679 );
1680 }
1681
1682 /**
1683 * Get Social Share link HTML.
1684 *
1685 * @param int $id Post ID.
1686 * @param array $types Preset type.
1687 * @param string $preset Style type.
1688 * @param string $show_icon Show icon.
1689 *
1690 * @return string
1691 */
1692 public static function get_social_share_html( int $id, array $types, string $preset = 'default', $show_icon = 'yes' ) {
1693 $attr = [ 'postid' => $id ];
1694 $output = '';
1695
1696 if ( empty( $types ) ) {
1697 return $output;
1698 }
1699
1700 foreach ( $types as $type ) {
1701 $link = [];
1702 $link['type'] = $type['share_items'];
1703 $link['class'] = '';
1704 $link['img'] = apply_filters( 'rtsb/elements/share/default_img', '', $id, $link );
1705
1706 if ( 'site' === $id ) {
1707 $link['url'] = esc_url( home_url() );
1708 $link['title'] = wp_strip_all_tags( get_bloginfo( 'name' ) );
1709 } elseif ( 0 === strpos( $id, 'http' ) ) {
1710 $link['url'] = esc_url( $id );
1711 $link['title'] = '';
1712 } else {
1713 $link['url'] = esc_url( get_permalink( $id ) );
1714 $link['title'] = wp_strip_all_tags( get_the_title( $id ) );
1715
1716 if ( has_post_thumbnail( $id ) ) {
1717 $link['img'] = wp_get_attachment_image_url( get_post_thumbnail_id( $id ), 'full' );
1718 }
1719
1720 $link['img'] = apply_filters( 'rtsb/elements/share/single_img', $link['img'], $id, $link );
1721 }
1722
1723 $link['url'] = apply_filters( 'rtsb/elements/share/url', $link['url'], $link );
1724
1725 switch ( $type['share_items'] ) {
1726 case 'facebook':
1727 $link['link'] = 'https://www.facebook.com/sharer/sharer.php?u=' . $link['url'] . '&display=popup&ref=plugin&src=share_button';
1728 $link['icon'] = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="18.8125" height="32" viewBox="0 0 602 1024"><path d="M548 6.857v150.857h-89.714q-49.143 0-66.286 20.571t-17.143 61.714v108h167.429l-22.286 169.143h-145.143v433.714h-174.857v-433.714h-145.714v-169.143h145.714v-124.571q0-106.286 59.429-164.857t158.286-58.571q84 0 130.286 6.857z"></path></svg>';
1729 $link['attr_title'] = esc_html__( 'Share on Facebook', 'shopbuilder' );
1730 $link['social_network'] = 'Facebook';
1731 $link['social_action'] = 'Share';
1732 break;
1733 case 'twitter':
1734 $link['link'] = 'https://twitter.com/intent/tweet?text=' . htmlspecialchars( rawurlencode( html_entity_decode( $link['title'], ENT_COMPAT, 'UTF-8' ) ), ENT_COMPAT, 'UTF-8' ) . '&url=' . $link['url'];
1735 $link['icon'] = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="29.71875" height="32" viewBox="0 0 951 1024"><path d="M925.714 233.143q-38.286 56-92.571 95.429 0.571 8 0.571 24 0 74.286-21.714 148.286t-66 142-105.429 120.286-147.429 83.429-184.571 31.143q-154.857 0-283.429-82.857 20 2.286 44.571 2.286 128.571 0 229.143-78.857-60-1.143-107.429-36.857t-65.143-91.143q18.857 2.857 34.857 2.857 24.571 0 48.571-6.286-64-13.143-106-63.714t-42-117.429v-2.286q38.857 21.714 83.429 23.429-37.714-25.143-60-65.714t-22.286-88q0-50.286 25.143-93.143 69.143 85.143 168.286 136.286t212.286 56.857q-4.571-21.714-4.571-42.286 0-76.571 54-130.571t130.571-54q80 0 134.857 58.286 62.286-12 117.143-44.571-21.143 65.714-81.143 101.714 53.143-5.714 106.286-28.571z"></path></svg>';
1736 $link['attr_title'] = esc_html__( 'Share on Twitter', 'shopbuilder' );
1737 $link['social_network'] = 'Twitter';
1738 $link['social_action'] = 'Tweet';
1739 break;
1740 case 'pinterest':
1741 $link['link'] = 'https://pinterest.com/pin/create/button/?url=' . $link['url'] . '&media=' . $link['img'] . '&description=' . $link['title'];
1742 $link['icon'] = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="22.84375" height="32" viewBox="0 0 731 1024"><path d="M0 341.143q0-61.714 21.429-116.286t59.143-95.143 86.857-70.286 105.714-44.571 115.429-14.857q90.286 0 168 38t126.286 110.571 48.571 164q0 54.857-10.857 107.429t-34.286 101.143-57.143 85.429-82.857 58.857-108 22q-38.857 0-77.143-18.286t-54.857-50.286q-5.714 22.286-16 64.286t-13.429 54.286-11.714 40.571-14.857 40.571-18.286 35.714-26.286 44.286-35.429 49.429l-8 2.857-5.143-5.714q-8.571-89.714-8.571-107.429 0-52.571 12.286-118t38-164.286 29.714-116q-18.286-37.143-18.286-96.571 0-47.429 29.714-89.143t75.429-41.714q34.857 0 54.286 23.143t19.429 58.571q0 37.714-25.143 109.143t-25.143 106.857q0 36 25.714 59.714t62.286 23.714q31.429 0 58.286-14.286t44.857-38.857 32-54.286 21.714-63.143 11.429-63.429 3.714-56.857q0-98.857-62.571-154t-163.143-55.143q-114.286 0-190.857 74t-76.571 187.714q0 25.143 7.143 48.571t15.429 37.143 15.429 26 7.143 17.429q0 16-8.571 41.714t-21.143 25.714q-1.143 0-9.714-1.714-29.143-8.571-51.714-32t-34.857-54-18.571-61.714-6.286-60.857z"></path></svg>';
1743 $link['attr_title'] = esc_html__( 'Share on Pinterest', 'shopbuilder' );
1744 $link['social_network'] = 'Pinterest';
1745 $link['social_action'] = 'Pin';
1746 break;
1747 case 'linkedin':
1748 $link['link'] = 'https://www.linkedin.com/shareArticle?url=' . $link['url'] . '&title=' . $link['title'];
1749 $link['icon'] = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="27.4375" height="32" viewBox="0 0 878 1024"><path d="M199.429 357.143v566.286h-188.571v-566.286h188.571zM211.429 182.286q0.571 41.714-28.857 69.714t-77.429 28h-1.143q-46.857 0-75.429-28t-28.571-69.714q0-42.286 29.429-70t76.857-27.714 76 27.714 29.143 70zM877.714 598.857v324.571h-188v-302.857q0-60-23.143-94t-72.286-34q-36 0-60.286 19.714t-36.286 48.857q-6.286 17.143-6.286 46.286v316h-188q1.143-228 1.143-369.714t-0.571-169.143l-0.571-27.429h188v82.286h-1.143q11.429-18.286 23.429-32t32.286-29.714 49.714-24.857 65.429-8.857q97.714 0 157.143 64.857t59.429 190z"></path></svg>';
1750 $link['attr_title'] = esc_html__( 'Share on LinkedIn', 'shopbuilder' );
1751 $link['social_network'] = 'LinkedIn';
1752 $link['social_action'] = 'Share';
1753 break;
1754 case 'skype':
1755 $link['link'] = 'https://web.skype.com/share?url=' . $link['url'];
1756 $link['icon'] = '<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="24px" height="24px" viewBox="0 0 24 24" enable-background="new 0 0 24 24" xml:space="preserve" class="eapps-social-share-buttons-item-icon"> <path d="M23.016,13.971c0.111-0.638,0.173-1.293,0.173-1.963 c0-6.213-5.014-11.249-11.199-11.249c-0.704,0-1.393,0.068-2.061,0.193C8.939,0.348,7.779,0,6.536,0C2.926,0,0,2.939,0,6.565 c0,1.264,0.357,2.443,0.973,3.445c-0.116,0.649-0.18,1.316-0.18,1.999c0,6.212,5.014,11.25,11.198,11.25 c0.719,0,1.419-0.071,2.099-0.201C15.075,23.656,16.229,24,17.465,24C21.074,24,24,21.061,24,17.435 C24,16.163,23.639,14.976,23.016,13.971z M12.386,19.88c-3.19,0-6.395-1.453-6.378-3.953c0.005-0.754,0.565-1.446,1.312-1.446 c1.877,0,1.86,2.803,4.85,2.803c2.098,0,2.814-1.15,2.814-1.95c0-2.894-9.068-1.12-9.068-6.563c0-2.945,2.409-4.977,6.196-4.753 c3.61,0.213,5.727,1.808,5.932,3.299c0.102,0.973-0.543,1.731-1.662,1.731c-1.633,0-1.8-2.188-4.613-2.188 c-1.269,0-2.341,0.53-2.341,1.679c0,2.402,9.014,1.008,9.014,6.295C18.441,17.882,16.012,19.88,12.386,19.88z"></path> </svg>';
1757 $link['attr_title'] = esc_html__( 'Share on Skype', 'shopbuilder' );
1758 $link['social_network'] = 'Skype';
1759 $link['social_action'] = 'Skype';
1760 break;
1761 case 'whatsapp':
1762 $link['link'] = 'https://wa.me/?text=' . $link['title'] . ' ' . $link['url'];
1763 $link['icon'] = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-whatsapp" viewBox="0 0 16 16"> <path d="M13.601 2.326A7.854 7.854 0 0 0 7.994 0C3.627 0 .068 3.558.064 7.926c0 1.399.366 2.76 1.057 3.965L0 16l4.204-1.102a7.933 7.933 0 0 0 3.79.965h.004c4.368 0 7.926-3.558 7.93-7.93A7.898 7.898 0 0 0 13.6 2.326zM7.994 14.521a6.573 6.573 0 0 1-3.356-.92l-.24-.144-2.494.654.666-2.433-.156-.251a6.56 6.56 0 0 1-1.007-3.505c0-3.626 2.957-6.584 6.591-6.584a6.56 6.56 0 0 1 4.66 1.931 6.557 6.557 0 0 1 1.928 4.66c-.004 3.639-2.961 6.592-6.592 6.592zm3.615-4.934c-.197-.099-1.17-.578-1.353-.646-.182-.065-.315-.099-.445.099-.133.197-.513.646-.627.775-.114.133-.232.148-.43.05-.197-.1-.836-.308-1.592-.985-.59-.525-.985-1.175-1.103-1.372-.114-.198-.011-.304.088-.403.087-.088.197-.232.296-.346.1-.114.133-.198.198-.33.065-.134.034-.248-.015-.347-.05-.099-.445-1.076-.612-1.47-.16-.389-.323-.335-.445-.34-.114-.007-.247-.007-.38-.007a.729.729 0 0 0-.529.247c-.182.198-.691.677-.691 1.654 0 .977.71 1.916.81 2.049.098.133 1.394 2.132 3.383 2.992.47.205.84.326 1.129.418.475.152.904.129 1.246.08.38-.058 1.171-.48 1.338-.943.164-.464.164-.86.114-.943-.049-.084-.182-.133-.38-.232z"/> </svg>';
1764 $link['attr_title'] = esc_html__( 'Share on Whatsapp', 'shopbuilder' );
1765 $link['social_network'] = 'Whatsapp';
1766 $link['social_action'] = 'Share';
1767 break;
1768 case 'reddit':
1769 $link['link'] = 'https://reddit.com/submit?url=' . $link['url'] . '&title=' . $link['title'];
1770 $link['icon'] = '<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512"><title>ionicons-v5_logos</title><path d="M324,256a36,36,0,1,0,36,36A36,36,0,0,0,324,256Z"/><circle cx="188" cy="292" r="36" transform="translate(-97.43 94.17) rotate(-22.5)"/><path d="M496,253.77c0-31.19-25.14-56.56-56-56.56a55.72,55.72,0,0,0-35.61,12.86c-35-23.77-80.78-38.32-129.65-41.27l22-79L363.15,103c1.9,26.48,24,47.49,50.65,47.49,28,0,50.78-23,50.78-51.21S441,48,413,48c-19.53,0-36.31,11.19-44.85,28.77l-90-17.89L247.05,168.4l-4.63.13c-50.63,2.21-98.34,16.93-134.77,41.53A55.38,55.38,0,0,0,72,197.21c-30.89,0-56,25.37-56,56.56a56.43,56.43,0,0,0,28.11,49.06,98.65,98.65,0,0,0-.89,13.34c.11,39.74,22.49,77,63,105C146.36,448.77,199.51,464,256,464s109.76-15.23,149.83-42.89c40.53-28,62.85-65.27,62.85-105.06a109.32,109.32,0,0,0-.84-13.3A56.32,56.32,0,0,0,496,253.77ZM414,75a24,24,0,1,1-24,24A24,24,0,0,1,414,75ZM42.72,253.77a29.6,29.6,0,0,1,29.42-29.71,29,29,0,0,1,13.62,3.43c-15.5,14.41-26.93,30.41-34.07,47.68A30.23,30.23,0,0,1,42.72,253.77ZM390.82,399c-35.74,24.59-83.6,38.14-134.77,38.14S157,423.61,121.29,399c-33-22.79-51.24-52.26-51.24-83A78.5,78.5,0,0,1,75,288.72c5.68-15.74,16.16-30.48,31.15-43.79a155.17,155.17,0,0,1,14.76-11.53l.3-.21,0,0,.24-.17c35.72-24.52,83.52-38,134.61-38s98.9,13.51,134.62,38l.23.17.34.25A156.57,156.57,0,0,1,406,244.92c15,13.32,25.48,28.05,31.16,43.81a85.44,85.44,0,0,1,4.31,17.67,77.29,77.29,0,0,1,.6,9.65C442.06,346.77,423.86,376.24,390.82,399Zm69.6-123.92c-7.13-17.28-18.56-33.29-34.07-47.72A29.09,29.09,0,0,1,440,224a29.59,29.59,0,0,1,29.41,29.71A30.07,30.07,0,0,1,460.42,275.1Z"/><path d="M323.23,362.22c-.25.25-25.56,26.07-67.15,26.27-42-.2-66.28-25.23-67.31-26.27h0a4.14,4.14,0,0,0-5.83,0l-13.7,13.47a4.15,4.15,0,0,0,0,5.89h0c3.4,3.4,34.7,34.23,86.78,34.45,51.94-.22,83.38-31.05,86.78-34.45h0a4.16,4.16,0,0,0,0-5.9l-13.71-13.47a4.13,4.13,0,0,0-5.81,0Z"/></svg>';
1771 $link['attr_title'] = esc_html__( 'Share on Reddit', 'shopbuilder' );
1772 $link['social_network'] = 'Reddit';
1773 $link['social_action'] = 'Share';
1774 break;
1775 case 'telegram':
1776 $link['link'] = 'https://telegram.me/share/url?text=' . $link['title'] . '&url=' . $link['url'];
1777 $link['icon'] = '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-telegram" viewBox="0 0 16 16"> <path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8.287 5.906c-.778.324-2.334.994-4.666 2.01-.378.15-.577.298-.595.442-.03.243.275.339.69.47l.175.055c.408.133.958.288 1.243.294.26.006.549-.1.868-.32 2.179-1.471 3.304-2.214 3.374-2.23.05-.012.12-.026.166.016.047.041.042.12.037.141-.03.129-1.227 1.241-1.846 1.817-.193.18-.33.307-.358.336a8.154 8.154 0 0 1-.188.186c-.38.366-.664.64.015 1.088.327.216.589.393.85.571.284.194.568.387.936.629.093.06.183.125.27.187.331.236.63.448.997.414.214-.02.435-.22.547-.82.265-1.417.786-4.486.906-5.751a1.426 1.426 0 0 0-.013-.315.337.337 0 0 0-.114-.217.526.526 0 0 0-.31-.093c-.3.005-.763.166-2.984 1.09z"/> </svg>';
1778 $link['attr_title'] = esc_html__( 'Share on Telegram', 'shopbuilder' );
1779 $link['social_network'] = 'Telegram';
1780 $link['social_action'] = 'Share';
1781 break;
1782 }
1783
1784 $link['label'] = $type['share_text'];
1785 $link['target'] = '_blank';
1786 $link['rel'] = 'nofollow noopener noreferrer';
1787
1788 $data = '';
1789 $link = apply_filters( 'rtsb/elements/share/share_link', $link, $id, $preset );
1790 $icon = apply_filters( 'rtsb/elements/share/share_icon', $link['icon'], $preset );
1791 $target = ! empty( $link['target'] ) ? ' target="' . esc_attr( $link['target'] ) . '" ' : '';
1792 $rel = ! empty( $link['rel'] ) ? ' rel="' . esc_attr( $link['rel'] ) . '" ' : '';
1793 $attr_title = ! empty( $link['attr_title'] ) ? ' title="' . esc_attr( $link['attr_title'] ) . '" ' : '';
1794 $elements = [];
1795
1796 // Add classes.
1797 $css_classes = [
1798 'rtsb-share-btn',
1799 sanitize_html_class( $link['type'] ),
1800 ];
1801 $css_classes = array_merge( $css_classes, explode( ' ', $link['class'] ) );
1802 $css_classes = array_map( 'sanitize_html_class', $css_classes );
1803 $css_classes = implode( ' ', array_filter( $css_classes ) );
1804
1805 unset( $attr['pin-do'], $attr['action'] );
1806
1807 if ( 'pinterest' === $type['share_items'] ) {
1808 $attr['pin-do'] = 'none';
1809 }
1810
1811 if ( 'whatsapp' === $type['share_items'] ) {
1812 $attr['action'] = 'share/whatsapp/share';
1813 }
1814
1815 $attr = apply_filters( 'rtsb/elements/share/link_data', $attr, $link, $id );
1816
1817 if ( ! empty( $attr ) ) {
1818 foreach ( $attr as $key => $val ) {
1819 $data .= ' data-' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '"';
1820 }
1821 }
1822
1823 $additional_attr = apply_filters( 'rtsb/elements/share/additional_attr', [], $link, $id, $preset );
1824
1825 if ( ! empty( $additional_attr ) ) {
1826 $attr_output = join( ' ', $additional_attr );
1827
1828 if ( ! empty( $data ) ) {
1829 $attr_output = ' ' . $attr_output;
1830 }
1831
1832 $data .= $attr_output;
1833 }
1834
1835 $elements['wrapper_start'] = sprintf(
1836 '<li class="rtsb-share-item"><a href="%s"%s%s%s class="%s"%s>',
1837 ! empty( $link['link'] ) ? esc_attr( $link['link'] ) : '',
1838 $attr_title,
1839 $target,
1840 $rel,
1841 $css_classes,
1842 $data
1843 );
1844 $elements['wrapper_end'] = '</a></li>';
1845
1846 $elements['icon'] = ! empty( $show_icon ) ? '<span class="rtsb-share-icon">' . ( ! empty( $icon ) ? $icon : null ) . '</span>' : null;
1847 $elements['label'] = ! empty( $link['label'] ) ? '<span class="rtsb-share-label">' . $link['label'] . '</span>' : null;
1848 $elements['icon_label'] = '<span class="rtsb-share-icon-label">' . $elements['icon'] . $elements['label'] . '</span>';
1849 $elements = apply_filters( 'rtsb/elements/share/output_elements', $elements, $link, $id );
1850
1851 $output .= $elements['wrapper_start'] . $elements['icon_label'] . $elements['wrapper_end'];
1852 }
1853
1854 // error_log( print_r( $output , true ) . "\n\n" , 3, __DIR__ . '/log.txt' );
1855 return apply_filters( 'rtsb/elements/share/list_output', $output );
1856 }
1857
1858 /**
1859 * Social Share Platforms.
1860 *
1861 * @return mixed|null
1862 */
1863 public static function is_module_active( $module ) {
1864 $modulelist = ModuleList::instance()->get_data();
1865 if ( ! empty( $modulelist[ $module ]['active'] ) ) {
1866 return true;
1867 }
1868 }
1869
1870 /**
1871 * @param array $links default plugin action link
1872 *
1873 * @return array [array] plugin action link
1874 */
1875 public static function plugins_setting_links( $links ) {
1876 $links[] = '<a href="' . admin_url( 'admin.php?page=rtsb-settings' ) . '">' . esc_html__( 'Settings', 'shopbuilder' ) . '</a>';
1877 // TODO:: This function will apply after pro version.
1878 if ( ! is_plugin_active( 'shopbuilder/shopbuilder.php' ) ) {
1879 $links['shopbuilder_pro'] = sprintf( '<a href="#" target="_blank" style="color: #39b54a; font-weight: bold;">' . esc_html__( 'Go Pro', 'shopbuilder' ) . '</a>' );
1880 }
1881
1882 return $links;
1883 }
1884
1885 /***
1886 * Save Settings data
1887 *
1888 * @param $section_id
1889 * @param $block_id
1890 * @param $rawOptions
1891 *
1892 * @return array
1893 */
1894 public static function set_options( $section_id = '', $block_id = '', $rawOptions = [] ) {
1895 $section_id = ! empty( $section_id ) ? sanitize_text_field( wp_unslash( $section_id ) ) : '';
1896 $block_id = ! empty( $block_id ) ? sanitize_text_field( wp_unslash( $block_id ) ) : '';
1897 $rawOptions = ! empty( $rawOptions ) ? $rawOptions : [];
1898
1899 $results = [
1900 'status' => true,
1901 'message' => '',
1902 ];
1903 if ( ! $section_id || ! $block_id ) {
1904 $results['status'] = false;
1905 $results['message'] = esc_html__( 'Section , block or options may be empty', 'shopbuilder' );
1906
1907 return $results;
1908 }
1909 $sections = Settings::instance()->get_sections();
1910 if ( empty( $sections[ $section_id ] ) || empty( $sections[ $section_id ]['list'][ $block_id ] ) ) {
1911 $results['status'] = false;
1912 $results['message'] = esc_html__( 'No section or block found with given data', 'shopbuilder' );
1913
1914 return $results;
1915 }
1916
1917 $options = DataModel::source()->get_option( $section_id, [] );
1918 $changed = false;
1919 $fields = [];
1920 if ( isset( $sections[ $section_id ]['list'][ $block_id ]['fields'] ) && ! empty( $sections[ $section_id ]['list'][ $block_id ]['fields'] ) ) {
1921 $fields = $sections[ $section_id ]['list'][ $block_id ]['fields'];
1922 }
1923
1924 if ( empty( $fields ) ) {
1925 if ( isset( $rawOptions['active'] ) ) {
1926 $changed = true;
1927 $options[ $block_id ]['active'] = 'on' === $rawOptions['active'] ? 'on' : '';
1928 }
1929 } else {
1930 foreach ( $rawOptions as $raw_option_key => $raw_value ) {
1931 if ( $raw_option_key === 'active' ) {
1932 $changed = true;
1933 $options[ $block_id ]['active'] = $sections[ $section_id ]['list'][ $block_id ]['active'] = 'on' === $raw_value ? 'on' : '';
1934 } else {
1935 if ( isset( $fields[ $raw_option_key ] ) ) {
1936 $field = $fields[ $raw_option_key ];
1937 if ( $field['type'] === 'switch' ) {
1938 $value = 'on' === $raw_value ? 'on' : '';
1939 } else {
1940 if ( ! empty( $field['multiple'] ) || 'checkbox' === $field['type'] ) {
1941 if ( isset( $raw_value ) && is_array( $raw_value ) ) {
1942 if ( ! empty( $field['sanitize_fn'] ) && is_callable( $field['sanitize_fn'] ) ) {
1943 $value = array_map( $field['sanitize_fn'], $raw_value );
1944 } else {
1945 $value = array_map( 'sanitize_text_field', $raw_value );
1946 }
1947 } else {
1948 $value = [];
1949 }
1950 } else {
1951 if ( ! empty( $field['sanitize_fn'] ) && is_callable( $field['sanitize_fn'] ) ) {
1952 $value = $field['sanitize_fn']( $raw_value );
1953 } else {
1954 $value = sanitize_text_field( $raw_value );
1955 }
1956 }
1957 }
1958 $options[ $block_id ][ $raw_option_key ] = $sections[ $section_id ]['list'][ $block_id ]['fields'][ $raw_option_key ]['value'] = $value;
1959 $changed = true;
1960 }
1961 }
1962 }
1963 }
1964 if ( ! $changed ) {
1965 $results['status'] = false;
1966 $results['message'] = esc_html__( 'No changes found for update', 'shopbuilder' );
1967
1968 return $results;
1969 }
1970
1971 DataModel::source()->set_option( $section_id, $options );
1972
1973 $results['status'] = true;
1974 $results['message'] = esc_html__( 'Successfully Saved', 'shopbuilder' );
1975 $results['sections'] = $sections;
1976
1977 return $results;
1978 }
1979
1980 /***
1981 * @param $meta_key
1982 * @param $meta_value
1983 *
1984 * @return mixed|void
1985 *
1986 */
1987 public static function get_post_id_by_meta_key_and_value( $meta_key, $meta_value ) {
1988 if( ! $meta_key || ! $meta_value ){
1989 return;
1990 }
1991 global $wpdb;
1992 $prepare_guery = $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '%s' and meta_value = '%d'", $meta_key, $meta_value );
1993 $the_products = $wpdb->get_col( $prepare_guery );
1994 if( count( $the_products ) > 0 ){
1995 return $the_products[0];
1996 }
1997 return;
1998 }
1999
2000 }
2001