PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 1.0.1
ShopBuilder – WooCommerce Builder For Elementor v1.0.1
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.0.1, at app/Helpers/Fns.php

1,971 lines 64.0 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 // TODO:: Get Product List for select in Create Template Modal .
249 if ( is_singular( 'product' ) ) {
250 return get_the_ID();
251 }
252 global $wpdb;
253 $cache_key = 'rtsb_prepared_product_id';
254 $_post_id = get_transient( $cache_key );
255 if ( false === $_post_id || 'publish' !== get_post_status( $_post_id ) ) {
256 delete_transient( $cache_key );
257 $_post_id = $wpdb->get_var(
258 $wpdb->prepare( "SELECT MAX(ID) FROM {$wpdb->prefix}posts WHERE post_type = %s AND post_status = %s", 'product', 'publish' )
259 );
260 set_transient( $cache_key, $_post_id, 12 * HOUR_IN_SECONDS );
261 }
262
263 return $_post_id;
264 }
265
266 /**
267 * Get the product function.
268 *
269 * @return object
270 */
271 public static function get_product() {
272 global $post, $product;
273 if ( is_singular( 'product' ) && $product instanceof WC_Product ) {
274 return $product;
275 }
276
277 return wc_get_product( self::get_prepared_product_id() );
278 }
279
280 /**
281 * Error function
282 *
283 * @param [type] $function function name.
284 * @param [type] $message message.
285 * @param [type] $version version.
286 *
287 * @return void
288 */
289 public static function doing_it_wrong( $function, $message, $version ) {
290 $message .= ' Backtrace: ' . wp_debug_backtrace_summary();
291 _doing_it_wrong( $function, $message, $version );
292 }
293
294 /**
295 * @return array
296 */
297 public static function get_pages() {
298 $pages = [];
299 $rawPages = get_pages();
300 if ( ! empty( $rawPages ) ) {
301 foreach ( $rawPages as $page ) {
302 $pages[ $page->ID ] = $page->post_title;
303 }
304 }
305
306 return $pages;
307 }
308
309 public static function get_section_items( $section_id ) {
310 if ( ! $section_id ) {
311 return [];
312 }
313
314 return DataModel::source()->get_option( $section_id, [] );
315 }
316
317 public static function get_options( $section_id, $item_id ) {
318 if ( ! $section_id || ! $item_id ) {
319 return [];
320 }
321 $sections = self::get_section_items( $section_id );
322
323 return isset( $sections[ $item_id ] ) ? $sections[ $item_id ] : [];
324 }
325
326 /**
327 * @param string $section_id
328 * @param string $item_id
329 * @param string $option_id
330 * @param null $default EXCEPT multi_checkbox you can provide default value if given option does not set any value
331 * @param null $type checkbox, multi_checkbox, number
332 *
333 * @return bool|int|mixed|null
334 */
335 public static function get_option( $section_id, $item_id, $option_id, $default = null, $type = null ) {
336 $options = self::get_options( $section_id, $item_id );
337
338 if ( $type === 'checkbox' ) {
339 if ( isset( $options[ $option_id ] ) ) {
340 return $options[ $option_id ] === 'on';
341 }
342
343 return $default;
344 } elseif ( $type === 'multi_checkbox' ) {
345 return isset( $options[ $option_id ] ) && is_array( $options[ $option_id ] ) && in_array( $default, $options[ $option_id ] );
346 } elseif ( $type === 'number' ) {
347 return isset( $options[ $option_id ] ) ? absint( $options[ $option_id ] ) : absint( $default );
348 }
349
350 return isset( $options[ $option_id ] ) && ! empty( $options[ $option_id ] ) ? $options[ $option_id ] : $default;
351 }
352
353
354 /**
355 * Create a page and store the ID in an option.
356 *
357 * @param mixed $slug Slug for the new page.
358 * @param array $options ['section_id', 'item_id', 'option_id']Option name to store the page's ID.
359 * @param string $page_title (default: '') Title for the new page.
360 * @param string $page_content (default: '') Content for the new page.
361 * @param int $post_parent (default: 0) Parent for the new page.
362 * @param string $post_status (default: publish) The post status of the new page.
363 *
364 * @return int page ID.
365 */
366 public static function create_page( $slug, $options = '', $page_title = '', $page_content = '', $post_parent = 0, $post_status = 'publish' ) {
367 global $wpdb;
368
369 $option_value = 0;
370 if ( ! empty( $options ) ) {
371 if ( is_array( $options ) ) {
372 $options = wp_parse_args(
373 $options,
374 [
375 'section_id' => '',
376 'item_id' => '',
377 'option_id' => '',
378 ]
379 );
380 $option_value = self::get_option( $options['section_id'], $options['item_id'], $options['option_id'], 0, 'number' );
381 } else {
382 $option_value = absint( get_option( $options ) );
383 }
384 }
385
386 if ( $option_value > 0 ) {
387 $page_object = get_post( $option_value );
388
389 if ( $page_object && 'page' === $page_object->post_type && ! in_array(
390 $page_object->post_status,
391 [
392 'pending',
393 'trash',
394 'future',
395 'auto-draft',
396 ],
397 true
398 ) ) {
399 // Valid page is already in place.
400 return $page_object->ID;
401 }
402 }
403
404 if ( strlen( $page_content ) > 0 ) {
405 // Search for an existing page with the specified page content (typically a shortcode).
406 $shortcode = str_replace( [ '<!-- wp:shortcode -->', '<!-- /wp:shortcode -->' ], '', $page_content );
407 $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}%" ) );
408 } else {
409 // Search for an existing page with the specified page slug.
410 $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 ) );
411 }
412
413 $valid_page_found = apply_filters( 'rtsb/core/create_page_id', $valid_page_found, $slug, $page_content, $options );
414
415 if ( $valid_page_found ) {
416 if ( is_array( $options ) ) {
417 if ( ! empty( $options['section_id'] ) && $options['item_id'] && $options['option_id'] ) {
418 $section_items = DataModel::source()->get_option( $options['section_id'], [] );
419 $section_items[ $options['item_id'] ][ $options['option_id'] ] = $valid_page_found;
420 DataModel::source()->set_option( $options['section_id'], $section_items );
421 }
422 } else {
423 if ( $options ) {
424 update_option( $options, $valid_page_found );
425 }
426 }
427
428 return $valid_page_found;
429 }
430
431 // Search for a matching valid trashed page.
432 if ( strlen( $page_content ) > 0 ) {
433 // Search for an existing page with the specified page content (typically a shortcode).
434 $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}%" ) );
435 } else {
436 // Search for an existing page with the specified page slug.
437 $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 ) );
438 }
439
440 if ( $trashed_page_found ) {
441 $page_id = $trashed_page_found;
442 $page_data = [
443 'ID' => $page_id,
444 'post_status' => $post_status,
445 ];
446 wp_update_post( $page_data );
447 } else {
448 $page_data = [
449 'post_status' => $post_status,
450 'post_type' => 'page',
451 'post_author' => 1,
452 'post_name' => $slug,
453 'post_title' => $page_title,
454 'post_content' => $page_content,
455 'post_parent' => $post_parent,
456 'comment_status' => 'closed',
457 ];
458 $page_id = wp_insert_post( $page_data );
459
460 do_action( 'rtsb/core/page_created', $page_id, $page_data );
461 }
462
463 if ( is_array( $options ) ) {
464 if ( ! empty( $options['section_id'] ) && $options['item_id'] && $options['option_id'] ) {
465 $section_items = DataModel::source()->get_option( $options['section_id'], [] );
466 $section_items[ $options['item_id'] ][ $options['option_id'] ] = $page_id;
467 DataModel::source()->set_option( $options['section_id'], $section_items );
468 }
469 } else {
470 if ( $options ) {
471 update_option( $options, $page_id );
472 }
473 }
474
475 return $page_id;
476 }
477
478 // TODO:: Need to remove if not used.
479 public static function get_kses_array() {
480 return [
481 'a' => [
482 'class' => [],
483 'href' => [],
484 'rel' => [],
485 'title' => [],
486 ],
487 'abbr' => [
488 'title' => [],
489 ],
490 'b' => [],
491 'blockquote' => [
492 'cite' => [],
493 ],
494 'cite' => [
495 'title' => [],
496 ],
497 'code' => [],
498 'del' => [
499 'datetime' => [],
500 'title' => [],
501 ],
502 'dd' => [],
503 'div' => [
504 'class' => [],
505 'title' => [],
506 'style' => [],
507 ],
508 'dl' => [],
509 'dt' => [],
510 'em' => [],
511 'h1' => [
512 'class' => [],
513 ],
514 'h2' => [
515 'class' => [],
516 ],
517 'h3' => [
518 'class' => [],
519 ],
520 'h4' => [
521 'class' => [],
522 ],
523 'h5' => [
524 'class' => [],
525 ],
526 'h6' => [
527 'class' => [],
528 ],
529 'i' => [
530 'class' => [],
531 ],
532 'img' => [
533 'alt' => [],
534 'class' => [],
535 'height' => [],
536 'src' => [],
537 'width' => [],
538 ],
539 'li' => [
540 'class' => [],
541 ],
542 'ol' => [
543 'class' => [],
544 ],
545 'p' => [
546 'class' => [],
547 ],
548 'q' => [
549 'cite' => [],
550 'title' => [],
551 ],
552 'span' => [
553 'class' => [],
554 'title' => [],
555 'style' => [],
556 ],
557 'iframe' => [
558 'width' => [],
559 'height' => [],
560 'scrolling' => [],
561 'frameborder' => [],
562 'allow' => [],
563 'src' => [],
564 ],
565 'strike' => [],
566 'br' => [],
567 'strong' => [],
568 'data-wow-duration' => [],
569 'data-wow-delay' => [],
570 'data-wallpaper-options' => [],
571 'data-stellar-background-ratio' => [],
572 'ul' => [
573 'class' => [],
574 ],
575 ];
576 }
577
578 // TODO:: Need to remove if not used.
579 public static function kses( $raw, $allowDanger = false ) {
580
581 if ( function_exists( 'wp_kses' ) && ! $allowDanger ) { // WP is here
582 return wp_kses( $raw, self::get_kses_array() );
583 } else {
584 return $raw;
585 }
586 }
587
588 /*
589 * Escape output of wishlist icon
590 *
591 * @param string $data Data to escape.
592 * @return string Escaped data
593 */
594 public static function print_icon( $data ) {
595 /**
596 * APPLY_FILTERS: rtsb/core/allowed_icon_html
597 *
598 * Filter the allowed HTML for the icons.
599 *
600 * @param array $allowed_icon_html Allowed HTML
601 *
602 * @return array
603 */
604 $allowed_icon_html = apply_filters(
605 'rtsb/core/allowed_icon_html',
606 [
607 'i' => [
608 'class' => true,
609 ],
610 'img' => [
611 'src' => true,
612 'alt' => true,
613 'width' => true,
614 'height' => true,
615 ],
616 'svg' => [
617 'class' => true,
618 'aria-hidden' => true,
619 'aria-labelledby' => true,
620 'role' => true,
621 'xmlns' => true,
622 'width' => true,
623 'height' => true,
624 'viewbox' => true,
625 'stroke' => true,
626 'fill' => true,
627 ],
628 'g' => [
629 'fill' => true,
630 ],
631 'title' => [
632 'title' => true,
633 ],
634 'path' => [
635 'd' => true,
636 'fill' => true,
637 'stroke-width' => true,
638 'stroke-linecap' => true,
639 'stroke-linejoin' => true,
640 ],
641 ]
642 );
643
644 echo wp_kses( $data, $allowed_icon_html );
645 }
646
647 /**
648 * Prints HTMl.
649 *
650 * @param string $html HTML.
651 * @param bool $allHtml All HTML.
652 *
653 * @return void
654 */
655 public static function print_html( $html, $allHtml = false ) {
656 if ( $allHtml ) {
657 echo stripslashes_deep( $html ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
658 } else {
659 echo wp_kses_post( stripslashes_deep( $html ) );
660 }
661 }
662
663 /**
664 * Allowed HTML for wp_kses.
665 *
666 * @param string $level Tag level.
667 *
668 * @return mixed
669 */
670 public static function allowedHtml( $level = 'basic' ) {
671 $allowed_html = [];
672 // TODO:: Need Optimize.
673 switch ( $level ) {
674 case 'basic':
675 $allowed_html = [
676 'b' => [
677 'class' => [],
678 'id' => [],
679 ],
680 'i' => [
681 'class' => [],
682 'id' => [],
683 ],
684 'u' => [
685 'class' => [],
686 'id' => [],
687 ],
688 'br' => [
689 'class' => [],
690 'id' => [],
691 ],
692 'em' => [
693 'class' => [],
694 'id' => [],
695 ],
696 'span' => [
697 'class' => [],
698 'id' => [],
699 ],
700 'strong' => [
701 'class' => [],
702 'id' => [],
703 ],
704 'hr' => [
705 'class' => [],
706 'id' => [],
707 ],
708 'div' => [
709 'class' => [],
710 'id' => [],
711 ],
712 'a' => [
713 'href' => [],
714 'title' => [],
715 'class' => [],
716 'id' => [],
717 'target' => [],
718 ],
719 ];
720 break;
721
722 case 'advanced':
723 $allowed_html = [
724 'b' => [
725 'class' => [],
726 'id' => [],
727 ],
728 'i' => [
729 'class' => [],
730 'id' => [],
731 ],
732 'u' => [
733 'class' => [],
734 'id' => [],
735 ],
736 'br' => [
737 'class' => [],
738 'id' => [],
739 ],
740 'em' => [
741 'class' => [],
742 'id' => [],
743 ],
744 'span' => [
745 'class' => [],
746 'id' => [],
747 ],
748 'strong' => [
749 'class' => [],
750 'id' => [],
751 ],
752 'hr' => [
753 'class' => [],
754 'id' => [],
755 ],
756 'a' => [
757 'href' => [],
758 'title' => [],
759 'class' => [],
760 'id' => [],
761 'target' => [],
762 ],
763 'input' => [
764 'type' => [],
765 'name' => [],
766 'class' => [],
767 'value' => [],
768 ],
769 ];
770 break;
771
772 case 'image':
773 $allowed_html = [
774 'img' => [
775 'src' => [],
776 'data-src' => [],
777 'alt' => [],
778 'height' => [],
779 'width' => [],
780 'class' => [],
781 'id' => [],
782 'style' => [],
783 'srcset' => [],
784 'loading' => [],
785 'sizes' => [],
786 ],
787 'div' => [
788 'class' => [],
789 ],
790 ];
791 break;
792
793 case 'anchor':
794 $allowed_html = [
795 'a' => [
796 'href' => [],
797 'title' => [],
798 'class' => [],
799 'id' => [],
800 'style' => [],
801 ],
802 ];
803 break;
804
805 default:
806 // code...
807 break;
808 }
809
810 return $allowed_html;
811 }
812
813 /**
814 * Definition for wp_kses.
815 *
816 * @param string $string String to check.
817 * @param string $level Tag level.
818 *
819 * @return string|void
820 */
821 // TODO:: Need to remove if not used.
822 public static function htmlKses( $string, $level ) {
823 if ( empty( $string ) ) {
824 return;
825 }
826
827 return wp_kses( $string, self::allowedHtml( $level ) );
828 }
829
830 /**
831 * Insert Some array element
832 *
833 * @param [type] $key The elements will insert nearby this key.
834 * @param [type] $main_array Original array.
835 * @param [type] $insert_array some element will insert in original array.
836 * @param boolean $is_after array insert position base on the key.
837 *
838 * @return array
839 */
840 public static function insert_controls( $key, $main_array, $insert_array, $is_after = false ) {
841 $index = array_search( $key, array_keys( $main_array ), true );
842 if ( 'integer' === gettype( $index ) ) {
843 if ( $is_after ) {
844 $index ++;
845 }
846 $main_array = array_merge(
847 array_slice( $main_array, 0, $index ),
848 $insert_array,
849 array_slice( $main_array, $index )
850 );
851 }
852
853 return $main_array;
854 }
855
856 /**
857 * Image Sizes
858 *
859 * @return array
860 */
861 public static function get_image_sizes() {
862 global $_wp_additional_image_sizes;
863
864 $sizes = [];
865
866 foreach ( get_intermediate_image_sizes() as $_size ) {
867 if ( in_array( $_size, [ 'thumbnail', 'medium', 'large' ], true ) ) {
868 $sizes[ $_size ]['width'] = get_option( "{$_size}_size_w" );
869 $sizes[ $_size ]['height'] = get_option( "{$_size}_size_h" );
870 $sizes[ $_size ]['crop'] = (bool) get_option( "{$_size}_crop" );
871 } elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
872 $sizes[ $_size ] = [
873 'width' => $_wp_additional_image_sizes[ $_size ]['width'],
874 'height' => $_wp_additional_image_sizes[ $_size ]['height'],
875 'crop' => $_wp_additional_image_sizes[ $_size ]['crop'],
876 ];
877 }
878 }
879
880 $imgSize = [];
881
882 foreach ( $sizes as $key => $img ) {
883 $imgSize[ $key ] = ucfirst( $key ) . " ({$img['width']}*{$img['height']})";
884 }
885
886 $imgSize['full'] = esc_html__( 'Full size', 'shopbuilder' );
887 $imgSize['rtsb_custom'] = esc_html__( 'Custom image size', 'shopbuilder' );
888
889 return $imgSize;
890 }
891
892 /**
893 * Free Layouts
894 *
895 * @return array
896 */
897 public static function free_layouts() {
898 $layouts = [
899 'grid-layout1' => esc_html__( 'Grid Layout 1', 'shopbuilder' ),
900 'grid-layout2' => esc_html__( 'Grid Layout 2', 'shopbuilder' ),
901 'list-layout1' => esc_html__( 'List Layout 1', 'shopbuilder' ),
902 'list-layout2' => esc_html__( 'List Layout 2', 'shopbuilder' ),
903 'slider-layout1' => esc_html__( 'Slider Layout 1', 'shopbuilder' ),
904 'slider-layout2' => esc_html__( 'Slider Layout 2', 'shopbuilder' ),
905 'category-single-layout1' => esc_html__( 'Category Single Layout 1', 'shopbuilder' ),
906 'category-layout1' => esc_html__( 'Category Layout 1', 'shopbuilder' ),
907 'category-layout2' => esc_html__( 'Category Layout 2', 'shopbuilder' ),
908 'category-layout3' => esc_html__( 'Category Layout 2', 'shopbuilder' ),
909 ];
910
911 return apply_filters( 'rtsb/elements/elementor/free_layouts', $layouts );
912 }
913
914 /**
915 * Get all terms by taxonomy
916 *
917 * @param string $taxonomy Taxonomy name.
918 *
919 * @return array
920 */
921 public static function get_all_terms( $taxonomy ) {
922 $terms = [];
923
924 if ( empty( $taxonomy ) ) {
925 return $terms;
926 }
927
928 $termList = get_terms( [ $taxonomy ], [ 'hide_empty' => 0 ] );
929
930 if ( is_array( $termList ) && ! empty( $termList ) && empty( $termList['errors'] ) ) {
931 foreach ( $termList as $term ) {
932 $terms[ $term->term_id ] = esc_html( $term->name );
933 }
934 }
935
936 return $terms;
937 }
938
939 /**
940 * Get all terms by attributes
941 *
942 * @return array
943 */
944 public static function get_all_attributes() {
945 $terms = [];
946 $termList = [];
947
948 $attributes = wc_get_attribute_taxonomies();
949
950 if ( $attributes ) {
951 foreach ( $attributes as $tax ) {
952 if ( taxonomy_exists( wc_attribute_taxonomy_name( $tax->attribute_name ) ) ) {
953 $termList[ $tax->attribute_name ] = get_terms( wc_attribute_taxonomy_name( $tax->attribute_name ), 'orderby=name&hide_empty=0' );
954 }
955 }
956 }
957
958 if ( ! empty( $termList ) && empty( $termList['errors'] ) && is_array( $termList ) ) {
959 foreach ( $termList as $name => $atts ) {
960 foreach ( $atts as $term ) {
961 $terms[ $term->term_id ] = esc_html( ucwords( str_replace( '-', ' ', $name ) ) . ' - ' . $term->name );
962 }
963 }
964 }
965
966 return $terms;
967 }
968
969 /**
970 * Get User list
971 *
972 * @return array
973 */
974 public static function get_users() {
975 $users = [];
976 $u = get_users();
977
978 if ( ! empty( $u ) ) {
979 foreach ( $u as $user ) {
980 $users[ $user->ID ] = $user->display_name;
981 }
982 }
983
984 return $users;
985 }
986
987 /**
988 * Get products list.
989 *
990 * @return array
991 */
992 public static function get_products_list() {
993 $products = [];
994 // TODO:: Need To replace with $wpdb.
995 $query = get_posts(
996 [
997 'post_type' => 'product',
998 'post_status' => 'publish',
999 'posts_per_page' => - 1,
1000 'orderby' => 'title',
1001 'order' => 'ASC',
1002 ]
1003 );
1004
1005 if ( ! empty( $query ) && is_array( $query ) ) {
1006 foreach ( $query as $product ) {
1007 $products[ $product->ID ] = $product->post_title;
1008 }
1009 }
1010
1011 return $products;
1012 }
1013
1014 /**
1015 * Get Taxonomy List.
1016 *
1017 * @return array
1018 */
1019 public static function get_tax_list() {
1020 return [
1021 'product_cat' => esc_html__( 'Product Category', 'shopbuilder' ),
1022 // 'product_tag' => esc_html__( 'Product Tag', 'shopbuilder' ), // Pro.
1023 // 'product_attr' => esc_html__( 'Product Attr', 'shopbuilder' ), // Pro.
1024 ];
1025 }
1026
1027 /**
1028 * Get Category Query List.
1029 *
1030 * @return array
1031 */
1032 public static function get_cat_list() {
1033 return [
1034 'all' => esc_html__( 'All Categories', 'shopbuilder' ),
1035 'specific_parent' => esc_html__( 'Sub-Categories by Parent', 'shopbuilder' ),
1036 'cat_ids' => esc_html__( 'Select by ID', 'shopbuilder' ),
1037 'selection' => esc_html__( 'Manual Selection', 'shopbuilder' ),
1038 ];
1039 }
1040
1041 /**
1042 * Get Term List.
1043 *
1044 * @param string $taxonomy Taxonomy.
1045 * @param bool $first_term First term.
1046 * @param bool $only_parents Only parent terms.
1047 * @param bool $return_slug Return with slug.
1048 *
1049 * @return int|array
1050 */
1051 public static function get_terms( $taxonomy, $first_term = false, $only_parents = false, $return_slug = false ) {
1052 // TODO:: Return Slug always true for all settings.
1053 $term_list = [];
1054 $args = [
1055 'taxonomy' => $taxonomy,
1056 'hide_empty' => false,
1057 ];
1058
1059 if ( $only_parents ) {
1060 $args['parent'] = 0;
1061 }
1062
1063 $terms = get_terms( $args );
1064
1065 if ( empty( $terms ) ) {
1066 return [ esc_html__( 'Nothing found', 'shopbuilder' ) ];
1067 }
1068
1069 foreach ( $terms as $term ) {
1070 if ( $return_slug ) {
1071 $term_list[ $term->slug ] = $term->name;
1072 } else {
1073 $term_list[ $term->term_id ] = $term->name;
1074 }
1075 }
1076
1077 if ( $first_term ) {
1078 return array_keys( $term_list )[0];
1079 } else {
1080 return $term_list;
1081 }
1082 }
1083
1084 /**
1085 * Get product rating.
1086 *
1087 * @return string|void
1088 */
1089 public static function get_product_rating_html() {
1090 global $product;
1091
1092 $html = '';
1093 $rating_count = $product->get_rating_count();
1094 $average = $product->get_average_rating();
1095
1096 if ( empty( wc_get_rating_html( $average, $rating_count ) ) ) {
1097 return $html;
1098 }
1099
1100 $html .= '<div class="product-rating">';
1101 $html .= wc_get_rating_html( $average, $rating_count );
1102 // TODO:: Disable Rating Count option need to apply.
1103 $html .= ! empty( $html ) ? '<span class="count">(' . $average . ')</span>' : '';
1104 $html .= '</div>';
1105
1106 self::print_html( $html, true );
1107 }
1108
1109 /**
1110 * Text truncation.
1111 *
1112 * @param string $text_to_truncate Text.
1113 * @param int $limit Limit.
1114 * @param string $after After text.
1115 *
1116 * @return string
1117 */
1118 public static function text_truncation( $text_to_truncate, $limit, $after = '&#8230;' ) {
1119 if ( empty( $limit ) ) {
1120 return $text_to_truncate;
1121 }
1122
1123 $limit ++;
1124
1125 $text = '';
1126
1127 if ( mb_strlen( $text_to_truncate ) > $limit ) {
1128 $subex = mb_substr( wp_strip_all_tags( $text_to_truncate ), 0, $limit );
1129 $exwords = explode( ' ', $subex );
1130 $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
1131
1132 if ( $excut < 0 ) {
1133 $text .= mb_substr( $subex, 0, $excut ) . $after;
1134 } else {
1135 $text .= $subex . $after;
1136 }
1137 } else {
1138 $text .= $text_to_truncate;
1139 }
1140
1141 return $text;
1142 }
1143
1144 /**
1145 * Promo Badge HTML
1146 *
1147 * @param string $text Text.
1148 * @param string $class Class.
1149 *
1150 * @return void
1151 */
1152 public static function get_badge_html( $text, $class = 'fill' ) {
1153 ob_start();
1154 ?>
1155
1156 <ul class="rtsb-promotion-list">
1157 <li class="rtsb-promotion-list-item">
1158 <span class="rtsb-tag-<?php echo ! empty( $class ) ? esc_attr( $class ) : ''; ?>"><?php echo esc_html( $text ); ?></span>
1159 </li>
1160 </ul>
1161
1162 <?php
1163 self::print_html( ob_get_clean() );
1164 }
1165
1166 /**
1167 * Categories HTML
1168 *
1169 * @param int $id Product ID.
1170 * @param string $class Custom class.
1171 *
1172 * @return void|string
1173 */
1174 public static function get_categories_list( $id, $class = 'rtsb-category-outline' ) {
1175 if ( empty( $id ) ) {
1176 return '';
1177 }
1178
1179 ob_start();
1180 ?>
1181
1182 <ul class="rtsb-category-list <?php echo esc_attr( $class ); ?>">
1183 <?php
1184 self::print_html(
1185 wc_get_product_category_list(
1186 $id,
1187 '</li><li class="rtsb-category-list-item">',
1188 '<li class="rtsb-category-list-item">',
1189 '</li>'
1190 )
1191 );
1192 ?>
1193 </ul>
1194
1195 <?php
1196 self::print_html( ob_get_clean() );
1197 }
1198
1199
1200 /**
1201 * Get Featured Image HTML.
1202 *
1203 * @param string $type Image type.
1204 * @param int $post_id Post ID.
1205 * @param string $f_img_size Image size.
1206 * @param null $default_img_id Default image ID.
1207 * @param array $custom_img_size Custom image size.
1208 * @param bool $lazy Lazy load check.
1209 * @param bool $hover Hover image.
1210 *
1211 * @return string|null
1212 */
1213 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 ) {
1214 $img_html = null;
1215 $attachment_id = null;
1216 $c_size = false;
1217 $hover_class = '';
1218 $post_title = '';
1219
1220 if ( 'rtsb_custom' === $f_img_size ) {
1221 $f_img_size = 'full';
1222 $c_size = true;
1223 }
1224
1225 if ( $hover ) {
1226 $a_id = $post_id;
1227 $hover_class = ' rtsb-img-hover';
1228 } else {
1229 if ( 'product' === $type ) {
1230 $a_id = get_post_thumbnail_id( $post_id );
1231 $post_title = get_the_title( $post_id );
1232 } elseif ( 'category' === $type ) {
1233 $a_id = get_term_meta( $post_id, 'thumbnail_id', true );
1234 $post_title = get_term( $post_id )->name;
1235 } else {
1236 $a_id = $default_img_id;
1237 }
1238 }
1239
1240 $img_alt = trim( wp_strip_all_tags( get_post_meta( $a_id, '_wp_attachment_image_alt', true ) ) );
1241 $alt_tag = ! empty( $img_alt ) ? $img_alt : wp_strip_all_tags( $post_title );
1242 $lazy_class = $lazy ? ' swiper-lazy' : '';
1243 $attr = [
1244 'class' => 'img-responsive rtsb-product-image' . $lazy_class . $hover_class,
1245 'alt' => $alt_tag,
1246 ];
1247
1248 if ( $a_id ) {
1249 $img_html = wp_get_attachment_image( $a_id, $f_img_size, false, $attr );
1250 $attachment_id = $a_id;
1251 }
1252
1253 if ( ! $img_html && $default_img_id ) {
1254 $img_html = wp_get_attachment_image( $default_img_id, $f_img_size, false, $attr );
1255 $attachment_id = $default_img_id;
1256 }
1257
1258 if ( $img_html && $c_size ) {
1259 preg_match( '@src="([^"]+)"@', $img_html, $match );
1260 $img_src = array_pop( $match );
1261 $w = ! empty( $custom_img_size['width'] ) ? absint( $custom_img_size['width'] ) : null;
1262 $h = ! empty( $custom_img_size['height'] ) ? absint( $custom_img_size['height'] ) : null;
1263 $c = ! empty( $custom_img_size['crop'] ) && 'soft' === $custom_img_size['crop'] ? false : true;
1264
1265 if ( $w && $h ) {
1266 $image = self::image_resize( $img_src, $w, $h, $c, false );
1267
1268 if ( ! empty( $image ) ) {
1269 [ $src, $width, $height ] = $image;
1270
1271 $hwstring = image_hwstring( $width, $height );
1272 $attachment = get_post( $attachment_id );
1273 $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $f_img_size );
1274
1275 if ( $lazy ) {
1276 $attr['data-src'] = $src;
1277 } else {
1278 $attr['src'] = $src;
1279 }
1280
1281 $attr = array_map( 'esc_attr', $attr );
1282 $img_html = rtrim( "<img $hwstring" );
1283
1284 foreach ( $attr as $name => $value ) {
1285 $img_html .= " $name=" . '"' . $value . '"';
1286 }
1287
1288 $img_html .= ' />';
1289 }
1290 }
1291 }
1292
1293 if ( ! $img_html ) {
1294 $hwstring = image_hwstring( 160, 160 );
1295 $attr = isset( $attr['src'] ) ? apply_filters( 'wp_get_attachment_image_attributes', $attr, false, $f_img_size ) : [];
1296 $attr['class'] = 'default-img';
1297 $attr['src'] = esc_url( rtsb()->get_assets_uri( 'images/demo.png' ) );
1298 $attr['alt'] = esc_html__( 'Default Image', 'shopbuilder' );
1299 $img_html = rtrim( "<img $hwstring" );
1300
1301 foreach ( $attr as $name => $value ) {
1302 $img_html .= " $name=" . '"' . $value . '"';
1303 }
1304
1305 $img_html .= ' />';
1306 }
1307
1308 if ( $lazy ) {
1309 $img_html = $img_html . '<div class="swiper-lazy-preloader swiper-lazy-preloader"></div>';
1310 }
1311
1312 return $img_html;
1313 }
1314
1315 /**
1316 * Call the Image resize model for resize function
1317 *
1318 * @param string $url URL.
1319 * @param int $width Width.
1320 * @param int $height Height.
1321 * @param string $crop Crop.
1322 * @param bool|true $single Single.
1323 * @param bool|false $upscale Upscale.
1324 *
1325 * @return array|bool|string
1326 */
1327 public static function image_resize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
1328 $rtResize = new ReSizer();
1329
1330 return $rtResize->process( $url, $width, $height, $crop, $single, $upscale );
1331 }
1332
1333 /**
1334 * Get Product Image
1335 *
1336 * @param string $f_image Featured Image.
1337 * @param string $h_image Hover Image.
1338 *
1339 * @return void
1340 */
1341 public static function get_product_image( $f_image, $h_image = null ) {
1342 echo wp_kses( $f_image, self::allowedHtml( 'image' ) );
1343
1344 if ( ! empty( $h_image ) ) {
1345 echo wp_kses( $h_image, self::allowedHtml( 'image' ) );
1346 }
1347 }
1348
1349 /**
1350 * Post Custom Field value.
1351 *
1352 * @param int $post_id Post id.
1353 * @param string $field_key Custom Field Key.
1354 * @param string $field_fallback FallBack text.
1355 *
1356 * @return string|void
1357 */
1358 public static function get_post_custom_field_value( $post_id, $field_key = '', $field_fallback = '' ) {
1359 if ( ! $post_id || ! $field_key ) {
1360 return;
1361 }
1362 $field_value = get_post_meta( $post_id, $field_key, true );
1363 if ( empty( $field_value ) ) {
1364 $field_value = ! empty( $field_fallback ) ? $field_fallback : $field_value;
1365 }
1366 $field_value = apply_filters( 'rtsb/get_post_custom_field_value/' . $field_key, $field_value, $field_key );
1367
1368 return sprintf( '<span class="rtsb-woo-custom-field">%s</span>', $field_value );
1369 }
1370
1371 /**
1372 * Elementor Icon
1373 *
1374 * @param array $control Elementor Control array.
1375 * @param string $class Custom class.
1376 * @param string $builder Builder name.
1377 *
1378 * @return string
1379 */
1380 public static function icons_manager( $control, $class = '', $builder = 'elementor' ): string {
1381 $attributes = [
1382 'aria-hidden' => 'true',
1383 ];
1384
1385 if ( ! empty( $class ) ) {
1386 $attributes['class'] = esc_attr( $class );
1387 }
1388
1389 ob_start();
1390
1391 if ( defined( 'ELEMENTOR_VERSION' ) && ! empty( $control ) && 'elementor' === $builder ) {
1392 Icons_Manager::render_icon( $control, $attributes );
1393 }
1394
1395 return ob_get_clean();
1396 }
1397
1398 /**
1399 * Get sale badge
1400 *
1401 * @param string $type Badge type.
1402 * @param string $text Badge text.
1403 * @param string $out_of_stock_text Out of stock text.
1404 *
1405 * @return string
1406 */
1407 public static function get_sale_badge( $type, $text, $out_of_stock_text ) {
1408 global $product;
1409
1410 if ( ! $product->is_in_stock() ) {
1411 return $out_of_stock_text;
1412 }
1413
1414 if ( ! $product->is_on_sale() ) {
1415 return '';
1416 }
1417
1418 $badge_text = '';
1419 $percentage = null;
1420 $max_percentage = '';
1421
1422 if ( $product->is_type( 'simple' ) ) {
1423 $max_percentage = ( ( $product->get_regular_price() - $product->get_sale_price() ) / $product->get_regular_price() ) * 100;
1424 } elseif ( $product->is_type( 'variable' ) ) {
1425 $max_percentage = 0;
1426
1427 foreach ( $product->get_children() as $child_id ) {
1428 $variation = wc_get_product( $child_id );
1429 $price = $variation->get_regular_price();
1430 $sale = $variation->get_sale_price();
1431
1432 if ( 0 !== $price && ! empty( $sale ) ) {
1433 $percentage = ( $price - $sale ) / $price * 100;
1434 }
1435
1436 if ( $percentage > $max_percentage ) {
1437 $max_percentage = $percentage;
1438 }
1439 }
1440 }
1441
1442 if ( $max_percentage > 0 ) {
1443 $badge_text = '-' . round( $max_percentage ) . '%';
1444 }
1445
1446 if ( 'text' === $type ) {
1447 $badge_text = $text;
1448 }
1449
1450 return $badge_text;
1451 }
1452
1453 /**
1454 * Pagination
1455 *
1456 * @param string $pages Pages.
1457 * @param integer $range Range.
1458 * @param boolean $ajax Ajax.
1459 *
1460 * @return string
1461 */
1462 public static function custom_pagination( $pages = '', $range = 4, $ajax = false ) {
1463 $html = null;
1464 $showitems = ( $range * 2 ) + 1;
1465
1466 global $paged;
1467
1468 if ( is_front_page() ) {
1469 $paged = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1;
1470 } else {
1471 $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
1472 }
1473
1474 if ( empty( $paged ) ) {
1475 $paged = 1;
1476 }
1477
1478 if ( $pages == '' ) {
1479 global $wp_query;
1480 $pages = $wp_query->max_num_pages;
1481
1482 if ( ! $pages ) {
1483 $pages = 1;
1484 }
1485 }
1486
1487 $ajaxClass = null;
1488 $dataAttr = null;
1489
1490 if ( $ajax ) {
1491 $ajaxClass = ' rtsb-ajax';
1492 $dataAttr = "data-paged='1'";
1493 }
1494
1495 if ( 1 != $pages ) {
1496 $html .= '<div class="rtsb-pagination' . $ajaxClass . '" ' . $dataAttr . '>';
1497 $html .= '<ul class="pagination-list">';
1498
1499 if ( $paged > 2 && $paged > $range + 1 && $showitems < $pages ) {
1500 $html .= "<li><a data-paged='1' href='" . get_pagenum_link( 1 ) . "' aria-label='First'>&laquo;</a></li>";
1501 }
1502
1503 if ( $paged > 1 && $showitems < $pages ) {
1504 $p = $paged - 1;
1505 $html .= "<li><a data-paged='{$p}' href='" . get_pagenum_link( $p ) . "' aria-label='Previous'>&lsaquo;</a></li>";
1506 }
1507
1508 for ( $i = 1; $i <= $pages; $i ++ ) {
1509 if ( 1 != $pages && ( ! ( $i >= $paged + $range + 1 || $i <= $paged - $range - 1 ) || $pages <= $showitems ) ) {
1510 $html .= ( $paged == $i ) ? '<li class="active"><span>' . $i . '</span></li>' : "<li><a data-paged='{$i}' href='" . get_pagenum_link( $i ) . "'>" . $i . '</a></li>';
1511 }
1512 }
1513
1514 if ( $paged < $pages && $showitems < $pages ) {
1515 $p = $paged + 1;
1516 $html .= "<li><a data-paged='{$p}' href=\"" . get_pagenum_link( $paged + 1 ) . "\" aria-label='Next'>&rsaquo;</a></li>";
1517 }
1518
1519 if ( $paged < $pages - 1 && $paged + $range - 1 < $pages && $showitems < $pages ) {
1520 $html .= "<li><a data-paged='{$pages}' href='" . get_pagenum_link( $pages ) . "' aria-label='Last'>&raquo;</a></li>";
1521 }
1522
1523 $html .= '</ul>';
1524 $html .= '</div>';
1525 }
1526
1527 return $html;
1528 }
1529
1530 /**
1531 * Action Buttons HTMl
1532 *
1533 * @param array $items Items.
1534 * @param array $ajax_cart Ajax cart HTML.
1535 * @param string $preset Button preset.
1536 * @param array $position Position.
1537 *
1538 * @return void|string
1539 */
1540 public static function get_formatted_action_buttons( $items, $ajax_cart = '', $preset = 'preset1', $position = 'above' ) {
1541 if ( empty( $items ) ) {
1542 return;
1543 }
1544
1545 $html = '';
1546 $class = '';
1547
1548 if ( 'after' === $position ) {
1549 $class .= 'after-content';
1550 }
1551
1552 if ( 'preset2' === $preset ) {
1553 $class .= ' rtsb-action-buttons-vertical vertical-delay-effect';
1554 } elseif ( 'preset4' === $preset ) {
1555 $class .= 'rtsb-action-buttons-vertical rtsb-action-buttons-vertical-left vertical-delay-effect';
1556 } elseif ( 'preset5' === $preset ) {
1557 $class .= ' action-buttons-outline horizontal-floating-btn';
1558 } else {
1559 $class .= ' rtsb-action-buttons-cart-box-width-auto horizontal-floating-btn';
1560 }
1561
1562 if ( 'preset3' === $preset ) {
1563 $html .= '<div class="rtsb-action-buttons top-part">';
1564 $html .= '<ul class="rtsb-action-button-list">';
1565 $html .= self::get_action_button_by_type( $items, 'wishlist' );
1566 $html .= self::get_action_button_by_type( $items, 'compare' );
1567 $html .= self::get_action_button_by_type( $items, 'quick_view' );
1568 $html .= '</ul>';
1569 $html .= '</div>';
1570
1571 $html .= '<div class="rtsb-action-buttons bottom-part">';
1572 $html .= '<ul class="rtsb-action-button-list">';
1573 $html .= self::get_action_button_by_type( $items, 'add_to_cart', $ajax_cart );
1574 } else {
1575 $html .= '<div class="rtsb-action-buttons ' . esc_attr( $class ) . '">';
1576 $html .= '<ul class="rtsb-action-button-list">';
1577 $html .= self::get_action_button_by_type( $items, 'add_to_cart', $ajax_cart );
1578 $html .= self::get_action_button_by_type( $items, 'wishlist' );
1579 $html .= self::get_action_button_by_type( $items, 'compare' );
1580 $html .= self::get_action_button_by_type( $items, 'quick_view' );
1581 }
1582
1583 $html .= '</ul>';
1584 $html .= '</div>';
1585
1586 return apply_filters( 'rtsb/elements/elementor/get_formatted_action_buttons', $html );
1587 }
1588
1589 /**
1590 * Get Action Button HTML
1591 *
1592 * @param array $items Items.
1593 * @param string $type Button type.
1594 * @param string $cart_html Ajax cart HTML.
1595 * @param string $wrapper Wrapper tag.
1596 *
1597 * @return void|string
1598 */
1599 public static function get_action_button_by_type( $items, $type, $cart_html = '', $wrapper = 'li' ) {
1600 if ( ! in_array( $type, $items, true ) ) {
1601 return;
1602 }
1603
1604 $html = '';
1605 $class = 'rtsb-action-button-item';
1606
1607 if ( 'add_to_cart' === $type ) {
1608 $class .= ' rtsb-cart' . ( empty( $cart_html ) ? esc_attr( ' no-cart-button' ) : '' );
1609 } else {
1610 $class .= ' rtsb-' . esc_attr( str_replace( '_', '-', $type ) );
1611 }
1612
1613 $html .= '<' . esc_attr( $wrapper ) . ' class="' . esc_attr( $class ) . '">';
1614
1615 if ( ( 'add_to_cart' === $type ) && ( ! empty( $cart_html ) ) ) {
1616 $html .= $cart_html;
1617 } else {
1618 $html .= do_shortcode( '[rtsb_' . $type . '_button]' );
1619 }
1620
1621 $html .= '</' . esc_attr( $wrapper ) . '>';
1622
1623 return apply_filters( 'rtsb/elements/elementor/get_action_button_by_type', $html );
1624 }
1625
1626 /**
1627 * Social Share Platforms.
1628 *
1629 * @return mixed|null
1630 */
1631 public static function social_share_platforms_list() {
1632 return apply_filters(
1633 'rtsb/settings/social_share/platforms',
1634 [
1635 [
1636 'value' => 'facebook',
1637 'label' => esc_html__( 'Facebook', 'shopbuilder' ),
1638 ],
1639 [
1640 'value' => 'twitter',
1641 'label' => esc_html__( 'Twitter', 'shopbuilder' ),
1642 ],
1643 [
1644 'value' => 'linkedin',
1645 'label' => esc_html__( 'Linkedin', 'shopbuilder' ),
1646 ],
1647 [
1648 'value' => 'pinterest',
1649 'label' => esc_html__( 'Pinterest', 'shopbuilder' ),
1650 ],
1651 [
1652 'value' => 'skype',
1653 'label' => esc_html__( 'Skype', 'shopbuilder' ),
1654 ],
1655 [
1656 'value' => 'whatsapp',
1657 'label' => esc_html__( 'Whatsapp', 'shopbuilder' ),
1658 ],
1659 [
1660 'value' => 'reddit',
1661 'label' => esc_html__( 'Reddit', 'shopbuilder' ),
1662 ],
1663 [
1664 'value' => 'telegram',
1665 'label' => esc_html__( 'Telegram', 'shopbuilder' ),
1666 ],
1667 ]
1668 );
1669 }
1670
1671 /**
1672 * Get Social Share link HTML.
1673 *
1674 * @param int $id Post ID.
1675 * @param array $types Preset type.
1676 * @param string $preset Style type.
1677 * @param string $show_icon Show icon.
1678 *
1679 * @return string
1680 */
1681 public static function get_social_share_html( int $id, array $types, string $preset = 'default', $show_icon = 'yes' ) {
1682 $attr = [ 'postid' => $id ];
1683 $output = '';
1684
1685 if ( empty( $types ) ) {
1686 return $output;
1687 }
1688
1689 foreach ( $types as $type ) {
1690 $link = [];
1691 $link['type'] = $type['share_items'];
1692 $link['class'] = '';
1693 $link['img'] = apply_filters( 'rtsb/elements/share/default_img', '', $id, $link );
1694
1695 if ( 'site' === $id ) {
1696 $link['url'] = esc_url( home_url() );
1697 $link['title'] = wp_strip_all_tags( get_bloginfo( 'name' ) );
1698 } elseif ( 0 === strpos( $id, 'http' ) ) {
1699 $link['url'] = esc_url( $id );
1700 $link['title'] = '';
1701 } else {
1702 $link['url'] = esc_url( get_permalink( $id ) );
1703 $link['title'] = wp_strip_all_tags( get_the_title( $id ) );
1704
1705 if ( has_post_thumbnail( $id ) ) {
1706 $link['img'] = wp_get_attachment_image_url( get_post_thumbnail_id( $id ), 'full' );
1707 }
1708
1709 $link['img'] = apply_filters( 'rtsb/elements/share/single_img', $link['img'], $id, $link );
1710 }
1711
1712 $link['url'] = apply_filters( 'rtsb/elements/share/url', $link['url'], $link );
1713
1714 switch ( $type['share_items'] ) {
1715 case 'facebook':
1716 $link['link'] = 'https://www.facebook.com/sharer/sharer.php?u=' . $link['url'] . '&display=popup&ref=plugin&src=share_button';
1717 $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>';
1718 $link['attr_title'] = esc_html__( 'Share on Facebook', 'shopbuilder' );
1719 $link['social_network'] = 'Facebook';
1720 $link['social_action'] = 'Share';
1721 break;
1722 case 'twitter':
1723 $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'];
1724 $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>';
1725 $link['attr_title'] = esc_html__( 'Share on Twitter', 'shopbuilder' );
1726 $link['social_network'] = 'Twitter';
1727 $link['social_action'] = 'Tweet';
1728 break;
1729 case 'pinterest':
1730 $link['link'] = 'https://pinterest.com/pin/create/button/?url=' . $link['url'] . '&media=' . $link['img'] . '&description=' . $link['title'];
1731 $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>';
1732 $link['attr_title'] = esc_html__( 'Share on Pinterest', 'shopbuilder' );
1733 $link['social_network'] = 'Pinterest';
1734 $link['social_action'] = 'Pin';
1735 break;
1736 case 'linkedin':
1737 $link['link'] = 'https://www.linkedin.com/shareArticle?url=' . $link['url'] . '&title=' . $link['title'];
1738 $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>';
1739 $link['attr_title'] = esc_html__( 'Share on LinkedIn', 'shopbuilder' );
1740 $link['social_network'] = 'LinkedIn';
1741 $link['social_action'] = 'Share';
1742 break;
1743 case 'skype':
1744 $link['link'] = 'https://web.skype.com/share?url=' . $link['url'];
1745 $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>';
1746 $link['attr_title'] = esc_html__( 'Share on Skype', 'shopbuilder' );
1747 $link['social_network'] = 'Skype';
1748 $link['social_action'] = 'Skype';
1749 break;
1750 case 'whatsapp':
1751 $link['link'] = 'https://wa.me/?text=' . $link['title'] . ' ' . $link['url'];
1752 $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>';
1753 $link['attr_title'] = esc_html__( 'Share on Whatsapp', 'shopbuilder' );
1754 $link['social_network'] = 'Whatsapp';
1755 $link['social_action'] = 'Share';
1756 break;
1757 case 'reddit':
1758 $link['link'] = 'https://reddit.com/submit?url=' . $link['url'] . '&title=' . $link['title'];
1759 $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>';
1760 $link['attr_title'] = esc_html__( 'Share on Reddit', 'shopbuilder' );
1761 $link['social_network'] = 'Reddit';
1762 $link['social_action'] = 'Share';
1763 break;
1764 case 'telegram':
1765 $link['link'] = 'https://telegram.me/share/url?text=' . $link['title'] . '&url=' . $link['url'];
1766 $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>';
1767 $link['attr_title'] = esc_html__( 'Share on Telegram', 'shopbuilder' );
1768 $link['social_network'] = 'Telegram';
1769 $link['social_action'] = 'Share';
1770 break;
1771 }
1772
1773 $link['label'] = $type['share_text'];
1774 $link['target'] = '_blank';
1775 $link['rel'] = 'nofollow noopener noreferrer';
1776
1777 $data = '';
1778 $link = apply_filters( 'rtsb/elements/share/share_link', $link, $id, $preset );
1779 $icon = apply_filters( 'rtsb/elements/share/share_icon', $link['icon'], $preset );
1780 $target = ! empty( $link['target'] ) ? ' target="' . esc_attr( $link['target'] ) . '" ' : '';
1781 $rel = ! empty( $link['rel'] ) ? ' rel="' . esc_attr( $link['rel'] ) . '" ' : '';
1782 $attr_title = ! empty( $link['attr_title'] ) ? ' title="' . esc_attr( $link['attr_title'] ) . '" ' : '';
1783 $elements = [];
1784
1785 // Add classes.
1786 $css_classes = [
1787 'rtsb-share-btn',
1788 sanitize_html_class( $link['type'] ),
1789 ];
1790 $css_classes = array_merge( $css_classes, explode( ' ', $link['class'] ) );
1791 $css_classes = array_map( 'sanitize_html_class', $css_classes );
1792 $css_classes = implode( ' ', array_filter( $css_classes ) );
1793
1794 unset( $attr['pin-do'], $attr['action'] );
1795
1796 if ( 'pinterest' === $type['share_items'] ) {
1797 $attr['pin-do'] = 'none';
1798 }
1799
1800 if ( 'whatsapp' === $type['share_items'] ) {
1801 $attr['action'] = 'share/whatsapp/share';
1802 }
1803
1804 $attr = apply_filters( 'rtsb/elements/share/link_data', $attr, $link, $id );
1805
1806 if ( ! empty( $attr ) ) {
1807 foreach ( $attr as $key => $val ) {
1808 $data .= ' data-' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '"';
1809 }
1810 }
1811
1812 $additional_attr = apply_filters( 'rtsb/elements/share/additional_attr', [], $link, $id, $preset );
1813
1814 if ( ! empty( $additional_attr ) ) {
1815 $attr_output = join( ' ', $additional_attr );
1816
1817 if ( ! empty( $data ) ) {
1818 $attr_output = ' ' . $attr_output;
1819 }
1820
1821 $data .= $attr_output;
1822 }
1823
1824 $elements['wrapper_start'] = sprintf(
1825 '<li class="rtsb-share-item"><a href="%s"%s%s%s class="%s"%s>',
1826 ! empty( $link['link'] ) ? esc_attr( $link['link'] ) : '',
1827 $attr_title,
1828 $target,
1829 $rel,
1830 $css_classes,
1831 $data
1832 );
1833 $elements['wrapper_end'] = '</a></li>';
1834
1835 $elements['icon'] = ! empty( $show_icon ) ? '<span class="rtsb-share-icon">' . ( ! empty( $icon ) ? $icon : null ) . '</span>' : null;
1836 $elements['label'] = ! empty( $link['label'] ) ? '<span class="rtsb-share-label">' . $link['label'] . '</span>' : null;
1837 $elements['icon_label'] = '<span class="rtsb-share-icon-label">' . $elements['icon'] . $elements['label'] . '</span>';
1838 $elements = apply_filters( 'rtsb/elements/share/output_elements', $elements, $link, $id );
1839
1840 $output .= $elements['wrapper_start'] . $elements['icon_label'] . $elements['wrapper_end'];
1841 }
1842
1843 // error_log( print_r( $output , true ) . "\n\n" , 3, __DIR__ . '/log.txt' );
1844 return apply_filters( 'rtsb/elements/share/list_output', $output );
1845 }
1846
1847 /**
1848 * Social Share Platforms.
1849 *
1850 * @return mixed|null
1851 */
1852 public static function is_module_active( $module ) {
1853 $modulelist = ModuleList::instance()->get_data();
1854 if ( ! empty( $modulelist[ $module ]['active'] ) ) {
1855 return true;
1856 }
1857 }
1858
1859 /**
1860 * @param array $links default plugin action link
1861 *
1862 * @return array [array] plugin action link
1863 */
1864 public static function plugins_setting_links( $links ) {
1865 $links[] = '<a href="' . admin_url( 'admin.php?page=rtsb-settings' ) . '">' . esc_html__( 'Settings', 'shopbuilder' ) . '</a>';
1866 // TODO:: This function will apply after pro version.
1867 if ( ! is_plugin_active( 'shopbuilder/shopbuilder.php' ) ) {
1868 $links['shopbuilder_pro'] = sprintf( '<a href="#" target="_blank" style="color: #39b54a; font-weight: bold;">' . esc_html__( 'Go Pro', 'shopbuilder' ) . '</a>' );
1869 }
1870
1871 return $links;
1872 }
1873
1874 /***
1875 * Save Settings data
1876 *
1877 * @param $section_id
1878 * @param $block_id
1879 * @param $rawOptions
1880 *
1881 * @return array
1882 */
1883 public static function set_options( $section_id = '', $block_id = '', $rawOptions = [] ) {
1884 $section_id = ! empty( $section_id ) ? sanitize_text_field( wp_unslash( $section_id ) ) : '';
1885 $block_id = ! empty( $block_id ) ? sanitize_text_field( wp_unslash( $block_id ) ) : '';
1886 $rawOptions = ! empty( $rawOptions ) ? $rawOptions : [];
1887
1888 $results = [
1889 'status' => true,
1890 'message' => '',
1891 ];
1892 if ( ! $section_id || ! $block_id ) {
1893 $results['status'] = false;
1894 $results['message'] = esc_html__( 'Section , block or options may be empty', 'shopbuilder' );
1895
1896 return $results;
1897 }
1898 $sections = Settings::instance()->get_sections();
1899 if ( empty( $sections[ $section_id ] ) || empty( $sections[ $section_id ]['list'][ $block_id ] ) ) {
1900 $results['status'] = false;
1901 $results['message'] = esc_html__( 'No section or block found with given data', 'shopbuilder' );
1902
1903 return $results;
1904 }
1905
1906 $options = DataModel::source()->get_option( $section_id, [] );
1907 $changed = false;
1908 $fields = [];
1909 if ( isset( $sections[ $section_id ]['list'][ $block_id ]['fields'] ) && ! empty( $sections[ $section_id ]['list'][ $block_id ]['fields'] ) ) {
1910 $fields = $sections[ $section_id ]['list'][ $block_id ]['fields'];
1911 }
1912
1913 if ( empty( $fields ) ) {
1914 if ( isset( $rawOptions['active'] ) ) {
1915 $changed = true;
1916 $options[ $block_id ]['active'] = 'on' === $rawOptions['active'] ? 'on' : '';
1917 }
1918 } else {
1919 foreach ( $rawOptions as $raw_option_key => $raw_value ) {
1920 if ( $raw_option_key === 'active' ) {
1921 $changed = true;
1922 $options[ $block_id ]['active'] = $sections[ $section_id ]['list'][ $block_id ]['active'] = 'on' === $raw_value ? 'on' : '';
1923 } else {
1924 if ( isset( $fields[ $raw_option_key ] ) ) {
1925 $field = $fields[ $raw_option_key ];
1926 if ( $field['type'] === 'switch' ) {
1927 $value = 'on' === $raw_value ? 'on' : '';
1928 } else {
1929 if ( ! empty( $field['multiple'] ) || 'checkbox' === $field['type'] ) {
1930 if ( isset( $raw_value ) && is_array( $raw_value ) ) {
1931 if ( ! empty( $field['sanitize_fn'] ) && is_callable( $field['sanitize_fn'] ) ) {
1932 $value = array_map( $field['sanitize_fn'], $raw_value );
1933 } else {
1934 $value = array_map( 'sanitize_text_field', $raw_value );
1935 }
1936 } else {
1937 $value = [];
1938 }
1939 } else {
1940 if ( ! empty( $field['sanitize_fn'] ) && is_callable( $field['sanitize_fn'] ) ) {
1941 $value = $field['sanitize_fn']( $raw_value );
1942 } else {
1943 $value = sanitize_text_field( $raw_value );
1944 }
1945 }
1946 }
1947 $options[ $block_id ][ $raw_option_key ] = $sections[ $section_id ]['list'][ $block_id ]['fields'][ $raw_option_key ]['value'] = $value;
1948 $changed = true;
1949 }
1950 }
1951 }
1952 }
1953 if ( ! $changed ) {
1954 $results['status'] = false;
1955 $results['message'] = esc_html__( 'No changes found for update', 'shopbuilder' );
1956
1957 return $results;
1958 }
1959
1960 DataModel::source()->set_option( $section_id, $options );
1961
1962 $results['status'] = true;
1963 $results['message'] = esc_html__( 'Successfully Saved', 'shopbuilder' );
1964 $results['sections'] = $sections;
1965
1966 return $results;
1967 }
1968
1969
1970 }
1971