PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.0.1
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.0.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
← All changes | includes/admin/class-form-builder-assets.php +506 -406 1.6.21.0.1 View file →
@@ -1,406 +1,506 @@
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 - add_action( 'in_admin_header', [ $this, 'remove_admin_notices' ] );
14 - add_action( 'admin_enqueue_scripts', [ $this, 'builder_enqueue_scripts' ], 2000 );
15 - add_action( 'admin_print_scripts', [ $this, 'builder_mixins_script' ] );
16 - add_action( 'admin_footer', [ $this, 'admin_footer_js_templates' ] );
17 -
18 - add_action( 'wpuf-form-builder-template-builder-stage-submit-area', [ $this, 'add_form_submit_area' ] );
19 -
20 - add_action( 'wpuf-form-builder-tabs-contact_form', [ $this, 'add_primary_tabs' ] );
21 - add_action( 'wpuf-form-builder-tab-contents-contact_form', [ $this, 'add_primary_tab_contents' ] );
22 -
23 - add_action( 'wpuf-form-builder-settings-tabs-contact_form', [ $this, 'add_settings_tabs' ] );
24 - add_action( 'wpuf-form-builder-settings-tab-contents-contact_form', [ $this, 'add_settings_tab_contents' ] );
25 -
26 - do_action( 'weforms_form_builder_init' );
27 - }
28 -
29 - /**
30 - * Remove all kinds of admin notices
31 - *
32 - * Since we don't have much space left on top of the page,
33 - * we have to remove all kinds of admin notices
34 - *
35 - * @since 1.2.6
36 - *
37 - * @return void
38 - */
39 - public function remove_admin_notices() {
40 - remove_all_actions( 'network_admin_notices' );
41 - remove_all_actions( 'user_admin_notices' );
42 - remove_all_actions( 'admin_notices' );
43 - remove_all_actions( 'all_admin_notices' );
44 - }
45 -
46 - public function builder_enqueue_scripts() {
47 - $prefix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
48 -
49 - weforms()->scripts->enqueue_backend();
50 -
51 - $recaptcha = weforms_get_settings( 'recaptcha' );
52 -
53 - $wpuf_form_builder = apply_filters( 'wpuf-form-builder-localize-script', [
54 - 'i18n' => $this->i18n(),
55 - 'panel_sections' => weforms()->fields->get_field_groups(),
56 - 'field_settings' => weforms()->fields->get_js_settings(),
57 - 'pro_link' => self::get_pro_url(),
58 - 'site_url' => site_url( '/' ),
59 - 'defaultNotification' => [
60 - 'active' => 'true',
61 - 'type' => 'email',
62 - 'smsTo' => '',
63 - 'smsText' => '[{form_name}] ' . __( 'New Form Submission', 'weforms' ) . ' #{entry_id}',
64 - 'name' => 'Admin Notification',
65 - 'subject' => '[{form_name}] New Form Submission #{entry_id}',
66 - 'to' => '{admin_email}',
67 - 'replyTo' => '',
68 - 'message' => '{all_fields}',
69 - 'fromName' => '',
70 - 'fromAddress' => '{admin_email}',
71 - 'cc' => '',
72 - 'bcc' => '',
73 - 'weforms_cond' => [
74 - 'condition_status' => 'no',
75 - 'cond_logic' => 'any',
76 - 'conditions' => [
77 - [
78 - 'name' => '',
79 - 'operator' => '=',
80 - 'option' => '',
81 - ],
82 - ],
83 - ],
84 - ],
85 - 'integrations' => weforms()->integrations->get_integration_js_settings(),
86 - 'recaptcha_site' => isset( $recaptcha->key ) ? $recaptcha->key : '',
87 - 'recaptcha_secret' => isset( $recaptcha->secret ) ? $recaptcha->secret : '',
88 - ] );
89 -
90 - // mixins
91 - $wpuf_mixins = [
92 - 'root' => apply_filters( 'weforms-builder-js-root-mixins', [ 'weforms_mixin_builder_root' ] ),
93 - 'builder_stage' => apply_filters( 'weforms-builder-js-builder-stage-mixins', [ 'weforms_mixin_builder_stage' ] ),
94 - 'form_fields' => apply_filters( 'weforms-builder-js-form-fields-mixins', [] ),
95 - 'field_options' => apply_filters( 'weforms-builder-js-field-options-mixins', [] ),
96 - ];
97 -
98 - $weforms = apply_filters( 'weforms_localized_script', [
99 - 'nonce' => wp_create_nonce( 'weforms' ),
100 - 'confirm' => __( 'Are you sure?', 'weforms' ),
101 - 'is_pro' => class_exists( 'WeForms_Pro' ) ? 'true' : 'false',
102 - 'has_payment' => class_exists( 'WeForms_Payment' ) ? 'true' : 'false',
103 - 'has_sms' => class_exists( 'WeForms_SMS_Notification' ) ? 'true' : 'false',
104 - 'routes' => $this->get_vue_routes(),
105 - 'routeComponents' => [ 'default' => null ],
106 - 'mixins' => [ 'default' => null ],
107 - 'assetsURL' => WEFORMS_ASSET_URI,
108 - 'shortcodes' => $this->shortcodes(),
109 - 'settings' => [
110 - 'recaptcha' => weforms_get_settings( 'recaptcha' ),
111 - ],
112 - ] );
113 -
114 - wp_localize_script( 'weforms-form-builder-mixins', 'wpuf_form_builder', $wpuf_form_builder );
115 - wp_localize_script( 'weforms-form-builder-mixins', 'wpuf_mixins', $wpuf_mixins );
116 - wp_localize_script( 'weforms-mixins', 'weForms', $weforms );
117 -
118 - do_action( 'weforms_admin_after_scripts_loaded' );
119 - }
120 -
121 - /**
122 - * The pro url
123 - *
124 - * @return string
125 - */
126 - public static function get_pro_url() {
127 - $link = 'https://weformspro.com/';
128 -
129 - if ( $aff = get_option( '_weforms_aff_ref' ) ) {
130 - $link = add_query_arg( [ 'ref' => $aff ], $link );
131 - }
132 -
133 - return $link;
134 - }
135 -
136 - /**
137 - * SPA Routes
138 - *
139 - * @return array
140 - */
141 - public function get_vue_routes() {
142 - $routes = [
143 - [
144 - 'path' => '/',
145 - 'name' => 'home',
146 - 'component' => 'Home',
147 - ],
148 - [
149 - 'path' => '/form/:id',
150 - 'component' => 'FormHome',
151 - 'children' => [
152 - [
153 - 'path' => '',
154 - 'name' => 'form',
155 - 'component' => 'SingleForm',
156 - ],
157 - [
158 - 'path' => 'entries',
159 - 'component' => 'FormEntriesHome',
160 - 'children' => [
161 - [
162 - 'path' => '',
163 - 'name' => 'formEntries',
164 - 'component' => 'FormEntries',
165 - 'props' => true,
166 - ],
167 - [
168 - 'path' => ':entryid',
169 - 'name' => 'formEntriesSingle',
170 - 'component' => 'FormEntriesSingle',
171 - ],
172 - ],
173 - ],
174 - [
175 - 'path' => 'edit',
176 - 'name' => 'edit',
177 - 'component' => 'FormEditComponent',
178 - ],
179 - ],
180 - ],
181 - [
182 - 'path' => '/tools',
183 - 'name' => 'tools',
184 - 'component' => 'Tools',
185 - ],
186 - [
187 - 'path' => '/entries',
188 - 'name' => 'entries',
189 - 'component' => 'Entries',
190 - ],
191 - [
192 - 'path' => '/help',
193 - 'name' => 'help',
194 - 'component' => 'Help',
195 - ],
196 - [
197 - 'path' => '/privacy',
198 - 'name' => 'privacy',
199 - 'component' => 'Privacy',
200 - ],
201 - [
202 - 'path' => '/premium',
203 - 'name' => 'premium',
204 - 'component' => 'Premium',
205 - ],
206 - [
207 - 'path' => '/settings',
208 - 'name' => 'settings',
209 - 'component' => 'Settings',
210 - ],
211 - ];
212 -
213 - return apply_filters( 'weforms_vue_routes', $routes );
214 - }
215 -
216 - /**
217 - * Print js scripts in admin head
218 - *
219 - * @since 2.5
220 - *
221 - * @return void
222 - */
223 - public function builder_mixins_script() {
224 - ?>
225 - <script>
226 - if (!window.Promise) {
227 - var promise_polyfill = document.createElement('script');
228 - promise_polyfill.setAttribute('src','https://cdn.polyfill.io/v2/polyfill.min.js');
229 - document.head.appendChild(promise_polyfill);
230 - }
231 - </script>
232 -
233 - <script>
234 - var wpuf_form_builder_mixins = function(mixins, mixin_parent) {
235 - if (!mixins || !mixins.length) {
236 - return [];
237 - }
238 -
239 - if (!mixin_parent) {
240 - mixin_parent = window;
241 - }
242 -
243 - return mixins.map(function (mixin) {
244 - return mixin_parent[mixin];
245 - });
246 - };
247 - </script>
248 - <?php
249 - }
250 -
251 - /**
252 - * Include vue component templates
253 - *
254 - * @since 2.5
255 - *
256 - * @return void
257 - */
258 - public function admin_footer_js_templates() {
259 - if ( !defined( 'WPUF_ASSET_URI' ) ) {
260 - define( 'WPUF_ASSET_URI', WEFORMS_ROOT_URI . '/assets' );
261 - }
262 -
263 - include WEFORMS_ROOT . '/assets/wpuf/js-templates/form-components.php';
264 - include WEFORMS_ROOT . '/assets/js-templates/form-components.php';
265 - include WEFORMS_ROOT . '/assets/js-templates/spa-components.php';
266 -
267 - do_action( 'wpuf-form-builder-add-js-templates' );
268 - }
269 -
270 - /**
271 - * i18n translatable strings
272 - *
273 - * @since 2.5
274 - *
275 - * @return array
276 - */
277 - private function i18n() {
278 - return apply_filters( 'wpuf-form-builder-i18n', [
279 - 'advanced_options' => __( 'Advanced Options', 'weforms' ),
280 - 'quiz_options' => __( 'Quiz Options', 'weforms' ),
281 - 'delete_field_warn_msg' => __( 'Are you sure you want to delete this field?', 'weforms' ),
282 - 'yes_delete_it' => __( 'Yes, delete it', 'weforms' ),
283 - 'no_cancel_it' => __( 'No, cancel it', 'weforms' ),
284 - 'ok' => __( 'OK', 'weforms' ),
285 - 'cancel' => __( 'Cancel', 'weforms' ),
286 - 'close' => __( 'Close', 'weforms' ),
287 - 'disable' => __( 'Disable', 'weforms' ),
288 - 'last_choice_warn_msg' => __( 'This field must contain at least one choice', 'weforms' ),
289 - 'option' => __( 'Option', 'weforms' ),
290 - 'row' => __( 'Row', 'weforms' ),
291 - 'column' => __( 'Column', 'weforms' ),
292 - 'last_column_warn_msg' => __( 'This field must contain at least one column', 'weforms' ),
293 - 'is_a_pro_feature' => __( 'is available in Pro version', 'weforms' ),
294 - 'pro_feature_msg' => __( 'Please upgrade to the Pro version to unlock all these awesome features', 'weforms' ),
295 - 'upgrade_to_pro' => __( 'Get the Pro version', 'weforms' ),
296 - 'select' => __( 'Select', 'weforms' ),
297 - 'saved_form_data' => __( 'Saved form data', 'weforms' ),
298 - 'unsaved_changes' => __( 'You have unsaved changes.', 'weforms' ),
299 - 'areYouSureToLeave' => __( 'Are you sure to leave this page?', 'weforms' ),
300 - 'copy_shortcode' => __( 'Click to copy shortcode', 'weforms' ),
301 -
302 - 'selectAnImage' => __( 'Select an image', 'weforms' ),
303 - 'pleaseSelectAnImage' => __( 'Please select an image', 'weforms' ),
304 - 'uploadAnImage' => __( 'Upload an image', 'weforms' ),
305 -
306 - 'shareYourForm' => __( 'Share Your Form', 'weforms' ),
307 - 'shareYourFormDesc' => __( 'Sharing your form enables <strong>anyone</strong> to view and submit the form without inserting the shortcode to a page.', 'weforms' ),
308 - 'shareYourFormText' => __( 'Anyone with this URL will be able to view and submit this form.', 'weforms' ),
309 - 'areYouSure' => __( 'Are you sure?', 'weforms' ),
310 - 'selectNotification' => __( 'You must select a notification', 'weforms' ),
311 - 'areYouSureDesc' => __( 'Anyone with existing URL won\'t be able to view and submit the form anymore.', 'weforms' ),
312 - 'disableSharing' => __( 'Disable Sharing', 'weforms' ),
313 - ] );
314 - }
315 -
316 - /**
317 - * Add buttons in form submit area
318 - *
319 - * @return void
320 - */
321 - public function add_form_submit_area() {
322 - ?>
323 - <input @click.prevent="" type="submit" name="submit" class="button button-primary" v-model="settings.submit_text">
324 - <?php
325 - }
326 -
327 - /**
328 - * Additional primary tabs
329 - *
330 - * @return void
331 - */
332 - public function add_primary_tabs() {
333 - $tabs = apply_filters( 'wpuf_contact_form_editor_tabs', [
334 - 'notification' => __( 'Notifications', 'weforms' ),
335 - 'integration' => __( 'Integrations', 'weforms' ),
336 - ] );
337 -
338 - foreach ( $tabs as $key => $label ) {
339 - ?>
340 - <a href="#wpuf-form-builder-tab-<?php echo esc_attr( $key ); ?>" :class="['nav-tab', isActiveTab( '<?php echo esc_attr( $key ); ?>' ) ? 'nav-tab-active' : '']" v-on:click.prevent="makeActive('<?php echo esc_attr( $key ); ?>')"><?php echo esc_attr( $label ); ?></a>
341 - <?php
342 - }
343 - }
344 -
345 - public function add_primary_tab_contents() {
346 - include __DIR__ . '/views/notification-integration.php';
347 - }
348 -
349 - /**
350 - * Add settings tabs
351 - *
352 - * @return void
353 - */
354 - public function add_settings_tabs() {
355 - ?>
356 -
357 - <a href="#" :class="['nav-tab', isActiveSettingsTab( 'form' ) ? 'nav-tab-active' : '']" v-on:click.prevent="makeActiveSettingsTab( 'form' )" class="nav-tab"><?php esc_html_e( 'Form Settings', 'weforms' ); ?></a>
358 - <a href="#" :class="['nav-tab', isActiveSettingsTab( 'restriction' ) ? 'nav-tab-active' : '']" v-on:click.prevent="makeActiveSettingsTab( 'restriction' )" class="nav-tab"><?php esc_html_e( 'Submission Restriction', 'weforms' ); ?></a>
359 - <a href="#" :class="['nav-tab', isActiveSettingsTab( 'display' ) ? 'nav-tab-active' : '']" v-on:click.prevent="makeActiveSettingsTab( 'display' )" class="nav-tab"><?php esc_html_e( 'Display Settings', 'weforms' ); ?></a>
360 -
361 - <?php do_action( 'wpuf_contact_form_settings_tab' ); ?>
362 -
363 - <?php
364 - }
365 -
366 - /**
367 - * Add settings tabs
368 - *
369 - * @return void
370 - */
371 - public function add_settings_tab_contents() {
372 - ?>
373 - <div id="wpuf-metabox-settings" class="tab-content" v-show="isActiveSettingsTab('form')">
374 - <?php include_once __DIR__ . '/views/form-settings.php'; ?>
375 - </div>
376 -
377 - <div id="wpuf-metabox-settings-restriction" class="tab-content" v-show="isActiveSettingsTab('restriction')">
378 - <?php include_once __DIR__ . '/views/submission-restriction.php'; ?>
379 - </div>
380 -
381 - <div id="wpuf-metabox-settings-display" class="tab-content" v-show="isActiveSettingsTab('display')">
382 - <?php include_once __DIR__ . '/views/display-settings.php'; ?>
383 - </div>
384 -
385 - <?php do_action( 'wpuf_contact_form_settings_tab_content' ); ?>
386 -
387 - <?php
388 - }
389 -
390 - public function shortcodes( $type = '' ) {
391 - $shortcodes = [];
392 -
393 - $shortcodes['user'] = [
394 - 'title' => __( 'User', 'weforms' ),
395 - 'codes' => [
396 - 'first_name' => [ 'title' => __( 'First Name', 'weforms' ), 'default' => 'reader' ],
397 - ],
398 - ];
399 -
400 - if ( !empty( $type ) && !empty( $shortcodes[ $type ] ) ) {
401 - return $shortcodes[ $type ];
402 - }
403 -
404 - return $shortcodes;
405 - }
406 -}
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 + $recaptcha = weforms_get_settings( 'recaptcha' );
93 +
94 + $wpuf_form_builder = apply_filters( 'wpuf-form-builder-localize-script', array(
95 + 'i18n' => $this->i18n(),
96 + 'panel_sections' => $this->get_panel_sections(),
97 + 'field_settings' => WPUF_Form_Builder_Field_Settings::get_field_settings(),
98 + 'pro_link' => self::get_pro_url(),
99 + 'site_url' => site_url('/'),
100 + 'defaultNotification' => array(
101 + 'active' => 'true',
102 + 'name' => 'Admin Notification',
103 + 'subject' => '[{from_name}] New Form Submission #{entry_id}',
104 + 'to' => '{admin_email}',
105 + 'replyTo' => '',
106 + 'message' => '{all_fields}',
107 + 'fromName' => '',
108 + 'fromAddress' => '{admin_email}',
109 + 'cc' => '',
110 + 'bcc' => ''
111 + ),
112 + 'integrations' => apply_filters( 'weforms_form_builder_integrations', array() ),
113 + 'recaptcha_site' => isset( $recaptcha->key ) ? $recaptcha->key : '',
114 + 'recaptcha_secret' => isset( $recaptcha->secret ) ? $recaptcha->secret : '',
115 + ) );
116 +
117 + wp_localize_script( 'wpuf-form-builder-mixins', 'wpuf_form_builder', $wpuf_form_builder );
118 +
119 + // mixins
120 + $wpuf_mixins = array(
121 + 'root' => apply_filters( 'wpuf-form-builder-js-root-mixins', array() ),
122 + 'builder_stage' => apply_filters( 'wpuf-form-builder-js-builder-stage-mixins', array() ),
123 + 'form_fields' => apply_filters( 'wpuf-form-builder-js-form-fields-mixins', array() ),
124 + 'field_options' => apply_filters( 'wpuf-form-builder-js-field-options-mixins', array() ),
125 + );
126 +
127 + wp_localize_script( 'wpuf-form-builder-mixins', 'wpuf_mixins', $wpuf_mixins );
128 +
129 + /**
130 + * SPA scripts
131 + */
132 + wp_enqueue_script( 'weforms-mixins', WEFORMS_ASSET_URI . '/js/spa-mixins.js', array( 'wpuf-vue-router', 'wp-util' ), false, true );
133 + wp_enqueue_script( 'weforms-app', WEFORMS_ASSET_URI . '/js/spa-app.js', array( 'wpuf-vue-router', 'wp-util' ), false, true );
134 + wp_localize_script( 'weforms-mixins', 'weForms', apply_filters( 'weforms_localized_script', array(
135 + 'nonce' => wp_create_nonce( 'weforms' ),
136 + 'confirm' => __( 'Are you sure?', 'weforms' ),
137 + 'is_pro' => class_exists( 'WeForms_Pro' ) ? 'true' : 'false',
138 + 'routes' => $this->get_vue_routes(),
139 + 'routeComponents' => array( 'default' => null ),
140 + 'mixins' => array( 'default' => null )
141 + ) ) );
142 + }
143 +
144 + /**
145 + * The pro url
146 + *
147 + * @return string
148 + */
149 + public static function get_pro_url() {
150 + return 'https://wedevs.com/weforms-upgrade/';
151 + }
152 +
153 + /**
154 + * SPA Routes
155 + *
156 + * @return array
157 + */
158 + public function get_vue_routes() {
159 + $routes = array(
160 + array(
161 + 'path' => '/',
162 + 'name' => 'home',
163 + 'component' => 'Home'
164 + ),
165 + array(
166 + 'path' => '/form/:id',
167 + 'component' => 'FormHome',
168 + 'children' => array(
169 + array(
170 + 'path' => '',
171 + 'name' => 'form',
172 + 'component' => 'SingleForm'
173 + ),
174 + array(
175 + 'path' => 'entries',
176 + 'component' => 'FormEntriesHome',
177 + 'children' => array(
178 + array(
179 + 'path' => '',
180 + 'name' => 'formEntries',
181 + 'component' => 'FormEntries',
182 + 'props' => true
183 + ),
184 + array(
185 + 'path' => ':entryid',
186 + 'name' => 'formEntriesSingle',
187 + 'component' => 'FormEntriesSingle'
188 + )
189 + )
190 + ),
191 + array(
192 + 'path' => 'edit',
193 + 'name' => 'edit',
194 + 'component' => 'FormEditComponent'
195 + )
196 + )
197 + ),
198 + array(
199 + 'path' => '/tools',
200 + 'name' => 'tools',
201 + 'component' => 'Tools'
202 + ),
203 + array(
204 + 'path' => '/help',
205 + 'name' => 'help',
206 + 'component' => 'Help'
207 + ),
208 + array(
209 + 'path' => '/premium',
210 + 'name' => 'premium',
211 + 'component' => 'Premium'
212 + ),
213 + array(
214 + 'path' => '/settings',
215 + 'name' => 'settings',
216 + 'component' => 'Settings'
217 + ),
218 + );
219 +
220 + return apply_filters( 'weforms_vue_routes', $routes );
221 + }
222 +
223 + /**
224 + * Print js scripts in admin head
225 + *
226 + * @since 2.5
227 + *
228 + * @return void
229 + */
230 + public function builder_mixins_script() {
231 + ?>
232 + <script>
233 + if (!window.Promise) {
234 + var promise_polyfill = document.createElement('script');
235 + promise_polyfill.setAttribute('src','https://cdn.polyfill.io/v2/polyfill.min.js');
236 + document.head.appendChild(promise_polyfill);
237 + }
238 + </script>
239 +
240 + <script>
241 + var wpuf_form_builder_mixins = function(mixins, mixin_parent) {
242 + if (!mixins || !mixins.length) {
243 + return [];
244 + }
245 +
246 + if (!mixin_parent) {
247 + mixin_parent = window;
248 + }
249 +
250 + return mixins.map(function (mixin) {
251 + return mixin_parent[mixin];
252 + });
253 + };
254 + </script>
255 + <?php
256 + }
257 +
258 + /**
259 + * Include vue component templates
260 + *
261 + * @since 2.5
262 + *
263 + * @return void
264 + */
265 + public function admin_footer_js_templates() {
266 + include WPUF_ROOT . '/assets/js-templates/form-components.php';
267 + include WEFORMS_ROOT . '/assets/js-templates/form-components.php';
268 + include WEFORMS_ROOT . '/assets/js-templates/spa-components.php';
269 +
270 + do_action( 'wpuf-form-builder-add-js-templates' );
271 + }
272 +
273 + /**
274 + * i18n translatable strings
275 + *
276 + * @since 2.5
277 + *
278 + * @return array
279 + */
280 + private function i18n() {
281 + return apply_filters( 'wpuf-form-builder-i18n', array(
282 + 'advanced_options' => __( 'Advanced Options', 'wpuf' ),
283 + 'delete_field_warn_msg' => __( 'Are you sure you want to delete this field?', 'wpuf' ),
284 + 'yes_delete_it' => __( 'Yes, delete it', 'wpuf' ),
285 + 'no_cancel_it' => __( 'No, cancel it', 'wpuf' ),
286 + 'ok' => __( 'OK', 'wpuf' ),
287 + 'cancel' => __( 'Cancel', 'wpuf' ),
288 + 'close' => __( 'Close', 'wpuf' ),
289 + 'last_choice_warn_msg' => __( 'This field must contain at least one choice', 'wpuf' ),
290 + 'option' => __( 'Option', 'wpuf' ),
291 + 'column' => __( 'Column', 'wpuf' ),
292 + 'last_column_warn_msg' => __( 'This field must contain at least one column', 'wpuf' ),
293 + 'is_a_pro_feature' => __( 'is available in Pro version', 'wpuf' ),
294 + 'pro_feature_msg' => __( 'Please upgrade to the Pro version to unlock all these awesome features', 'wpuf' ),
295 + 'upgrade_to_pro' => __( 'Get the Pro version', 'wpuf' ),
296 + 'select' => __( 'Select', 'wpuf' ),
297 + 'saved_form_data' => __( 'Saved form data', 'wpuf' ),
298 + 'unsaved_changes' => __( 'You have unsaved changes.', 'wpuf' ),
299 + 'copy_shortcode' => __( 'Click to copy shortcode', 'wpuf' ),
300 + ) );
301 + }
302 +
303 + /**
304 + * Add Fields panel sections
305 + *
306 + * @since 2.5
307 + *
308 + * @return array
309 + */
310 + private function get_panel_sections() {
311 + $before_custom_fields = apply_filters( 'wpuf-form-builder-fields-section-before', array() );
312 +
313 + $sections = array_merge( $before_custom_fields, $this->get_custom_fields() );
314 + $sections = array_merge( $sections, $this->get_others_fields() );
315 +
316 + $after_custom_fields = apply_filters( 'wpuf-form-builder-fields-section-after', array() );
317 +
318 + $sections = array_merge( $sections, $after_custom_fields );
319 +
320 + return $sections;
321 + }
322 +
323 + /**
324 + * Custom field section
325 + *
326 + * @since 2.5
327 + *
328 + * @return array
329 + */
330 + private function get_custom_fields() {
331 + $fields = apply_filters( 'wpuf-form-builder-fields-custom-fields', array(
332 + 'text_field', 'textarea_field', 'dropdown_field', 'multiple_select',
333 + 'radio_field', 'checkbox_field', 'website_url', 'email_address',
334 + 'custom_hidden_field', 'image_upload'
335 + ) );
336 +
337 + return array(
338 + array(
339 + 'title' => __( 'Custom Fields', 'wpuf' ),
340 + 'id' => 'custom-fields',
341 + 'fields' => $fields
342 + )
343 + );
344 + }
345 +
346 + /**
347 + * Add custom fields
348 + *
349 + * @param array $fields
350 + */
351 + public function add_custom_fields( $fields ) {
352 + $new_fields = array( 'name_field' );
353 + $fields = array_merge( $new_fields, $fields );
354 +
355 + return $fields;
356 + }
357 +
358 + /**
359 + * Add dependencies to form builder script
360 + *
361 + * @param array $deps
362 + *
363 + * @return array
364 + */
365 + public function js_dependencies( $deps ) {
366 + array_push( $deps, 'wpuf-contact-form-builder-mixin' );
367 +
368 + return $deps;
369 + }
370 +
371 + /**
372 + * Add mixins to form builder builder stage component
373 + *
374 + * @param array $mixins
375 + *
376 + * @return array
377 + */
378 + public function js_builder_stage_mixins( $mixins ) {
379 + array_push( $mixins , 'wpuf_forms_mixin_builder_stage' );
380 +
381 + return $mixins;
382 + }
383 +
384 + /**
385 + * Others field section
386 + *
387 + * @since 2.5
388 + *
389 + * @return array
390 + */
391 + private function get_others_fields() {
392 + $fields = apply_filters( 'wpuf-form-builder-fields-others-fields', array(
393 + 'section_break', 'custom_html', 'recaptcha'
394 + ) );
395 +
396 + return array(
397 + array(
398 + 'title' => __( 'Others', 'wpuf' ),
399 + 'id' => 'others',
400 + 'fields' => $fields
401 + )
402 + );
403 + }
404 +
405 + /**
406 + * Field settings for custom components
407 + *
408 + * @param array $settings
409 + */
410 + public function add_field_settings( $settings ) {
411 + require_once dirname( __FILE__ ) . '/class-builder-field-settings.php';
412 +
413 + $settings = array_merge( WeForms_Builder_Field_Settings::get_field_settings(), $settings );
414 +
415 + // filter out recaptcha settings url in message
416 + if ( isset( $settings['recaptcha'] ) ) {
417 + $message = $settings['recaptcha']['validator']['msg'];
418 + $settings['recaptcha']['validator']['msg'] = str_replace( 'admin.php?page=wpuf-settings', 'admin.php?page=weforms#/settings', $message );
419 + }
420 +
421 + return $settings;
422 + }
423 +
424 + /**
425 + * Enqueue form builder components
426 + *
427 + * @return void
428 + */
429 + public function admin_enqueue_scripts_components() {
430 + wp_enqueue_script( 'wpuf-cf-form-builder-components', WEFORMS_ASSET_URI . '/js/form-builder-components.js', array( 'wpuf-form-builder-components' ), WEFORMS_VERSION, true );
431 + }
432 +
433 + /**
434 + * Add buttons in form submit area
435 + *
436 + * @return void
437 + */
438 + public function add_form_submit_area() {
439 + ?>
440 + <input @click.prevent="" type="submit" name="submit" v-model="settings.submit_text">
441 + <?php
442 + }
443 +
444 + /**
445 + * Additional primary tabs
446 + *
447 + * @return void
448 + */
449 + public function add_primary_tabs() {
450 + $tabs = apply_filters( 'wpuf_contact_form_editor_tabs', array(
451 + 'notification' => __( 'Notifications', 'weforms' ),
452 + 'integration' => __( 'Integrations', 'weforms' )
453 + ) );
454 +
455 + foreach ($tabs as $key => $label) {
456 + ?>
457 + <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>
458 + <?php
459 + }
460 + }
461 +
462 + public function add_primary_tab_contents() {
463 + include dirname( __FILE__ ) . '/views/notification-integration.php';
464 + }
465 +
466 + /**
467 + * Add settings tabs
468 + *
469 + * @return void
470 + */
471 + public function add_settings_tabs() {
472 + ?>
473 +
474 + <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>
475 + <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>
476 + <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>
477 +
478 + <?php do_action( 'wpuf_contact_form_settings_tab' ); ?>
479 +
480 + <?php
481 + }
482 +
483 + /**
484 + * Add settings tabs
485 + *
486 + * @return void
487 + */
488 + public function add_settings_tab_contents() {
489 + ?>
490 + <div id="wpuf-metabox-settings" class="tab-content" v-show="isActiveSettingsTab('form')">
491 + <?php include_once dirname( __FILE__ ) . '/views/form-settings.php'; ?>
492 + </div>
493 +
494 + <div id="wpuf-metabox-settings-restriction" class="tab-content" v-show="isActiveSettingsTab('restriction')">
495 + <?php include_once dirname( __FILE__ ) . '/views/submission-restriction.php'; ?>
496 + </div>
497 +
498 + <div id="wpuf-metabox-settings-display" class="tab-content" v-show="isActiveSettingsTab('display')">
499 + <?php include_once dirname( __FILE__ ) . '/views/display-settings.php'; ?>
500 + </div>
501 +
502 + <?php do_action( 'wpuf_contact_form_settings_tab_content' ); ?>
503 +
504 + <?php
505 + }
506 +}