PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.16
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.16
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 +24 -261 6.286.16 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 - $ep = 'aHR0cHM6Ly91c2FnZTIuZm9ybWlkYWJsZWZvcm1zLmNvbS9zbmFwc2hvdA==';
21 + $ep = 'aHR0cHM6Ly91c2FnZS5mb3JtaWRhYmxlZm9ybXMuY29tL2FwcC9zbmFwc2hvdAo=';
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',
@@ -33,25 +30,15 @@
33 30 'Content-Type' => 'application/json',
34 31 'Content-Length' => strlen( $body ),
35 32 ),
36 33 'body' => $body,
37 - // Without this, Debug Log catches the `http_request_failed` error.
38 - 'timeout' => 45,
39 34 );
40 35
41 - // Remove time limit to execute this function.
42 - if ( function_exists( 'set_time_limit' ) ) {
43 - set_time_limit( 0 );
44 - }
45 -
46 36 wp_remote_request( base64_decode( $ep ), $post );
47 37 }
48 38
49 39 /**
50 40 * @since 3.06.04
51 - *
52 - * @param bool $regenerate
53 - *
54 41 * @return string
55 42 */
56 43 public function uuid( $regenerate = false ) {
57 44 $uuid_key = 'frm-usage-uuid';
@@ -56,13 +43,13 @@
56 43 public function uuid( $regenerate = false ) {
57 44 $uuid_key = 'frm-usage-uuid';
58 45 $uuid = get_option( $uuid_key );
59 46
60 - if ( $regenerate || ! $uuid ) {
47 + if ( $regenerate || empty( $uuid ) ) {
61 48 // Definitely not cryptographically secure but
62 - // close enough to provide a unique id
49 + // close enough to provide an unique id
63 50 $uuid = md5( uniqid() . site_url() );
64 - update_option( $uuid_key, $uuid, false );
51 + update_option( $uuid_key, $uuid, 'no' );
65 52 }
66 53
67 54 return $uuid;
68 55 }
@@ -68,9 +55,8 @@
68 55 }
69 56
70 57 /**
71 58 * @since 3.06.04
72 - *
73 59 * @return array
74 60 */
75 61 public function snapshot() {
76 62 global $wpdb, $wp_version;
@@ -79,8 +65,10 @@
79 65 $form_counts = FrmForm::get_count();
80 66
81 67 $snap = array(
82 68 'uuid' => $this->uuid(),
69 + // Let's keep it anonymous.
70 + 'admin_email' => '',
83 71 'wp_version' => $wp_version,
84 72 'php_version' => phpversion(),
85 73 'mysql_version' => $wpdb->db_version(),
86 74 'os' => FrmAppHelper::get_server_os(),
@@ -99,204 +87,22 @@
99 87 'forms' => $this->forms(),
100 88 'fields' => $this->fields(),
101 89 'actions' => $this->actions(),
102 90
103 - 'onboarding-wizard' => $this->onboarding_wizard(),
104 - 'welcome-tour' => FrmWelcomeTourController::get_usage_data(),
105 - 'flows' => FrmUsageController::get_flows_data(),
106 - 'payments' => $this->payments(),
107 - 'subscriptions' => $this->payments( 'frm_subscriptions' ),
91 + 'onboarding-wizard' => FrmOnboardingWizardController::get_usage_data(),
108 92 );
109 93
110 - if ( method_exists( 'FrmProAddonsController', 'get_readable_license_type' ) ) {
111 - $snap['active_license'] = FrmProAddonsController::get_readable_license_type();
112 - }
113 -
114 94 return apply_filters( 'frm_usage_snapshot', $snap );
115 95 }
116 96
117 97 /**
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 || in_array( $key, $skip_keys, true ) || str_ends_with( $key, '_url' ) ) {
202 - continue;
203 - }
204 -
205 - if ( is_array( $value ) ) {
206 - $this->clean_before_send( $value );
207 - continue;
208 - }
209 -
210 - if ( in_array( $key, $long_text_keys, true ) || str_ends_with( $key, '_msg' ) ) {
211 - // Replace it with a placeholder.
212 - $value = '{{long_text}}';
213 - continue;
214 - }
215 -
216 - // If key ends with `_email`, or value contains `@`, this might contain an email address.
217 - if ( str_ends_with( $key, '_email' ) || str_contains( $value, '@' ) ) {
218 - // Replace it with a placeholder.
219 - $value = '{{contain_email}}';
220 - }
221 - }//end foreach
222 - }
223 -
224 - /**
225 - * Gets onboarding wizard data.
226 - *
227 - * @since 6.16.1
228 - *
229 - * @return array
230 - */
231 - private function onboarding_wizard() {
232 - $data = FrmOnboardingWizardController::get_usage_data();
233 - $skipped_keys = array(
234 - 'default_email',
235 - 'is_subscribed',
236 - 'allows_tracking',
237 - 'summary_emails',
238 - 'installed_addons',
239 - );
240 -
241 - foreach ( $skipped_keys as $skipped_key ) {
242 - unset( $data[ $skipped_key ] );
243 - }
244 -
245 - return $data;
246 - }
247 -
248 - /**
249 - * Gets payments data.
250 - *
251 - * @since 6.16.1
252 - *
253 - * @param string $table Database table name.
254 - *
255 - * @return array
256 - */
257 - private function payments( $table = 'frm_payments' ) {
258 - $allowed_tables = array( 'frm_payments', 'frm_subscriptions' );
259 -
260 - if ( ! in_array( $table, $allowed_tables, true ) ) {
261 - return array();
262 - }
263 -
264 - if ( ! FrmTransLiteAppHelper::payments_table_exists() ) {
265 - return array();
266 - }
267 -
268 - global $wpdb;
269 - $rows = $wpdb->get_results(
270 - $wpdb->prepare(
271 - 'SELECT amount, status, paysys, created_at FROM %1$s',
272 - $wpdb->prefix . $table
273 - )
274 - );
275 -
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 98 * @since 3.06.04
292 - *
293 99 * @return array
294 100 */
295 101 private function plugins() {
296 102 $plugin_list = FrmAppHelper::get_plugins();
297 - $plugins = array();
298 103
104 + $plugins = array();
299 105 foreach ( $plugin_list as $slug => $info ) {
300 106 $plugins[] = array(
301 107 'name' => $info['Name'],
302 108 'slug' => $slug,
@@ -311,9 +117,8 @@
311 117 /**
312 118 * Add global settings to tracking data.
313 119 *
314 120 * @since 3.06.04
315 - *
316 121 * @return array
317 122 */
318 123 private function settings() {
319 124 $settings_list = FrmAppHelper::get_settings();
@@ -322,9 +127,11 @@
322 127 'permissions' => $this->permissions( $settings_list ),
323 128 );
324 129 $pass_settings = array(
325 130 'load_style',
131 + 'use_html',
326 132 'fade_form',
133 + 'jquery_css',
327 134 're_type',
328 135 're_lang',
329 136 're_multi',
330 137 'menu',
@@ -329,20 +136,11 @@
329 136 're_multi',
330 137 'menu',
331 138 'mu_menu',
332 139 'no_ips',
333 - 'custom_header_ip',
334 - 'enable_gdpr',
335 - 'no_gdpr_cookies',
336 140 'btsp_css',
337 - 'btsp_version',
141 + 'btsp_errors',
338 142 'admin_bar',
339 - 'summary_emails',
340 - 'active_captcha',
341 - 'honeypot',
342 - 'wp_spam_check',
343 - 'denylist_check',
344 - 'email_style',
345 143 );
346 144
347 145 foreach ( $pass_settings as $setting ) {
348 146 if ( isset( $settings_list->$setting ) ) {
@@ -363,9 +161,8 @@
363 161 *
364 162 * @since 3.06.04
365 163 *
366 164 * @param FrmSettings $settings_list
367 - *
368 165 * @return array
369 166 */
370 167 private function messages( $settings_list ) {
371 168 $messages = array(
@@ -378,13 +175,11 @@
378 175 'login_msg',
379 176 'admin_permission',
380 177 );
381 178
382 - $default = $settings_list->default_options();
383 179 $message_settings = array();
384 -
385 180 foreach ( $messages as $message ) {
386 - $message_settings[ 'changed-' . $message ] = $settings_list->$message === $default[ $message ] ? 0 : 1;
181 + $message_settings[ $message ] = $settings_list->$message;
387 182 }
388 183
389 184 return $message_settings;
390 185 }
@@ -394,9 +189,8 @@
394 189 *
395 190 * @since 3.06.04
396 191 *
397 192 * @param FrmSettings $settings_list
398 - *
399 193 * @return array
400 194 */
401 195 private function permissions( $settings_list ) {
402 196 $permissions = array();
@@ -412,9 +206,8 @@
412 206 }
413 207
414 208 /**
415 209 * @since 3.06.04
416 - *
417 210 * @return array
418 211 */
419 212 private function forms() {
420 213 $s_query = array(
@@ -429,10 +222,10 @@
429 222 $forms = array();
430 223 $settings = array(
431 224 'form_class',
432 225 'akismet',
226 + 'honeypot',
433 227 'antispam',
434 - 'stopforumspam',
435 228 'custom_style',
436 229 'success_action',
437 230 'show_form',
438 231 'no_save',
@@ -461,10 +254,8 @@
461 254 'prev_value',
462 255 'submit_conditions',
463 256 );
464 257
465 - $style = new FrmStyle();
466 -
467 258 foreach ( $saved_forms as $form ) {
468 259 $new_form = array(
469 260 'form_id' => $form->id,
470 261 'description' => $form->description,
@@ -477,29 +268,14 @@
477 268 );
478 269
479 270 foreach ( $settings as $setting ) {
480 271 if ( isset( $form->options[ $setting ] ) ) {
481 - if ( 'custom_style' === $setting ) {
482 - $style->id = $form->options[ $setting ];
483 -
484 - if ( ! $style->id ) {
485 - $style_name = 0;
486 - } elseif ( 1 === intval( $style->id ) ) {
487 - $style_name = 'formidable-style';
488 - } else {
489 - $style_post = $style->get_one();
490 - $style_name = $style_post ? $style_post->post_name : 'formidable-style';
491 - }
492 -
493 - $new_form[ $setting ] = $style_name;
494 - } else {
495 - $new_form[ $setting ] = $this->maybe_json( $form->options[ $setting ] );
496 - }
272 + $new_form[ $setting ] = $this->maybe_json( $form->options[ $setting ] );
497 273 }
498 274 }
499 275
500 276 $forms[] = apply_filters( 'frm_usage_form', $new_form, compact( 'form' ) );
501 - }//end foreach
277 + }
502 278
503 279 // If the array uses numeric keys, reset them.
504 280 return $forms;
505 281 }
@@ -505,17 +281,14 @@
505 281 }
506 282
507 283 /**
508 284 * @since 3.06.04
509 - *
510 - * @param int|string $form_id Form ID.
511 - *
512 285 * @return int
513 286 */
514 287 private function form_field_count( $form_id ) {
515 288 global $wpdb;
516 289
517 - $join = $wpdb->prefix . 'frm_fields fi JOIN ' . $wpdb->prefix . 'frm_forms fo ON (fi.form_id=fo.id)';
290 + $join = $wpdb->prefix . 'frm_fields fi LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fo ON (fi.form_id=fo.id)';
518 291
519 292 $field_query = array(
520 293 'or' => 1,
521 294 'fi.form_id' => $form_id,
@@ -526,11 +299,8 @@
526 299 }
527 300
528 301 /**
529 302 * @since 3.06.04
530 - *
531 - * @param int|string $form_id Form ID.
532 - *
533 303 * @return int
534 304 */
535 305 private function form_action_count( $form_id ) {
536 306 $args = array(
@@ -546,9 +316,8 @@
546 316 /**
547 317 * Get the last 100 fields created.
548 318 *
549 319 * @since 3.06.04
550 - *
551 320 * @return array
552 321 */
553 322 private function fields() {
554 323 $args = array(
@@ -555,21 +324,18 @@
555 324 'limit' => 50,
556 325 'order_by' => 'id DESC',
557 326 );
558 327
559 - $fields = FrmDb::get_results( 'frm_fields', array(), 'id, form_id, name, type, field_options', $args );
560 -
328 + $fields = FrmDb::get_results( 'frm_fields', array(), 'form_id, name, type, field_options', $args );
561 329 foreach ( $fields as $k => $field ) {
562 330 FrmAppHelper::unserialize_or_decode( $field->field_options );
563 - $fields[ $k ]->field_options = $field->field_options;
331 + $fields[ $k ]->field_options = json_encode( $field->field_options );
564 332 }
565 -
566 333 return $fields;
567 334 }
568 335
569 336 /**
570 337 * @since 3.06.04
571 - *
572 338 * @return array
573 339 */
574 340 private function actions() {
575 341 $args = array(
@@ -576,17 +342,17 @@
576 342 'post_type' => FrmFormActionsController::$action_post_type,
577 343 'numberposts' => 100,
578 344 );
579 345
580 - $actions = array();
346 + $actions = array();
347 +
581 348 $saved_actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
582 -
583 349 foreach ( $saved_actions as $action ) {
584 350 $actions[] = array(
585 351 'form_id' => $action->menu_order,
586 352 'type' => $action->post_excerpt,
587 353 'status' => $action->post_status,
588 - 'settings' => FrmAppHelper::maybe_json_decode( $action->post_content ),
354 + 'settings' => $action->post_content,
589 355 );
590 356 }
591 357
592 358 return $actions;
@@ -593,20 +359,17 @@
593 359 }
594 360
595 361 /**
596 362 * @since 3.06.04
597 - *
598 363 * @return bool
599 364 */
600 365 private function tracking_allowed() {
601 - return FrmUsageController::tracking_allowed();
366 + $settings = FrmAppHelper::get_settings();
367 + return $settings->tracking;
602 368 }
603 369
604 370 /**
605 371 * @since 3.06.04
606 - *
607 - * @param mixed $value Value.
608 - *
609 372 * @return string
610 373 */
611 374 private function maybe_json( $value ) {
612 375 return is_array( $value ) ? json_encode( $value ) : $value;