PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.2.6
ShopBuilder – WooCommerce Builder For Elementor v3.2.6
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 / Modules / VariationGallery / VariationGalleryInit.php

VariationGalleryInit.php in ShopBuilder – WooCommerce Builder For Elementor 3.2.6, at app/Modules/VariationGallery/VariationGalleryInit.php

187 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace RadiusTheme\SB\Modules\VariationGallery;
4
5 use RadiusTheme\SB\Helpers\BuilderFns;
6 use RadiusTheme\SB\Helpers\Fns;
7 use RadiusTheme\SB\Traits\SingletonTrait;
8
9 // Do not allow directly accessing this file.
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit( 'This script cannot be accessed directly.' );
12 }
13 /**
14 * Variation Swatches
15 */
16 final class VariationGalleryInit {
17
18 /**
19 * SingleTon
20 */
21 use SingletonTrait;
22
23 /**
24 * Asset Handle
25 *
26 * @var string
27 */
28 private $handle = 'rtsb-variation-gallery';
29
30 /**
31 * Constructor.
32 *
33 * @return void
34 */
35 private function __construct() {
36 $already_active = Fns::check_plugin_active( 'woo-product-variation-gallery/woo-product-variation-gallery.php' );
37 if ( ! $already_active ) {
38 $this->scripts();
39 $this->init();
40 do_action( 'rtsb/variation/gallery/init' );
41 }
42 }
43 /**
44 * Initialize Functionality.
45 *
46 * @return void
47 */
48 private function scripts() {
49 add_filter( 'rtsb/optimizer/scripts/deps', [ $this, 'extend_shared_dependencies' ] );
50 add_action( 'wp_enqueue_scripts', [ $this, 'frontend_assets' ], 99 );
51 add_action( 'admin_enqueue_scripts', [ $this, 'register_backend_assets' ], 1 );
52 }
53 /**
54 * Initialize Functionality.
55 *
56 * @return void
57 */
58 private function init() {
59 GalleryAdmin::instance();
60 GalleryFrontEnd::instance();
61 }
62 /**
63 * Shared dependencies.
64 *
65 * @param array $deps Dependencies.
66 *
67 * @return array
68 */
69 public function extend_shared_dependencies( $deps ) {
70 if ( is_product() || BuilderFns::is_product() ) {
71 $deps[] = 'swiper';
72 }
73 return $deps;
74 }
75
76 /**
77 * Assets.
78 *
79 * @return void
80 */
81 public function frontend_assets() {
82 wp_dequeue_script( 'wc-flexslider' );
83 // Enqueue assets.
84 $this->handle = Fns::enqueue_module_assets(
85 $this->handle,
86 'variation-gallery',
87 [
88 'context' => ( function_exists( 'rtsbpro' ) && rtsb()->has_pro() ) ? rtsbpro() : rtsb(),
89 'version' => rtsb()->has_pro() ? RTSBPRO_VERSION : RTSB_VERSION,
90 'type' => 'css',
91 ]
92 );
93 $this->handle = Fns::enqueue_module_assets(
94 $this->handle,
95 'variation-gallery',
96 [
97 'context' => rtsb(),
98 'version' => RTSB_VERSION,
99 'type' => 'js',
100 ]
101 );
102 // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
103 if ( in_array( 'sitepress-multilingual-cms/sitepress.php', get_option( 'active_plugins' ) ) ) {
104 $ajaxurl = admin_url( 'admin-ajax.php?lang=' . ICL_LANGUAGE_CODE );
105 } else {
106 $ajaxurl = admin_url( 'admin-ajax.php' );
107 }
108 wp_localize_script(
109 $this->handle,
110 'rtsbVgParams',
111 [
112 'ajaxurl' => esc_url( $ajaxurl ),
113 'admin_url' => esc_url( admin_url() ),
114 'pro_version' => defined( 'RTSBPRO_VERSION' ) ? RTSBPRO_VERSION : false,
115 rtsb()->nonceId => wp_create_nonce( rtsb()->nonceText ),
116 ]
117 );
118 $this->frontend_dynamic_css();
119 }
120
121 /**
122 * @return void
123 */
124 private function frontend_dynamic_css() {
125 $options = GalleryFns::get_options();
126 $dynamic_css = ':root{';
127 $alignment = 'on' === ( $options['main_slider_alignment'] ?? '' ) ? 'center' : 'flex-start';
128 $col = GalleryFns::get_options( 'thumbnails_columns', 3 );
129 $dynamic_css .= '--vg-main-slider-v-alignment:' . $alignment . ';';
130 $dynamic_css .= '--vg-grid-column:' . absint( $col ) . ';';
131 $dynamic_css .= '--vg-main-slider-border-color:' . ( ! empty( $options['main_image_border_color'] ) ? $options['main_image_border_color'] : 'transparent' ) . ';';
132 $dynamic_css .= '--vg-thumb-border-color:' . ( ! empty( $options['thumbnail_item_border_color'] ) ? $options['thumbnail_item_border_color'] : '#eee' ) . ';';
133 $dynamic_css .= '--vg-thumb-item-inner-padding:' . ( ! empty( $options['thumbnail_item_inner_padding'] ) ? $options['thumbnail_item_inner_padding'] : '8' ) . 'px;';
134 $dynamic_css .= '--vg-thumb-border-radius:' . ( ! empty( $options['thumbnail_item_border_radius'] ) ? absint( $options['thumbnail_item_border_radius'] ) : '3' ) . 'px;';
135 $dynamic_css .= '--vg-thumb-gap:' . ( ! empty( $options['thumbnails_gap'] ) ? absint( $options['thumbnails_gap'] ) : '10' ) . 'px;';
136 if ( ! empty( $options['main_image_section_width'] ) && absint( $options['image_section_height'] ) ) {
137 $dynamic_css .= '--vg-image-slider-height:' . absint( $options['image_section_height'] ) . 'px;';
138 }
139 if ( ! empty( $options['thumb_image_section_width'] ) && absint( $options['thumb_image_section_width'] ) ) {
140 $dynamic_css .= '--vg-thumb-slider-width:' . absint( $options['thumb_image_section_width'] ) . 'px;';
141 }
142 $dynamic_css .= '}';
143 if ( ! empty( $dynamic_css ) ) {
144 $dynamic_css = apply_filters( 'rtsb/variation/gallery/dynamic/css', $dynamic_css, $options );
145 wp_add_inline_style( $this->handle, $dynamic_css );
146 }
147 }
148 /**
149 * Assets.
150 *
151 * @return void
152 */
153 public function register_backend_assets() {
154 global $post;
155 $current_screen = get_current_screen();
156 $screen_id = $current_screen ? $current_screen->id : '';
157 // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
158 if ( in_array( 'sitepress-multilingual-cms/sitepress.php', get_option( 'active_plugins' ) ) ) {
159 $ajaxurl = admin_url( 'admin-ajax.php?lang=' . ICL_LANGUAGE_CODE );
160 } else {
161 $ajaxurl = admin_url( 'admin-ajax.php' );
162 }
163 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
164 if ( ( 'product' === sanitize_text_field( wp_unslash( $_GET['post_type'] ?? '' ) ) && isset( $_GET['taxonomy'] ) ) || 'product' === $screen_id ) {
165 wp_register_style( 'rtsb-variation-gallery-admin', rtsb()->get_assets_uri( 'css/backend/variation-gallery-admin.css' ), '', '1.0' );
166 wp_register_script( 'rtsb-variation-gallery-admin', rtsb()->get_assets_uri( 'js/backend/variation-gallery-admin.js' ), '', '1.0', true );
167 wp_enqueue_script( 'rtsb-variation-gallery-admin' );
168 wp_enqueue_style( 'rtsb-variation-gallery-admin' );
169 wp_localize_script(
170 'rtsb-variation-gallery-admin',
171 'rtsbVgParams',
172 [
173 'ajaxurl' => esc_url( $ajaxurl ),
174 'admin_url' => esc_url( admin_url() ),
175 'pro_version' => defined( 'RTSBPRO_VERSION' ) ? RTSBPRO_VERSION : false,
176 'nonce' => wp_create_nonce( 'rtsb_vg_nonce' ),
177 'media_title' => esc_html__( 'Choose an Image', 'shopbuilder' ),
178 'button_title' => esc_html__( 'Use Image', 'shopbuilder' ),
179 'add_media' => esc_html__( 'Add Media', 'shopbuilder' ),
180 'add_video' => esc_html__( 'Add Video', 'shopbuilder' ),
181 'sure_txt' => esc_html__( 'Are you sure to delete?', 'shopbuilder' ),
182 ]
183 );
184 }
185 }
186 }
187