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

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