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

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