PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 1.1.1
ShopBuilder – WooCommerce Builder For Elementor v1.1.1
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
← All changes | app/Controllers/AssetsController.php +369 -637 3.4.21.1.1 View file →
@@ -1,637 +1,369 @@
1 -<?php
2 -/**
3 - * Assets Controller Class
4 - *
5 - * @package RadiusTheme\SB
6 - */
7 -
8 -namespace RadiusTheme\SB\Controllers;
9 -
10 -use RadiusTheme\SB\AI\AIFns;
11 -use RadiusTheme\SB\Helpers\Fns;
12 -use RadiusTheme\SB\Models\Settings;
13 -use RadiusTheme\SB\Helpers\BuilderFns;
14 -use RadiusTheme\SB\Traits\SingletonTrait;
15 -
16 -// Do not allow directly accessing this file.
17 -if ( ! defined( 'ABSPATH' ) ) {
18 - exit( 'This script cannot be accessed directly.' );
19 -}
20 -
21 -/**
22 - * Assets Controller Class
23 - */
24 -class AssetsController {
25 -
26 - use SingletonTrait;
27 -
28 - /**
29 - * Plugin version
30 - *
31 - * @var string
32 - */
33 - private $version;
34 -
35 - /**
36 - * Ajax URL
37 - *
38 - * @var string
39 - */
40 - private static $ajaxurl;
41 -
42 - /**
43 - * Styles.
44 - *
45 - * @var array
46 - */
47 - private $styles = [];
48 -
49 - /**
50 - * Scripts.
51 - *
52 - * @var array
53 - */
54 - private $scripts = [];
55 -
56 - /**
57 - * Cached bundled assets.
58 - *
59 - * @var array|null
60 - */
61 - private $cached_bundled_assets = null;
62 -
63 - /**
64 - * Class Constructor
65 - */
66 - public function __construct() {
67 - $this->version = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? time() : RTSB_VERSION;
68 -
69 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
70 - if ( in_array( 'sitepress-multilingual-cms/sitepress.php', get_option( 'active_plugins' ) ) ) {
71 - self::$ajaxurl = admin_url( 'admin-ajax.php?lang=' . ICL_LANGUAGE_CODE );
72 - } else {
73 - self::$ajaxurl = admin_url( 'admin-ajax.php' );
74 - }
75 - add_filter( 'rtsb/optimizer/scripts/deps', [ $this, 'extend_shared_dependencies' ], 99 );
76 - /**
77 - * Admin scripts.
78 - */
79 - add_action( 'admin_enqueue_scripts', [ $this, 'register_backend_assets' ], 1 );
80 - add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_backend_scripts' ], 15 );
81 -
82 - /**
83 - * Public scripts.
84 - */
85 - add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_public_scripts' ], 25 );
86 - /**
87 - * General scripts.
88 - */
89 - add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_general_public_scripts' ], 30 );
90 - }
91 - /**
92 - * Shared dependencies.
93 - *
94 - * @param array $deps Dependencies.
95 - *
96 - * @return array
97 - */
98 - public function extend_shared_dependencies( $deps ) {
99 - if ( Fns::is_elementor_widget_active( 'products_slider' ) ) {
100 - $deps[] = 'swiper';
101 - }
102 - return array_unique( $deps );
103 - }
104 - /**
105 - * Get all frontend scripts.
106 - *
107 - * @return void
108 - */
109 - private function get_public_assets() {
110 - $this->get_public_styles()->get_public_scripts();
111 - }
112 -
113 - /**
114 - * Get public styles.
115 - *
116 - * @return object
117 - */
118 - private function get_public_styles() {
119 - $rtl_suffix = is_rtl() ? '-rtl' : '';
120 - $rtl_dir = is_rtl() ? trailingslashit( 'rtl' ) : trailingslashit( 'css' );
121 -
122 - $this->styles[] = [
123 - 'handle' => 'rtsb-odometer',
124 - 'src' => rtsb()->get_assets_uri( 'vendor/odometer/css/odometer.min.css' ),
125 - ];
126 -
127 - $this->styles[] = [
128 - 'handle' => 'rtsb-fonts',
129 - 'src' => rtsb()->get_assets_uri( 'css/frontend/rtsb-fonts.css' ),
130 - ];
131 - if ( rtsb()->has_pro() ) {
132 - $this->styles[] = [
133 - 'handle' => 'rtsb-noui-slider',
134 - 'src' => rtsbpro()->get_assets_uri( 'vendors/nouislider/nouislider.min.css' ),
135 - ];
136 - }
137 -
138 - $pro_version = defined( 'RTSBPRO_VERSION' ) ? RTSBPRO_VERSION : '0';
139 - $addon_condition = version_compare( $pro_version, '1.9.0', '<' );
140 -
141 - $optimized = [];
142 -
143 - if ( ! rtsb()->has_pro() && Fns::is_optimization_enabled() ) {
144 - $optimized = AssetRegistry::instance()->load_optimized_assets();
145 - }
146 -
147 - // An empty `src` means the bundle could not be built. Registering it would
148 - // produce a handle WordPress never prints, so use the unbundled assets.
149 - if ( ! empty( $optimized['src'] ) ) {
150 - $this->styles[] = $optimized;
151 - } else {
152 - if ( $addon_condition ) {
153 - $this->styles[] = [
154 - 'handle' => 'rtsb-general-addons',
155 - 'src' => rtsb()->get_assets_uri( $rtl_dir . 'frontend/general-addons' . $rtl_suffix . '.css' ),
156 - ];
157 - }
158 - $this->styles[] = [
159 - 'handle' => 'rtsb-frontend',
160 - 'src' => rtsb()->get_assets_uri( $rtl_dir . 'frontend/frontend' . $rtl_suffix . '.css' ),
161 - ];
162 - }
163 - if ( BuilderFns::is_builder_preview() && 'elementor' == Fns::page_edit_with( get_the_ID() ) ) {
164 - $this->styles[] = [
165 - 'handle' => 'photoswipe',
166 - 'src' => plugins_url( 'assets/css/photoswipe/photoswipe.min.css', WC_PLUGIN_FILE ),
167 - ];
168 -
169 - $this->styles[] = [
170 - 'handle' => 'photoswipe-default-skin',
171 - 'src' => plugins_url( 'assets/css/photoswipe/default-skin/default-skin.min.css', WC_PLUGIN_FILE ),
172 - ];
173 -
174 - // Load only for elementor editor page and fix some issue.
175 - $this->styles[] = [
176 - 'handle' => 'elementor-editor-style-fix',
177 - 'src' => rtsb()->get_assets_uri( 'css/backend/elementor-editor-style-fix.css' ),
178 - ];
179 - }
180 -
181 - return $this;
182 - }
183 -
184 - /**
185 - * Get public scripts.
186 - *
187 - * @return object
188 - */
189 - private function get_public_scripts() {
190 - $this->scripts[] = [
191 - 'handle' => 'swiper',
192 - 'src' => esc_url( $this->get_swiper_url() ),
193 - 'deps' => [ 'jquery' ],
194 - 'footer' => true,
195 - ];
196 - $this->scripts[] = [
197 - 'handle' => 'rtsb-waypoints',
198 - 'src' => rtsb()->get_assets_uri( 'vendor/waypoints/js/jquery.waypoints.min.js' ),
199 - 'deps' => [ 'jquery' ],
200 - 'footer' => true,
201 - ];
202 - $this->scripts[] = [
203 - 'handle' => 'rtsb-odometer',
204 - 'src' => rtsb()->get_assets_uri( 'vendor/odometer/js/odometer.min.js' ),
205 - 'deps' => [ 'jquery' ],
206 - 'footer' => true,
207 - ];
208 -
209 - $this->scripts[] = [
210 - 'handle' => 'rtsb-tipsy',
211 - 'src' => rtsb()->get_assets_uri( 'vendor/tipsy/tipsy.min.js' ),
212 - 'deps' => [ 'jquery' ],
213 - 'footer' => true,
214 - ];
215 -
216 - if ( BuilderFns::is_builder_preview() && 'elementor' == Fns::page_edit_with( get_the_ID() ) ) {
217 - $this->scripts[] = [
218 - 'handle' => 'wc-flexslider',
219 - 'src' => plugins_url( 'assets/js/flexslider/jquery.flexslider.js', WC_PLUGIN_FILE ),
220 - 'deps' => [ 'jquery' ],
221 - 'footer' => true,
222 - ];
223 -
224 - $this->scripts[] = [
225 - 'handle' => 'photoswipe',
226 - 'src' => plugins_url( 'assets/js/photoswipe/photoswipe.js', WC_PLUGIN_FILE ),
227 - 'deps' => [ 'jquery' ],
228 - 'footer' => true,
229 - ];
230 -
231 - $this->scripts[] = [
232 - 'handle' => 'wc-zoom',
233 - 'src' => plugins_url( 'assets/js/zoom/jquery.zoom.js', WC_PLUGIN_FILE ),
234 - 'deps' => [ 'jquery' ],
235 - 'footer' => true,
236 - ];
237 -
238 - $this->scripts[] = [
239 - 'handle' => 'wc-photoswipe-ui-default',
240 - 'src' => plugins_url( 'assets/js/photoswipe/photoswipe-ui-default.js', WC_PLUGIN_FILE ),
241 - 'deps' => [ 'jquery', 'photoswipe' ],
242 - 'footer' => true,
243 - ];
244 -
245 - $this->scripts[] = [
246 - 'handle' => 'wc-single-product',
247 - 'src' => plugins_url( 'assets/js/frontend/single-product.js', WC_PLUGIN_FILE ),
248 - 'deps' => [ 'jquery', 'wc-flexslider', 'photoswipe', 'wc-photoswipe-ui-default', 'wc-zoom' ],
249 - 'footer' => true,
250 - ];
251 -
252 - }
253 -
254 - if ( rtsb()->has_pro() ) {
255 - $this->scripts[] = [
256 - 'handle' => 'rtsb-noui-slider',
257 - 'src' => rtsbpro()->get_assets_uri( 'vendors/nouislider/nouislider.min.js' ),
258 - 'deps' => [ 'jquery' ],
259 - 'footer' => true,
260 - ];
261 -
262 - $this->scripts[] = [
263 - 'handle' => 'rtsb-sticky-sidebar',
264 - 'src' => rtsbpro()->get_assets_uri( 'vendors/sticky-sidebar/sticky-sidebar.min.js' ),
265 - 'deps' => [ 'jquery' ],
266 - 'footer' => true,
267 - ];
268 -
269 - $this->scripts[] = [
270 - 'handle' => 'rtsb-popper',
271 - 'src' => rtsbpro()->get_assets_uri( 'vendors/tippy/popper.min.js' ),
272 - 'deps' => [ 'jquery' ],
273 - 'footer' => true,
274 - ];
275 -
276 - $this->scripts[] = [
277 - 'handle' => 'rtsb-tippy',
278 - 'src' => rtsbpro()->get_assets_uri( 'vendors/tippy/tippy.min.js' ),
279 - 'deps' => [ 'jquery', 'rtsb-popper' ],
280 - 'footer' => true,
281 - ];
282 - }
283 -
284 - $optimized = [];
285 -
286 - if ( ! rtsb()->has_pro() && Fns::is_optimization_enabled() ) {
287 - $optimized = AssetRegistry::instance()->load_optimized_assets( 'js' );
288 - }
289 -
290 - // See get_public_styles(): an empty `src` means the bundle build failed.
291 - if ( ! empty( $optimized['src'] ) ) {
292 - $this->scripts[] = $optimized;
293 - } else {
294 - $this->scripts[] = [
295 - 'handle' => 'rtsb-public',
296 - 'src' => rtsb()->get_assets_uri( 'js/frontend/frontend.js' ),
297 - 'deps' => [ 'jquery', 'imagesloaded', 'swiper' ],
298 - 'footer' => true,
299 - ];
300 - }
301 -
302 - return $this;
303 - }
304 -
305 - /**
306 - * Register public scripts.
307 - *
308 - * @return void
309 - */
310 - public function register_public_scripts() {
311 - $this->get_public_assets();
312 - $this->styles = array_filter( $this->styles );
313 - $this->scripts = array_filter( $this->scripts );
314 -
315 - // Register public styles.
316 - foreach ( $this->styles as $style ) {
317 - wp_register_style( $style['handle'], $style['src'], '', $this->version );
318 - }
319 -
320 - // Register public scripts.
321 - foreach ( $this->scripts as $script ) {
322 - wp_register_script( $script['handle'], $script['src'], $script['deps'], $this->version, $script['footer'] );
323 - }
324 - }
325 -
326 - /**
327 - * Enqueues public scripts.
328 - *
329 - * @return void
330 - */
331 - public function enqueue_public_scripts() {
332 - /**
333 - * Register scripts.
334 - */
335 - $this->register_public_scripts();
336 -
337 - /**
338 - * Enqueue scripts.
339 - */
340 - if ( BuilderFns::is_builder_preview() && 'elementor' === Fns::page_edit_with( get_the_ID() ) ) {
341 - /**
342 - * Styles.
343 - */
344 - wp_enqueue_style( 'photoswipe' );
345 - wp_enqueue_style( 'photoswipe-default-skin' );
346 - wp_enqueue_style( 'elementor-editor-style-fix' );
347 - wp_enqueue_style( 'woocommerce-general' );
348 -
349 - /**
350 - * Scripts.
351 - */
352 - $handle = Fns::optimized_handle( 'rtsb-public' );
353 -
354 - wp_enqueue_script( 'wc-flexslider' );
355 - wp_enqueue_script( 'wc-single-product' );
356 - wp_dequeue_script( $handle );
357 - wp_enqueue_script( 'swiper' );
358 -
359 - if ( Fns::is_optimization_enabled() ) {
360 - Fns::enqueue_optimized_assets();
361 - } else {
362 - wp_enqueue_script( $handle );
363 - }
364 - }
365 -
366 - wp_enqueue_script( 'rtsb-tipsy' );
367 -
368 - if ( Fns::is_optimization_enabled() ) {
369 - Fns::enqueue_optimized_assets();
370 - } else {
371 - wp_enqueue_style( 'rtsb-fonts' );
372 - wp_enqueue_style( 'rtsb-frontend' );
373 - wp_enqueue_script( 'rtsb-public' );
374 - }
375 -
376 - /**
377 - * Localize script.
378 - */
379 - self::localizeData();
380 - }
381 -
382 - /**
383 - * Localized Data.
384 - *
385 - * @static
386 - * @return void
387 - */
388 - public static function localizeData() {
389 - $handle = Fns::optimized_handle( 'rtsb-public' );
390 - $ai_data = AIFns::activated_ai_data();
391 - wp_localize_script(
392 - $handle,
393 - 'rtsbPublicParams',
394 - [
395 - 'ajaxUrl' => esc_url( self::$ajaxurl ),
396 - 'aiActivated' => ! empty( $ai_data ),
397 - 'homeurl' => home_url(),
398 - 'shopUrl' => function_exists( 'wc_get_page_permalink' ) ? esc_url( wc_get_page_permalink( 'shop' ) ) : home_url( '/' ),
399 - 'wcCartUrl' => wc_get_cart_url(),
400 - 'addedToCartText' => esc_html__( 'Product Added', 'shopbuilder' ),
401 - 'singleCartToastrText' => esc_html__( 'Successfully Added', 'shopbuilder' ),
402 - 'singleCartBtnText' => apply_filters( 'rtsb/global/single_add_to_cart_success', esc_html__( 'Added to Cart', 'shopbuilder' ) ),
403 - 'browseCartText' => esc_html__( 'Browse Cart', 'shopbuilder' ),
404 - 'noProductsText' => apply_filters( 'rtsb/global/no_products_text', esc_html__( 'No more products to load', 'shopbuilder' ) ),
405 - 'isOptimizationEnabled' => Fns::is_optimization_enabled(),
406 - 'isLoaderEnabled' => Fns::enable_loader(),
407 - 'notice' => [
408 - 'position' => Fns::get_option( 'general', 'notification', 'notification_position', 'center-center' ),
409 - 'timeOut' => absint( Fns::get_option( 'general', 'notification', 'notification_timeOut', 5 ) ),
410 - ],
411 - rtsb()->nonceId => wp_create_nonce( rtsb()->nonceText ),
412 - ]
413 - );
414 - }
415 -
416 - /**
417 - * Registers Admin scripts.
418 - *
419 - * @return void
420 - */
421 - public function register_backend_assets() {
422 - /**
423 - * Styles.
424 - */
425 - wp_register_style( 'rtsb-admin-app', rtsb()->get_assets_uri( 'css/backend/admin-settings.css' ), '', $this->version );
426 - wp_register_style( 'rtsb-fonts', rtsb()->get_assets_uri( 'css/frontend/rtsb-fonts.css' ), '', $this->version );
427 -
428 - $current_screen = get_current_screen();
429 -
430 - if ( 'edit-rtsb_builder' === $current_screen->id ) {
431 - if ( ! function_exists( 'woocommerce_get_asset_url' ) ) {
432 - include_once WC_ABSPATH . 'includes/wc-template-functions.php';
433 - }
434 -
435 - wp_deregister_style( 'select2' );
436 - wp_register_style( 'select2', plugins_url( 'assets/css/select2.css', WC_PLUGIN_FILE ) ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
437 - }
438 - wp_register_style( 'rtsb-templatebuilder', rtsb()->get_assets_uri( 'css/backend/template-builder.css' ), '', $this->version );
439 -
440 - /**
441 - * Scripts.
442 - */
443 - wp_register_script( 'rtsb-admin-app', rtsb()->get_assets_uri( 'js/backend/admin-settings.js' ), '', $this->version, true );
444 - wp_register_script( 'rtsb-templatebuilder', rtsb()->get_assets_uri( 'js/backend/template-builder.js' ), '', $this->version, true );
445 - wp_localize_script(
446 - 'rtsb-admin-app',
447 - 'rtsbParams',
448 - [
449 - 'ajaxurl' => esc_url( self::$ajaxurl ),
450 - 'homeurl' => home_url(),
451 - 'adminLogo' => rtsb()->get_assets_uri( 'images/icon/ShopBuilder-Logo.svg' ),
452 - 'blackFriday' => rtsb()->get_assets_uri( 'images/black-friday-ribbon.svg' ),
453 - 'restApiUrl' => esc_url_raw( rest_url() ),
454 - 'rest_nonce' => wp_create_nonce( 'wp_rest' ),
455 - 'nonce' => wp_create_nonce( rtsb()->nonceText ),
456 - 'pages' => Fns::get_pages(),
457 - 'hasPro' => rtsb()->has_pro() ? 'yes' : 'no',
458 - 'validLicence' => Fns::has_valid_license() ? 'yes' : 'no',
459 - 'proVersion' => defined( 'RTSBPRO_VERSION' ) ? RTSBPRO_VERSION : '0',
460 - 'updateRates' => esc_html__( 'Update All Rates', 'shopbuilder' ),
461 - 'sections' => Settings::instance()->get_sections(),
462 - 'userRoles' => Fns::get_all_user_roles(),
463 - 'hasElementor' => defined( 'ELEMENTOR_VERSION' ),
464 - 'loadElementor' => Fns::should_load_elementor_scripts(),
465 - 'isOptimizationEnabled' => Fns::is_optimization_enabled(),
466 - ]
467 - );
468 - wp_localize_script(
469 - 'rtsb-admin-app',
470 - 'rtsbCaAbandonment',
471 - [
472 - 'mainTitle' => esc_html__( 'Abandoned Carts Follow Up', 'shopbuilder' ),
473 - 'followUpColumnTitle' => [
474 - 'UserName' => esc_html__( 'Name', 'shopbuilder' ),
475 - 'EmailTo' => esc_html__( 'Email To', 'shopbuilder' ),
476 - 'CartTotal' => esc_html__( 'Cart Total', 'shopbuilder' ),
477 - 'OrderStatus' => esc_html__( 'Order Status', 'shopbuilder' ),
478 - 'DateTime' => esc_html__( 'Date / Time', 'shopbuilder' ),
479 - 'Action' => esc_html__( 'Action', 'shopbuilder' ),
480 - ],
481 - ]
482 - );
483 - }
484 -
485 - /**
486 - * Enqueues admin scripts.
487 - *
488 - * @return void
489 - */
490 - public function enqueue_backend_scripts() {
491 - ob_start(); ?>
492 - #adminmenu .toplevel_page_rtsb .wp-menu-image img {
493 - width: auto;
494 - height: 22px;
495 - padding: 4px 0;
496 - box-sizing: content-box;
497 - }
498 - .post-type-rtsb_builder li#wp-admin-bar-WPML_ALS_all,
499 - .post-type-rtsb_builder li.language_all{
500 - display: none;
501 - }
502 -
503 - <?php
504 - $admin_global_style = ob_get_clean();
505 - // Speed Optimization.
506 - wp_add_inline_style( 'admin-menu', $admin_global_style );
507 -
508 - global $pagenow;
509 -
510 - $whitelisted_pages = [ 'rtsb-settings', 'rtsb-get-help', 'rtsb-themes' ];
511 - $current_page = ! empty( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
512 -
513 - if ( 'admin.php' === $pagenow && ! empty( $_GET['page'] ) && in_array( $current_page, $whitelisted_pages, true ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
514 - /**
515 - * Styles.
516 - */
517 - wp_enqueue_style( 'rtsb-admin-app' );
518 - wp_enqueue_style( 'rtsb-fonts' );
519 - }
520 -
521 - if ( 'admin.php' === $pagenow && ! empty( $_GET['page'] ) && 'rtsb-settings' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
522 - // Elementor Console Error Fixed For "rtsb-settings" Page.
523 - wp_dequeue_script( 'elementor-admin-top-bar' );
524 - wp_dequeue_script( 'elementor-common' );
525 - wp_dequeue_script( 'elementor-dev-tools' );
526 - wp_dequeue_script( 'elementor-web-cli' );
527 - wp_dequeue_script( 'elementor-import-export-admin' );
528 - wp_dequeue_script( 'elementor-app-loader' );
529 - wp_dequeue_script( 'elementor-admin-modules' );
530 - wp_dequeue_script( 'elementor-ai-media-library' );
531 - wp_dequeue_script( 'elementor-admin' );
532 -
533 - wp_dequeue_style( 'elementor-admin-top-bar' );
534 - wp_dequeue_style( 'elementor-admin' );
535 - wp_dequeue_style( 'e-theme-ui-light' );
536 - wp_dequeue_style( 'elementor-common' );
537 -
538 - /**
539 - * Scripts.
540 - */
541 - wp_enqueue_media();
542 - wp_enqueue_script( 'updates' );
543 - wp_enqueue_script( 'rtsb-admin-app' );
544 - } else {
545 - $current_screen = get_current_screen();
546 -
547 - if ( 'edit-rtsb_builder' === $current_screen->id ) {
548 - if ( ! function_exists( 'woocommerce_get_asset_url' ) ) {
549 - include_once WC_ABSPATH . 'includes/wc-template-functions.php';
550 - }
551 - /**
552 - * Styles.
553 - */
554 - wp_enqueue_style( 'rtsb-templatebuilder' );
555 -
556 - wp_enqueue_style( 'select2', plugins_url( 'assets/css/select2.css', WC_PLUGIN_FILE ) ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
557 -
558 - wp_enqueue_script( 'selectWoo' );
559 - /**
560 - * Scripts.
561 - */
562 - wp_enqueue_script( 'rtsb-templatebuilder' );
563 -
564 - wp_localize_script(
565 - 'rtsb-templatebuilder',
566 - 'rtsbParams',
567 - [
568 - 'ajaxurl' => esc_url( self::$ajaxurl ),
569 - 'homeurl' => home_url(),
570 - rtsb()->nonceId => wp_create_nonce( rtsb()->nonceText ),
571 - 'hasPro' => rtsb()->has_pro() ? 'yes' : 'no',
572 - 'singletonTypes' => apply_filters(
573 - 'rtsb/builder/singleton_types',
574 - array_keys( \RadiusTheme\SB\Helpers\BuilderFns::builder_page_types() )
575 - ),
576 - ]
577 - );
578 - }
579 - }
580 - }
581 -
582 - /**
583 - * Enqueues general public scripts.
584 - *
585 - * @return void
586 - */
587 - public function enqueue_general_public_scripts() {
588 - $notification_color = Fns::get_option( 'general', 'notification', 'notification_color', '#004BFF' );
589 - $notification_bgcolor = Fns::get_option( 'general', 'notification', 'notification_bg', '#F5F8FF' );
590 - $notification_button_color = Fns::get_option( 'general', 'notification', 'notification_btn_color', '#0039C0' );
591 -
592 - $dynamic_css = '';
593 -
594 - if ( ! empty( $notification_color ) ) {
595 - $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-success{color:{$notification_color}}";
596 - $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-success:before{background-color:{$notification_color}}";
597 - $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-close-button{color:{$notification_color}}";
598 - }
599 -
600 - if ( ! empty( $notification_bgcolor ) ) {
601 - $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-success{background-color:{$notification_bgcolor}}";
602 - }
603 -
604 - if ( ! empty( $notification_button_color ) ) {
605 - $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-success a{color:{$notification_button_color}}";
606 - }
607 -
608 - if ( ! empty( $dynamic_css ) ) {
609 - wp_add_inline_style( Fns::optimized_handle( 'rtsb-frontend' ), $dynamic_css );
610 - }
611 - }
612 -
613 - /**
614 - * Get the appropriate Swiper JS file URL.
615 - *
616 - * @return string
617 - */
618 - private function get_swiper_url() {
619 - $default_swiper_url = rtsb()->get_assets_uri( 'vendor/swiper/js/swiper-bundle.min.js' );
620 -
621 - if ( defined( 'ELEMENTOR_ASSETS_PATH' ) && defined( 'ELEMENTOR_ASSETS_URL' ) ) {
622 - $experiment = get_option( 'elementor_experiment-e_swiper_latest' );
623 -
624 - $el_relative_path = ( 'active' === $experiment || 'default' === $experiment )
625 - ? 'lib/swiper/v8/swiper.min.js'
626 - : 'lib/swiper/swiper.min.js';
627 -
628 - $el_full_path = ELEMENTOR_ASSETS_PATH . $el_relative_path;
629 -
630 - if ( file_exists( $el_full_path ) ) {
631 - return ELEMENTOR_ASSETS_URL . $el_relative_path;
632 - }
633 - }
634 -
635 - return $default_swiper_url;
636 - }
637 -}
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 $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 + if ( in_array( 'sitepress-multilingual-cms/sitepress.php', get_option( 'active_plugins' ) ) ) {
53 + $this->ajaxurl = admin_url( 'admin-ajax.php?lang=' . ICL_LANGUAGE_CODE );
54 + } else {
55 + $this->ajaxurl = admin_url( 'admin-ajax.php' );
56 + }
57 +
58 + /**
59 + * Admin scripts.
60 + */
61 + add_action( 'admin_enqueue_scripts', [ $this, 'register_backend_assets' ], 1 );
62 + add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_backend_scripts' ] );
63 +
64 + /**
65 + * Public scripts.
66 + */
67 + add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_public_scripts' ], 15 );
68 + }
69 +
70 + /**
71 + * Get all frontend scripts.
72 + *
73 + * @return void
74 + */
75 + private function get_public_assets() {
76 + $this->get_public_styles()->get_public_scripts();
77 + }
78 +
79 + /**
80 + * Get public styles.
81 + *
82 + * @return object
83 + */
84 + private function get_public_styles() {
85 + $this->styles[] = [
86 + 'handle' => 'rtsb-fonts',
87 + 'src' => rtsb()->get_assets_uri( 'fonts/rtsbfont.css' ),
88 + ];
89 +
90 + $this->styles[] = [
91 + 'handle' => 'rtsb-frontend',
92 + 'src' => rtsb()->get_assets_uri( 'css/frontend/frontend.css' ),
93 + ];
94 +
95 + $this->styles[] = [
96 + 'handle' => 'swiper',
97 + 'src' => rtsb()->get_assets_uri( 'vendor/swiper/css/swiper-bundle.min.css' ),
98 + ];
99 +
100 + if ( BuilderFns::is_builder_preview() && 'elementor' == Fns::page_edit_with( get_the_ID() ) ) {
101 + $this->styles[] = [
102 + 'handle' => 'photoswipe',
103 + 'src' => plugins_url( 'assets/css/photoswipe/photoswipe.min.css', WC_PLUGIN_FILE ),
104 + ];
105 +
106 + $this->styles[] = [
107 + 'handle' => 'photoswipe-default-skin',
108 + 'src' => plugins_url( 'assets/css/photoswipe/default-skin/default-skin.min.css', WC_PLUGIN_FILE ),
109 + ];
110 +
111 + // Load only for elementor editor page and fix some issue.
112 + $this->styles[] = [
113 + 'handle' => 'elementor-editor-style-fix',
114 + 'src' => rtsb()->get_assets_uri( 'css/backend/elementor-editor-style-fix.css' ),
115 + ];
116 + }
117 +
118 + return $this;
119 + }
120 +
121 + /**
122 + * Get public scripts.
123 + *
124 + * @return object
125 + */
126 + private function get_public_scripts() {
127 + $this->scripts[] = [
128 + 'handle' => 'swiper',
129 + 'src' => rtsb()->get_assets_uri( 'vendor/swiper/js/swiper-bundle.min.js' ),
130 + 'deps' => [ 'jquery' ],
131 + 'footer' => true,
132 + ];
133 +
134 + $this->scripts[] = [
135 + 'handle' => 'rtsb-imagesloaded',
136 + 'src' => rtsb()->get_assets_uri( 'vendor/isotope/imagesloaded.pkgd.min.js' ),
137 + 'deps' => [ 'jquery' ],
138 + 'footer' => true,
139 + ];
140 +
141 + $this->scripts[] = [
142 + 'handle' => 'rtsb-tipsy',
143 + 'src' => rtsb()->get_assets_uri( 'vendor/tipsy/tipsy.min.js' ),
144 + 'deps' => [ 'jquery' ],
145 + 'footer' => true,
146 + ];
147 +
148 + if ( BuilderFns::is_builder_preview() && 'elementor' == Fns::page_edit_with( get_the_ID() ) ) {
149 +
150 + $this->scripts[] = [
151 + 'handle' => 'flexslider',
152 + 'src' => plugins_url( 'assets/js/flexslider/jquery.flexslider.js', WC_PLUGIN_FILE ),
153 + 'deps' => [ 'jquery' ],
154 + 'footer' => true,
155 + ];
156 +
157 + $this->scripts[] = [
158 + 'handle' => 'photoswipe',
159 + 'src' => plugins_url( 'assets/js/photoswipe/photoswipe.js', WC_PLUGIN_FILE ),
160 + 'deps' => [ 'jquery' ],
161 + 'footer' => true,
162 + ];
163 +
164 + $this->scripts[] = [
165 + 'handle' => 'zoom',
166 + 'src' => plugins_url( 'assets/js/zoom/jquery.zoom.js', WC_PLUGIN_FILE ),
167 + 'deps' => [ 'jquery' ],
168 + 'footer' => true,
169 + ];
170 +
171 + $this->scripts[] = [
172 + 'handle' => 'photoswipe-ui-default',
173 + 'src' => plugins_url( 'assets/js/photoswipe/photoswipe-ui-default.js', WC_PLUGIN_FILE ),
174 + 'deps' => [ 'jquery', 'photoswipe' ],
175 + 'footer' => true,
176 + ];
177 +
178 + $this->scripts[] = [
179 + 'handle' => 'wc-single-product',
180 + 'src' => plugins_url( 'assets/js/frontend/single-product.js', WC_PLUGIN_FILE ),
181 + 'deps' => [ 'jquery', 'flexslider', 'photoswipe', 'photoswipe-ui-default', 'zoom' ],
182 + 'footer' => true,
183 + ];
184 +
185 + }
186 +
187 + $this->scripts[] = [
188 + 'handle' => 'rtsb-public',
189 + 'src' => rtsb()->get_assets_uri( 'js/frontend/frontend.js' ),
190 + 'deps' => [ 'jquery', 'rtsb-imagesloaded', 'swiper' ],
191 + 'footer' => true,
192 + ];
193 +
194 + return $this;
195 + }
196 +
197 + /**
198 + * Register public scripts.
199 + *
200 + * @return void
201 + */
202 + public function register_public_scripts() {
203 + $this->get_public_assets();
204 +
205 + // Register public styles.
206 + foreach ( $this->styles as $style ) {
207 + wp_register_style( $style['handle'], $style['src'], '', $this->version );
208 + }
209 +
210 + // Register public scripts.
211 + foreach ( $this->scripts as $script ) {
212 + wp_register_script( $script['handle'], $script['src'], $script['deps'], $this->version, $script['footer'] );
213 + }
214 + }
215 +
216 + /**
217 + * Enqueues public scripts.
218 + *
219 + * @return void
220 + */
221 + public function enqueue_public_scripts() {
222 + /**
223 + * Register scripts.
224 + */
225 + $this->register_public_scripts();
226 + /**
227 + * Enqueue scripts.
228 + */
229 + if ( BuilderFns::is_builder_preview() && 'elementor' === Fns::page_edit_with( get_the_ID() ) ) {
230 + /**
231 + * Styles.
232 + */
233 + wp_enqueue_style( 'swiper' );
234 + wp_enqueue_style( 'photoswipe' );
235 + wp_enqueue_style( 'photoswipe-default-skin' );
236 + wp_enqueue_style( 'elementor-editor-style-fix' );
237 + // TODO: Need to remove 'woocommerce-general' if conflict arises.
238 + wp_enqueue_style( 'woocommerce-general' );
239 +
240 + /**
241 + * Scripts.
242 + */
243 + wp_enqueue_script( 'flexslider' );
244 + wp_enqueue_script( 'wc-single-product' );
245 + wp_dequeue_script( 'rtsb-public' );
246 + wp_enqueue_script( 'swiper' );
247 + wp_enqueue_script( 'rtsb-public' );
248 + }
249 +
250 + /**
251 + * Styles.
252 + */
253 + wp_enqueue_style( 'rtsb-fonts' );
254 + wp_enqueue_style( 'rtsb-frontend' );
255 +
256 + /**
257 + * Scripts.
258 + */
259 + wp_enqueue_script( 'rtsb-imagesloaded' );
260 + wp_enqueue_script( 'rtsb-tipsy' );
261 + wp_enqueue_script( 'rtsb-public' );
262 +
263 + wp_localize_script(
264 + 'rtsb-public',
265 + 'rtsbPublicParams',
266 + [
267 + 'ajaxUrl' => esc_url( $this->ajaxurl ),
268 + 'homeurl' => home_url(),
269 + 'wcCartUrl' => wc_get_cart_url(),
270 + 'addedToCartText' => esc_html__( 'Product Added', 'shopbuilder' ),
271 + 'browseCartText' => esc_html__( 'Browse Cart', 'shopbuilder' ),
272 + rtsb()->nonceId => wp_create_nonce( rtsb()->nonceText ),
273 + ]
274 + );
275 + }
276 +
277 + /**
278 + * Registers Admin scripts.
279 + *
280 + * @return void
281 + */
282 + public function register_backend_assets() {
283 + /**
284 + * Styles.
285 + */
286 + wp_register_style( 'rtsb-admin-app', rtsb()->get_assets_uri( 'css/backend/admin-settings.css' ), '', $this->version );
287 + wp_register_style( 'rtsb-admin-global', rtsb()->get_assets_uri( 'css/backend/admin-global.css' ), '', $this->version );
288 + wp_register_style( 'rtsb-templatebuilder', rtsb()->get_assets_uri( 'css/backend/template-builder.css' ), '', $this->version );
289 +
290 + /**
291 + * Scripts.
292 + */
293 + wp_register_script( 'rtsb-admin-app', rtsb()->get_assets_uri( 'js/backend/admin-settings.js' ), '', $this->version, true );
294 + wp_register_script( 'rtsb-templatebuilder', rtsb()->get_assets_uri( 'js/backend/template-builder.js' ), '', $this->version, true );
295 +
296 + }
297 +
298 + /**
299 + * Enqueues admin scripts.
300 + *
301 + * @param string $hook Hooks.
302 + *
303 + * @return void
304 + */
305 + public function enqueue_backend_scripts( $hook ) {
306 +
307 + wp_enqueue_style( 'rtsb-admin-global' );
308 +
309 + global $pagenow;
310 +
311 + if ( 'admin.php' === $pagenow && 'rtsb-settings' === $_GET['page'] ) {
312 +
313 + /**
314 + * Styles.
315 + */
316 + wp_enqueue_style( 'rtsb-admin-app' );
317 +// add_thickbox();
318 +// wp_enqueue_script( 'plugin-install' );
319 + wp_enqueue_script( 'updates' );
320 +
321 + /**
322 + * Scripts.
323 + */
324 + wp_enqueue_script( 'rtsb-admin-app' );
325 + wp_localize_script(
326 + 'rtsb-admin-app',
327 + 'rtsbParams',
328 + [
329 + 'ajaxurl' => esc_url( $this->ajaxurl ),
330 + 'homeurl' => home_url(),
331 + 'nonce' => wp_create_nonce( rtsb()->nonceText ),
332 + 'sections' => Settings::instance()->get_sections(),
333 + 'pages' => Fns::get_pages(),
334 + ]
335 + );
336 + } else {
337 + $current_screen = get_current_screen();
338 +
339 + if ( 'edit-rtsb_builder' === $current_screen->id ) {
340 + if ( ! function_exists( 'woocommerce_get_asset_url' ) ) {
341 + include_once WC_ABSPATH . 'includes/wc-template-functions.php';
342 + }
343 + /**
344 + * Styles.
345 + */
346 + wp_enqueue_style( 'rtsb-templatebuilder' );
347 +
348 + wp_enqueue_style( 'select2', plugins_url( 'assets/css/select2.css', WC_PLUGIN_FILE ) );
349 +
350 + wp_enqueue_script( 'selectWoo' );
351 + /**
352 + * Scripts.
353 + */
354 + wp_enqueue_script( 'rtsb-templatebuilder' );
355 +
356 +
357 + wp_localize_script(
358 + 'rtsb-templatebuilder',
359 + 'rtsbParams',
360 + [
361 + 'ajaxurl' => esc_url( $this->ajaxurl ),
362 + 'homeurl' => home_url(),
363 + rtsb()->nonceId => wp_create_nonce( rtsb()->nonceText ),
364 + ]
365 + );
366 + }
367 + }
368 + }
369 +}