PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.4.2
ShopBuilder – WooCommerce Builder For Elementor v3.4.2
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.4.2, at app/Modules/VariationGallery/VariationGalleryInit.php

207 lines 7.6 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 GalleryMigration::instance();
62 }
63 /**
64 * Shared dependencies.
65 *
66 * @param array $deps Dependencies.
67 *
68 * @return array
69 */
70 public function extend_shared_dependencies( $deps ) {
71 if ( is_product() || BuilderFns::is_product() ) {
72 $deps[] = 'swiper';
73 }
74 return $deps;
75 }
76
77 /**
78 * Assets.
79 *
80 * @return void
81 */
82 public function frontend_assets() {
83 wp_dequeue_script( 'wc-flexslider' );
84 // Enqueue assets.
85 $this->handle = Fns::enqueue_module_assets(
86 $this->handle,
87 'variation-gallery',
88 [
89 'context' => ( function_exists( 'rtsbpro' ) && rtsb()->has_pro() ) ? rtsbpro() : rtsb(),
90 'version' => rtsb()->has_pro() ? RTSBPRO_VERSION : RTSB_VERSION,
91 'type' => 'css',
92 ]
93 );
94 $this->handle = Fns::enqueue_module_assets(
95 $this->handle,
96 'variation-gallery',
97 [
98 'context' => rtsb(),
99 'version' => RTSB_VERSION,
100 'type' => 'js',
101 ]
102 );
103 // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
104 if ( in_array( 'sitepress-multilingual-cms/sitepress.php', get_option( 'active_plugins' ) ) ) {
105 $ajaxurl = admin_url( 'admin-ajax.php?lang=' . ICL_LANGUAGE_CODE );
106 } else {
107 $ajaxurl = admin_url( 'admin-ajax.php' );
108 }
109 // The fileupload control stores [ 'id' => attachment ID, 'source' => URL ],
110 // but it can come back from the options store as a JSON string, so decode it
111 // before reading the URL; a raw JSON string must never be used as the URL.
112 $preloader_image = GalleryFns::get_options( 'preloader_image' );
113 if ( is_string( $preloader_image ) && '' !== trim( $preloader_image ) ) {
114 $decoded = json_decode( wp_unslash( $preloader_image ), true );
115 if ( is_array( $decoded ) ) {
116 $preloader_image = $decoded;
117 }
118 }
119 $preloader_image_url = '';
120 if ( is_array( $preloader_image ) && ! empty( $preloader_image['source'] ) ) {
121 $preloader_image_url = $preloader_image['source'];
122 } elseif ( is_string( $preloader_image ) && filter_var( $preloader_image, FILTER_VALIDATE_URL ) ) {
123 $preloader_image_url = $preloader_image;
124 }
125 wp_localize_script(
126 $this->handle,
127 'rtsbVgParams',
128 [
129 'ajaxurl' => esc_url( $ajaxurl ),
130 'admin_url' => esc_url( admin_url() ),
131 'pro_version' => defined( 'RTSBPRO_VERSION' ) ? RTSBPRO_VERSION : false,
132 'preloader' => GalleryFns::get_options( 'preloader' ) ? 'on' : '',
133 'preloaderImage' => $preloader_image_url ? esc_url( $preloader_image_url ) : '',
134 'changeEffect' => GalleryFns::get_options( 'gallery_change_effect', 'blur' ),
135 rtsb()->nonceId => wp_create_nonce( rtsb()->nonceText ),
136 ]
137 );
138 $this->frontend_dynamic_css();
139 }
140
141 /**
142 * @return void
143 */
144 private function frontend_dynamic_css() {
145 $options = GalleryFns::get_options();
146 $dynamic_css = ':root{';
147 $alignment = 'on' === ( $options['main_slider_alignment'] ?? '' ) ? 'center' : 'flex-start';
148 $col = GalleryFns::get_options( 'thumbnails_columns', 3 );
149 $dynamic_css .= '--vg-main-slider-v-alignment:' . $alignment . ';';
150 $dynamic_css .= '--vg-grid-column:' . absint( $col ) . ';';
151 $dynamic_css .= '--vg-main-slider-border-color:' . ( ! empty( $options['main_image_border_color'] ) ? $options['main_image_border_color'] : 'transparent' ) . ';';
152 $dynamic_css .= '--vg-thumb-border-color:' . ( ! empty( $options['thumbnail_item_border_color'] ) ? $options['thumbnail_item_border_color'] : '#eee' ) . ';';
153 $dynamic_css .= '--vg-thumb-active-border-color:' . ( ! empty( $options['thumbnail_active_border_color'] ) ? $options['thumbnail_active_border_color'] : '#444' ) . ';';
154 $dynamic_css .= '--vg-thumb-item-inner-padding:' . ( isset( $options['thumbnail_item_inner_padding'] ) && '' !== $options['thumbnail_item_inner_padding'] ? absint( $options['thumbnail_item_inner_padding'] ) : '8' ) . 'px;';
155 $dynamic_css .= '--vg-thumb-border-radius:' . ( ! empty( $options['thumbnail_item_border_radius'] ) ? absint( $options['thumbnail_item_border_radius'] ) : '3' ) . 'px;';
156 $dynamic_css .= '--vg-thumb-gap:' . ( isset( $options['thumbnails_gap'] ) && '' !== $options['thumbnails_gap'] ? absint( $options['thumbnails_gap'] ) : '10' ) . 'px;';
157 $dynamic_css .= '}';
158 if ( ! empty( $dynamic_css ) ) {
159 $dynamic_css = apply_filters( 'rtsb/variation/gallery/dynamic/css', $dynamic_css, $options );
160 wp_add_inline_style( $this->handle, $dynamic_css );
161 }
162 }
163 /**
164 * Assets.
165 *
166 * @return void
167 */
168 public function register_backend_assets() {
169 global $post;
170 $current_screen = get_current_screen();
171 $screen_id = $current_screen ? $current_screen->id : '';
172 // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
173 if ( in_array( 'sitepress-multilingual-cms/sitepress.php', get_option( 'active_plugins' ) ) ) {
174 $ajaxurl = admin_url( 'admin-ajax.php?lang=' . ICL_LANGUAGE_CODE );
175 } else {
176 $ajaxurl = admin_url( 'admin-ajax.php' );
177 }
178 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
179 if ( ( 'product' === sanitize_text_field( wp_unslash( $_GET['post_type'] ?? '' ) ) && isset( $_GET['taxonomy'] ) ) || 'product' === $screen_id ) {
180 wp_register_style( 'rtsb-variation-gallery-admin', rtsb()->get_assets_uri( 'css/backend/variation-gallery-admin.css' ), '', '1.0' );
181 wp_register_script( 'rtsb-variation-gallery-admin', rtsb()->get_assets_uri( 'js/backend/variation-gallery-admin.js' ), '', '1.0', true );
182 wp_enqueue_script( 'rtsb-variation-gallery-admin' );
183 wp_enqueue_style( 'rtsb-variation-gallery-admin' );
184 wp_localize_script(
185 'rtsb-variation-gallery-admin',
186 'rtsbVgParams',
187 [
188 'ajaxurl' => esc_url( $ajaxurl ),
189 'admin_url' => esc_url( admin_url() ),
190 'pro_version' => defined( 'RTSBPRO_VERSION' ) ? RTSBPRO_VERSION : false,
191 'nonce' => wp_create_nonce( 'rtsb_vg_nonce' ),
192 'media_title' => esc_html__( 'Choose an Image', 'shopbuilder' ),
193 'button_title' => esc_html__( 'Use Image', 'shopbuilder' ),
194 'add_media' => esc_html__( 'Add Media', 'shopbuilder' ),
195 'add_video' => esc_html__( 'Add Video', 'shopbuilder' ),
196 'sure_txt' => esc_html__( 'Are you sure to delete?', 'shopbuilder' ),
197 'choose_image' => esc_html__( 'Choose an Image', 'shopbuilder' ),
198 'add_image' => esc_html__( 'Add Image', 'shopbuilder' ),
199 'edit_image' => esc_html__( 'Edit Image', 'shopbuilder' ),
200 'update_image' => esc_html__( 'Update Image', 'shopbuilder' ),
201 'remove_image' => esc_html__( 'Remove', 'shopbuilder' ),
202 ]
203 );
204 }
205 }
206 }
207