PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.6.5
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.6.5
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.6.5, at includes/admin/class-form-builder-assets.php

389 lines 15.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The 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
35 $wpuf_form_builder = apply_filters( 'wpuf-form-builder-localize-script', [
36 'i18n' => $this->i18n(),
37 'panel_sections' => weforms()->fields->get_field_groups(),
38 'field_settings' => weforms()->fields->get_js_settings(),
39 'pro_link' => self::get_pro_url(),
40 'site_url' => site_url( '/' ),
41 'defaultNotification' => [
42 'active' => 'true',
43 'type' => 'email',
44 'smsTo' => '',
45 'smsText' => '[{form_name}] ' . __( 'New Form Submission', 'weforms' ) . ' #{entry_id}',
46 'name' => 'Admin Notification',
47 'subject' => '[{form_name}] New Form Submission #{entry_id}',
48 'to' => '{admin_email}',
49 'replyTo' => '',
50 'message' => '{all_fields}',
51 'fromName' => '',
52 'fromAddress' => '{admin_email}',
53 'cc' => '',
54 'bcc' => '',
55 'weforms_cond' => [
56 'condition_status' => 'no',
57 'cond_logic' => 'any',
58 'conditions' => [
59 [
60 'name' => '',
61 'operator' => '=',
62 'option' => '',
63 ],
64 ],
65 ],
66 ],
67 'integrations' => weforms()->integrations->get_integration_js_settings(),
68 'recaptcha_site' => isset( $recaptcha->key ) ? $recaptcha->key : '',
69 'recaptcha_secret' => isset( $recaptcha->secret ) ? $recaptcha->secret : '',
70 ] );
71
72 // mixins
73 $wpuf_mixins = [
74 'root' => apply_filters( 'weforms-builder-js-root-mixins', [ 'weforms_mixin_builder_root' ] ),
75 'builder_stage' => apply_filters( 'weforms-builder-js-builder-stage-mixins', [ 'weforms_mixin_builder_stage' ] ),
76 'form_fields' => apply_filters( 'weforms-builder-js-form-fields-mixins', [] ),
77 'field_options' => apply_filters( 'weforms-builder-js-field-options-mixins', [] ),
78 ];
79
80 $weforms = apply_filters( 'weforms_localized_script', [
81 'nonce' => wp_create_nonce( 'weforms' ),
82 'confirm' => __( 'Are you sure?', 'weforms' ),
83 'is_pro' => class_exists( 'WeForms_Pro' ) ? 'true' : 'false',
84 'has_payment' => class_exists( 'WeForms_Payment' ) ? 'true' : 'false',
85 'has_sms' => class_exists( 'WeForms_SMS_Notification' ) ? 'true' : 'false',
86 'routes' => $this->get_vue_routes(),
87 'routeComponents' => [ 'default' => null ],
88 'mixins' => [ 'default' => null ],
89 'assetsURL' => WEFORMS_ASSET_URI,
90 'shortcodes' => $this->shortcodes(),
91 'settings' => [
92 'recaptcha' => weforms_get_settings( 'recaptcha' ),
93 ],
94 ] );
95
96 wp_localize_script( 'weforms-form-builder-mixins', 'wpuf_form_builder', $wpuf_form_builder );
97 wp_localize_script( 'weforms-form-builder-mixins', 'wpuf_mixins', $wpuf_mixins );
98 wp_localize_script( 'weforms-mixins', 'weForms', $weforms );
99
100 do_action( 'weforms_admin_after_scripts_loaded' );
101 }
102
103 /**
104 * The pro url
105 *
106 * @return string
107 */
108 public static function get_pro_url() {
109 $link = 'https://weformspro.com/';
110
111 if ( $aff = get_option( '_weforms_aff_ref' ) ) {
112 $link = add_query_arg( [ 'ref' => $aff ], $link );
113 }
114
115 return $link;
116 }
117
118 /**
119 * SPA Routes
120 *
121 * @return array
122 */
123 public function get_vue_routes() {
124 $routes = [
125 [
126 'path' => '/',
127 'name' => 'home',
128 'component' => 'Home',
129 ],
130 [
131 'path' => '/form/:id',
132 'component' => 'FormHome',
133 'children' => [
134 [
135 'path' => '',
136 'name' => 'form',
137 'component' => 'SingleForm',
138 ],
139 [
140 'path' => 'entries',
141 'component' => 'FormEntriesHome',
142 'children' => [
143 [
144 'path' => '',
145 'name' => 'formEntries',
146 'component' => 'FormEntries',
147 'props' => true,
148 ],
149 [
150 'path' => ':entryid',
151 'name' => 'formEntriesSingle',
152 'component' => 'FormEntriesSingle',
153 ],
154 ],
155 ],
156 [
157 'path' => 'edit',
158 'name' => 'edit',
159 'component' => 'FormEditComponent',
160 ],
161 ],
162 ],
163 [
164 'path' => '/tools',
165 'name' => 'tools',
166 'component' => 'Tools',
167 ],
168 [
169 'path' => '/entries',
170 'name' => 'entries',
171 'component' => 'Entries',
172 ],
173 [
174 'path' => '/help',
175 'name' => 'help',
176 'component' => 'Help',
177 ],
178 [
179 'path' => '/privacy',
180 'name' => 'privacy',
181 'component' => 'Privacy',
182 ],
183 [
184 'path' => '/premium',
185 'name' => 'premium',
186 'component' => 'Premium',
187 ],
188 [
189 'path' => '/settings',
190 'name' => 'settings',
191 'component' => 'Settings',
192 ],
193 ];
194
195 return apply_filters( 'weforms_vue_routes', $routes );
196 }
197
198 /**
199 * Print js scripts in admin head
200 *
201 * @since 2.5
202 *
203 * @return void
204 */
205 public function builder_mixins_script() {
206 ?>
207 <script>
208 if (!window.Promise) {
209 var promise_polyfill = document.createElement('script');
210 promise_polyfill.setAttribute('src','https://cdn.polyfill.io/v2/polyfill.min.js');
211 document.head.appendChild(promise_polyfill);
212 }
213 </script>
214
215 <script>
216 var wpuf_form_builder_mixins = function(mixins, mixin_parent) {
217 if (!mixins || !mixins.length) {
218 return [];
219 }
220
221 if (!mixin_parent) {
222 mixin_parent = window;
223 }
224
225 return mixins.map(function (mixin) {
226 return mixin_parent[mixin];
227 });
228 };
229 </script>
230 <?php
231 }
232
233 /**
234 * Include vue component templates
235 *
236 * @since 2.5
237 *
238 * @return void
239 */
240 public function admin_footer_js_templates() {
241 if ( !defined( 'WPUF_ASSET_URI' ) ) {
242 define( 'WPUF_ASSET_URI', WEFORMS_ROOT_URI . '/assets' );
243 }
244
245 include WEFORMS_ROOT . '/assets/wpuf/js-templates/form-components.php';
246 include WEFORMS_ROOT . '/assets/js-templates/form-components.php';
247 include WEFORMS_ROOT . '/assets/js-templates/spa-components.php';
248
249 do_action( 'wpuf-form-builder-add-js-templates' );
250 }
251
252 /**
253 * i18n translatable strings
254 *
255 * @since 2.5
256 *
257 * @return array
258 */
259 private function i18n() {
260 return apply_filters( 'wpuf-form-builder-i18n', [
261 'advanced_options' => __( 'Advanced Options', 'weforms' ),
262 'quiz_options' => __( 'Quiz Options', 'weforms' ),
263 'delete_field_warn_msg' => __( 'Are you sure you want to delete this field?', 'weforms' ),
264 'yes_delete_it' => __( 'Yes, delete it', 'weforms' ),
265 'no_cancel_it' => __( 'No, cancel it', 'weforms' ),
266 'ok' => __( 'OK', 'weforms' ),
267 'cancel' => __( 'Cancel', 'weforms' ),
268 'close' => __( 'Close', 'weforms' ),
269 'disable' => __( 'Disable', 'weforms' ),
270 'last_choice_warn_msg' => __( 'This field must contain at least one choice', 'weforms' ),
271 'option' => __( 'Option', 'weforms' ),
272 'row' => __( 'Row', 'weforms' ),
273 'column' => __( 'Column', 'weforms' ),
274 'last_column_warn_msg' => __( 'This field must contain at least one column', 'weforms' ),
275 'is_a_pro_feature' => __( 'is available in Pro version', 'weforms' ),
276 'pro_feature_msg' => __( 'Please upgrade to the Pro version to unlock all these awesome features', 'weforms' ),
277 'upgrade_to_pro' => __( 'Get the Pro version', 'weforms' ),
278 'select' => __( 'Select', 'weforms' ),
279 'saved_form_data' => __( 'Saved form data', 'weforms' ),
280 'unsaved_changes' => __( 'You have unsaved changes.', 'weforms' ),
281 'areYouSureToLeave' => __( 'Are you sure to leave this page?', 'weforms' ),
282 'copy_shortcode' => __( 'Click to copy shortcode', 'weforms' ),
283
284 'selectAnImage' => __( 'Select an image', 'weforms' ),
285 'pleaseSelectAnImage' => __( 'Please select an image', 'weforms' ),
286 'uploadAnImage' => __( 'Upload an image', 'weforms' ),
287
288 'shareYourForm' => __( 'Share Your Form', 'weforms' ),
289 'shareYourFormDesc' => __( 'Sharing your form enables <strong>anyone</strong> to view and submit the form without inserting the shortcode to a page.', 'weforms' ),
290 'shareYourFormText' => __( 'Anyone with this URL will be able to view and submit this form.', 'weforms' ),
291 'areYouSure' => __( 'Are you sure?', 'weforms' ),
292 'selectNotification' => __( 'You must select a notification', 'weforms' ),
293 'areYouSureDesc' => __( 'Anyone with existing URL won\'t be able to view and submit the form anymore.', 'weforms' ),
294 'disableSharing' => __( 'Disable Sharing', 'weforms' ),
295 ] );
296 }
297
298 /**
299 * Add buttons in form submit area
300 *
301 * @return void
302 */
303 public function add_form_submit_area() {
304 ?>
305 <input @click.prevent="" type="submit" name="submit" class="button button-primary" v-model="settings.submit_text">
306 <?php
307 }
308
309 /**
310 * Additional primary tabs
311 *
312 * @return void
313 */
314 public function add_primary_tabs() {
315 $tabs = apply_filters( 'wpuf_contact_form_editor_tabs', [
316 'notification' => __( 'Notifications', 'weforms' ),
317 'integration' => __( 'Integrations', 'weforms' ),
318 ] );
319
320 foreach ( $tabs as $key => $label ) {
321 ?>
322 <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>
323 <?php
324 }
325 }
326
327 public function add_primary_tab_contents() {
328 include __DIR__ . '/views/notification-integration.php';
329 }
330
331 /**
332 * Add settings tabs
333 *
334 * @return void
335 */
336 public function add_settings_tabs() {
337 ?>
338
339 <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>
340 <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>
341 <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>
342
343 <?php do_action( 'wpuf_contact_form_settings_tab' ); ?>
344
345 <?php
346 }
347
348 /**
349 * Add settings tabs
350 *
351 * @return void
352 */
353 public function add_settings_tab_contents() {
354 ?>
355 <div id="wpuf-metabox-settings" class="tab-content" v-show="isActiveSettingsTab('form')">
356 <?php include_once __DIR__ . '/views/form-settings.php'; ?>
357 </div>
358
359 <div id="wpuf-metabox-settings-restriction" class="tab-content" v-show="isActiveSettingsTab('restriction')">
360 <?php include_once __DIR__ . '/views/submission-restriction.php'; ?>
361 </div>
362
363 <div id="wpuf-metabox-settings-display" class="tab-content" v-show="isActiveSettingsTab('display')">
364 <?php include_once __DIR__ . '/views/display-settings.php'; ?>
365 </div>
366
367 <?php do_action( 'wpuf_contact_form_settings_tab_content' ); ?>
368
369 <?php
370 }
371
372 public function shortcodes( $type = '' ) {
373 $shortcodes = [];
374
375 $shortcodes['user'] = [
376 'title' => __( 'User', 'weforms' ),
377 'codes' => [
378 'first_name' => [ 'title' => __( 'First Name', 'weforms' ), 'default' => 'reader' ],
379 ],
380 ];
381
382 if ( !empty( $type ) && !empty( $shortcodes[ $type ] ) ) {
383 return $shortcodes[ $type ];
384 }
385
386 return $shortcodes;
387 }
388 }
389