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

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