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

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