PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.2.3
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.2.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.2.3, at includes/class-scripts-styles.php

406 lines 12.5 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' ) );
17 } else {
18 add_action( 'wp_enqueue_scripts', array( $this, 'register_frontend' ) );
19 }
20 }
21
22 /**
23 * Register frontend scripts and styles
24 *
25 * @return void
26 */
27 public function register_frontend() {
28 $this->register_styles( $this->get_frontend_styles() );
29 $this->register_scripts( $this->get_frontend_scripts() );
30
31 $this->get_frontend_localized();
32 }
33
34 /**
35 * Register frontend scripts and styles
36 *
37 * @return void
38 */
39 public function register_backend() {
40 $this->register_styles( $this->get_admin_styles() );
41 $this->register_scripts( $this->get_admin_scripts() );
42
43 $this->get_frontend_localized();
44 }
45
46 /**
47 * Enqueue all the scripts and styles for frontend
48 *
49 * @return void
50 */
51 public function enqueue_frontend() {
52 $this->enqueue_scripts( $this->get_frontend_scripts() );
53 $this->enqueue_styles( $this->get_frontend_styles() );
54 }
55
56 /**
57 * Enqueue all the scripts and styles for backend
58 *
59 * @return void
60 */
61 public function enqueue_backend() {
62 $this->enqueue_scripts( $this->get_admin_scripts() );
63 $this->enqueue_styles( $this->get_admin_styles() );
64 }
65
66 /**
67 * Get file prefix
68 *
69 * @return string
70 */
71 public function get_prefix() {
72 $prefix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
73
74 return $prefix;
75 }
76
77 /**
78 * Get all registered admin scripts
79 *
80 * @return array
81 */
82 public function get_admin_scripts() {
83 $prefix = $this->get_prefix();
84
85 $form_builder_js_deps = apply_filters( 'wpuf-form-builder-js-deps', array(
86 'jquery',
87 'jquery-ui-sortable',
88 'jquery-ui-draggable',
89 'underscore',
90 'wpuf-vue',
91 'wpuf-vuex',
92 'wpuf-sweetalert2',
93 'wpuf-jquery-scrollTo',
94 'wpuf-selectize',
95 'wpuf-toastr',
96 'wpuf-clipboard',
97 'wpuf-tooltip'
98 ) );
99
100 $builder_scripts = apply_filters( 'weforms_builder_scripts', array(
101 'wpuf-vue' => array(
102 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/vue/vue' . $prefix . '.js',
103 'deps' => false,
104 'in_footer' => true
105 ),
106 'wpuf-vuex' => array(
107 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/vuex/vuex' . $prefix . '.js',
108 'deps' => array( 'wpuf-vue' ),
109 'in_footer' => true
110 ),
111 'wpuf-vue-router' => array(
112 'src' => WEFORMS_ASSET_URI . '/js/vendor/vue-router.js',
113 'deps' => array( 'jquery', 'wpuf-vue', 'wpuf-vuex' ),
114 'in_footer' => true
115 ),
116 'nprogress' => array(
117 'src' => WEFORMS_ASSET_URI . '/js/vendor/nprogress.js',
118 'deps' => array( 'jquery' ),
119 'in_footer' => true
120 ),
121 'wpuf-sweetalert2' => array(
122 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/sweetalert2/dist/sweetalert2.js',
123 'deps' => false,
124 'in_footer' => true
125 ),
126 'wpuf-jquery-scrollTo' => array(
127 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/jquery.scrollTo/jquery.scrollTo' . $prefix . '.js',
128 'deps' => array( 'jquery' ),
129 'in_footer' => true
130 ),
131 'wpuf-selectize' => array(
132 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/selectize/js/standalone/selectize' . $prefix . '.js',
133 'deps' => array( 'jquery' ),
134 'in_footer' => true
135 ),
136 'wpuf-toastr' => array(
137 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/toastr/toastr' . $prefix . '.js',
138 'deps' => false,
139 'in_footer' => true
140 ),
141 'wpuf-clipboard' => array(
142 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/clipboard/clipboard' . $prefix . '.js',
143 'deps' => false,
144 'in_footer' => true
145 ),
146 'wpuf-tooltip' => array(
147 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/tooltip/tooltip' . $prefix . '.js',
148 'deps' => false,
149 'in_footer' => true
150 ),
151 'jquery-ui-timepicker' => array(
152 'src' => WEFORMS_ASSET_URI . '/wpuf/js/jquery-ui-timepicker-addon.js',
153 'deps' => array( 'jquery-ui-datepicker' ),
154 'in_footer' => true
155 ),
156 'wpuf-form-builder-mixins' => array(
157 'src' => WEFORMS_ASSET_URI . '/wpuf/js/wpuf-form-builder-mixins.js',
158 'deps' => $form_builder_js_deps,
159 'in_footer' => true
160 ),
161 'wpuf-form-builder-mixins-form' => array(
162 'src' => WEFORMS_ASSET_URI . '/js/wpuf-form-builder-contact-forms.js',
163 'deps' => $form_builder_js_deps,
164 'in_footer' => true
165 ),
166 'wpuf-form-builder-components' => array(
167 'src' => WEFORMS_ASSET_URI . '/wpuf/js/wpuf-form-builder-components.js',
168 'deps' => array( 'wpuf-form-builder-mixins', 'wpuf-form-builder-mixins-form' ),
169 'in_footer' => true
170 ),
171 'weforms-tiny-mce' => array(
172 'src' => site_url( '/wp-includes/js/tinymce/tinymce.min.js' ),
173 'deps' => array(),
174 'in_footer' => true
175 ),
176 'weforms-tiny-mce-code' => array(
177 'src' => WEFORMS_ASSET_URI . '/js/vendor/tinymce/plugins/code/plugin.min.js',
178 'deps' => array( 'weforms-tiny-mce' ),
179 'in_footer' => true
180 ),
181 'weforms-tiny-mce-hr' => array(
182 'src' => WEFORMS_ASSET_URI . '/js/vendor/tinymce/plugins/hr/plugin.min.js',
183 'deps' => array( 'weforms-tiny-mce-code' ),
184 'in_footer' => true
185 ),
186
187 ) );
188
189 $spa_scripts = array(
190 'weforms-mixins' => array(
191 'src' => WEFORMS_ASSET_URI . '/js/spa-mixins.js',
192 'deps' => array( 'wpuf-vue-router', 'wp-util' ),
193 'in_footer' => true
194 ),
195 'weforms-components' => array(
196 'src' => WEFORMS_ASSET_URI . '/js/form-builder-components.js',
197 'deps' => array( 'wpuf-vue', 'wp-util' ),
198 'in_footer' => true
199 ),
200 'weforms-app' => array(
201 'src' => WEFORMS_ASSET_URI . '/js/spa-app.js',
202 'deps' => array( 'wpuf-vue-router', 'wp-util', 'wpuf-form-builder-components' ),
203 'in_footer' => true
204 ),
205 );
206
207 $scripts = array_merge( $builder_scripts, $spa_scripts );
208
209 return apply_filters( 'weforms_admin_scripts', $scripts );
210 }
211
212 /**
213 * Get admin styles
214 *
215 * @return array
216 */
217 public function get_admin_styles() {
218 $frontend_styles = $this->get_frontend_styles();
219
220 $backend_styles = array(
221 'wpuf-font-awesome' => array(
222 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/font-awesome/css/font-awesome.min.css',
223 ),
224 'wpuf-sweetalert2' => array(
225 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/sweetalert2/dist/sweetalert2.css',
226 ),
227 'wpuf-selectize' => array(
228 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/selectize/css/selectize.default.css',
229 ),
230 'wpuf-toastr' => array(
231 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/toastr/toastr.min.css',
232 ),
233 'wpuf-tooltip' => array(
234 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/tooltip/tooltip.css',
235 ),
236 'wpuf-form-builder' => array(
237 'src' => WEFORMS_ASSET_URI . '/wpuf/css/wpuf-form-builder.css',
238 'deps' => array(
239 'wpuf-css',
240 'wpuf-font-awesome',
241 'wpuf-sweetalert2',
242 'wpuf-selectize',
243 'wpuf-toastr',
244 'wpuf-tooltip'
245 )
246 ),
247 'weforms-style' => array(
248 'src' => WEFORMS_ASSET_URI . '/css/admin.css',
249 ),
250 'weforms-tiny-mce-css' => array(
251 'src' => site_url( '/wp-includes/css/editor.css' ),
252 'deps' => array( 'wp-color-picker' )
253 )
254
255 );
256
257 $styles = array_merge( $frontend_styles, $backend_styles );
258
259 return apply_filters( 'weforms_admin_styles', $styles );
260 }
261
262 /**
263 * Get all registered frontend scripts
264 *
265 * @return array
266 */
267 public function get_frontend_scripts() {
268 $scripts = array(
269 'wpuf-form' => array(
270 'src' => WEFORMS_ASSET_URI . '/wpuf/js/frontend-form.js',
271 'deps' => array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-slider' ),
272 'in_footer' => false
273 ),
274 'jquery-ui-timepicker' => array(
275 'src' => WEFORMS_ASSET_URI . '/wpuf/js/jquery-ui-timepicker-addon.js',
276 'deps' => array( 'jquery-ui-datepicker' ),
277 'in_footer' => false
278 ),
279 'wpuf-upload' => array(
280 'src' => WEFORMS_ASSET_URI . '/wpuf/js/upload.js',
281 'deps' => array( 'jquery', 'plupload-handlers' ),
282 'in_footer' => false
283 )
284 );
285
286 return apply_filters( 'weforms_frontend_scripts', $scripts );
287 }
288
289 /**
290 * Get all registered frontend styles
291 *
292 * @return array
293 */
294 public function get_frontend_styles() {
295 $styles = array(
296 'wpuf-css' => array(
297 'src' => WEFORMS_ASSET_URI . '/wpuf/css/frontend-forms.css',
298 ),
299 'jquery-ui' => array(
300 'src' => WEFORMS_ASSET_URI . '/wpuf/css/jquery-ui-1.9.1.custom.css',
301 )
302 );
303
304 return apply_filters( 'weforms_frontend_styles', $styles );
305 }
306
307 /**
308 * Frontend localized scripts
309 *
310 * @return void
311 */
312 public function get_frontend_localized() {
313 wp_localize_script( 'wpuf-form', 'wpuf_frontend', array(
314 'ajaxurl' => admin_url( 'admin-ajax.php' ),
315 'error_message' => __( 'Please fix the errors to proceed', 'weforms' ),
316 'nonce' => wp_create_nonce( 'wpuf_nonce' ),
317 'word_limit' => __( 'Word limit reached', 'weforms' )
318 ) );
319
320 wp_localize_script( 'wpuf-form', 'error_str_obj', array(
321 'required' => __( 'is required', 'weforms' ),
322 'mismatch' => __( 'does not match', 'weforms' ),
323 'validation' => __( 'is not valid', 'weforms' ),
324 'duplicate' => __( 'requires a unique entry and this value has already been used', 'weforms' ),
325 ) );
326
327 wp_localize_script( 'wpuf-upload', 'wpuf_frontend_upload', array(
328 'confirmMsg' => __( 'Are you sure?', 'weforms' ),
329 'nonce' => wp_create_nonce( 'wpuf_nonce' ),
330 'ajaxurl' => admin_url( 'admin-ajax.php' ),
331 'plupload' => array(
332 'url' => admin_url( 'admin-ajax.php' ) . '?nonce=' . wp_create_nonce( 'wpuf-upload-nonce' ),
333 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
334 'filters' => array(
335 array(
336 'title' => __( 'Allowed Files', 'weforms' ),
337 'extensions' => '*'
338 )
339 ),
340 'multipart' => true,
341 'urlstream_upload' => true,
342 'warning' => __( 'Maximum number of files reached!', 'weforms' ),
343 'size_error' => __( 'The file you have uploaded exceeds the file size limit. Please try again.', 'weforms' ),
344 'type_error' => __( 'You have uploaded an incorrect file type. Please try again.', 'weforms' )
345 )
346 ) );
347 }
348
349 /**
350 * Register scripts
351 *
352 * @param array $scripts
353 *
354 * @return void
355 */
356 public function register_scripts( $scripts ) {
357 foreach ( $scripts as $handle => $script ) {
358 $deps = isset( $script['deps'] ) ? $script['deps'] : false;
359 $in_footer = isset( $script['in_footer'] ) ? $script['in_footer'] : false;
360
361 wp_register_script( $handle, $script['src'], $deps, WEFORMS_VERSION, $in_footer );
362 }
363 }
364
365 /**
366 * Register styles
367 *
368 * @param array $styles
369 *
370 * @return void
371 */
372 public function register_styles( $styles ) {
373 foreach ( $styles as $handle => $style ) {
374 $deps = isset( $style['deps'] ) ? $style['deps'] : false;
375
376 wp_register_style( $handle, $style['src'], $deps, WEFORMS_VERSION );
377 }
378 }
379
380 /**
381 * Enqueue the scripts
382 *
383 * @param array $scripts
384 *
385 * @return void
386 */
387 public function enqueue_scripts( $scripts ) {
388 foreach ( $scripts as $handle => $script ) {
389 wp_enqueue_script( $handle );
390 }
391 }
392
393 /**
394 * Enqueue styles
395 *
396 * @param array $styles
397 *
398 * @return void
399 */
400 public function enqueue_styles( $styles ) {
401 foreach ( $styles as $handle => $script ) {
402 wp_enqueue_style( $handle );
403 }
404 }
405 }
406