PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.2
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 +60 -297 6.286.2 View file →
@@ -17,41 +17,28 @@
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 = 'aHR0cHM6Ly9mcm0tdXNlci10cmFja2luZy5oZXJva3VhcHAuY29tL3NuYXBzaG90';
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 - 'method' => 'POST',
31 - 'headers' => array(
27 + 'method' => 'POST',
28 + 'headers' => array(
32 29 'Accept' => 'application/json',
33 30 'Content-Type' => 'application/json',
34 31 'Content-Length' => strlen( $body ),
35 32 ),
36 - 'body' => $body,
37 - // Without this, Debug Log catches the `http_request_failed` error.
38 - 'timeout' => 45,
33 + 'body' => $body,
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;
@@ -78,231 +64,48 @@
78 64 $theme_data = wp_get_theme();
79 65 $form_counts = FrmForm::get_count();
80 66
81 67 $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(),
68 + 'uuid' => $this->uuid(),
69 + 'admin_email' => '', // Let's keep it anonymous.
70 + 'wp_version' => $wp_version,
71 + 'php_version' => phpversion(),
72 + 'mysql_version' => $wpdb->db_version(),
73 + 'os' => php_uname( 's' ),
74 + 'locale' => get_locale(),
88 75
89 - 'active_license' => FrmAppHelper::pro_is_installed(),
90 - 'form_count' => $form_counts->published,
91 - 'entry_count' => FrmEntry::getRecordCount(),
92 - 'timestamp' => gmdate( 'c' ),
76 + 'active_license' => FrmAppHelper::pro_is_installed(),
77 + 'form_count' => $form_counts->published,
78 + 'entry_count' => FrmEntry::getRecordCount(),
79 + 'timestamp' => gmdate( 'c' ),
93 80
94 - 'theme_name' => is_object( $theme_data ) ? $theme_data->Name : '', // phpcs:ignore WordPress.NamingConventions
95 - 'plugins' => $this->plugins(),
96 - 'settings' => array(
81 + 'theme_name' => is_object( $theme_data ) ? $theme_data->Name : '', // phpcs:ignore WordPress.NamingConventions
82 + 'plugins' => $this->plugins(),
83 + 'settings' => array(
97 84 $this->settings(),
98 85 ),
99 - 'forms' => $this->forms(),
100 - 'fields' => $this->fields(),
101 - 'actions' => $this->actions(),
102 -
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' ),
86 + 'forms' => $this->forms(),
87 + 'fields' => $this->fields(),
88 + 'actions' => $this->actions(),
108 89 );
109 90
110 - if ( method_exists( 'FrmProAddonsController', 'get_readable_license_type' ) ) {
111 - $snap['active_license'] = FrmProAddonsController::get_readable_license_type();
112 - }
113 -
114 91 return apply_filters( 'frm_usage_snapshot', $snap );
115 92 }
116 93
117 94 /**
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 95 * @since 3.06.04
292 - *
293 96 * @return array
294 97 */
295 98 private function plugins() {
296 99 $plugin_list = FrmAppHelper::get_plugins();
297 - $plugins = array();
298 100
101 + $plugins = array();
299 102 foreach ( $plugin_list as $slug => $info ) {
300 103 $plugins[] = array(
301 - 'name' => $info['Name'],
302 - 'slug' => $slug,
303 - 'version' => $info['Version'],
304 - 'active' => is_plugin_active( $slug ),
104 + 'name' => $info['Name'],
105 + 'slug' => $slug,
106 + 'version' => $info['Version'],
107 + 'active' => is_plugin_active( $slug ),
305 108 );
306 109 }
307 110
308 111 return $plugins;
@@ -311,20 +114,21 @@
311 114 /**
312 115 * Add global settings to tracking data.
313 116 *
314 117 * @since 3.06.04
315 - *
316 118 * @return array
317 119 */
318 120 private function settings() {
319 - $settings_list = FrmAppHelper::get_settings();
320 - $settings = array(
121 + $settings_list = FrmAppHelper::get_settings();
122 + $settings = array(
321 123 'messages' => $this->messages( $settings_list ),
322 124 'permissions' => $this->permissions( $settings_list ),
323 125 );
324 126 $pass_settings = array(
325 127 'load_style',
128 + 'use_html',
326 129 'fade_form',
130 + 'jquery_css',
327 131 're_type',
328 132 're_lang',
329 133 're_multi',
330 134 'menu',
@@ -329,20 +133,11 @@
329 133 're_multi',
330 134 'menu',
331 135 'mu_menu',
332 136 'no_ips',
333 - 'custom_header_ip',
334 - 'enable_gdpr',
335 - 'no_gdpr_cookies',
336 137 'btsp_css',
337 - 'btsp_version',
138 + 'btsp_errors',
338 139 'admin_bar',
339 - 'summary_emails',
340 - 'active_captcha',
341 - 'honeypot',
342 - 'wp_spam_check',
343 - 'denylist_check',
344 - 'email_style',
345 140 );
346 141
347 142 foreach ( $pass_settings as $setting ) {
348 143 if ( isset( $settings_list->$setting ) ) {
@@ -362,10 +157,11 @@
362 157 * Include the permissions settings for each capability.
363 158 *
364 159 * @since 3.06.04
365 160 *
161 + * @return array
162 + *
366 163 * @param FrmSettings $settings_list
367 - *
368 164 * @return array
369 165 */
370 166 private function messages( $settings_list ) {
371 167 $messages = array(
@@ -378,13 +174,11 @@
378 174 'login_msg',
379 175 'admin_permission',
380 176 );
381 177
382 - $default = $settings_list->default_options();
383 178 $message_settings = array();
384 -
385 179 foreach ( $messages as $message ) {
386 - $message_settings[ 'changed-' . $message ] = $settings_list->$message === $default[ $message ] ? 0 : 1;
180 + $message_settings[ $message ] = $settings_list->$message;
387 181 }
388 182
389 183 return $message_settings;
390 184 }
@@ -394,9 +188,8 @@
394 188 *
395 189 * @since 3.06.04
396 190 *
397 191 * @param FrmSettings $settings_list
398 - *
399 192 * @return array
400 193 */
401 194 private function permissions( $settings_list ) {
402 195 $permissions = array();
@@ -412,16 +205,15 @@
412 205 }
413 206
414 207 /**
415 208 * @since 3.06.04
416 - *
417 209 * @return array
418 210 */
419 211 private function forms() {
420 212 $s_query = array(
421 213 array(
422 - 'or' => 1,
423 - 'parent_form_id' => null,
214 + 'or' => 1,
215 + 'parent_form_id' => null,
424 216 'parent_form_id <' => 1,
425 217 ),
426 218 );
427 219
@@ -429,10 +221,10 @@
429 221 $forms = array();
430 222 $settings = array(
431 223 'form_class',
432 224 'akismet',
225 + 'honeypot',
433 226 'antispam',
434 - 'stopforumspam',
435 227 'custom_style',
436 228 'success_action',
437 229 'show_form',
438 230 'no_save',
@@ -461,45 +253,28 @@
461 253 'prev_value',
462 254 'submit_conditions',
463 255 );
464 256
465 - $style = new FrmStyle();
466 -
467 257 foreach ( $saved_forms as $form ) {
468 258 $new_form = array(
469 - 'form_id' => $form->id,
470 - 'description' => $form->description,
471 - 'logged_in' => $form->logged_in,
472 - 'editable' => $form->editable,
473 - 'is_template' => $form->is_template,
474 - 'entry_count' => FrmEntry::getRecordCount( $form->id ),
475 - 'field_count' => $this->form_field_count( $form->id ),
259 + 'form_id' => $form->id,
260 + 'description' => $form->description,
261 + 'logged_in' => $form->logged_in,
262 + 'editable' => $form->editable,
263 + 'is_template' => $form->is_template,
264 + 'entry_count' => FrmEntry::getRecordCount( $form->id ),
265 + 'field_count' => $this->form_field_count( $form->id ),
476 266 'form_action_count' => $this->form_action_count( $form->id ),
477 267 );
478 268
479 269 foreach ( $settings as $setting ) {
480 270 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 - }
271 + $new_form[ $setting ] = $this->maybe_json( $form->options[ $setting ] );
497 272 }
498 273 }
499 274
500 275 $forms[] = apply_filters( 'frm_usage_form', $new_form, compact( 'form' ) );
501 - }//end foreach
276 + }
502 277
503 278 // If the array uses numeric keys, reset them.
504 279 return $forms;
505 280 }
@@ -505,17 +280,14 @@
505 280 }
506 281
507 282 /**
508 283 * @since 3.06.04
509 - *
510 - * @param int|string $form_id Form ID.
511 - *
512 284 * @return int
513 285 */
514 286 private function form_field_count( $form_id ) {
515 287 global $wpdb;
516 288
517 - $join = $wpdb->prefix . 'frm_fields fi JOIN ' . $wpdb->prefix . 'frm_forms fo ON (fi.form_id=fo.id)';
289 + $join = $wpdb->prefix . 'frm_fields fi LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fo ON (fi.form_id=fo.id)';
518 290
519 291 $field_query = array(
520 292 'or' => 1,
521 293 'fi.form_id' => $form_id,
@@ -526,11 +298,8 @@
526 298 }
527 299
528 300 /**
529 301 * @since 3.06.04
530 - *
531 - * @param int|string $form_id Form ID.
532 - *
533 302 * @return int
534 303 */
535 304 private function form_action_count( $form_id ) {
536 305 $args = array(
@@ -546,30 +315,26 @@
546 315 /**
547 316 * Get the last 100 fields created.
548 317 *
549 318 * @since 3.06.04
550 - *
551 319 * @return array
552 320 */
553 321 private function fields() {
554 - $args = array(
322 + $args = array(
555 323 'limit' => 50,
556 324 'order_by' => 'id DESC',
557 325 );
558 326
559 - $fields = FrmDb::get_results( 'frm_fields', array(), 'id, form_id, name, type, field_options', $args );
560 -
327 + $fields = FrmDb::get_results( 'frm_fields', array(), 'form_id, name, type, field_options', $args );
561 328 foreach ( $fields as $k => $field ) {
562 329 FrmAppHelper::unserialize_or_decode( $field->field_options );
563 - $fields[ $k ]->field_options = $field->field_options;
330 + $fields[ $k ]->field_options = json_encode( $field->field_options );
564 331 }
565 -
566 332 return $fields;
567 333 }
568 334
569 335 /**
570 336 * @since 3.06.04
571 - *
572 337 * @return array
573 338 */
574 339 private function actions() {
575 340 $args = array(
@@ -576,17 +341,17 @@
576 341 'post_type' => FrmFormActionsController::$action_post_type,
577 342 'numberposts' => 100,
578 343 );
579 344
580 - $actions = array();
345 + $actions = array();
346 +
581 347 $saved_actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
582 -
583 348 foreach ( $saved_actions as $action ) {
584 349 $actions[] = array(
585 350 'form_id' => $action->menu_order,
586 351 'type' => $action->post_excerpt,
587 352 'status' => $action->post_status,
588 - 'settings' => FrmAppHelper::maybe_json_decode( $action->post_content ),
353 + 'settings' => $action->post_content,
589 354 );
590 355 }
591 356
592 357 return $actions;
@@ -593,20 +358,17 @@
593 358 }
594 359
595 360 /**
596 361 * @since 3.06.04
597 - *
598 362 * @return bool
599 363 */
600 364 private function tracking_allowed() {
601 - return FrmUsageController::tracking_allowed();
365 + $settings = FrmAppHelper::get_settings();
366 + return $settings->tracking;
602 367 }
603 368
604 369 /**
605 370 * @since 3.06.04
606 - *
607 - * @param mixed $value Value.
608 - *
609 371 * @return string
610 372 */
611 373 private function maybe_json( $value ) {
612 374 return is_array( $value ) ? json_encode( $value ) : $value;
@@ -611,4 +373,5 @@
611 373 private function maybe_json( $value ) {
612 374 return is_array( $value ) ? json_encode( $value ) : $value;
613 375 }
614 376 }
377 +