PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.3.3
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.3.3
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / includes / class-scripts-styles.php

class-scripts-styles.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.3.3, at includes/class-scripts-styles.php

495 lines 16.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The scripts class
5 *
6 * @since 1.1.0
7 */
8 class WeForms_Scripts_Styles {
9
10 /**
11 * The constructor
12 */
13 function __construct() {
14
15 if ( is_admin() ) {
16 add_action( 'admin_enqueue_scripts', array( $this, 'register_backend' ), 1800 );
17 add_action( 'admin_enqueue_scripts', array( $this, 'no_conflict_mode' ), 1500 );
18 } else {
19 add_action( 'wp_enqueue_scripts', array( $this, 'register_frontend' ) );
20 }
21 }
22
23 /**
24 * Helper function for No-Conflict Mode
25 *
26 * @return void
27 */
28 public function no_conflict_mode() {
29 global $wp_scripts;
30
31 $reg_arr = array();
32 $required_objects = array (
33 'utils',
34 'common',
35 'wp-ajax-response',
36 'wp-api-request',
37 'wp-pointer',
38 'wp-auth-check',
39 'wp-lists',
40 'prototype',
41 'jquery',
42 'jquery-core',
43 'jquery-migrate',
44 'jquery-ui-core',
45 'jquery-effects-core',
46 'jquery-effects-blind',
47 'jquery-effects-bounce',
48 'jquery-effects-clip',
49 'jquery-effects-drop',
50 'jquery-effects-explode',
51 'jquery-effects-fade',
52 'jquery-effects-fold',
53 'jquery-effects-highlight',
54 'jquery-effects-puff',
55 'jquery-effects-pulsate',
56 'jquery-effects-scale',
57 'jquery-effects-shake',
58 'jquery-effects-size',
59 'jquery-effects-slide',
60 'jquery-effects-transfer',
61 'jquery-ui-accordion',
62 'jquery-ui-autocomplete',
63 'jquery-ui-button',
64 'jquery-ui-datepicker',
65 'jquery-ui-dialog',
66 'jquery-ui-draggable',
67 'jquery-ui-droppable',
68 'jquery-ui-menu',
69 'jquery-ui-mouse',
70 'jquery-ui-position',
71 'jquery-ui-progressbar',
72 'jquery-ui-resizable',
73 'jquery-ui-selectable',
74 'jquery-ui-selectmenu',
75 'jquery-ui-slider',
76 'jquery-ui-sortable',
77 'jquery-ui-spinner',
78 'jquery-ui-tabs',
79 'jquery-ui-tooltip',
80 'jquery-ui-widget',
81 'jquery-form',
82 'jquery-color',
83 'schedule',
84 'jquery-query',
85 'jquery-serialize-object',
86 'jquery-hotkeys',
87 'jquery-table-hotkeys',
88 'jquery-touch-punch',
89 'thickbox',
90 'json2',
91 'underscore',
92 'backbone',
93 'wp-util',
94 'wp-sanitize',
95 'wp-backbone',
96 'wp-embed',
97 'wp-api',
98 'postbox',
99 'post',
100 'link',
101 'inline-edit-post',
102 'inline-edit-tax',
103 'iris',
104 'wp-color-picker',
105 'dashboard',
106 'weforms-chart-js',
107 'weforms-tiny-mce',
108 'weforms-vendor',
109 'weforms-form-builder-mixins',
110 'weforms-form-builder-mixins-form',
111 'weforms-form-builder-components',
112 'weforms-int-payment-settings',
113 'weforms-int-mailpoet',
114 'weforms-int-aweber',
115 'weforms-int-campaign-monitor',
116 'weforms-int-constant-contact',
117 'weforms-int-convertkit',
118 'weforms-int-getresponse',
119 'weforms-int-google-analytics',
120 'weforms-int-google-sheets',
121 'weforms-int-hubspot',
122 'weforms-int-mailchimp',
123 'weforms-int-salesforce',
124 'weforms-int-trello',
125 'weforms-int-zapier',
126 'weforms-int-zoho',
127 'weforms-mixins',
128 'weforms-components',
129 'weforms-app',
130 'weforms-pro-wpuf-form-mixins',
131 'weforms-pro-wpuf-form-components',
132 'weforms-pro-components',
133 );
134
135 $wpuf_settings = weforms_get_settings();
136 $screen = get_current_screen();
137
138 if ( isset( $wpuf_settings['no_conflict'] ) && $wpuf_settings['no_conflict'] && $screen->base == 'toplevel_page_weforms' ) {
139 $registered_scripts = array_keys( $wp_scripts->registered );
140
141 foreach ( $registered_scripts as $r_script ) {
142 if ( !in_array( $r_script, $required_objects ) ) {
143 $reg_arr[] = $r_script;
144 wp_deregister_script( $r_script );
145 }
146 }
147
148 // $this->enqueue_scripts( $this->get_admin_scripts() );
149
150 // foreach ( $reg_arr as $reg_obj ) {
151 // if ( !in_array( $reg_obj, $wp_scripts->queue ) ) {
152 // wp_enqueue_script( $reg_obj );
153 // }
154 // }
155 }
156
157 }
158
159 /**
160 * Register frontend scripts and styles
161 *
162 * @return void
163 */
164 public function register_frontend() {
165 $this->register_styles( $this->get_frontend_styles() );
166 $this->register_scripts( $this->get_frontend_scripts() );
167
168 $this->get_frontend_localized();
169 }
170
171 /**
172 * Register frontend scripts and styles
173 *
174 * @return void
175 */
176 public function register_backend() {
177 // bail out if not weforms screen
178 $screen = get_current_screen();
179 if ( $screen->base != 'toplevel_page_weforms' ) {
180 return;
181 }
182
183 $this->register_styles( $this->get_admin_styles() );
184 $this->register_scripts( $this->get_admin_scripts() );
185
186 $this->get_frontend_localized();
187 }
188
189 /**
190 * Enqueue all the scripts and styles for frontend
191 *
192 * @return void
193 */
194 public function enqueue_frontend() {
195 $this->enqueue_scripts( $this->get_frontend_scripts() );
196 $this->enqueue_styles( $this->get_frontend_styles() );
197 }
198
199 /**
200 * Enqueue all the scripts and styles for backend
201 *
202 * @return void
203 */
204 public function enqueue_backend() {
205 $this->enqueue_scripts( $this->get_admin_scripts() );
206 $this->enqueue_styles( $this->get_admin_styles() );
207 }
208
209 /**
210 * Get file prefix
211 *
212 * @return string
213 */
214 public function get_prefix() {
215 $prefix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
216
217 return $prefix;
218 }
219
220 /**
221 * Get all registered admin scripts
222 *
223 * @return array
224 */
225 public function get_admin_scripts() {
226 $prefix = $this->get_prefix();
227
228 $form_builder_js_deps = apply_filters( 'weforms-form-builder-js-deps', array(
229 'jquery',
230 'jquery-ui-sortable',
231 'jquery-ui-draggable',
232 'jquery-ui-datepicker',
233 'weforms-tiny-mce',
234 'underscore',
235 ) );
236
237 $builder_scripts = apply_filters( 'weforms_builder_scripts', array(
238 'weforms-tiny-mce' => array(
239 'src' => site_url( '/wp-includes/js/tinymce/tinymce.min.js' ),
240 'deps' => array(),
241 'in_footer' => true
242 ),
243 'weforms-vendor' => array(
244 'src' => WEFORMS_ASSET_URI . '/js/vendor' . $prefix . '.js',
245 'deps' => $form_builder_js_deps,
246 'in_footer' => true
247 ),
248 'weforms-form-builder-mixins' => array(
249 'src' => WEFORMS_ASSET_URI . '/wpuf/js/wpuf-form-builder-mixins.js',
250 'deps' => array('weforms-vendor'),
251 'in_footer' => true
252 ),
253 'weforms-form-builder-mixins-form' => array(
254 'src' => WEFORMS_ASSET_URI . '/js/wpuf-form-builder-contact-forms' . $prefix . '.js',
255 'deps' => array('weforms-vendor'),
256 'in_footer' => true
257 ),
258 'weforms-form-builder-components' => array(
259 'src' => WEFORMS_ASSET_URI . '/wpuf/js/wpuf-form-builder-components' . $prefix . '.js',
260 'deps' => array( 'weforms-form-builder-mixins', 'weforms-form-builder-mixins-form' ),
261 'in_footer' => true
262 ),
263 ) );
264
265 $spa_scripts = array(
266 'weforms-mixins' => array(
267 'src' => WEFORMS_ASSET_URI . '/js/spa-mixins' . $prefix . '.js',
268 'deps' => array( 'weforms-vendor', 'wp-util' ),
269 'in_footer' => true
270 ),
271 'weforms-components' => array(
272 'src' => WEFORMS_ASSET_URI . '/js/form-builder-components' . $prefix . '.js',
273 'deps' => array( 'weforms-vendor', 'wp-util' ),
274 'in_footer' => true
275 ),
276 'weforms-app' => array(
277 'src' => WEFORMS_ASSET_URI . '/js/spa-app' . $prefix . '.js',
278 'deps' => array( 'weforms-vendor', 'wp-util', 'weforms-form-builder-components' ),
279 'in_footer' => true
280 ),
281 );
282
283 $scripts = array_merge( $builder_scripts, $spa_scripts );
284
285 return apply_filters( 'weforms_admin_scripts', $scripts );
286 }
287
288 /**
289 * Get admin styles
290 *
291 * @return array
292 */
293 public function get_admin_styles() {
294 $frontend_styles = $this->get_frontend_styles();
295
296 $backend_styles = array(
297 'weforms-font-awesome' => array(
298 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/font-awesome/css/font-awesome.min.css',
299 ),
300 'weforms-sweetalert2' => array(
301 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/sweetalert2/dist/sweetalert2.css',
302 ),
303 'weforms-selectize' => array(
304 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/selectize/css/selectize.default.css',
305 ),
306 'weforms-toastr' => array(
307 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/toastr/toastr.min.css',
308 ),
309 'weforms-tooltip' => array(
310 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/tooltip/tooltip.css',
311 ),
312 'weforms-form-builder' => array(
313 'src' => WEFORMS_ASSET_URI . '/wpuf/css/wpuf-form-builder.css',
314 'deps' => array(
315 'weforms-css',
316 'weforms-font-awesome',
317 'weforms-sweetalert2',
318 'weforms-selectize',
319 'weforms-toastr',
320 'weforms-tooltip'
321 )
322 ),
323 'weforms-style' => array(
324 'src' => WEFORMS_ASSET_URI . '/css/admin.css',
325 ),
326 'weforms-tiny-mce-css' => array(
327 'src' => site_url( '/wp-includes/css/editor.css' ),
328 'deps' => array( 'wp-color-picker' )
329 )
330
331 );
332
333 $styles = array_merge( $frontend_styles, $backend_styles );
334
335 return apply_filters( 'weforms_admin_styles', $styles );
336 }
337
338 /**
339 * Get all registered frontend scripts
340 *
341 * @return array
342 */
343 public function get_frontend_scripts() {
344
345 $prefix = $this->get_prefix();
346
347 $scripts = array(
348 'wpuf-form' => array(
349 'src' => WEFORMS_ASSET_URI . '/wpuf/js/frontend-form' . $prefix . '.js',
350 'deps' => array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-slider' ),
351 'in_footer' => false
352 ),
353 'wpuf-sweetalert2' => array(
354 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/sweetalert2/dist/sweetalert2' . $prefix . '.js',
355 'in_footer' => false
356 ),
357 'jquery-ui-timepicker' => array(
358 'src' => WEFORMS_ASSET_URI . '/wpuf/js/jquery-ui-timepicker-addon' . $prefix . '.js',
359 'deps' => array( 'jquery-ui-datepicker' ),
360 'in_footer' => false
361 ),
362 'wpuf-upload' => array(
363 'src' => WEFORMS_ASSET_URI . '/wpuf/js/upload' . $prefix . '.js',
364 'deps' => array( 'jquery', 'plupload-handlers', 'jquery-ui-sortable' ),
365 'in_footer' => false
366 )
367 );
368
369 return apply_filters( 'weforms_frontend_scripts', $scripts );
370 }
371
372 /**
373 * Get all registered frontend styles
374 *
375 * @return array
376 */
377 public function get_frontend_styles() {
378 $styles = array(
379 'weforms-css' => array(
380 'src' => WEFORMS_ASSET_URI . '/wpuf/css/frontend-forms.css',
381 ),
382 'wpuf-sweetalert2' => array(
383 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/sweetalert2/dist/sweetalert2.css',
384 ),
385 'jquery-ui' => array(
386 'src' => WEFORMS_ASSET_URI . '/wpuf/css/jquery-ui-1.9.1.custom.css',
387 )
388 );
389
390 return apply_filters( 'weforms_frontend_styles', $styles );
391 }
392
393 /**
394 * Frontend localized scripts
395 *
396 * @return void
397 */
398 public function get_frontend_localized() {
399
400 wp_localize_script( 'wpuf-form', 'wpuf_frontend', apply_filters( 'wpuf_frontend_js_data' , array(
401 'ajaxurl' => admin_url( 'admin-ajax.php' ),
402 'error_message' => __( 'Please fix the errors to proceed', 'weforms' ),
403 'nonce' => wp_create_nonce( 'wpuf_nonce' ),
404 'word_limit' => __( 'Word limit reached', 'weforms' )
405 ) ) );
406
407 wp_localize_script( 'wpuf-form', 'error_str_obj', array(
408 'required' => __( 'is required', 'weforms' ),
409 'mismatch' => __( 'does not match', 'weforms' ),
410 'validation' => __( 'is not valid', 'weforms' ),
411 'duplicate' => __( 'requires a unique entry and this value has already been used', 'weforms' ),
412 ) );
413
414 wp_localize_script( 'wpuf-upload', 'wpuf_frontend_upload', array(
415 'confirmMsg' => __( 'Are you sure?', 'weforms' ),
416 'delete_it' => __( 'Yes, delete it', 'weforms' ),
417 'cancel_it' => __( 'No, cancel it', 'weforms' ),
418 'nonce' => wp_create_nonce( 'wpuf_nonce' ),
419 'ajaxurl' => admin_url( 'admin-ajax.php' ),
420 'plupload' => array(
421 'url' => admin_url( 'admin-ajax.php' ) . '?nonce=' . wp_create_nonce( 'wpuf-upload-nonce' ),
422 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
423 'filters' => array(
424 array(
425 'title' => __( 'Allowed Files', 'weforms' ),
426 'extensions' => '*'
427 )
428 ),
429 'multipart' => true,
430 'urlstream_upload' => true,
431 'warning' => __( 'Maximum number of files reached!', 'weforms' ),
432 'size_error' => __( 'The file you have uploaded exceeds the file size limit. Please try again.', 'weforms' ),
433 'type_error' => __( 'You have uploaded an incorrect file type. Please try again.', 'weforms' )
434 )
435 ) );
436 }
437
438 /**
439 * Register scripts
440 *
441 * @param array $scripts
442 *
443 * @return void
444 */
445 public function register_scripts( $scripts ) {
446 foreach ( $scripts as $handle => $script ) {
447 $deps = isset( $script['deps'] ) ? $script['deps'] : false;
448 $in_footer = isset( $script['in_footer'] ) ? $script['in_footer'] : false;
449
450 wp_register_script( $handle, $script['src'], $deps, WEFORMS_VERSION, $in_footer );
451 }
452 }
453
454 /**
455 * Register styles
456 *
457 * @param array $styles
458 *
459 * @return void
460 */
461 public function register_styles( $styles ) {
462 foreach ( $styles as $handle => $style ) {
463 $deps = isset( $style['deps'] ) ? $style['deps'] : false;
464
465 wp_register_style( $handle, $style['src'], $deps, WEFORMS_VERSION );
466 }
467 }
468
469 /**
470 * Enqueue the scripts
471 *
472 * @param array $scripts
473 *
474 * @return void
475 */
476 public function enqueue_scripts( $scripts ) {
477 foreach ( $scripts as $handle => $script ) {
478 wp_enqueue_script( $handle );
479 }
480 }
481
482 /**
483 * Enqueue styles
484 *
485 * @param array $styles
486 *
487 * @return void
488 */
489 public function enqueue_styles( $styles ) {
490 foreach ( $styles as $handle => $script ) {
491 wp_enqueue_style( $handle );
492 }
493 }
494 }
495