PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.0.0-beta.3
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.0.0-beta.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 / admin / class-form-builder-assets.php

class-form-builder-assets.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.0.0-beta.3, at includes/admin/class-form-builder-assets.php

422 lines 17.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The Assets Class
5 */
6 class WeForms_Form_Builder_Assets {
7
8 public function __construct() {
9 $this->init_actions();
10 }
11
12 public function init_actions() {
13
14 add_action( 'admin_enqueue_scripts', array( $this, 'builder_enqueue_scripts' ) );
15 add_action( 'admin_print_scripts', array( $this, 'builder_mixins_script' ) );
16 add_action( 'admin_footer', array( $this, 'admin_footer_js_templates' ) );
17
18 add_action( 'wpuf-form-builder-enqueue-after-components', array( $this, 'admin_enqueue_scripts_components' ) );
19 add_filter( 'wpuf-form-builder-field-settings', array( $this, 'add_field_settings' ) );
20 add_filter( 'wpuf-form-builder-fields-custom-fields', array( $this, 'add_custom_fields' ) );
21 add_action( 'wpuf-form-builder-js-builder-stage-mixins', array( $this, 'js_builder_stage_mixins' ) );
22 add_action( 'wpuf-form-builder-template-builder-stage-submit-area', array( $this, 'add_form_submit_area' ) );
23
24 add_action( 'wpuf-form-builder-tabs-contact_form', array( $this, 'add_primary_tabs' ) );
25 add_action( 'wpuf-form-builder-tab-contents-contact_form', array( $this, 'add_primary_tab_contents' ) );
26
27 add_action( 'wpuf-form-builder-settings-tabs-contact_form', array( $this, 'add_settings_tabs' ) );
28 add_action( 'wpuf-form-builder-settings-tab-contents-contact_form', array( $this, 'add_settings_tab_contents' ) );
29
30 do_action( 'wpuf-form-builder-init-type-wpuf_forms' );
31 }
32
33 public function builder_enqueue_scripts() {
34 $prefix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
35
36 /**
37 * All the styles
38 */
39 wp_enqueue_style( 'wpuf-css', WPUF_ASSET_URI . '/css/frontend-forms.css' );
40 wp_enqueue_style( 'jquery-ui', WPUF_ASSET_URI . '/css/jquery-ui-1.9.1.custom.css' );
41 wp_enqueue_style( 'wpuf-font-awesome', WPUF_ASSET_URI . '/vendor/font-awesome/css/font-awesome.min.css', array(), WPUF_VERSION );
42 wp_enqueue_style( 'wpuf-sweetalert2', WPUF_ASSET_URI . '/vendor/sweetalert2/dist/sweetalert2.css', array(), WPUF_VERSION );
43 wp_enqueue_style( 'wpuf-selectize', WPUF_ASSET_URI . '/vendor/selectize/css/selectize.default.css', array(), WPUF_VERSION );
44 wp_enqueue_style( 'wpuf-toastr', WPUF_ASSET_URI . '/vendor/toastr/toastr.min.css', array(), WPUF_VERSION );
45 wp_enqueue_style( 'wpuf-tooltip', WPUF_ASSET_URI . '/vendor/tooltip/tooltip.css', array(), WPUF_VERSION );
46
47 $form_builder_css_deps = apply_filters( 'wpuf-form-builder-css-deps', array(
48 'wpuf-css', 'wpuf-font-awesome', 'wpuf-sweetalert2', 'wpuf-selectize', 'wpuf-toastr', 'wpuf-tooltip'
49 ) );
50
51 wp_enqueue_style( 'wpuf-form-builder', WPUF_ASSET_URI . '/css/wpuf-form-builder.css', $form_builder_css_deps, WPUF_VERSION );
52 wp_enqueue_style( 'wpuf-cf-style', WEFORMS_ASSET_URI . '/css/admin.css', false );
53
54 /**
55 * All the scripts
56 */
57 wp_enqueue_script( 'wpuf-vue', WPUF_ASSET_URI . '/vendor/vue/vue' . $prefix . '.js', array(), WPUF_VERSION, true );
58 wp_enqueue_script( 'wpuf-vuex', WPUF_ASSET_URI . '/vendor/vuex/vuex' . $prefix . '.js', array( 'wpuf-vue' ), WPUF_VERSION, true );
59 wp_enqueue_script( 'wpuf-vue-router', WEFORMS_ASSET_URI . '/js/vendor/vue-router.js', array( 'jquery', 'wpuf-vue', 'wpuf-vuex' ), false, true );
60 wp_enqueue_script( 'nprogress', WEFORMS_ASSET_URI . '/js/vendor/nprogress.js', array( 'jquery' ), false, true );
61 wp_enqueue_script( 'wpuf-sweetalert2', WPUF_ASSET_URI . '/vendor/sweetalert2/dist/sweetalert2.js', array(), WPUF_VERSION, true );
62 wp_enqueue_script( 'wpuf-jquery-scrollTo', WPUF_ASSET_URI . '/vendor/jquery.scrollTo/jquery.scrollTo' . $prefix . '.js', array( 'jquery' ), WPUF_VERSION, true );
63 wp_enqueue_script( 'wpuf-selectize', WPUF_ASSET_URI . '/vendor/selectize/js/standalone/selectize' . $prefix . '.js', array( 'jquery' ), WPUF_VERSION, true );
64 wp_enqueue_script( 'wpuf-toastr', WPUF_ASSET_URI . '/vendor/toastr/toastr' . $prefix . '.js', array(), WPUF_VERSION, true );
65 wp_enqueue_script( 'wpuf-clipboard', WPUF_ASSET_URI . '/vendor/clipboard/clipboard' . $prefix . '.js', array(), WPUF_VERSION, true );
66 wp_enqueue_script( 'wpuf-tooltip', WPUF_ASSET_URI . '/vendor/tooltip/tooltip' . $prefix . '.js', array(), WPUF_VERSION, true );
67 wp_enqueue_script( 'jquery-ui-datepicker' );
68 wp_enqueue_script( 'jquery-ui-slider' );
69 wp_enqueue_script( 'jquery-ui-timepicker', WPUF_ASSET_URI . '/js/jquery-ui-timepicker-addon.js', array('jquery-ui-datepicker') );
70
71 $form_builder_js_deps = apply_filters( 'wpuf-form-builder-js-deps', array(
72 'jquery', 'jquery-ui-sortable', 'jquery-ui-draggable', 'underscore',
73 'wpuf-vue', 'wpuf-vuex', 'wpuf-sweetalert2', 'wpuf-jquery-scrollTo',
74 'wpuf-selectize', 'wpuf-toastr', 'wpuf-clipboard', 'wpuf-tooltip'
75 ) );
76
77 wp_enqueue_script( 'wpuf-form-builder-mixins', WPUF_ASSET_URI . '/js/wpuf-form-builder-mixins.js', $form_builder_js_deps, WPUF_VERSION, true );
78 wp_enqueue_script( 'wpuf-form-builder-mixins-form', WEFORMS_ASSET_URI . '/js/wpuf-form-builder-contact-forms.js', $form_builder_js_deps, WPUF_VERSION, true );
79
80 do_action( 'wpuf-form-builder-enqueue-after-mixins' );
81
82 wp_enqueue_script( 'wpuf-form-builder-components', WPUF_ASSET_URI . '/js/wpuf-form-builder-components.js', array( 'wpuf-form-builder-mixins' ), WPUF_VERSION, true );
83
84 do_action( 'wpuf-form-builder-enqueue-after-components' );
85
86 /*
87 * Data required for building the form
88 */
89 require_once WPUF_ROOT . '/admin/form-builder/class-wpuf-form-builder-field-settings.php';
90 require_once WPUF_ROOT . '/includes/free/prompt.php';
91
92 $wpuf_form_builder = apply_filters( 'wpuf-form-builder-localize-script', array(
93 'i18n' => $this->i18n(),
94 'panel_sections' => $this->get_panel_sections(),
95 'field_settings' => WPUF_Form_Builder_Field_Settings::get_field_settings(),
96 'pro_link' => self::get_pro_url(),
97 'site_url' => site_url('/'),
98 'defaultNotification' => array(
99 'active' => 'true',
100 'name' => 'Admin Notification',
101 'subject' => '[{from_name}] New Form Submission #{entry_id}',
102 'to' => '{admin_email}',
103 'replyTo' => '',
104 'message' => '{all_fields}',
105 'fromName' => '',
106 'fromAddress' => '{admin_email}',
107 'cc' => '',
108 'bcc' => ''
109 ),
110 'integrations' => apply_filters( 'weforms_form_builder_integrations', array() ),
111 ) );
112
113 wp_localize_script( 'wpuf-form-builder-mixins', 'wpuf_form_builder', $wpuf_form_builder );
114
115 // mixins
116 $wpuf_mixins = array(
117 'root' => apply_filters( 'wpuf-form-builder-js-root-mixins', array() ),
118 'builder_stage' => apply_filters( 'wpuf-form-builder-js-builder-stage-mixins', array() ),
119 'form_fields' => apply_filters( 'wpuf-form-builder-js-form-fields-mixins', array() ),
120 'field_options' => apply_filters( 'wpuf-form-builder-js-field-options-mixins', array() ),
121 );
122
123 wp_localize_script( 'wpuf-form-builder-mixins', 'wpuf_mixins', $wpuf_mixins );
124
125 /**
126 * Contact form SPA scripts
127 */
128 wp_enqueue_script( 'wpuf-cf-spa', WEFORMS_ASSET_URI . '/js/spa-app.js', array( 'wpuf-vue-router', 'wp-util' ), false, true );
129 wp_localize_script( 'wpuf-cf-spa', 'weForms', array(
130 'nonce' => wp_create_nonce( 'weforms' ),
131 'confirm' => __( 'Are you sure?', 'weforms' ),
132 'is_pro' => class_exists( 'WeForms_Pro' ) ? 'true' : 'false'
133 ) );
134 }
135
136 /**
137 * The pro url
138 *
139 * @return string
140 */
141 public static function get_pro_url() {
142 return 'https://wedevs.com/weforms/pricing/?utm_source=freeplugin&utm_medium=prompt&utm_term=weforms_free_plugin&utm_content=textlink&utm_campaign=pro_prompt';
143 }
144
145 /**
146 * Print js scripts in admin head
147 *
148 * @since 2.5
149 *
150 * @return void
151 */
152 public function builder_mixins_script() {
153 ?>
154 <script>
155 if (!window.Promise) {
156 var promise_polyfill = document.createElement('script');
157 promise_polyfill.setAttribute('src','https://cdn.polyfill.io/v2/polyfill.min.js');
158 document.head.appendChild(promise_polyfill);
159 }
160 </script>
161
162 <script>
163 var wpuf_form_builder_mixins = function(mixins, mixin_parent) {
164 if (!mixins || !mixins.length) {
165 return [];
166 }
167
168 if (!mixin_parent) {
169 mixin_parent = window;
170 }
171
172 return mixins.map(function (mixin) {
173 return mixin_parent[mixin];
174 });
175 };
176 </script>
177 <?php
178 }
179
180 /**
181 * Include vue component templates
182 *
183 * @since 2.5
184 *
185 * @return void
186 */
187 public function admin_footer_js_templates() {
188 include WPUF_ROOT . '/assets/js-templates/form-components.php';
189 include WEFORMS_ROOT . '/assets/js-templates/form-components.php';
190 include WEFORMS_ROOT . '/assets/js-templates/spa-components.php';
191
192 do_action( 'wpuf-form-builder-add-js-templates' );
193 }
194
195 /**
196 * i18n translatable strings
197 *
198 * @since 2.5
199 *
200 * @return array
201 */
202 private function i18n() {
203 return apply_filters( 'wpuf-form-builder-i18n', array(
204 'advanced_options' => __( 'Advanced Options', 'wpuf' ),
205 'delete_field_warn_msg' => __( 'Are you sure you want to delete this field?', 'wpuf' ),
206 'yes_delete_it' => __( 'Yes, delete it', 'wpuf' ),
207 'no_cancel_it' => __( 'No, cancel it', 'wpuf' ),
208 'ok' => __( 'OK', 'wpuf' ),
209 'cancel' => __( 'Cancel', 'wpuf' ),
210 'close' => __( 'Close', 'wpuf' ),
211 'last_choice_warn_msg' => __( 'This field must contain at least one choice', 'wpuf' ),
212 'option' => __( 'Option', 'wpuf' ),
213 'column' => __( 'Column', 'wpuf' ),
214 'last_column_warn_msg' => __( 'This field must contain at least one column', 'wpuf' ),
215 'is_a_pro_feature' => __( 'is available in Pro version', 'wpuf' ),
216 'pro_feature_msg' => __( 'Please upgrade to the Pro version to unlock all these awesome features', 'wpuf' ),
217 'upgrade_to_pro' => __( 'Get the Pro version', 'wpuf' ),
218 'select' => __( 'Select', 'wpuf' ),
219 'saved_form_data' => __( 'Saved form data', 'wpuf' ),
220 'unsaved_changes' => __( 'You have unsaved changes.', 'wpuf' ),
221 'copy_shortcode' => __( 'Click to copy shortcode', 'wpuf' ),
222 ) );
223 }
224
225 /**
226 * Add Fields panel sections
227 *
228 * @since 2.5
229 *
230 * @return array
231 */
232 private function get_panel_sections() {
233 $before_custom_fields = apply_filters( 'wpuf-form-builder-fields-section-before', array() );
234
235 $sections = array_merge( $before_custom_fields, $this->get_custom_fields() );
236 $sections = array_merge( $sections, $this->get_others_fields() );
237
238 $after_custom_fields = apply_filters( 'wpuf-form-builder-fields-section-after', array() );
239
240 $sections = array_merge( $sections, $after_custom_fields );
241
242 return $sections;
243 }
244
245 /**
246 * Custom field section
247 *
248 * @since 2.5
249 *
250 * @return array
251 */
252 private function get_custom_fields() {
253 $fields = apply_filters( 'wpuf-form-builder-fields-custom-fields', array(
254 'text_field', 'textarea_field', 'dropdown_field', 'multiple_select',
255 'radio_field', 'checkbox_field', 'website_url', 'email_address',
256 'custom_hidden_field', 'image_upload'
257 ) );
258
259 return array(
260 array(
261 'title' => __( 'Custom Fields', 'wpuf' ),
262 'id' => 'custom-fields',
263 'fields' => $fields
264 )
265 );
266 }
267
268 /**
269 * Add custom fields
270 *
271 * @param array $fields
272 */
273 public function add_custom_fields( $fields ) {
274 $new_fields = array( 'name_field' );
275 $fields = array_merge( $new_fields, $fields );
276
277 return $fields;
278 }
279
280 /**
281 * Add dependencies to form builder script
282 *
283 * @param array $deps
284 *
285 * @return array
286 */
287 public function js_dependencies( $deps ) {
288 array_push( $deps, 'wpuf-contact-form-builder-mixin' );
289
290 return $deps;
291 }
292
293 /**
294 * Add mixins to form builder builder stage component
295 *
296 * @param array $mixins
297 *
298 * @return array
299 */
300 public function js_builder_stage_mixins( $mixins ) {
301 array_push( $mixins , 'wpuf_forms_mixin_builder_stage' );
302
303 return $mixins;
304 }
305
306 /**
307 * Others field section
308 *
309 * @since 2.5
310 *
311 * @return array
312 */
313 private function get_others_fields() {
314 $fields = apply_filters( 'wpuf-form-builder-fields-others-fields', array(
315 'section_break', 'custom_html'
316 ) );
317
318 return array(
319 array(
320 'title' => __( 'Others', 'wpuf' ),
321 'id' => 'others',
322 'fields' => $fields
323 )
324 );
325 }
326
327 /**
328 * Field settings for custom components
329 *
330 * @param array $settings
331 */
332 public function add_field_settings( $settings ) {
333 require_once dirname( __FILE__ ) . '/class-builder-field-settings.php';
334
335 $settings = array_merge( WeForms_Builder_Field_Settings::get_field_settings(), $settings );
336
337 return $settings;
338 }
339
340 /**
341 * Enqueue form builder components
342 *
343 * @return void
344 */
345 public function admin_enqueue_scripts_components() {
346 wp_enqueue_script( 'wpuf-cf-form-builder-components', WEFORMS_ASSET_URI . '/js/form-builder-components.js', array( 'wpuf-form-builder-components' ), WEFORMS_VERSION, true );
347 }
348
349 /**
350 * Add buttons in form submit area
351 *
352 * @return void
353 */
354 public function add_form_submit_area() {
355 ?>
356 <input @click.prevent="" type="submit" name="submit" v-model="settings.submit_text">
357 <?php
358 }
359
360 /**
361 * Additional primary tabs
362 *
363 * @return void
364 */
365 public function add_primary_tabs() {
366 $tabs = apply_filters( 'wpuf_contact_form_editor_tabs', array(
367 'notification' => __( 'Notifications', 'weforms' ),
368 'integration' => __( 'Integrations', 'weforms' )
369 ) );
370
371 foreach ($tabs as $key => $label) {
372 ?>
373 <a href="#wpuf-form-builder-tab-<?php echo $key; ?>" :class="['nav-tab', isActiveTab( '<?php echo $key; ?>' ) ? 'nav-tab-active' : '']" v-on:click.prevent="makeActive('<?php echo $key; ?>')"><?php echo $label; ?></a>
374 <?php
375 }
376 }
377
378 public function add_primary_tab_contents() {
379 include dirname( __FILE__ ) . '/views/notification-integration.php';
380 }
381
382 /**
383 * Add settings tabs
384 *
385 * @return void
386 */
387 public function add_settings_tabs() {
388 ?>
389
390 <a href="#" :class="['nav-tab', isActiveSettingsTab( 'form' ) ? 'nav-tab-active' : '']" v-on:click.prevent="makeActiveSettingsTab( 'form' )" class="nav-tab"><?php _e( 'Form Settings', 'weforms' ); ?></a>
391 <a href="#" :class="['nav-tab', isActiveSettingsTab( 'restriction' ) ? 'nav-tab-active' : '']" v-on:click.prevent="makeActiveSettingsTab( 'restriction' )" class="nav-tab"><?php _e( 'Submission Restriction', 'weforms' ); ?></a>
392 <a href="#" :class="['nav-tab', isActiveSettingsTab( 'display' ) ? 'nav-tab-active' : '']" v-on:click.prevent="makeActiveSettingsTab( 'display' )" class="nav-tab"><?php _e( 'Display Settings', 'weforms' ); ?></a>
393
394 <?php do_action( 'wpuf_contact_form_settings_tab' ); ?>
395
396 <?php
397 }
398
399 /**
400 * Add settings tabs
401 *
402 * @return void
403 */
404 public function add_settings_tab_contents() {
405 ?>
406 <div id="wpuf-metabox-settings" class="tab-content" v-show="isActiveSettingsTab('form')">
407 <?php include_once dirname( __FILE__ ) . '/views/form-settings.php'; ?>
408 </div>
409
410 <div id="wpuf-metabox-settings-restriction" class="tab-content" v-show="isActiveSettingsTab('restriction')">
411 <?php include_once dirname( __FILE__ ) . '/views/submission-restriction.php'; ?>
412 </div>
413
414 <div id="wpuf-metabox-settings-display" class="tab-content" v-show="isActiveSettingsTab('display')">
415 <?php include_once dirname( __FILE__ ) . '/views/display-settings.php'; ?>
416 </div>
417
418 <?php do_action( 'wpuf_contact_form_settings_tab_content' ); ?>
419
420 <?php
421 }
422 }