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

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

201 lines 7.3 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 // The fileupload control stores [ 'id' => attachment ID, 'source' => URL ],
109 // but it can come back from the options store as a JSON string, so decode it
110 // before reading the URL; a raw JSON string must never be used as the URL.
111 $preloader_image = GalleryFns::get_options( 'preloader_image' );
112 if ( is_string( $preloader_image ) && '' !== trim( $preloader_image ) ) {
113 $decoded = json_decode( wp_unslash( $preloader_image ), true );
114 if ( is_array( $decoded ) ) {
115 $preloader_image = $decoded;
116 }
117 }
118 $preloader_image_url = '';
119 if ( is_array( $preloader_image ) && ! empty( $preloader_image['source'] ) ) {
120 $preloader_image_url = $preloader_image['source'];
121 } elseif ( is_string( $preloader_image ) && filter_var( $preloader_image, FILTER_VALIDATE_URL ) ) {
122 $preloader_image_url = $preloader_image;
123 }
124 wp_localize_script(
125 $this->handle,
126 'rtsbVgParams',
127 [
128 'ajaxurl' => esc_url( $ajaxurl ),
129 'admin_url' => esc_url( admin_url() ),
130 'pro_version' => defined( 'RTSBPRO_VERSION' ) ? RTSBPRO_VERSION : false,
131 'preloader' => GalleryFns::get_options( 'preloader' ) ? 'on' : '',
132 'preloaderImage' => $preloader_image_url ? esc_url( $preloader_image_url ) : '',
133 'changeEffect' => GalleryFns::get_options( 'gallery_change_effect', 'blur' ),
134 rtsb()->nonceId => wp_create_nonce( rtsb()->nonceText ),
135 ]
136 );
137 $this->frontend_dynamic_css();
138 }
139
140 /**
141 * @return void
142 */
143 private function frontend_dynamic_css() {
144 $options = GalleryFns::get_options();
145 $dynamic_css = ':root{';
146 $alignment = 'on' === ( $options['main_slider_alignment'] ?? '' ) ? 'center' : 'flex-start';
147 $col = GalleryFns::get_options( 'thumbnails_columns', 3 );
148 $dynamic_css .= '--vg-main-slider-v-alignment:' . $alignment . ';';
149 $dynamic_css .= '--vg-grid-column:' . absint( $col ) . ';';
150 $dynamic_css .= '--vg-main-slider-border-color:' . ( ! empty( $options['main_image_border_color'] ) ? $options['main_image_border_color'] : 'transparent' ) . ';';
151 $dynamic_css .= '--vg-thumb-border-color:' . ( ! empty( $options['thumbnail_item_border_color'] ) ? $options['thumbnail_item_border_color'] : '#eee' ) . ';';
152 $dynamic_css .= '--vg-thumb-active-border-color:' . ( ! empty( $options['thumbnail_active_border_color'] ) ? $options['thumbnail_active_border_color'] : '#444' ) . ';';
153 $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;';
154 $dynamic_css .= '--vg-thumb-border-radius:' . ( ! empty( $options['thumbnail_item_border_radius'] ) ? absint( $options['thumbnail_item_border_radius'] ) : '3' ) . 'px;';
155 $dynamic_css .= '--vg-thumb-gap:' . ( isset( $options['thumbnails_gap'] ) && '' !== $options['thumbnails_gap'] ? absint( $options['thumbnails_gap'] ) : '10' ) . 'px;';
156 $dynamic_css .= '}';
157 if ( ! empty( $dynamic_css ) ) {
158 $dynamic_css = apply_filters( 'rtsb/variation/gallery/dynamic/css', $dynamic_css, $options );
159 wp_add_inline_style( $this->handle, $dynamic_css );
160 }
161 }
162 /**
163 * Assets.
164 *
165 * @return void
166 */
167 public function register_backend_assets() {
168 global $post;
169 $current_screen = get_current_screen();
170 $screen_id = $current_screen ? $current_screen->id : '';
171 // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
172 if ( in_array( 'sitepress-multilingual-cms/sitepress.php', get_option( 'active_plugins' ) ) ) {
173 $ajaxurl = admin_url( 'admin-ajax.php?lang=' . ICL_LANGUAGE_CODE );
174 } else {
175 $ajaxurl = admin_url( 'admin-ajax.php' );
176 }
177 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
178 if ( ( 'product' === sanitize_text_field( wp_unslash( $_GET['post_type'] ?? '' ) ) && isset( $_GET['taxonomy'] ) ) || 'product' === $screen_id ) {
179 wp_register_style( 'rtsb-variation-gallery-admin', rtsb()->get_assets_uri( 'css/backend/variation-gallery-admin.css' ), '', '1.0' );
180 wp_register_script( 'rtsb-variation-gallery-admin', rtsb()->get_assets_uri( 'js/backend/variation-gallery-admin.js' ), '', '1.0', true );
181 wp_enqueue_script( 'rtsb-variation-gallery-admin' );
182 wp_enqueue_style( 'rtsb-variation-gallery-admin' );
183 wp_localize_script(
184 'rtsb-variation-gallery-admin',
185 'rtsbVgParams',
186 [
187 'ajaxurl' => esc_url( $ajaxurl ),
188 'admin_url' => esc_url( admin_url() ),
189 'pro_version' => defined( 'RTSBPRO_VERSION' ) ? RTSBPRO_VERSION : false,
190 'nonce' => wp_create_nonce( 'rtsb_vg_nonce' ),
191 'media_title' => esc_html__( 'Choose an Image', 'shopbuilder' ),
192 'button_title' => esc_html__( 'Use Image', 'shopbuilder' ),
193 'add_media' => esc_html__( 'Add Media', 'shopbuilder' ),
194 'add_video' => esc_html__( 'Add Video', 'shopbuilder' ),
195 'sure_txt' => esc_html__( 'Are you sure to delete?', 'shopbuilder' ),
196 ]
197 );
198 }
199 }
200 }
201