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

375 lines 14.0 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', 'wpuf' ),
258 'delete_field_warn_msg' => __( 'Are you sure you want to delete this field?', 'wpuf' ),
259 'yes_delete_it' => __( 'Yes, delete it', 'wpuf' ),
260 'no_cancel_it' => __( 'No, cancel it', 'wpuf' ),
261 'ok' => __( 'OK', 'wpuf' ),
262 'cancel' => __( 'Cancel', 'wpuf' ),
263 'close' => __( 'Close', 'wpuf' ),
264 'last_choice_warn_msg' => __( 'This field must contain at least one choice', 'wpuf' ),
265 'option' => __( 'Option', 'wpuf' ),
266 'row' => __( 'Row', 'wpuf' ),
267 'column' => __( 'Column', 'wpuf' ),
268 'last_column_warn_msg' => __( 'This field must contain at least one column', 'wpuf' ),
269 'is_a_pro_feature' => __( 'is available in Pro version', 'wpuf' ),
270 'pro_feature_msg' => __( 'Please upgrade to the Pro version to unlock all these awesome features', 'wpuf' ),
271 'upgrade_to_pro' => __( 'Get the Pro version', 'wpuf' ),
272 'select' => __( 'Select', 'wpuf' ),
273 'saved_form_data' => __( 'Saved form data', 'wpuf' ),
274 'unsaved_changes' => __( 'You have unsaved changes.', 'wpuf' ),
275 'copy_shortcode' => __( 'Click to copy shortcode', 'wpuf' ),
276
277 'selectAnImage' => __( 'Select an image', 'wpuf' ),
278 'pleaseSelectAnImage' => __( 'Please select an image', 'wpuf' ),
279 'uploadAnImage' => __( 'Upload an image', 'wpuf' ),
280 ) );
281 }
282
283 /**
284 * Add buttons in form submit area
285 *
286 * @return void
287 */
288 public function add_form_submit_area() {
289 ?>
290 <input @click.prevent="" type="submit" name="submit" v-model="settings.submit_text">
291 <?php
292 }
293
294 /**
295 * Additional primary tabs
296 *
297 * @return void
298 */
299 public function add_primary_tabs() {
300 $tabs = apply_filters( 'wpuf_contact_form_editor_tabs', array(
301 'notification' => __( 'Notifications', 'weforms' ),
302 'integration' => __( 'Integrations', 'weforms' )
303 ) );
304
305 foreach ($tabs as $key => $label) {
306 ?>
307 <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>
308 <?php
309 }
310 }
311
312 public function add_primary_tab_contents() {
313 include dirname( __FILE__ ) . '/views/notification-integration.php';
314 }
315
316 /**
317 * Add settings tabs
318 *
319 * @return void
320 */
321 public function add_settings_tabs() {
322 ?>
323
324 <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>
325 <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>
326 <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>
327
328 <?php do_action( 'wpuf_contact_form_settings_tab' ); ?>
329
330 <?php
331 }
332
333 /**
334 * Add settings tabs
335 *
336 * @return void
337 */
338 public function add_settings_tab_contents() {
339 ?>
340 <div id="wpuf-metabox-settings" class="tab-content" v-show="isActiveSettingsTab('form')">
341 <?php include_once dirname( __FILE__ ) . '/views/form-settings.php'; ?>
342 </div>
343
344 <div id="wpuf-metabox-settings-restriction" class="tab-content" v-show="isActiveSettingsTab('restriction')">
345 <?php include_once dirname( __FILE__ ) . '/views/submission-restriction.php'; ?>
346 </div>
347
348 <div id="wpuf-metabox-settings-display" class="tab-content" v-show="isActiveSettingsTab('display')">
349 <?php include_once dirname( __FILE__ ) . '/views/display-settings.php'; ?>
350 </div>
351
352 <?php do_action( 'wpuf_contact_form_settings_tab_content' ); ?>
353
354 <?php
355 }
356
357
358 public function shortcodes( $type = '' ) {
359 $shortcodes = [];
360
361 $shortcodes['user'] = [
362 'title' => __( 'User', 'wemail' ),
363 'codes' => [
364 'first_name' => [ 'title' => __( 'First Name', 'wemail' ), 'default' => 'reader' ],
365 ]
366 ];
367
368 if ( !empty( $type ) && !empty( $shortcodes[ $type ] ) ) {
369 return $shortcodes[ $type ];
370 }
371
372 return $shortcodes;
373 }
374 }
375