PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.6.2
ShopBuilder – WooCommerce Builder For Elementor v2.6.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.6.2, at app/Controllers/AssetsController.php

556 lines 15.8 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
92 $this->styles[] = [
93 'handle' => 'rtsb-odometer',
94 'src' => rtsb()->get_assets_uri( 'vendor/odometer/css/odometer.min.css' ),
95 ];
96
97 $this->styles[] = [
98 'handle' => 'rtsb-fonts',
99 'src' => rtsb()->get_assets_uri( 'css/frontend/rtsb-fonts.css' ),
100 ];
101 if ( rtsb()->has_pro() ) {
102 $this->styles[] = [
103 'handle' => 'rtsb-noui-slider',
104 'src' => rtsbpro()->get_assets_uri( 'vendors/nouislider/nouislider.min.css' ),
105 ];
106 }
107
108 $pro_version = defined( 'RTSBPRO_VERSION' ) ? RTSBPRO_VERSION : '0';
109 $addon_condition = version_compare( $pro_version, '1.9.0', '<' );
110
111 if ( $addon_condition ) {
112 $this->styles[] = [
113 'handle' => 'rtsb-general-addons',
114 'src' => rtsb()->get_assets_uri( 'css/frontend/general-addons' . $rtl_suffix . '.css' ),
115 ];
116 }
117 $this->styles[] = [
118 'handle' => 'rtsb-frontend',
119 'src' => rtsb()->get_assets_uri( 'css/frontend/frontend' . $rtl_suffix . '.css' ),
120 ];
121
122 /*
123 $this->styles[] = [
124 'handle' => 'swiper',
125 'src' => rtsb()->get_assets_uri( 'vendor/swiper/css/swiper-bundle.min.css' ),
126 ];
127 */
128
129 if ( BuilderFns::is_builder_preview() && 'elementor' == Fns::page_edit_with( get_the_ID() ) ) {
130 $this->styles[] = [
131 'handle' => 'photoswipe',
132 'src' => plugins_url( 'assets/css/photoswipe/photoswipe.min.css', WC_PLUGIN_FILE ),
133 ];
134
135 $this->styles[] = [
136 'handle' => 'photoswipe-default-skin',
137 'src' => plugins_url( 'assets/css/photoswipe/default-skin/default-skin.min.css', WC_PLUGIN_FILE ),
138 ];
139
140 // Load only for elementor editor page and fix some issue.
141 $this->styles[] = [
142 'handle' => 'elementor-editor-style-fix',
143 'src' => rtsb()->get_assets_uri( 'css/backend/elementor-editor-style-fix.css' ),
144 ];
145 }
146
147 return $this;
148 }
149
150 /**
151 * Get public scripts.
152 *
153 * @return object
154 */
155 private function get_public_scripts() {
156
157 $default_swiper_path = rtsb()->get_assets_uri( 'vendor/swiper/js/swiper-bundle.min.js' );
158
159 if ( defined( 'ELEMENTOR_ASSETS_PATH' ) ) {
160 $is_swiper8_enable = get_option( 'elementor_experiment-e_swiper_latest' );
161
162 if ( 'active' === $is_swiper8_enable || 'default' === $is_swiper8_enable ) {
163 $el_swiper_path = 'lib/swiper/v8/swiper.min.js';
164 } else {
165 $el_swiper_path = 'lib/swiper/swiper.min.js';
166 }
167
168 $elementor_swiper_path = ELEMENTOR_ASSETS_PATH . $el_swiper_path;
169
170 if ( file_exists( $elementor_swiper_path ) ) {
171 $default_swiper_path = ELEMENTOR_ASSETS_URL . $el_swiper_path;
172 }
173 }
174
175 $this->scripts[] = [
176 'handle' => 'swiper',
177 'src' => esc_url( $default_swiper_path ),
178 'deps' => [ 'jquery' ],
179 'footer' => true,
180 ];
181 $this->scripts[] = [
182 'handle' => 'rtsb-waypoints',
183 'src' => rtsb()->get_assets_uri( 'vendor/waypoints/js/jquery.waypoints.min.js' ),
184 'deps' => [ 'jquery' ],
185 'footer' => true,
186 ];
187 $this->scripts[] = [
188 'handle' => 'rtsb-odometer',
189 'src' => rtsb()->get_assets_uri( 'vendor/odometer/js/odometer.min.js' ),
190 'deps' => [ 'jquery' ],
191 'footer' => true,
192 ];
193
194 $this->scripts[] = [
195 'handle' => 'rtsb-imagesloaded',
196 'src' => rtsb()->get_assets_uri( 'vendor/isotope/imagesloaded.pkgd.min.js' ),
197 'deps' => [ 'jquery' ],
198 'footer' => true,
199 ];
200
201 $this->scripts[] = [
202 'handle' => 'rtsb-tipsy',
203 'src' => rtsb()->get_assets_uri( 'vendor/tipsy/tipsy.min.js' ),
204 'deps' => [ 'jquery' ],
205 'footer' => true,
206 ];
207
208 if ( BuilderFns::is_builder_preview() && 'elementor' == Fns::page_edit_with( get_the_ID() ) ) {
209 $this->scripts[] = [
210 'handle' => 'flexslider',
211 'src' => plugins_url( 'assets/js/flexslider/jquery.flexslider.js', WC_PLUGIN_FILE ),
212 'deps' => [ 'jquery' ],
213 'footer' => true,
214 ];
215
216 $this->scripts[] = [
217 'handle' => 'photoswipe',
218 'src' => plugins_url( 'assets/js/photoswipe/photoswipe.js', WC_PLUGIN_FILE ),
219 'deps' => [ 'jquery' ],
220 'footer' => true,
221 ];
222
223 $this->scripts[] = [
224 'handle' => 'zoom',
225 'src' => plugins_url( 'assets/js/zoom/jquery.zoom.js', WC_PLUGIN_FILE ),
226 'deps' => [ 'jquery' ],
227 'footer' => true,
228 ];
229
230 $this->scripts[] = [
231 'handle' => 'photoswipe-ui-default',
232 'src' => plugins_url( 'assets/js/photoswipe/photoswipe-ui-default.js', WC_PLUGIN_FILE ),
233 'deps' => [ 'jquery', 'photoswipe' ],
234 'footer' => true,
235 ];
236
237 $this->scripts[] = [
238 'handle' => 'wc-single-product',
239 'src' => plugins_url( 'assets/js/frontend/single-product.js', WC_PLUGIN_FILE ),
240 'deps' => [ 'jquery', 'flexslider', 'photoswipe', 'photoswipe-ui-default', 'zoom' ],
241 'footer' => true,
242 ];
243
244 }
245
246 if ( rtsb()->has_pro() ) {
247 $this->scripts[] = [
248 'handle' => 'rtsb-noui-slider',
249 'src' => rtsbpro()->get_assets_uri( 'vendors/nouislider/nouislider.min.js' ),
250 'deps' => [ 'jquery' ],
251 'footer' => true,
252 ];
253
254 $this->scripts[] = [
255 'handle' => 'rtsb-sticky-sidebar',
256 'src' => rtsbpro()->get_assets_uri( 'vendors/sticky-sidebar/sticky-sidebar.min.js' ),
257 'deps' => [ 'jquery' ],
258 'footer' => true,
259 ];
260
261 $this->scripts[] = [
262 'handle' => 'rtsb-popper',
263 'src' => rtsbpro()->get_assets_uri( 'vendors/tippy/popper.min.js' ),
264 'deps' => [ 'jquery' ],
265 'footer' => true,
266 ];
267
268 $this->scripts[] = [
269 'handle' => 'rtsb-tippy',
270 'src' => rtsbpro()->get_assets_uri( 'vendors/tippy/tippy.min.js' ),
271 'deps' => [ 'jquery', 'rtsb-popper' ],
272 'footer' => true,
273 ];
274 }
275
276 $this->scripts[] = [
277 'handle' => 'rtsb-public',
278 'src' => rtsb()->get_assets_uri( 'js/frontend/frontend.js' ),
279 'deps' => [ 'jquery', 'rtsb-imagesloaded', 'swiper' ],
280 'footer' => true,
281 ];
282
283 return $this;
284 }
285
286 /**
287 * Register public scripts.
288 *
289 * @return void
290 */
291 public function register_public_scripts() {
292 $this->get_public_assets();
293
294 // Register public styles.
295 foreach ( $this->styles as $style ) {
296 wp_register_style( $style['handle'], $style['src'], '', $this->version );
297 }
298
299 // Register public scripts.
300 foreach ( $this->scripts as $script ) {
301 wp_register_script( $script['handle'], $script['src'], $script['deps'], $this->version, $script['footer'] );
302 }
303 }
304
305 /**
306 * Enqueues public scripts.
307 *
308 * @return void
309 */
310 public function enqueue_public_scripts() {
311 /**
312 * Register scripts.
313 */
314 $this->register_public_scripts();
315 // wp_enqueue_style( 'swiper' );
316 /**
317 * Enqueue scripts.
318 */
319 if ( BuilderFns::is_builder_preview() && 'elementor' === Fns::page_edit_with( get_the_ID() ) ) {
320 /**
321 * Styles.
322 */
323 wp_enqueue_style( 'photoswipe' );
324 wp_enqueue_style( 'photoswipe-default-skin' );
325 wp_enqueue_style( 'elementor-editor-style-fix' );
326 wp_enqueue_style( 'woocommerce-general' );
327
328 /**
329 * Scripts.
330 */
331 wp_enqueue_script( 'flexslider' );
332 wp_enqueue_script( 'wc-single-product' );
333 wp_dequeue_script( 'rtsb-public' );
334 wp_enqueue_script( 'swiper' );
335 wp_enqueue_script( 'rtsb-public' );
336 }
337
338 /**
339 * Styles.
340 */
341 wp_enqueue_style( 'rtsb-fonts' );
342 wp_enqueue_style( 'rtsb-frontend' );
343
344 /**
345 * Scripts.
346 */
347 wp_enqueue_script( 'rtsb-imagesloaded' );
348 wp_enqueue_script( 'rtsb-tipsy' );
349 wp_enqueue_script( 'rtsb-public' );
350
351 /**
352 * Localize script.
353 */
354 self::localizeData();
355 }
356
357 /**
358 * Localized Data.
359 *
360 * @static
361 * @return void
362 */
363 public static function localizeData() {
364 wp_localize_script(
365 'rtsb-public',
366 'rtsbPublicParams',
367 [
368 'ajaxUrl' => esc_url( self::$ajaxurl ),
369 'homeurl' => home_url(),
370 'wcCartUrl' => wc_get_cart_url(),
371 'addedToCartText' => esc_html__( 'Product Added', 'shopbuilder' ),
372 'singleCartToastrText' => esc_html__( 'Successfully Added', 'shopbuilder' ),
373 'singleCartBtnText' => apply_filters( 'rtsb/global/single_add_to_cart_success', esc_html__( 'Added to Cart', 'shopbuilder' ) ),
374 'browseCartText' => esc_html__( 'Browse Cart', 'shopbuilder' ),
375 'noProductsText' => apply_filters( 'rtsb/global/no_products_text', esc_html__( 'No more products to load', 'shopbuilder' ) ),
376 'notice' => [
377 'position' => Fns::get_option( 'general', 'notification', 'notification_position', 'center-center' ),
378 ],
379 rtsb()->nonceId => wp_create_nonce( rtsb()->nonceText ),
380 ]
381 );
382 }
383
384 /**
385 * Registers Admin scripts.
386 *
387 * @return void
388 */
389 public function register_backend_assets() {
390 /**
391 * Styles.
392 */
393 wp_register_style( 'rtsb-admin-app', rtsb()->get_assets_uri( 'css/backend/admin-settings.css' ), '', $this->version );
394 wp_register_style( 'rtsb-fonts', rtsb()->get_assets_uri( 'css/frontend/rtsb-fonts.css' ), '', $this->version );
395
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 wp_deregister_style( 'select2' );
404 wp_register_style( 'select2', plugins_url( 'assets/css/select2.css', WC_PLUGIN_FILE ) ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
405 }
406 wp_register_style( 'rtsb-templatebuilder', rtsb()->get_assets_uri( 'css/backend/template-builder.css' ), '', $this->version );
407
408 /**
409 * Scripts.
410 */
411 wp_register_script( 'rtsb-admin-app', rtsb()->get_assets_uri( 'js/backend/admin-settings.js' ), '', $this->version, true );
412 wp_register_script( 'rtsb-templatebuilder', rtsb()->get_assets_uri( 'js/backend/template-builder.js' ), '', $this->version, true );
413 }
414
415 /**
416 * Enqueues admin scripts.
417 *
418 * @param string $hook Hooks.
419 *
420 * @return void
421 */
422 public function enqueue_backend_scripts( $hook ) {
423 ob_start(); ?>
424 #adminmenu .toplevel_page_rtsb .wp-menu-image img {
425 width: auto;
426 height: 22px;
427 padding: 4px 0;
428 }
429 .post-type-rtsb_builder li#wp-admin-bar-WPML_ALS_all,
430 .post-type-rtsb_builder li.language_all{
431 display: none;
432 }
433
434 <?php
435 $admin_global_style = ob_get_clean();
436 // Speed Optimization.
437 wp_add_inline_style( 'admin-menu', $admin_global_style );
438 // wp_enqueue_style( 'rtsb-admin-global' );
439
440 global $pagenow;
441
442 $whitelisted_pages = [ 'rtsb-settings', 'rtsb-get-help', 'rtsb-themes' ];
443 $current_page = ! empty( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
444
445 if ( 'admin.php' === $pagenow && ! empty( $_GET['page'] ) && in_array( $current_page, $whitelisted_pages, true ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
446 /**
447 * Styles.
448 */
449 wp_enqueue_style( 'rtsb-admin-app' );
450 wp_enqueue_style( 'rtsb-fonts' );
451 }
452
453 if ( 'admin.php' === $pagenow && ! empty( $_GET['page'] ) && 'rtsb-settings' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
454 // Elementor Console Error Fixed For "rtsb-settings" Page.
455 wp_dequeue_script( 'elementor-admin-top-bar' );
456 wp_dequeue_script( 'elementor-common' );
457 wp_dequeue_script( 'elementor-dev-tools' );
458 wp_dequeue_script( 'elementor-web-cli' );
459 wp_dequeue_script( 'elementor-import-export-admin' );
460 wp_dequeue_script( 'elementor-app-loader' );
461 wp_dequeue_script( 'elementor-admin-modules' );
462 wp_dequeue_script( 'elementor-admin' );
463
464 wp_dequeue_style( 'elementor-admin-top-bar' );
465 wp_dequeue_style( 'elementor-admin' );
466 wp_dequeue_style( 'e-theme-ui-light' );
467 wp_dequeue_style( 'elementor-common' );
468
469 /**
470 * Scripts.
471 */
472 wp_enqueue_script( 'updates' );
473 wp_enqueue_script( 'rtsb-admin-app' );
474 wp_localize_script(
475 'rtsb-admin-app',
476 'rtsbParams',
477 [
478 'ajaxurl' => esc_url( self::$ajaxurl ),
479 'homeurl' => home_url(),
480 'adminLogo' => rtsb()->get_assets_uri( 'images/icon/ShopBuilder-Logo.svg' ),
481 'restApiUrl' => esc_url_raw( rest_url() ),
482 'rest_nonce' => wp_create_nonce( 'wp_rest' ),
483 'nonce' => wp_create_nonce( rtsb()->nonceText ),
484 'pages' => Fns::get_pages(),
485 'hasPro' => rtsb()->has_pro() ? 'yes' : 'no',
486 'updateRates' => esc_html__( 'Update All Rates', 'shopbuilder' ),
487 'sections' => Settings::instance()->get_sections(),
488 'userRoles' => Fns::get_all_user_roles(),
489 'hasElementor' => defined( 'ELEMENTOR_VERSION' ),
490 ]
491 );
492 } else {
493 $current_screen = get_current_screen();
494
495 if ( 'edit-rtsb_builder' === $current_screen->id ) {
496 if ( ! function_exists( 'woocommerce_get_asset_url' ) ) {
497 include_once WC_ABSPATH . 'includes/wc-template-functions.php';
498 }
499 /**
500 * Styles.
501 */
502 wp_enqueue_style( 'rtsb-templatebuilder' );
503
504 wp_enqueue_style( 'select2', plugins_url( 'assets/css/select2.css', WC_PLUGIN_FILE ) ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
505
506 wp_enqueue_script( 'selectWoo' );
507 /**
508 * Scripts.
509 */
510 wp_enqueue_script( 'rtsb-templatebuilder' );
511
512 wp_localize_script(
513 'rtsb-templatebuilder',
514 'rtsbParams',
515 [
516 'ajaxurl' => esc_url( self::$ajaxurl ),
517 'homeurl' => home_url(),
518 rtsb()->nonceId => wp_create_nonce( rtsb()->nonceText ),
519 'hasPro' => rtsb()->has_pro() ? 'yes' : 'no',
520 ]
521 );
522 }
523 }
524 }
525
526 /**
527 * Enqueues general public scripts.
528 *
529 * @return void
530 */
531 public function enqueue_general_public_scripts() {
532 $notification_color = Fns::get_option( 'general', 'notification', 'notification_color', '#004BFF' );
533 $notification_bgcolor = Fns::get_option( 'general', 'notification', 'notification_bg', '#F5F8FF' );
534 $notification_button_color = Fns::get_option( 'general', 'notification', 'notification_btn_color', '#0039C0' );
535
536 $dynamic_css = '';
537
538 if ( ! empty( $notification_color ) ) {
539 $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-success{color:{$notification_color}}";
540 $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-success:before{background-color:{$notification_color}}";
541 }
542
543 if ( ! empty( $notification_bgcolor ) ) {
544 $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-success{background-color:{$notification_bgcolor}}";
545 }
546
547 if ( ! empty( $notification_button_color ) ) {
548 $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-success a{color:{$notification_button_color}}";
549 }
550
551 if ( ! empty( $dynamic_css ) ) {
552 wp_add_inline_style( 'rtsb-frontend', $dynamic_css );
553 }
554 }
555 }
556