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

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