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

class-form-builder-assets.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.4.4, at includes/admin/class-form-builder-assets.php

399 lines 15.5 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 /**
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 ] );
110
111 wp_localize_script( 'weforms-form-builder-mixins', 'wpuf_form_builder', $wpuf_form_builder );
112 wp_localize_script( 'weforms-form-builder-mixins', 'wpuf_mixins', $wpuf_mixins );
113 wp_localize_script( 'weforms-mixins', 'weForms', $weforms );
114
115 do_action( 'weforms_admin_after_scripts_loaded' );
116 }
117
118 /**
119 * The pro url
120 *
121 * @return string
122 */
123 public static function get_pro_url() {
124 $link = 'https://wedevs.com/weforms-upgrade/';
125
126 if ( $aff = get_option( '_weforms_aff_ref' ) ) {
127 $link = add_query_arg( [ 'ref' => $aff ], $link );
128 }
129
130 return $link;
131 }
132
133 /**
134 * SPA Routes
135 *
136 * @return array
137 */
138 public function get_vue_routes() {
139 $routes = [
140 [
141 'path' => '/',
142 'name' => 'home',
143 'component' => 'Home',
144 ],
145 [
146 'path' => '/form/:id',
147 'component' => 'FormHome',
148 'children' => [
149 [
150 'path' => '',
151 'name' => 'form',
152 'component' => 'SingleForm',
153 ],
154 [
155 'path' => 'entries',
156 'component' => 'FormEntriesHome',
157 'children' => [
158 [
159 'path' => '',
160 'name' => 'formEntries',
161 'component' => 'FormEntries',
162 'props' => true,
163 ],
164 [
165 'path' => ':entryid',
166 'name' => 'formEntriesSingle',
167 'component' => 'FormEntriesSingle',
168 ],
169 ],
170 ],
171 [
172 'path' => 'edit',
173 'name' => 'edit',
174 'component' => 'FormEditComponent',
175 ],
176 ],
177 ],
178 [
179 'path' => '/tools',
180 'name' => 'tools',
181 'component' => 'Tools',
182 ],
183 [
184 'path' => '/entries',
185 'name' => 'entries',
186 'component' => 'Entries',
187 ],
188 [
189 'path' => '/help',
190 'name' => 'help',
191 'component' => 'Help',
192 ],
193 [
194 'path' => '/premium',
195 'name' => 'premium',
196 'component' => 'Premium',
197 ],
198 [
199 'path' => '/settings',
200 'name' => 'settings',
201 'component' => 'Settings',
202 ],
203 ];
204
205 return apply_filters( 'weforms_vue_routes', $routes );
206 }
207
208 /**
209 * Print js scripts in admin head
210 *
211 * @since 2.5
212 *
213 * @return void
214 */
215 public function builder_mixins_script() {
216 ?>
217 <script>
218 if (!window.Promise) {
219 var promise_polyfill = document.createElement('script');
220 promise_polyfill.setAttribute('src','https://cdn.polyfill.io/v2/polyfill.min.js');
221 document.head.appendChild(promise_polyfill);
222 }
223 </script>
224
225 <script>
226 var wpuf_form_builder_mixins = function(mixins, mixin_parent) {
227 if (!mixins || !mixins.length) {
228 return [];
229 }
230
231 if (!mixin_parent) {
232 mixin_parent = window;
233 }
234
235 return mixins.map(function (mixin) {
236 return mixin_parent[mixin];
237 });
238 };
239 </script>
240 <?php
241 }
242
243 /**
244 * Include vue component templates
245 *
246 * @since 2.5
247 *
248 * @return void
249 */
250 public function admin_footer_js_templates() {
251 if ( !defined( 'WPUF_ASSET_URI' ) ) {
252 define( 'WPUF_ASSET_URI', WEFORMS_ROOT_URI . '/assets' );
253 }
254
255 include WEFORMS_ROOT . '/assets/wpuf/js-templates/form-components.php';
256 include WEFORMS_ROOT . '/assets/js-templates/form-components.php';
257 include WEFORMS_ROOT . '/assets/js-templates/spa-components.php';
258
259 do_action( 'wpuf-form-builder-add-js-templates' );
260 }
261
262 /**
263 * i18n translatable strings
264 *
265 * @since 2.5
266 *
267 * @return array
268 */
269 private function i18n() {
270 return apply_filters( 'wpuf-form-builder-i18n', [
271 'advanced_options' => __( 'Advanced Options', 'weforms' ),
272 'quiz_options' => __( 'Quiz Options', 'weforms' ),
273 'delete_field_warn_msg' => __( 'Are you sure you want to delete this field?', 'weforms' ),
274 'yes_delete_it' => __( 'Yes, delete it', 'weforms' ),
275 'no_cancel_it' => __( 'No, cancel it', 'weforms' ),
276 'ok' => __( 'OK', 'weforms' ),
277 'cancel' => __( 'Cancel', 'weforms' ),
278 'close' => __( 'Close', 'weforms' ),
279 'disable' => __( 'Disable', 'weforms' ),
280 'last_choice_warn_msg' => __( 'This field must contain at least one choice', 'weforms' ),
281 'option' => __( 'Option', 'weforms' ),
282 'row' => __( 'Row', 'weforms' ),
283 'column' => __( 'Column', 'weforms' ),
284 'last_column_warn_msg' => __( 'This field must contain at least one column', 'weforms' ),
285 'is_a_pro_feature' => __( 'is available in Pro version', 'weforms' ),
286 'pro_feature_msg' => __( 'Please upgrade to the Pro version to unlock all these awesome features', 'weforms' ),
287 'upgrade_to_pro' => __( 'Get the Pro version', 'weforms' ),
288 'select' => __( 'Select', 'weforms' ),
289 'saved_form_data' => __( 'Saved form data', 'weforms' ),
290 'unsaved_changes' => __( 'You have unsaved changes.', 'weforms' ),
291 'areYouSureToLeave' => __( 'Are you sure to leave this page?', 'weforms' ),
292 'copy_shortcode' => __( 'Click to copy shortcode', 'weforms' ),
293
294 'selectAnImage' => __( 'Select an image', 'weforms' ),
295 'pleaseSelectAnImage' => __( 'Please select an image', 'weforms' ),
296 'uploadAnImage' => __( 'Upload an image', 'weforms' ),
297
298 'shareYourForm' => __( 'Share Your Form', 'weforms' ),
299 'shareYourFormDesc' => __( 'Sharing your form enables <strong>anyone</strong> to view and submit the form without inserting the shortcode to a page.', 'weforms' ),
300 'shareYourFormText' => __( 'Anyone with this URL will be able to view and submit this form.', 'weforms' ),
301 'areYouSure' => __( 'Are you sure?', 'weforms' ),
302 'selectNotification' => __( 'You must select a notification', 'weforms' ),
303 'areYouSureDesc' => __( 'Anyone with existing URL won\'t be able to view and submit the form anymore.', 'weforms' ),
304 'disableSharing' => __( 'Disable Sharing', 'weforms' ),
305 ] );
306 }
307
308 /**
309 * Add buttons in form submit area
310 *
311 * @return void
312 */
313 public function add_form_submit_area() {
314 ?>
315 <input @click.prevent="" type="submit" name="submit" class="button button-primary" v-model="settings.submit_text">
316 <?php
317 }
318
319 /**
320 * Additional primary tabs
321 *
322 * @return void
323 */
324 public function add_primary_tabs() {
325 $tabs = apply_filters( 'wpuf_contact_form_editor_tabs', [
326 'notification' => __( 'Notifications', 'weforms' ),
327 'integration' => __( 'Integrations', 'weforms' ),
328 ] );
329
330 foreach ( $tabs as $key => $label ) {
331 ?>
332 <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>
333 <?php
334 }
335 }
336
337 public function add_primary_tab_contents() {
338 include __DIR__ . '/views/notification-integration.php';
339 }
340
341 /**
342 * Add settings tabs
343 *
344 * @return void
345 */
346 public function add_settings_tabs() {
347 ?>
348
349 <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>
350 <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>
351 <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>
352
353 <?php do_action( 'wpuf_contact_form_settings_tab' ); ?>
354
355 <?php
356 }
357
358 /**
359 * Add settings tabs
360 *
361 * @return void
362 */
363 public function add_settings_tab_contents() {
364 ?>
365 <div id="wpuf-metabox-settings" class="tab-content" v-show="isActiveSettingsTab('form')">
366 <?php include_once __DIR__ . '/views/form-settings.php'; ?>
367 </div>
368
369 <div id="wpuf-metabox-settings-restriction" class="tab-content" v-show="isActiveSettingsTab('restriction')">
370 <?php include_once __DIR__ . '/views/submission-restriction.php'; ?>
371 </div>
372
373 <div id="wpuf-metabox-settings-display" class="tab-content" v-show="isActiveSettingsTab('display')">
374 <?php include_once __DIR__ . '/views/display-settings.php'; ?>
375 </div>
376
377 <?php do_action( 'wpuf_contact_form_settings_tab_content' ); ?>
378
379 <?php
380 }
381
382 public function shortcodes( $type = '' ) {
383 $shortcodes = [];
384
385 $shortcodes['user'] = [
386 'title' => __( 'User', 'weforms' ),
387 'codes' => [
388 'first_name' => [ 'title' => __( 'First Name', 'weforms' ), 'default' => 'reader' ],
389 ],
390 ];
391
392 if ( !empty( $type ) && !empty( $shortcodes[ $type ] ) ) {
393 return $shortcodes[ $type ];
394 }
395
396 return $shortcodes;
397 }
398 }
399