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

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