PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.0
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmUsage.php +59 -335 6.316.0 View file →
@@ -9,10 +9,8 @@
9 9 class FrmUsage {
10 10
11 11 /**
12 12 * @since 3.06.04
13 - *
14 - * @return void
15 13 */
16 14 public function send_snapshot() {
17 15 if ( ! $this->tracking_allowed() ) {
18 16 return;
@@ -17,41 +15,28 @@
17 15 if ( ! $this->tracking_allowed() ) {
18 16 return;
19 17 }
20 18
21 - $snapshot = $this->snapshot();
22 - $this->clean_before_send( $snapshot );
23 -
24 - $ep = 'aHR0cHM6Ly91c2FnZTIuZm9ybWlkYWJsZWZvcm1zLmNvbS9zbmFwc2hvdA==';
19 + $ep = 'aHR0cHM6Ly9mcm0tdXNlci10cmFja2luZy5oZXJva3VhcHAuY29tL3NuYXBzaG90';
25 20 // $ep = base64_encode( 'http://localhost:4567/snapshot' ); // Uncomment for testing
26 - $body = json_encode( $snapshot );
21 + $body = json_encode( $this->snapshot() );
27 22
28 23 // Setup variable for wp_remote_request.
29 24 $post = array(
30 - 'method' => 'POST',
31 - 'headers' => array(
25 + 'method' => 'POST',
26 + 'headers' => array(
32 27 'Accept' => 'application/json',
33 28 'Content-Type' => 'application/json',
34 29 'Content-Length' => strlen( $body ),
35 30 ),
36 - 'body' => $body,
37 - // Without this, Debug Log catches the `http_request_failed` error.
38 - 'timeout' => 45,
31 + 'body' => $body,
39 32 );
40 33
41 - // Remove time limit to execute this function.
42 - if ( function_exists( 'set_time_limit' ) ) {
43 - set_time_limit( 0 );
44 - }
45 -
46 34 wp_remote_request( base64_decode( $ep ), $post );
47 35 }
48 36
49 37 /**
50 38 * @since 3.06.04
51 - *
52 - * @param bool $regenerate
53 - *
54 39 * @return string
55 40 */
56 41 public function uuid( $regenerate = false ) {
57 42 $uuid_key = 'frm-usage-uuid';
@@ -56,13 +41,13 @@
56 41 public function uuid( $regenerate = false ) {
57 42 $uuid_key = 'frm-usage-uuid';
58 43 $uuid = get_option( $uuid_key );
59 44
60 - if ( $regenerate || ! $uuid ) {
45 + if ( $regenerate || empty( $uuid ) ) {
61 46 // Definitely not cryptographically secure but
62 - // close enough to provide a unique id
47 + // close enough to provide an unique id
63 48 $uuid = md5( uniqid() . site_url() );
64 - update_option( $uuid_key, $uuid, false );
49 + update_option( $uuid_key, $uuid, 'no' );
65 50 }
66 51
67 52 return $uuid;
68 53 }
@@ -68,9 +53,8 @@
68 53 }
69 54
70 55 /**
71 56 * @since 3.06.04
72 - *
73 57 * @return array
74 58 */
75 59 public function snapshot() {
76 60 global $wpdb, $wp_version;
@@ -78,259 +62,48 @@
78 62 $theme_data = wp_get_theme();
79 63 $form_counts = FrmForm::get_count();
80 64
81 65 $snap = array(
82 - 'uuid' => $this->uuid(),
83 - 'wp_version' => $wp_version,
84 - 'php_version' => phpversion(),
85 - 'mysql_version' => $wpdb->db_version(),
86 - 'os' => FrmAppHelper::get_server_os(),
87 - 'locale' => get_locale(),
66 + 'uuid' => $this->uuid(),
67 + 'admin_email' => '', // Let's keep it anonymous.
68 + 'wp_version' => $wp_version,
69 + 'php_version' => phpversion(),
70 + 'mysql_version' => $wpdb->db_version(),
71 + 'os' => php_uname( 's' ),
72 + 'locale' => get_locale(),
88 73
89 - 'active_license' => FrmAppHelper::pro_is_installed(),
90 - 'form_count' => $form_counts->published,
91 - 'entry_count' => FrmEntry::getRecordCount(),
92 - 'timestamp' => gmdate( 'c' ),
93 - 'misc' => array(),
74 + 'active_license' => FrmAppHelper::pro_is_installed(),
75 + 'form_count' => $form_counts->published,
76 + 'entry_count' => FrmEntry::getRecordCount(),
77 + 'timestamp' => gmdate( 'c' ),
94 78
95 - 'theme_name' => is_object( $theme_data ) ? $theme_data->Name : '', // phpcs:ignore WordPress.NamingConventions
96 - 'plugins' => $this->plugins(),
97 - 'settings' => array(
79 + 'theme_name' => is_object( $theme_data ) ? $theme_data->Name : '', // phpcs:ignore WordPress.NamingConventions
80 + 'plugins' => $this->plugins(),
81 + 'settings' => array(
98 82 $this->settings(),
99 83 ),
100 - 'forms' => $this->forms(),
101 - 'fields' => $this->fields(),
102 - 'actions' => $this->actions(),
103 -
104 - 'onboarding-wizard' => $this->onboarding_wizard(),
105 - 'welcome-tour' => FrmWelcomeTourController::get_usage_data(),
106 - 'flows' => FrmUsageController::get_flows_data(),
107 - 'payments' => $this->payments(),
108 - 'subscriptions' => $this->payments( 'frm_subscriptions' ),
84 + 'forms' => $this->forms(),
85 + 'fields' => $this->fields(),
86 + 'actions' => $this->actions(),
109 87 );
110 88
111 - if ( method_exists( 'FrmProAddonsController', 'get_readable_license_type' ) ) {
112 - $snap['active_license'] = FrmProAddonsController::get_readable_license_type();
113 - }
114 -
115 89 return apply_filters( 'frm_usage_snapshot', $snap );
116 90 }
117 91
118 92 /**
119 - * Cleans the snapshot data before sending.
120 - *
121 - * @param array $data Snapshot data.
122 - *
123 - * @return void
124 - */
125 - private function clean_before_send( &$data ) {
126 - $skip_keys = array(
127 - 'plan_id',
128 - 'paypal_item_name',
129 - 'account_num',
130 - 'routing_num',
131 - 'bank_name',
132 - 'business_email',
133 -
134 - // Form action settings.
135 - 'quiz',
136 - 'email_to',
137 - 'cc',
138 - 'bcc',
139 - 'from',
140 - 'email_subject',
141 - 'email_msg',
142 - 'email_message',
143 - 'success_msg',
144 - 'success_url',
145 - 'success_page_id',
146 - 'redirect_msg',
147 - 'conditions',
148 - 'list_id',
149 - 'api_key',
150 - 'url',
151 - 'data_fields',
152 - 'reg_email_msg',
153 -
154 - // Form settings.
155 - 'form_id',
156 - 'description',
157 - 'submit_conditions-hide_field',
158 - 'submit_conditions-hide_field_cond',
159 - 'submit_conditions-hide_opt',
160 - 'submit_conditions-show_hide',
161 - 'submit_conditions-any_all',
162 -
163 - // Field settings.
164 - 'show_hide',
165 - 'any_all',
166 - 'hide_field',
167 - 'hide_field_cond',
168 - 'hide_opt',
169 - 'custom_html',
170 - 'blank',
171 - 'required_indicator',
172 - 'invalid',
173 - 'unique_msg',
174 - 'edit_text',
175 - 'start_over_label',
176 - 'add_label',
177 - 'remove_label',
178 - 'draft',
179 - );
180 -
181 - /**
182 - * Filter the keys to skip when cleaning the snapshot data before sending.
183 - *
184 - * @since 6.28
185 - *
186 - * @param array $skip_keys Data keys.
187 - */
188 - $skip_keys = apply_filters( 'frm_usage_skip_keys', $skip_keys );
189 -
190 - $long_text_keys = array( 'description' );
191 -
192 - /**
193 - * Filter the keys to replace with a long text placeholder before sending.
194 - *
195 - * @since 6.28
196 - *
197 - * @paramm array $long_text_keys Data keys.
198 - */
199 - $long_text_keys = apply_filters( 'frm_usage_long_text_keys', $long_text_keys );
200 -
201 - foreach ( $data as $key => &$value ) {
202 - if ( ! $value ) {
203 - continue;
204 - }
205 -
206 - if ( in_array( $key, $skip_keys, true ) || str_ends_with( $key, '_url' ) ) {
207 - unset( $data[ $key ] );
208 - continue;
209 - }
210 -
211 - if ( is_object( $value ) ) {
212 - $value = '{{object}}';
213 - continue;
214 - }
215 -
216 - if ( is_array( $value ) ) {
217 - $this->clean_before_send( $value );
218 - continue;
219 - }
220 -
221 - if ( in_array( $key, $long_text_keys, true ) || str_ends_with( $key, '_msg' ) ) {
222 - // Replace it with a placeholder.
223 - $value = '{{long_text}}';
224 - continue;
225 - }
226 -
227 - // If key ends with `_email`, or value contains `@`, this might contain an email address.
228 - if ( str_ends_with( $key, '_email' ) || str_contains( $value, '@' ) ) {
229 - // Replace it with a placeholder.
230 - $value = '{{contain_email}}';
231 - }
232 - }//end foreach
233 - }
234 -
235 - /**
236 - * Gets onboarding wizard data.
237 - *
238 - * @since 6.16.1
239 - *
240 - * @return array
241 - */
242 - private function onboarding_wizard() {
243 - $data = FrmOnboardingWizardController::get_usage_data();
244 - $skipped_keys = array(
245 - 'default_email',
246 - 'is_subscribed',
247 - 'allows_tracking',
248 - 'summary_emails',
249 - 'installed_addons',
250 - );
251 -
252 - foreach ( $skipped_keys as $skipped_key ) {
253 - unset( $data[ $skipped_key ] );
254 - }
255 -
256 - return $data;
257 - }
258 -
259 - /**
260 - * Gets payments data.
261 - *
262 - * @since 6.16.1
263 - *
264 - * @param string $table Database table name.
265 - *
266 - * @return array
267 - */
268 - private function payments( $table = 'frm_payments' ) {
269 - $allowed_tables = array( 'frm_payments', 'frm_subscriptions' );
270 -
271 - if ( ! in_array( $table, $allowed_tables, true ) || ! FrmTransLiteAppHelper::payments_table_exists() ) {
272 - return array();
273 - }
274 -
275 - $rows = $this->get_payment_db_rows( $table );
276 - $payments = array();
277 -
278 - foreach ( $rows as $row ) {
279 - $payments[] = array(
280 - 'amount' => (float) $row->amount,
281 - 'status' => $row->status,
282 - 'gateway' => $row->paysys,
283 - 'created_at' => $row->created_at,
284 - );
285 - }
286 -
287 - return $payments;
288 - }
289 -
290 - /**
291 - * @since 6.30
292 - *
293 - * @param string $table
294 - *
295 - * @return array
296 - */
297 - private function get_payment_db_rows( $table ) {
298 - global $wpdb;
299 -
300 - if ( FrmDb::db_column_exists( $table, 'test' ) ) {
301 - return $wpdb->get_results(
302 - $wpdb->prepare(
303 - 'SELECT amount, status, paysys, created_at FROM %i WHERE test IS NULL OR test != 1',
304 - $wpdb->prefix . $table
305 - )
306 - );
307 - }
308 -
309 - // Fallback for PayPal add-on where this column does not exist.
310 - return $wpdb->get_results(
311 - $wpdb->prepare(
312 - 'SELECT amount, status, paysys, created_at FROM %i',
313 - $wpdb->prefix . $table
314 - )
315 - );
316 - }
317 -
318 - /**
319 93 * @since 3.06.04
320 - *
321 94 * @return array
322 95 */
323 96 private function plugins() {
324 97 $plugin_list = FrmAppHelper::get_plugins();
325 - $plugins = array();
326 98
99 + $plugins = array();
327 100 foreach ( $plugin_list as $slug => $info ) {
328 101 $plugins[] = array(
329 - 'name' => $info['Name'],
330 - 'slug' => $slug,
331 - 'version' => $info['Version'],
332 - 'active' => is_plugin_active( $slug ),
102 + 'name' => $info['Name'],
103 + 'slug' => $slug,
104 + 'version' => $info['Version'],
105 + 'active' => is_plugin_active( $slug ),
333 106 );
334 107 }
335 108
336 109 return $plugins;
@@ -339,20 +112,21 @@
339 112 /**
340 113 * Add global settings to tracking data.
341 114 *
342 115 * @since 3.06.04
343 - *
344 116 * @return array
345 117 */
346 118 private function settings() {
347 - $settings_list = FrmAppHelper::get_settings();
348 - $settings = array(
119 + $settings_list = FrmAppHelper::get_settings();
120 + $settings = array(
349 121 'messages' => $this->messages( $settings_list ),
350 122 'permissions' => $this->permissions( $settings_list ),
351 123 );
352 124 $pass_settings = array(
353 125 'load_style',
126 + 'use_html',
354 127 'fade_form',
128 + 'jquery_css',
355 129 're_type',
356 130 're_lang',
357 131 're_multi',
358 132 'menu',
@@ -357,20 +131,11 @@
357 131 're_multi',
358 132 'menu',
359 133 'mu_menu',
360 134 'no_ips',
361 - 'custom_header_ip',
362 - 'enable_gdpr',
363 - 'no_gdpr_cookies',
364 135 'btsp_css',
365 - 'btsp_version',
136 + 'btsp_errors',
366 137 'admin_bar',
367 - 'summary_emails',
368 - 'active_captcha',
369 - 'honeypot',
370 - 'wp_spam_check',
371 - 'denylist_check',
372 - 'email_style',
373 138 );
374 139
375 140 foreach ( $pass_settings as $setting ) {
376 141 if ( isset( $settings_list->$setting ) ) {
@@ -389,11 +154,8 @@
389 154 /**
390 155 * Include the permissions settings for each capability.
391 156 *
392 157 * @since 3.06.04
393 - *
394 - * @param FrmSettings $settings_list
395 - *
396 158 * @return array
397 159 */
398 160 private function messages( $settings_list ) {
399 161 $messages = array(
@@ -406,13 +168,11 @@
406 168 'login_msg',
407 169 'admin_permission',
408 170 );
409 171
410 - $default = $settings_list->default_options();
411 172 $message_settings = array();
412 -
413 173 foreach ( $messages as $message ) {
414 - $message_settings[ 'changed-' . $message ] = $settings_list->$message === $default[ $message ] ? 0 : 1;
174 + $message_settings[ $message ] = $settings_list->$message;
415 175 }
416 176
417 177 return $message_settings;
418 178 }
@@ -420,11 +180,8 @@
420 180 /**
421 181 * Include the permissions settings for each capability.
422 182 *
423 183 * @since 3.06.04
424 - *
425 - * @param FrmSettings $settings_list
426 - *
427 184 * @return array
428 185 */
429 186 private function permissions( $settings_list ) {
430 187 $permissions = array();
@@ -440,16 +197,15 @@
440 197 }
441 198
442 199 /**
443 200 * @since 3.06.04
444 - *
445 201 * @return array
446 202 */
447 203 private function forms() {
448 204 $s_query = array(
449 205 array(
450 - 'or' => 1,
451 - 'parent_form_id' => null,
206 + 'or' => 1,
207 + 'parent_form_id' => null,
452 208 'parent_form_id <' => 1,
453 209 ),
454 210 );
455 211
@@ -457,10 +213,10 @@
457 213 $forms = array();
458 214 $settings = array(
459 215 'form_class',
460 216 'akismet',
217 + 'honeypot',
461 218 'antispam',
462 - 'stopforumspam',
463 219 'custom_style',
464 220 'success_action',
465 221 'show_form',
466 222 'no_save',
@@ -489,48 +245,28 @@
489 245 'prev_value',
490 246 'submit_conditions',
491 247 );
492 248
493 - $style = new FrmStyle();
494 -
495 249 foreach ( $saved_forms as $form ) {
496 250 $new_form = array(
497 - 'form_id' => $form->id,
498 - 'description' => $form->description,
499 - 'logged_in' => $form->logged_in,
500 - 'editable' => $form->editable,
501 - 'is_template' => $form->is_template,
502 - 'entry_count' => FrmEntry::getRecordCount( $form->id ),
503 - 'field_count' => $this->form_field_count( $form->id ),
251 + 'form_id' => $form->id,
252 + 'description' => $form->description,
253 + 'logged_in' => $form->logged_in,
254 + 'editable' => $form->editable,
255 + 'is_template' => $form->is_template,
256 + 'entry_count' => FrmEntry::getRecordCount( $form->id ),
257 + 'field_count' => $this->form_field_count( $form->id ),
504 258 'form_action_count' => $this->form_action_count( $form->id ),
505 259 );
506 260
507 261 foreach ( $settings as $setting ) {
508 - if ( ! isset( $form->options[ $setting ] ) ) {
509 - continue;
510 - }
511 -
512 - if ( 'custom_style' !== $setting ) {
262 + if ( isset( $form->options[ $setting ] ) ) {
513 263 $new_form[ $setting ] = $this->maybe_json( $form->options[ $setting ] );
514 - continue;
515 264 }
265 + }
516 266
517 - $style->id = $form->options[ $setting ];
518 -
519 - if ( ! $style->id ) {
520 - $style_name = 0;
521 - } elseif ( 1 === intval( $style->id ) ) {
522 - $style_name = 'formidable-style';
523 - } else {
524 - $style_post = $style->get_one();
525 - $style_name = $style_post ? $style_post->post_name : 'formidable-style';
526 - }
527 -
528 - $new_form[ $setting ] = $style_name;
529 - }//end foreach
530 -
531 267 $forms[] = apply_filters( 'frm_usage_form', $new_form, compact( 'form' ) );
532 - }//end foreach
268 + }
533 269
534 270 // If the array uses numeric keys, reset them.
535 271 return $forms;
536 272 }
@@ -536,17 +272,14 @@
536 272 }
537 273
538 274 /**
539 275 * @since 3.06.04
540 - *
541 - * @param int|string $form_id Form ID.
542 - *
543 276 * @return int
544 277 */
545 278 private function form_field_count( $form_id ) {
546 279 global $wpdb;
547 280
548 - $join = $wpdb->prefix . 'frm_fields fi JOIN ' . $wpdb->prefix . 'frm_forms fo ON (fi.form_id=fo.id)';
281 + $join = $wpdb->prefix . 'frm_fields fi LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fo ON (fi.form_id=fo.id)';
549 282
550 283 $field_query = array(
551 284 'or' => 1,
552 285 'fi.form_id' => $form_id,
@@ -557,11 +290,8 @@
557 290 }
558 291
559 292 /**
560 293 * @since 3.06.04
561 - *
562 - * @param int|string $form_id Form ID.
563 - *
564 294 * @return int
565 295 */
566 296 private function form_action_count( $form_id ) {
567 297 $args = array(
@@ -577,30 +307,26 @@
577 307 /**
578 308 * Get the last 100 fields created.
579 309 *
580 310 * @since 3.06.04
581 - *
582 311 * @return array
583 312 */
584 313 private function fields() {
585 - $args = array(
314 + $args = array(
586 315 'limit' => 50,
587 316 'order_by' => 'id DESC',
588 317 );
589 318
590 - $fields = FrmDb::get_results( 'frm_fields', array(), 'id, form_id, name, type, field_options', $args );
591 -
319 + $fields = FrmDb::get_results( 'frm_fields', array(), 'form_id, name, type, field_options', $args );
592 320 foreach ( $fields as $k => $field ) {
593 321 FrmAppHelper::unserialize_or_decode( $field->field_options );
594 - $fields[ $k ]->field_options = $field->field_options;
322 + $fields[ $k ]->field_options = json_encode( $field->field_options );
595 323 }
596 -
597 324 return $fields;
598 325 }
599 326
600 327 /**
601 328 * @since 3.06.04
602 - *
603 329 * @return array
604 330 */
605 331 private function actions() {
606 332 $args = array(
@@ -607,17 +333,17 @@
607 333 'post_type' => FrmFormActionsController::$action_post_type,
608 334 'numberposts' => 100,
609 335 );
610 336
611 - $actions = array();
337 + $actions = array();
338 +
612 339 $saved_actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
613 -
614 340 foreach ( $saved_actions as $action ) {
615 341 $actions[] = array(
616 342 'form_id' => $action->menu_order,
617 343 'type' => $action->post_excerpt,
618 344 'status' => $action->post_status,
619 - 'settings' => FrmAppHelper::maybe_json_decode( $action->post_content ),
345 + 'settings' => $action->post_content,
620 346 );
621 347 }
622 348
623 349 return $actions;
@@ -624,20 +350,17 @@
624 350 }
625 351
626 352 /**
627 353 * @since 3.06.04
628 - *
629 354 * @return bool
630 355 */
631 356 private function tracking_allowed() {
632 - return FrmUsageController::tracking_allowed();
357 + $settings = FrmAppHelper::get_settings();
358 + return $settings->tracking;
633 359 }
634 360
635 361 /**
636 362 * @since 3.06.04
637 - *
638 - * @param mixed $value Value.
639 - *
640 363 * @return string
641 364 */
642 365 private function maybe_json( $value ) {
643 366 return is_array( $value ) ? json_encode( $value ) : $value;
@@ -642,4 +365,5 @@
642 365 private function maybe_json( $value ) {
643 366 return is_array( $value ) ? json_encode( $value ) : $value;
644 367 }
645 368 }
369 +