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

488 lines 13.3 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-admin-global', rtsb()->get_assets_uri( 'css/backend/admin-global.css' ), '', $this->version );
353 wp_register_style( 'rtsb-templatebuilder', rtsb()->get_assets_uri( 'css/backend/template-builder.css' ), '', $this->version );
354
355 /**
356 * Scripts.
357 */
358 wp_register_script( 'rtsb-admin-app', rtsb()->get_assets_uri( 'js/backend/admin-settings.js' ), '', $this->version, true );
359 wp_register_script( 'rtsb-templatebuilder', rtsb()->get_assets_uri( 'js/backend/template-builder.js' ), '', $this->version, true );
360 }
361
362 /**
363 * Enqueues admin scripts.
364 *
365 * @param string $hook Hooks.
366 *
367 * @return void
368 */
369 public function enqueue_backend_scripts( $hook ) {
370 ob_start(); ?>
371 #adminmenu .toplevel_page_rtsb .wp-menu-image img {
372 width: auto;
373 height: 22px;
374 padding: 4px 0;
375 }
376 <?php
377 $admin_global_style = ob_get_clean();
378 // Speed Optimization.
379 wp_add_inline_style( 'admin-menu', $admin_global_style );
380 // wp_enqueue_style( 'rtsb-admin-global' );
381
382 global $pagenow;
383
384 if ( 'admin.php' === $pagenow && ! empty( $_GET['page'] ) && 'rtsb-settings' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
385 // Elementor Console Error Fixed For "rtsb-settings" Page.
386 wp_dequeue_script( 'elementor-admin-top-bar' );
387 wp_dequeue_script( 'elementor-common' );
388 wp_dequeue_script( 'elementor-dev-tools' );
389 wp_dequeue_script( 'elementor-web-cli' );
390 wp_dequeue_script( 'elementor-import-export-admin' );
391 wp_dequeue_script( 'elementor-app-loader' );
392 wp_dequeue_script( 'elementor-admin-modules' );
393 wp_dequeue_script( 'elementor-admin' );
394
395 wp_dequeue_style( 'elementor-admin-top-bar' );
396 wp_dequeue_style( 'elementor-admin' );
397 wp_dequeue_style( 'e-theme-ui-light' );
398 wp_dequeue_style( 'elementor-common' );
399
400 /**
401 * Styles.
402 */
403 wp_enqueue_style( 'rtsb-admin-app' );
404
405 /**
406 * Scripts.
407 */
408 wp_enqueue_script( 'updates' );
409 wp_enqueue_script( 'rtsb-admin-app' );
410 wp_localize_script(
411 'rtsb-admin-app',
412 'rtsbParams',
413 [
414 'ajaxurl' => esc_url( self::$ajaxurl ),
415 'homeurl' => home_url(),
416 'restApiUrl' => esc_url_raw( rest_url() ),
417 'rest_nonce' => wp_create_nonce( 'wp_rest' ),
418 'nonce' => wp_create_nonce( rtsb()->nonceText ),
419 'sections' => Settings::instance()->get_sections(),
420 'pages' => Fns::get_pages(),
421 'hasPro' => rtsb()->has_pro() ? 'yes' : 'no',
422 ]
423 );
424 } else {
425 $current_screen = get_current_screen();
426
427 if ( 'edit-rtsb_builder' === $current_screen->id ) {
428 if ( ! function_exists( 'woocommerce_get_asset_url' ) ) {
429 include_once WC_ABSPATH . 'includes/wc-template-functions.php';
430 }
431 /**
432 * Styles.
433 */
434 wp_enqueue_style( 'rtsb-templatebuilder' );
435
436 wp_enqueue_style( 'select2', plugins_url( 'assets/css/select2.css', WC_PLUGIN_FILE ) ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
437
438 wp_enqueue_script( 'selectWoo' );
439 /**
440 * Scripts.
441 */
442 wp_enqueue_script( 'rtsb-templatebuilder' );
443
444 wp_localize_script(
445 'rtsb-templatebuilder',
446 'rtsbParams',
447 [
448 'ajaxurl' => esc_url( self::$ajaxurl ),
449 'homeurl' => home_url(),
450 rtsb()->nonceId => wp_create_nonce( rtsb()->nonceText ),
451 'hasPro' => rtsb()->has_pro() ? 'yes' : 'no',
452 ]
453 );
454 }
455 }
456 }
457
458 /**
459 * Enqueues general public scripts.
460 *
461 * @return void
462 */
463 public function enqueue_general_public_scripts() {
464 $notification_color = Fns::get_option( 'general', 'notification', 'notification_color', '#004BFF' );
465 $notification_bgcolor = Fns::get_option( 'general', 'notification', 'notification_bg', '#F5F8FF' );
466 $notification_button_color = Fns::get_option( 'general', 'notification', 'notification_btn_color', '#0039C0' );
467
468 $dynamic_css = '';
469
470 if ( ! empty( $notification_color ) ) {
471 $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-success{color:{$notification_color}}";
472 $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-success:before{background-color:{$notification_color}}";
473 }
474
475 if ( ! empty( $notification_bgcolor ) ) {
476 $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-success{background-color:{$notification_bgcolor}}";
477 }
478
479 if ( ! empty( $notification_button_color ) ) {
480 $dynamic_css .= ".rtsb-shopbuilder-plugin #toast-container .toast-success a{color:{$notification_button_color}}";
481 }
482
483 if ( ! empty( $dynamic_css ) ) {
484 wp_add_inline_style( 'rtsb-frontend', $dynamic_css );
485 }
486 }
487 }
488