PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.2.0
ShopBuilder – WooCommerce Builder For Elementor v2.2.0
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 2.3.0 All 62 releases
shopbuilder / app / Controllers / AssetsController.php

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

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