PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.22
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.22
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 +29 -179 6.296.22 View file →
@@ -17,14 +17,11 @@
17 17 if ( ! $this->tracking_allowed() ) {
18 18 return;
19 19 }
20 20
21 - $snapshot = $this->snapshot();
22 - $this->clean_before_send( $snapshot );
23 -
24 21 $ep = 'aHR0cHM6Ly91c2FnZTIuZm9ybWlkYWJsZWZvcm1zLmNvbS9zbmFwc2hvdA==';
25 22 // $ep = base64_encode( 'http://localhost:4567/snapshot' ); // Uncomment for testing
26 - $body = json_encode( $snapshot );
23 + $body = json_encode( $this->snapshot() );
27 24
28 25 // Setup variable for wp_remote_request.
29 26 $post = array(
30 27 'method' => 'POST',
@@ -47,11 +44,8 @@
47 44 }
48 45
49 46 /**
50 47 * @since 3.06.04
51 - *
52 - * @param bool $regenerate
53 - *
54 48 * @return string
55 49 */
56 50 public function uuid( $regenerate = false ) {
57 51 $uuid_key = 'frm-usage-uuid';
@@ -56,13 +50,13 @@
56 50 public function uuid( $regenerate = false ) {
57 51 $uuid_key = 'frm-usage-uuid';
58 52 $uuid = get_option( $uuid_key );
59 53
60 - if ( $regenerate || ! $uuid ) {
54 + if ( $regenerate || empty( $uuid ) ) {
61 55 // Definitely not cryptographically secure but
62 - // close enough to provide a unique id
56 + // close enough to provide an unique id
63 57 $uuid = md5( uniqid() . site_url() );
64 - update_option( $uuid_key, $uuid, false );
58 + update_option( $uuid_key, $uuid, 'no' );
65 59 }
66 60
67 61 return $uuid;
68 62 }
@@ -68,9 +62,8 @@
68 62 }
69 63
70 64 /**
71 65 * @since 3.06.04
72 - *
73 66 * @return array
74 67 */
75 68 public function snapshot() {
76 69 global $wpdb, $wp_version;
@@ -79,8 +72,10 @@
79 72 $form_counts = FrmForm::get_count();
80 73
81 74 $snap = array(
82 75 'uuid' => $this->uuid(),
76 + // Let's keep it anonymous.
77 + 'admin_email' => '',
83 78 'wp_version' => $wp_version,
84 79 'php_version' => phpversion(),
85 80 'mysql_version' => $wpdb->db_version(),
86 81 'os' => FrmAppHelper::get_server_os(),
@@ -100,9 +95,8 @@
100 95 'fields' => $this->fields(),
101 96 'actions' => $this->actions(),
102 97
103 98 'onboarding-wizard' => $this->onboarding_wizard(),
104 - 'welcome-tour' => FrmWelcomeTourController::get_usage_data(),
105 99 'flows' => FrmUsageController::get_flows_data(),
106 100 'payments' => $this->payments(),
107 101 'subscriptions' => $this->payments( 'frm_subscriptions' ),
108 102 );
@@ -114,125 +108,8 @@
114 108 return apply_filters( 'frm_usage_snapshot', $snap );
115 109 }
116 110
117 111 /**
118 - * Cleans the snapshot data before sending.
119 - *
120 - * @param array $data Snapshot data.
121 - *
122 - * @return void
123 - */
124 - private function clean_before_send( &$data ) {
125 - $skip_keys = array(
126 - 'plan_id',
127 - 'paypal_item_name',
128 - 'account_num',
129 - 'routing_num',
130 - 'bank_name',
131 - 'business_email',
132 -
133 - // Form action settings.
134 - 'quiz',
135 - 'email_to',
136 - 'cc',
137 - 'bcc',
138 - 'from',
139 - 'email_subject',
140 - 'email_msg',
141 - 'email_message',
142 - 'success_msg',
143 - 'success_url',
144 - 'success_page_id',
145 - 'redirect_msg',
146 - 'conditions',
147 - 'list_id',
148 - 'api_key',
149 - 'url',
150 - 'data_fields',
151 - 'reg_email_msg',
152 -
153 - // Form settings.
154 - 'form_id',
155 - 'description',
156 - 'submit_conditions-hide_field',
157 - 'submit_conditions-hide_field_cond',
158 - 'submit_conditions-hide_opt',
159 - 'submit_conditions-show_hide',
160 - 'submit_conditions-any_all',
161 -
162 - // Field settings.
163 - 'show_hide',
164 - 'any_all',
165 - 'hide_field',
166 - 'hide_field_cond',
167 - 'hide_opt',
168 - 'custom_html',
169 - 'blank',
170 - 'required_indicator',
171 - 'invalid',
172 - 'unique_msg',
173 - 'edit_text',
174 - 'start_over_label',
175 - 'add_label',
176 - 'remove_label',
177 - 'draft',
178 - );
179 -
180 - /**
181 - * Filter the keys to skip when cleaning the snapshot data before sending.
182 - *
183 - * @since 6.28
184 - *
185 - * @param array $skip_keys Data keys.
186 - */
187 - $skip_keys = apply_filters( 'frm_usage_skip_keys', $skip_keys );
188 -
189 - $long_text_keys = array( 'description' );
190 -
191 - /**
192 - * Filter the keys to replace with a long text placeholder before sending.
193 - *
194 - * @since 6.28
195 - *
196 - * @paramm array $long_text_keys Data keys.
197 - */
198 - $long_text_keys = apply_filters( 'frm_usage_long_text_keys', $long_text_keys );
199 -
200 - foreach ( $data as $key => &$value ) {
201 - if ( ! $value ) {
202 - continue;
203 - }
204 -
205 - if ( in_array( $key, $skip_keys, true ) || str_ends_with( $key, '_url' ) ) {
206 - unset( $data[ $key ] );
207 - continue;
208 - }
209 -
210 - if ( is_object( $value ) ) {
211 - $value = '{{object}}';
212 - continue;
213 - }
214 -
215 - if ( is_array( $value ) ) {
216 - $this->clean_before_send( $value );
217 - continue;
218 - }
219 -
220 - if ( in_array( $key, $long_text_keys, true ) || str_ends_with( $key, '_msg' ) ) {
221 - // Replace it with a placeholder.
222 - $value = '{{long_text}}';
223 - continue;
224 - }
225 -
226 - // If key ends with `_email`, or value contains `@`, this might contain an email address.
227 - if ( str_ends_with( $key, '_email' ) || str_contains( $value, '@' ) ) {
228 - // Replace it with a placeholder.
229 - $value = '{{contain_email}}';
230 - }
231 - }//end foreach
232 - }
233 -
234 - /**
235 112 * Gets onboarding wizard data.
236 113 *
237 114 * @since 6.16.1
238 115 *
@@ -260,14 +137,12 @@
260 137 *
261 138 * @since 6.16.1
262 139 *
263 140 * @param string $table Database table name.
264 - *
265 141 * @return array
266 142 */
267 143 private function payments( $table = 'frm_payments' ) {
268 144 $allowed_tables = array( 'frm_payments', 'frm_subscriptions' );
269 -
270 145 if ( ! in_array( $table, $allowed_tables, true ) ) {
271 146 return array();
272 147 }
273 148
@@ -283,9 +158,8 @@
283 158 )
284 159 );
285 160
286 161 $payments = array();
287 -
288 162 foreach ( $rows as $row ) {
289 163 $payments[] = array(
290 164 'amount' => (float) $row->amount,
291 165 'status' => $row->status,
@@ -298,15 +172,14 @@
298 172 }
299 173
300 174 /**
301 175 * @since 3.06.04
302 - *
303 176 * @return array
304 177 */
305 178 private function plugins() {
306 179 $plugin_list = FrmAppHelper::get_plugins();
307 - $plugins = array();
308 180
181 + $plugins = array();
309 182 foreach ( $plugin_list as $slug => $info ) {
310 183 $plugins[] = array(
311 184 'name' => $info['Name'],
312 185 'slug' => $slug,
@@ -321,9 +194,8 @@
321 194 /**
322 195 * Add global settings to tracking data.
323 196 *
324 197 * @since 3.06.04
325 - *
326 198 * @return array
327 199 */
328 200 private function settings() {
329 201 $settings_list = FrmAppHelper::get_settings();
@@ -350,9 +222,8 @@
350 222 'active_captcha',
351 223 'honeypot',
352 224 'wp_spam_check',
353 225 'denylist_check',
354 - 'email_style',
355 226 );
356 227
357 228 foreach ( $pass_settings as $setting ) {
358 229 if ( isset( $settings_list->$setting ) ) {
@@ -373,9 +244,8 @@
373 244 *
374 245 * @since 3.06.04
375 246 *
376 247 * @param FrmSettings $settings_list
377 - *
378 248 * @return array
379 249 */
380 250 private function messages( $settings_list ) {
381 251 $messages = array(
@@ -388,11 +258,11 @@
388 258 'login_msg',
389 259 'admin_permission',
390 260 );
391 261
392 - $default = $settings_list->default_options();
262 + $default = $settings_list->default_options();
263 +
393 264 $message_settings = array();
394 -
395 265 foreach ( $messages as $message ) {
396 266 $message_settings[ 'changed-' . $message ] = $settings_list->$message === $default[ $message ] ? 0 : 1;
397 267 }
398 268
@@ -404,9 +274,8 @@
404 274 *
405 275 * @since 3.06.04
406 276 *
407 277 * @param FrmSettings $settings_list
408 - *
409 278 * @return array
410 279 */
411 280 private function permissions( $settings_list ) {
412 281 $permissions = array();
@@ -422,9 +291,8 @@
422 291 }
423 292
424 293 /**
425 294 * @since 3.06.04
426 - *
427 295 * @return array
428 296 */
429 297 private function forms() {
430 298 $s_query = array(
@@ -472,9 +340,8 @@
472 340 'submit_conditions',
473 341 );
474 342
475 343 $style = new FrmStyle();
476 -
477 344 foreach ( $saved_forms as $form ) {
478 345 $new_form = array(
479 346 'form_id' => $form->id,
480 347 'description' => $form->description,
@@ -486,31 +353,28 @@
486 353 'form_action_count' => $this->form_action_count( $form->id ),
487 354 );
488 355
489 356 foreach ( $settings as $setting ) {
490 - if ( ! isset( $form->options[ $setting ] ) ) {
491 - continue;
492 - }
357 + if ( isset( $form->options[ $setting ] ) ) {
358 + if ( 'custom_style' === $setting ) {
359 + $style->id = $form->options[ $setting ];
493 360
494 - if ( 'custom_style' !== $setting ) {
495 - $new_form[ $setting ] = $this->maybe_json( $form->options[ $setting ] );
496 - continue;
497 - }
361 + if ( ! $style->id ) {
362 + $style_name = 0;
363 + } elseif ( 1 === intval( $style->id ) ) {
364 + $style_name = 'formidable-style';
365 + } else {
366 + $style_post = $style->get_one();
367 + $style_name = $style_post ? $style_post->post_name : 'formidable-style';
368 + }
498 369
499 - $style->id = $form->options[ $setting ];
500 -
501 - if ( ! $style->id ) {
502 - $style_name = 0;
503 - } elseif ( 1 === intval( $style->id ) ) {
504 - $style_name = 'formidable-style';
505 - } else {
506 - $style_post = $style->get_one();
507 - $style_name = $style_post ? $style_post->post_name : 'formidable-style';
370 + $new_form[ $setting ] = $style_name;
371 + } else {
372 + $new_form[ $setting ] = $this->maybe_json( $form->options[ $setting ] );
373 + }
508 374 }
375 + }
509 376
510 - $new_form[ $setting ] = $style_name;
511 - }//end foreach
512 -
513 377 $forms[] = apply_filters( 'frm_usage_form', $new_form, compact( 'form' ) );
514 378 }//end foreach
515 379
516 380 // If the array uses numeric keys, reset them.
@@ -518,11 +382,8 @@
518 382 }
519 383
520 384 /**
521 385 * @since 3.06.04
522 - *
523 - * @param int|string $form_id Form ID.
524 - *
525 386 * @return int
526 387 */
527 388 private function form_field_count( $form_id ) {
528 389 global $wpdb;
@@ -539,11 +400,8 @@
539 400 }
540 401
541 402 /**
542 403 * @since 3.06.04
543 - *
544 - * @param int|string $form_id Form ID.
545 - *
546 404 * @return int
547 405 */
548 406 private function form_action_count( $form_id ) {
549 407 $args = array(
@@ -559,9 +417,8 @@
559 417 /**
560 418 * Get the last 100 fields created.
561 419 *
562 420 * @since 3.06.04
563 - *
564 421 * @return array
565 422 */
566 423 private function fields() {
567 424 $args = array(
@@ -569,20 +426,17 @@
569 426 'order_by' => 'id DESC',
570 427 );
571 428
572 429 $fields = FrmDb::get_results( 'frm_fields', array(), 'id, form_id, name, type, field_options', $args );
573 -
574 430 foreach ( $fields as $k => $field ) {
575 431 FrmAppHelper::unserialize_or_decode( $field->field_options );
576 - $fields[ $k ]->field_options = $field->field_options;
432 + $fields[ $k ]->field_options = json_encode( $field->field_options );
577 433 }
578 -
579 434 return $fields;
580 435 }
581 436
582 437 /**
583 438 * @since 3.06.04
584 - *
585 439 * @return array
586 440 */
587 441 private function actions() {
588 442 $args = array(
@@ -589,17 +443,17 @@
589 443 'post_type' => FrmFormActionsController::$action_post_type,
590 444 'numberposts' => 100,
591 445 );
592 446
593 - $actions = array();
447 + $actions = array();
448 +
594 449 $saved_actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
595 -
596 450 foreach ( $saved_actions as $action ) {
597 451 $actions[] = array(
598 452 'form_id' => $action->menu_order,
599 453 'type' => $action->post_excerpt,
600 454 'status' => $action->post_status,
601 - 'settings' => FrmAppHelper::maybe_json_decode( $action->post_content ),
455 + 'settings' => $action->post_content,
602 456 );
603 457 }
604 458
605 459 return $actions;
@@ -606,9 +460,8 @@
606 460 }
607 461
608 462 /**
609 463 * @since 3.06.04
610 - *
611 464 * @return bool
612 465 */
613 466 private function tracking_allowed() {
614 467 return FrmUsageController::tracking_allowed();
@@ -615,11 +468,8 @@
615 468 }
616 469
617 470 /**
618 471 * @since 3.06.04
619 - *
620 - * @param mixed $value Value.
621 - *
622 472 * @return string
623 473 */
624 474 private function maybe_json( $value ) {
625 475 return is_array( $value ) ? json_encode( $value ) : $value;