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