PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.0.2
ShopBuilder – WooCommerce Builder For Elementor v2.0.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 / Controllers / AssetsController.php

AssetsController.php in ShopBuilder – WooCommerce Builder For Elementor 2.0.2, at app/Controllers/AssetsController.php

459 lines 12.1 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\Controllers;
4
5 use RadiusTheme\SB\Helpers\BuilderFns;
6 use RadiusTheme\SB\Helpers\Fns;
7 use RadiusTheme\SB\Models\Settings;
8 use RadiusTheme\SB\Traits\SingletonTrait;
9
10 // Do not allow directly accessing this file.
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit( 'This script cannot be accessed directly.' );
13 }
14
15 class AssetsController {
16
17 use SingletonTrait;
18
19 /**
20 * Plugin version
21 *
22 * @var string
23 */
24 private $version;
25
26 /**
27 * Ajax URL
28 *
29 * @var string
30 */
31 private static $ajaxurl;
32
33 /**
34 * Styles.
35 *
36 * @var array
37 */
38 private $styles = [];
39
40 /**
41 * Scripts.
42 *
43 * @var array
44 */
45 private $scripts = [];
46
47 /**
48 * Class Constructor
49 */
50 public function __construct() {
51 $this->version = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? time() : RTSB_VERSION;
52
53 if ( in_array( 'sitepress-multilingual-cms/sitepress.php', get_option( 'active_plugins' ) ) ) {
54 self::$ajaxurl = admin_url( 'admin-ajax.php?lang=' . ICL_LANGUAGE_CODE );
55 } else {
56 self::$ajaxurl = admin_url( 'admin-ajax.php' );
57 }
58
59 /**
60 * Admin scripts.
61 */
62 add_action( 'admin_enqueue_scripts', [ $this, 'register_backend_assets' ], 1 );
63 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_backend_scripts' ], 15 );
64
65 /**
66 * Public scripts.
67 */
68 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_public_scripts' ], 15 );
69 /**
70 * General scripts.
71 */
72 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_general_public_scripts' ], 30 );
73 }
74
75 /**
76 * Get all frontend scripts.
77 *
78 * @return void
79 */
80 private function get_public_assets() {
81 $this->get_public_styles()->get_public_scripts();
82 }
83
84 /**
85 * Get public styles.
86 *
87 * @return object
88 */
89 private function get_public_styles() {
90 $rtl_suffix = is_rtl() ? '-rtl' : '';
91 $this->styles[] = [
92 'handle' => 'rtsb-fonts',
93 'src' => rtsb()->get_assets_uri( 'css/frontend/rtsb-fonts.css' ),
94 ];
95
96 if ( rtsb()->has_pro() ) {
97 $this->styles[] = [
98 'handle' => 'rtsb-noui-slider',
99 'src' => rtsbpro()->get_assets_uri( 'vendors/nouislider/nouislider.min.css' ),
100 ];
101 }
102
103 $this->styles[] = [
104 'handle' => 'rtsb-frontend',
105 'src' => rtsb()->get_assets_uri( 'css/frontend/frontend' . $rtl_suffix . '.css' ),
106 ];
107
108 $this->styles[] = [
109 'handle' => 'swiper',
110 'src' => rtsb()->get_assets_uri( 'vendor/swiper/css/swiper-bundle.min.css' ),
111 ];
112
113 if ( BuilderFns::is_builder_preview() && 'elementor' == Fns::page_edit_with( get_the_ID() ) ) {
114 $this->styles[] = [
115 'handle' => 'photoswipe',
116 'src' => plugins_url( 'assets/css/photoswipe/photoswipe.min.css', WC_PLUGIN_FILE ),
117 ];
118
119 $this->styles[] = [
120 'handle' => 'photoswipe-default-skin',
121 'src' => plugins_url( 'assets/css/photoswipe/default-skin/default-skin.min.css', WC_PLUGIN_FILE ),
122 ];
123
124 // Load only for elementor editor page and fix some issue.
125 $this->styles[] = [
126 'handle' => 'elementor-editor-style-fix',
127 'src' => rtsb()->get_assets_uri( 'css/backend/elementor-editor-style-fix.css' ),
128 ];
129 }
130
131 return $this;
132 }
133
134 /**
135 * Get public scripts.
136 *
137 * @return object
138 */
139 private function get_public_scripts() {
140 $this->scripts[] = [
141 'handle' => 'swiper',
142 'src' => rtsb()->get_assets_uri( 'vendor/swiper/js/swiper-bundle.min.js' ),
143 'deps' => [ 'jquery' ],
144 'footer' => true,
145 ];
146
147 $this->scripts[] = [
148 'handle' => 'rtsb-imagesloaded',
149 'src' => rtsb()->get_assets_uri( 'vendor/isotope/imagesloaded.pkgd.min.js' ),
150 'deps' => [ 'jquery' ],
151 'footer' => true,
152 ];
153
154 $this->scripts[] = [
155 'handle' => 'rtsb-tipsy',
156 'src' => rtsb()->get_assets_uri( 'vendor/tipsy/tipsy.min.js' ),
157 'deps' => [ 'jquery' ],
158 'footer' => true,
159 ];
160
161 if ( BuilderFns::is_builder_preview() && 'elementor' == Fns::page_edit_with( get_the_ID() ) ) {
162 $this->scripts[] = [
163 'handle' => 'flexslider',
164 'src' => plugins_url( 'assets/js/flexslider/jquery.flexslider.js', WC_PLUGIN_FILE ),
165 'deps' => [ 'jquery' ],
166 'footer' => true,
167 ];
168
169 $this->scripts[] = [
170 'handle' => 'photoswipe',
171 'src' => plugins_url( 'assets/js/photoswipe/photoswipe.js', WC_PLUGIN_FILE ),
172 'deps' => [ 'jquery' ],
173 'footer' => true,
174 ];
175
176 $this->scripts[] = [
177 'handle' => 'zoom',
178 'src' => plugins_url( 'assets/js/zoom/jquery.zoom.js', WC_PLUGIN_FILE ),
179 'deps' => [ 'jquery' ],
180 'footer' => true,
181 ];
182
183 $this->scripts[] = [
184 'handle' => 'photoswipe-ui-default',
185 'src' => plugins_url( 'assets/js/photoswipe/photoswipe-ui-default.js', WC_PLUGIN_FILE ),
186 'deps' => [ 'jquery', 'photoswipe' ],
187 'footer' => true,
188 ];
189
190 $this->scripts[] = [
191 'handle' => 'wc-single-product',
192 'src' => plugins_url( 'assets/js/frontend/single-product.js', WC_PLUGIN_FILE ),
193 'deps' => [ 'jquery', 'flexslider', 'photoswipe', 'photoswipe-ui-default', 'zoom' ],
194 'footer' => true,
195 ];
196
197 }
198
199 if ( rtsb()->has_pro() ) {
200 $this->scripts[] = [
201 'handle' => 'rtsb-noui-slider',
202 'src' => rtsbpro()->get_assets_uri( 'vendors/nouislider/nouislider.min.js' ),
203 'deps' => [ 'jquery' ],
204 'footer' => true,
205 ];
206
207 $this->scripts[] = [
208 'handle' => 'rtsb-sticky-sidebar',
209 'src' => rtsbpro()->get_assets_uri( 'vendors/sticky-sidebar/sticky-sidebar.min.js' ),
210 'deps' => [ 'jquery' ],
211 'footer' => true,
212 ];
213 }
214
215 $this->scripts[] = [
216 'handle' => 'rtsb-public',
217 'src' => rtsb()->get_assets_uri( 'js/frontend/frontend.js' ),
218 'deps' => [ 'jquery', 'rtsb-imagesloaded', 'swiper' ],
219 'footer' => true,
220 ];
221
222 return $this;
223 }
224
225 /**
226 * Register public scripts.
227 *
228 * @return void
229 */
230 public function register_public_scripts() {
231 $this->get_public_assets();
232
233 // Register public styles.
234 foreach ( $this->styles as $style ) {
235 wp_register_style( $style['handle'], $style['src'], '', $this->version );
236 }
237
238 // Register public scripts.
239 foreach ( $this->scripts as $script ) {
240 wp_register_script( $script['handle'], $script['src'], $script['deps'], $this->version, $script['footer'] );
241 }
242 }
243
244 /**
245 * Enqueues public scripts.
246 *
247 * @return void
248 */
249 public function enqueue_public_scripts() {
250 /**
251 * Register scripts.
252 */
253 $this->register_public_scripts();
254 /**
255 * Enqueue scripts.
256 */
257 if ( BuilderFns::is_builder_preview() && 'elementor' === Fns::page_edit_with( get_the_ID() ) ) {
258 /**
259 * Styles.
260 */
261 wp_enqueue_style( 'swiper' );
262 wp_enqueue_style( 'photoswipe' );
263 wp_enqueue_style( 'photoswipe-default-skin' );
264 wp_enqueue_style( 'elementor-editor-style-fix' );
265 wp_enqueue_style( 'woocommerce-general' );
266
267 /**
268 * Scripts.
269 */
270 wp_enqueue_script( 'flexslider' );
271 wp_enqueue_script( 'wc-single-product' );
272 wp_dequeue_script( 'rtsb-public' );
273 wp_enqueue_script( 'swiper' );
274 wp_enqueue_script( 'rtsb-public' );
275 }
276
277 /**
278 * Styles.
279 */
280 wp_enqueue_style( 'rtsb-fonts' );
281 wp_enqueue_style( 'rtsb-frontend' );
282
283 /**
284 * Scripts.
285 */
286 wp_enqueue_script( 'rtsb-imagesloaded' );
287 wp_enqueue_script( 'rtsb-tipsy' );
288 wp_enqueue_script( 'rtsb-public' );
289
290 /**
291 * Localize script.
292 */
293 self::localizeData();
294 }
295
296 /**
297 * Localized Data.
298 *
299 * @static
300 * @return void
301 */
302 public static function localizeData() {
303 wp_localize_script(
304 'rtsb-public',
305 'rtsbPublicParams',
306 [
307 'ajaxUrl' => esc_url( self::$ajaxurl ),
308 'homeurl' => home_url(),
309 'wcCartUrl' => wc_get_cart_url(),
310 'addedToCartText' => esc_html__( 'Product Added', 'shopbuilder' ),
311 'browseCartText' => esc_html__( 'Browse Cart', 'shopbuilder' ),
312 'noProductsText' => apply_filters( 'rtsb/global/no_products_text', esc_html__( 'No more products to load', 'shopbuilder' ) ),
313 'notice' => [
314 'position' => Fns::get_option( 'general', 'notification', 'notification_position', 'center-center' ),
315 ],
316 rtsb()->nonceId => wp_create_nonce( rtsb()->nonceText ),
317 ]
318 );
319 }
320
321 /**
322 * Registers Admin scripts.
323 *
324 * @return void
325 */
326 public function register_backend_assets() {
327 /**
328 * Styles.
329 */
330 wp_register_style( 'rtsb-admin-app', rtsb()->get_assets_uri( 'css/backend/admin-settings.css' ), '', $this->version );
331 wp_register_style( 'rtsb-admin-global', rtsb()->get_assets_uri( 'css/backend/admin-global.css' ), '', $this->version );
332 wp_register_style( 'rtsb-templatebuilder', rtsb()->get_assets_uri( 'css/backend/template-builder.css' ), '', $this->version );
333
334 /**
335 * Scripts.
336 */
337 wp_register_script( 'rtsb-admin-app', rtsb()->get_assets_uri( 'js/backend/admin-settings.js' ), '', $this->version, true );
338 wp_register_script( 'rtsb-templatebuilder', rtsb()->get_assets_uri( 'js/backend/template-builder.js' ), '', $this->version, true );
339
340 }
341
342 /**
343 * Enqueues admin scripts.
344 *
345 * @param string $hook Hooks.
346 *
347 * @return void
348 */
349 public function enqueue_backend_scripts( $hook ) {
350
351 wp_enqueue_style( 'rtsb-admin-global' );
352
353 global $pagenow;
354
355 if ( 'admin.php' === $pagenow && ! empty( $_GET['page'] ) && 'rtsb-settings' === $_GET['page'] ) {
356 // Elementor Console Error Fixed For "rtsb-settings" Page.
357 wp_dequeue_script( 'elementor-admin-top-bar' );
358 wp_dequeue_script( 'elementor-common' );
359 wp_dequeue_script( 'elementor-dev-tools' );
360 wp_dequeue_script( 'elementor-web-cli' );
361 wp_dequeue_script( 'elementor-import-export-admin' );
362 wp_dequeue_script( 'elementor-app-loader' );
363 wp_dequeue_script( 'elementor-admin-modules' );
364 wp_dequeue_script( 'elementor-admin' );
365
366 wp_dequeue_style( 'elementor-admin-top-bar' );
367 wp_dequeue_style( 'elementor-admin' );
368 wp_dequeue_style( 'e-theme-ui-light' );
369 wp_dequeue_style( 'elementor-common' );
370
371 /**
372 * Styles.
373 */
374 wp_enqueue_style( 'rtsb-admin-app' );
375
376 /**
377 * Scripts.
378 */
379 wp_enqueue_script( 'updates' );
380 wp_enqueue_script( 'rtsb-admin-app' );
381 wp_localize_script(
382 'rtsb-admin-app',
383 'rtsbParams',
384 [
385 'ajaxurl' => esc_url( self::$ajaxurl ),
386 'homeurl' => home_url(),
387 'restApiUrl' => esc_url_raw( rest_url() ),
388 'rest_nonce' => wp_create_nonce( 'wp_rest' ),
389 'nonce' => wp_create_nonce( rtsb()->nonceText ),
390 'sections' => Settings::instance()->get_sections(),
391 'pages' => Fns::get_pages(),
392 'hasPro' => rtsb()->has_pro() ? 'yes' : 'no'
393 ]
394 );
395 } else {
396 $current_screen = get_current_screen();
397
398 if ( 'edit-rtsb_builder' === $current_screen->id ) {
399 if ( ! function_exists( 'woocommerce_get_asset_url' ) ) {
400 include_once WC_ABSPATH . 'includes/wc-template-functions.php';
401 }
402 /**
403 * Styles.
404 */
405 wp_enqueue_style( 'rtsb-templatebuilder' );
406
407 wp_enqueue_style( 'select2', plugins_url( 'assets/css/select2.css', WC_PLUGIN_FILE ) );
408
409 wp_enqueue_script( 'selectWoo' );
410 /**
411 * Scripts.
412 */
413 wp_enqueue_script( 'rtsb-templatebuilder' );
414
415 wp_localize_script(
416 'rtsb-templatebuilder',
417 'rtsbParams',
418 [
419 'ajaxurl' => esc_url( self::$ajaxurl ),
420 'homeurl' => home_url(),
421 rtsb()->nonceId => wp_create_nonce( rtsb()->nonceText ),
422 'hasPro' => rtsb()->has_pro() ? 'yes' : 'no'
423 ]
424 );
425 }
426 }
427 }
428
429 /**
430 * Enqueues general public scripts.
431 *
432 * @return void
433 */
434 public function enqueue_general_public_scripts() {
435 $notification_color = Fns::get_option( 'general', 'notification', 'notification_color', '#004BFF' );
436 $notification_bgcolor = Fns::get_option( 'general', 'notification', 'notification_bg', '#F5F8FF' );
437 $notification_button_color = Fns::get_option( 'general', 'notification', 'notification_btn_color', '#0039C0' );
438
439 $dynamic_css = '';
440
441 if ( ! empty( $notification_color ) ) {
442 $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-success{color:{$notification_color}}";
443 $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-success:before{background-color:{$notification_color}}";
444 }
445
446 if ( ! empty( $notification_bgcolor ) ) {
447 $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-success{background-color:{$notification_bgcolor}}";
448 }
449
450 if ( ! empty( $notification_button_color ) ) {
451 $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-success a{color:{$notification_button_color}}";
452 }
453
454 if ( ! empty( $dynamic_css ) ) {
455 wp_add_inline_style( 'rtsb-frontend', $dynamic_css );
456 }
457 }
458 }
459