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

327 lines 12.3 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 'name' => 'Admin Notification',
45 'subject' => '[{from_name}] New Form Submission #{entry_id}',
46 'to' => '{admin_email}',
47 'replyTo' => '',
48 'message' => '{all_fields}',
49 'fromName' => '',
50 'fromAddress' => '{admin_email}',
51 'cc' => '',
52 'bcc' => ''
53 ),
54 'integrations' => weforms()->integrations->get_integration_js_settings(),
55 'recaptcha_site' => isset( $recaptcha->key ) ? $recaptcha->key : '',
56 'recaptcha_secret' => isset( $recaptcha->secret ) ? $recaptcha->secret : '',
57 ) );
58
59 // mixins
60 $wpuf_mixins = array(
61 'root' => apply_filters( 'weforms-builder-js-root-mixins', array( 'weforms_mixin_builder_root' ) ),
62 'builder_stage' => apply_filters( 'weforms-builder-js-builder-stage-mixins', array( 'weforms_mixin_builder_stage' ) ),
63 'form_fields' => apply_filters( 'weforms-builder-js-form-fields-mixins', array() ),
64 'field_options' => apply_filters( 'weforms-builder-js-field-options-mixins', array() ),
65 );
66
67 $weforms = apply_filters( 'weforms_localized_script', array(
68 'nonce' => wp_create_nonce( 'weforms' ),
69 'confirm' => __( 'Are you sure?', 'weforms' ),
70 'is_pro' => class_exists( 'WeForms_Pro' ) ? 'true' : 'false',
71 'routes' => $this->get_vue_routes(),
72 'routeComponents' => array( 'default' => null ),
73 'mixins' => array( 'default' => null )
74 ) );
75
76 wp_localize_script( 'wpuf-form-builder-mixins', 'wpuf_form_builder', $wpuf_form_builder );
77 wp_localize_script( 'wpuf-form-builder-mixins', 'wpuf_mixins', $wpuf_mixins );
78 wp_localize_script( 'weforms-mixins', 'weForms', $weforms );
79
80 do_action( 'weforms_admin_after_scripts_loaded' );
81 }
82
83 /**
84 * The pro url
85 *
86 * @return string
87 */
88 public static function get_pro_url() {
89 $link = 'https://wedevs.com/weforms-upgrade/';
90
91 if ( $aff = get_option( '_weforms_aff_ref' ) ) {
92 $link = add_query_arg( array( 'ref' => $aff ), $link );
93 }
94
95 return $link;
96 }
97
98 /**
99 * SPA Routes
100 *
101 * @return array
102 */
103 public function get_vue_routes() {
104 $routes = array(
105 array(
106 'path' => '/',
107 'name' => 'home',
108 'component' => 'Home'
109 ),
110 array(
111 'path' => '/form/:id',
112 'component' => 'FormHome',
113 'children' => array(
114 array(
115 'path' => '',
116 'name' => 'form',
117 'component' => 'SingleForm'
118 ),
119 array(
120 'path' => 'entries',
121 'component' => 'FormEntriesHome',
122 'children' => array(
123 array(
124 'path' => '',
125 'name' => 'formEntries',
126 'component' => 'FormEntries',
127 'props' => true
128 ),
129 array(
130 'path' => ':entryid',
131 'name' => 'formEntriesSingle',
132 'component' => 'FormEntriesSingle'
133 )
134 )
135 ),
136 array(
137 'path' => 'edit',
138 'name' => 'edit',
139 'component' => 'FormEditComponent'
140 )
141 )
142 ),
143 array(
144 'path' => '/tools',
145 'name' => 'tools',
146 'component' => 'Tools'
147 ),
148 array(
149 'path' => '/help',
150 'name' => 'help',
151 'component' => 'Help'
152 ),
153 array(
154 'path' => '/premium',
155 'name' => 'premium',
156 'component' => 'Premium'
157 ),
158 array(
159 'path' => '/settings',
160 'name' => 'settings',
161 'component' => 'Settings'
162 ),
163 );
164
165 return apply_filters( 'weforms_vue_routes', $routes );
166 }
167
168 /**
169 * Print js scripts in admin head
170 *
171 * @since 2.5
172 *
173 * @return void
174 */
175 public function builder_mixins_script() {
176 ?>
177 <script>
178 if (!window.Promise) {
179 var promise_polyfill = document.createElement('script');
180 promise_polyfill.setAttribute('src','https://cdn.polyfill.io/v2/polyfill.min.js');
181 document.head.appendChild(promise_polyfill);
182 }
183 </script>
184
185 <script>
186 var wpuf_form_builder_mixins = function(mixins, mixin_parent) {
187 if (!mixins || !mixins.length) {
188 return [];
189 }
190
191 if (!mixin_parent) {
192 mixin_parent = window;
193 }
194
195 return mixins.map(function (mixin) {
196 return mixin_parent[mixin];
197 });
198 };
199 </script>
200 <?php
201 }
202
203 /**
204 * Include vue component templates
205 *
206 * @since 2.5
207 *
208 * @return void
209 */
210 public function admin_footer_js_templates() {
211
212 if ( ! defined( 'WPUF_ASSET_URI' ) ) {
213 define( 'WPUF_ASSET_URI', WEFORMS_ROOT_URI . '/assets' );
214 }
215
216 include WEFORMS_ROOT . '/assets/wpuf/js-templates/form-components.php';
217 include WEFORMS_ROOT . '/assets/js-templates/form-components.php';
218 include WEFORMS_ROOT . '/assets/js-templates/spa-components.php';
219
220 do_action( 'wpuf-form-builder-add-js-templates' );
221 }
222
223 /**
224 * i18n translatable strings
225 *
226 * @since 2.5
227 *
228 * @return array
229 */
230 private function i18n() {
231 return apply_filters( 'wpuf-form-builder-i18n', array(
232 'advanced_options' => __( 'Advanced Options', 'wpuf' ),
233 'delete_field_warn_msg' => __( 'Are you sure you want to delete this field?', 'wpuf' ),
234 'yes_delete_it' => __( 'Yes, delete it', 'wpuf' ),
235 'no_cancel_it' => __( 'No, cancel it', 'wpuf' ),
236 'ok' => __( 'OK', 'wpuf' ),
237 'cancel' => __( 'Cancel', 'wpuf' ),
238 'close' => __( 'Close', 'wpuf' ),
239 'last_choice_warn_msg' => __( 'This field must contain at least one choice', 'wpuf' ),
240 'option' => __( 'Option', 'wpuf' ),
241 'column' => __( 'Column', 'wpuf' ),
242 'last_column_warn_msg' => __( 'This field must contain at least one column', 'wpuf' ),
243 'is_a_pro_feature' => __( 'is available in Pro version', 'wpuf' ),
244 'pro_feature_msg' => __( 'Please upgrade to the Pro version to unlock all these awesome features', 'wpuf' ),
245 'upgrade_to_pro' => __( 'Get the Pro version', 'wpuf' ),
246 'select' => __( 'Select', 'wpuf' ),
247 'saved_form_data' => __( 'Saved form data', 'wpuf' ),
248 'unsaved_changes' => __( 'You have unsaved changes.', 'wpuf' ),
249 'copy_shortcode' => __( 'Click to copy shortcode', 'wpuf' ),
250 ) );
251 }
252
253 /**
254 * Add buttons in form submit area
255 *
256 * @return void
257 */
258 public function add_form_submit_area() {
259 ?>
260 <input @click.prevent="" type="submit" name="submit" v-model="settings.submit_text">
261 <?php
262 }
263
264 /**
265 * Additional primary tabs
266 *
267 * @return void
268 */
269 public function add_primary_tabs() {
270 $tabs = apply_filters( 'wpuf_contact_form_editor_tabs', array(
271 'notification' => __( 'Notifications', 'weforms' ),
272 'integration' => __( 'Integrations', 'weforms' )
273 ) );
274
275 foreach ($tabs as $key => $label) {
276 ?>
277 <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>
278 <?php
279 }
280 }
281
282 public function add_primary_tab_contents() {
283 include dirname( __FILE__ ) . '/views/notification-integration.php';
284 }
285
286 /**
287 * Add settings tabs
288 *
289 * @return void
290 */
291 public function add_settings_tabs() {
292 ?>
293
294 <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>
295 <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>
296 <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>
297
298 <?php do_action( 'wpuf_contact_form_settings_tab' ); ?>
299
300 <?php
301 }
302
303 /**
304 * Add settings tabs
305 *
306 * @return void
307 */
308 public function add_settings_tab_contents() {
309 ?>
310 <div id="wpuf-metabox-settings" class="tab-content" v-show="isActiveSettingsTab('form')">
311 <?php include_once dirname( __FILE__ ) . '/views/form-settings.php'; ?>
312 </div>
313
314 <div id="wpuf-metabox-settings-restriction" class="tab-content" v-show="isActiveSettingsTab('restriction')">
315 <?php include_once dirname( __FILE__ ) . '/views/submission-restriction.php'; ?>
316 </div>
317
318 <div id="wpuf-metabox-settings-display" class="tab-content" v-show="isActiveSettingsTab('display')">
319 <?php include_once dirname( __FILE__ ) . '/views/display-settings.php'; ?>
320 </div>
321
322 <?php do_action( 'wpuf_contact_form_settings_tab_content' ); ?>
323
324 <?php
325 }
326 }
327