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

392 lines 16.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The Assets Class
5 */
6 class WeForms_Form_Builder_Assets {
7
8 public function __construct() {
9 $this->init_actions();
10 }
11
12 public function init_actions() {
13 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 var wpuf_form_builder_mixins = function(mixins, mixin_parent) {
215 if (!mixins || !mixins.length) {
216 return [];
217 }
218
219 if (!mixin_parent) {
220 mixin_parent = window;
221 }
222
223 return mixins.map(function (mixin) {
224 return mixin_parent[mixin];
225 });
226 };
227 </script>
228 <?php
229 }
230
231 /**
232 * Include vue component templates
233 *
234 * @since 2.5
235 *
236 * @return void
237 */
238 public function admin_footer_js_templates() {
239 if ( !defined( 'WPUF_ASSET_URI' ) ) {
240 define( 'WPUF_ASSET_URI', WEFORMS_ROOT_URI . '/assets' );
241 }
242
243 include WEFORMS_ROOT . '/assets/wpuf/js-templates/form-components.php';
244 include WEFORMS_ROOT . '/assets/js-templates/form-components.php';
245 include WEFORMS_ROOT . '/assets/js-templates/spa-components.php';
246
247 do_action( 'wpuf-form-builder-add-js-templates' );
248 }
249
250 /**
251 * i18n translatable strings
252 *
253 * @since 2.5
254 *
255 * @return array
256 */
257 private function i18n() {
258 return apply_filters( 'wpuf-form-builder-i18n', [
259 'advanced_options' => __( 'Advanced Options', 'weforms' ),
260 'quiz_options' => __( 'Quiz Options', 'weforms' ),
261 'delete_field_warn_msg' => __( 'Are you sure you want to delete this field?', 'weforms' ),
262 'yes_delete_it' => __( 'Yes, delete it', 'weforms' ),
263 'no_cancel_it' => __( 'No, cancel it', 'weforms' ),
264 'ok' => __( 'OK', 'weforms' ),
265 'cancel' => __( 'Cancel', 'weforms' ),
266 'close' => __( 'Close', 'weforms' ),
267 'disable' => __( 'Disable', 'weforms' ),
268 'last_choice_warn_msg' => __( 'This field must contain at least one choice', 'weforms' ),
269 'option' => __( 'Option', 'weforms' ),
270 'row' => __( 'Row', 'weforms' ),
271 'column' => __( 'Column', 'weforms' ),
272 'last_column_warn_msg' => __( 'This field must contain at least one column', 'weforms' ),
273 'is_a_pro_feature' => __( 'is available in Pro version', 'weforms' ),
274 'pro_feature_msg' => __( 'Please upgrade to the Pro version to unlock all these awesome features', 'weforms' ),
275 'upgrade_to_pro' => __( 'Get the Pro version', 'weforms' ),
276 'select' => __( 'Select', 'weforms' ),
277 'saved_form_data' => __( 'Saved form data', 'weforms' ),
278 'unsaved_changes' => __( 'You have unsaved changes.', 'weforms' ),
279 'areYouSureToLeave' => __( 'Are you sure to leave this page?', 'weforms' ),
280 'copy_shortcode' => __( 'Click to copy shortcode', 'weforms' ),
281
282 'selectAnImage' => __( 'Select an image', 'weforms' ),
283 'pleaseSelectAnImage' => __( 'Please select an image', 'weforms' ),
284 'uploadAnImage' => __( 'Upload an image', 'weforms' ),
285
286 'shareYourForm' => __( 'Share Your Form', 'weforms' ),
287 'shareYourFormDesc' => __( 'Sharing your form enables <strong>anyone</strong> to view and submit the form without inserting the shortcode to a page.', 'weforms' ),
288 'shareYourFormText' => __( 'Anyone with this URL will be able to view and submit this form.', 'weforms' ),
289 'areYouSure' => __( 'Are you sure?', 'weforms' ),
290 'selectNotification' => __( 'You must select a notification', 'weforms' ),
291 'areYouSureDesc' => __( 'Anyone with existing URL won\'t be able to view and submit the form anymore.', 'weforms' ),
292 'disableSharing' => __( 'Disable Sharing', 'weforms' ),
293 ] );
294 }
295
296 /**
297 * Add buttons in form submit area
298 *
299 * @return void
300 */
301 public function add_form_submit_area() {
302 ?>
303 <input @click.prevent="" type="submit" name="submit" class="button button-primary" v-model="settings.submit_text">
304 <?php
305 }
306
307 /**
308 * Additional primary tabs
309 *
310 * @return void
311 */
312 public function add_primary_tabs() {
313 $tabs = apply_filters( 'wpuf_contact_form_editor_tabs', [
314 'notification' => __( 'Notifications', 'weforms' ),
315 'integration' => __( 'Integrations', 'weforms' ),
316 ] );
317
318 foreach ( $tabs as $key => $label ) {
319 ?>
320 <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>
321 <?php
322 }
323 }
324
325 public function add_primary_tab_contents() {
326 include __DIR__ . '/views/notification-integration.php';
327 }
328
329 /**
330 * Add settings tabs
331 *
332 * @return void
333 */
334 public function add_settings_tabs() {
335 ?>
336
337 <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>
338 <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>
339 <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>
340 <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>
341
342 <?php do_action( 'wpuf_contact_form_settings_tab' ); ?>
343
344 <?php
345 }
346
347 /**
348 * Add settings tabs
349 *
350 * @return void
351 */
352 public function add_settings_tab_contents() {
353 ?>
354 <div id="wpuf-metabox-settings" class="tab-content" v-show="isActiveSettingsTab('form')">
355 <?php include_once __DIR__ . '/views/form-settings.php'; ?>
356 </div>
357
358 <div id="wpuf-metabox-settings-restriction" class="tab-content" v-show="isActiveSettingsTab('restriction')">
359 <?php include_once __DIR__ . '/views/submission-restriction.php'; ?>
360 </div>
361
362 <div id="wpuf-metabox-settings-display" class="tab-content" v-show="isActiveSettingsTab('display')">
363 <?php include_once __DIR__ . '/views/display-settings.php'; ?>
364 </div>
365
366 <div id="wpuf-metabox-settings-humanpresence" class="tab-content" v-show="isActiveSettingsTab('humanpresence')">
367 <?php include_once __DIR__ . '/views/humanpresence-settings.php'; ?>
368 </div>
369
370 <?php do_action( 'wpuf_contact_form_settings_tab_content' ); ?>
371
372 <?php
373 }
374
375 public function shortcodes( $type = '' ) {
376 $shortcodes = [];
377
378 $shortcodes['user'] = [
379 'title' => __( 'User', 'weforms' ),
380 'codes' => [
381 'first_name' => [ 'title' => __( 'First Name', 'weforms' ), 'default' => 'reader' ],
382 ],
383 ];
384
385 if ( !empty( $type ) && !empty( $shortcodes[ $type ] ) ) {
386 return $shortcodes[ $type ];
387 }
388
389 return $shortcodes;
390 }
391 }
392