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

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