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

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