PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.7
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.7
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 +61 -311 6.296.7 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,241 +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' => FrmAppHelper::get_server_os(),
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 ) {
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 - * Gets onboarding wizard data.
236 - *
237 - * @since 6.16.1
238 - *
239 - * @return array
240 - */
241 - private function onboarding_wizard() {
242 - $data = FrmOnboardingWizardController::get_usage_data();
243 - $skipped_keys = array(
244 - 'default_email',
245 - 'is_subscribed',
246 - 'allows_tracking',
247 - 'summary_emails',
248 - 'installed_addons',
249 - );
250 -
251 - foreach ( $skipped_keys as $skipped_key ) {
252 - unset( $data[ $skipped_key ] );
253 - }
254 -
255 - return $data;
256 - }
257 -
258 - /**
259 - * Gets payments data.
260 - *
261 - * @since 6.16.1
262 - *
263 - * @param string $table Database table name.
264 - *
265 - * @return array
266 - */
267 - private function payments( $table = 'frm_payments' ) {
268 - $allowed_tables = array( 'frm_payments', 'frm_subscriptions' );
269 -
270 - if ( ! in_array( $table, $allowed_tables, true ) ) {
271 - return array();
272 - }
273 -
274 - if ( ! FrmTransLiteAppHelper::payments_table_exists() ) {
275 - return array();
276 - }
277 -
278 - global $wpdb;
279 - $rows = $wpdb->get_results(
280 - $wpdb->prepare(
281 - 'SELECT amount, status, paysys, created_at FROM %1$s',
282 - $wpdb->prefix . $table
283 - )
284 - );
285 -
286 - $payments = array();
287 -
288 - foreach ( $rows as $row ) {
289 - $payments[] = array(
290 - 'amount' => (float) $row->amount,
291 - 'status' => $row->status,
292 - 'gateway' => $row->paysys,
293 - 'created_at' => $row->created_at,
294 - );
295 - }
296 -
297 - return $payments;
298 - }
299 -
300 - /**
301 95 * @since 3.06.04
302 - *
303 96 * @return array
304 97 */
305 98 private function plugins() {
306 99 $plugin_list = FrmAppHelper::get_plugins();
307 - $plugins = array();
308 100
101 + $plugins = array();
309 102 foreach ( $plugin_list as $slug => $info ) {
310 103 $plugins[] = array(
311 - 'name' => $info['Name'],
312 - 'slug' => $slug,
313 - 'version' => $info['Version'],
314 - 'active' => is_plugin_active( $slug ),
104 + 'name' => $info['Name'],
105 + 'slug' => $slug,
106 + 'version' => $info['Version'],
107 + 'active' => is_plugin_active( $slug ),
315 108 );
316 109 }
317 110
318 111 return $plugins;
@@ -321,20 +114,21 @@
321 114 /**
322 115 * Add global settings to tracking data.
323 116 *
324 117 * @since 3.06.04
325 - *
326 118 * @return array
327 119 */
328 120 private function settings() {
329 - $settings_list = FrmAppHelper::get_settings();
330 - $settings = array(
121 + $settings_list = FrmAppHelper::get_settings();
122 + $settings = array(
331 123 'messages' => $this->messages( $settings_list ),
332 124 'permissions' => $this->permissions( $settings_list ),
333 125 );
334 126 $pass_settings = array(
335 127 'load_style',
128 + 'use_html',
336 129 'fade_form',
130 + 'jquery_css',
337 131 're_type',
338 132 're_lang',
339 133 're_multi',
340 134 'menu',
@@ -339,20 +133,11 @@
339 133 're_multi',
340 134 'menu',
341 135 'mu_menu',
342 136 'no_ips',
343 - 'custom_header_ip',
344 - 'enable_gdpr',
345 - 'no_gdpr_cookies',
346 137 'btsp_css',
347 - 'btsp_version',
138 + 'btsp_errors',
348 139 'admin_bar',
349 - 'summary_emails',
350 - 'active_captcha',
351 - 'honeypot',
352 - 'wp_spam_check',
353 - 'denylist_check',
354 - 'email_style',
355 140 );
356 141
357 142 foreach ( $pass_settings as $setting ) {
358 143 if ( isset( $settings_list->$setting ) ) {
@@ -372,10 +157,11 @@
372 157 * Include the permissions settings for each capability.
373 158 *
374 159 * @since 3.06.04
375 160 *
161 + * @return array
162 + *
376 163 * @param FrmSettings $settings_list
377 - *
378 164 * @return array
379 165 */
380 166 private function messages( $settings_list ) {
381 167 $messages = array(
@@ -388,13 +174,11 @@
388 174 'login_msg',
389 175 'admin_permission',
390 176 );
391 177
392 - $default = $settings_list->default_options();
393 178 $message_settings = array();
394 -
395 179 foreach ( $messages as $message ) {
396 - $message_settings[ 'changed-' . $message ] = $settings_list->$message === $default[ $message ] ? 0 : 1;
180 + $message_settings[ $message ] = $settings_list->$message;
397 181 }
398 182
399 183 return $message_settings;
400 184 }
@@ -404,9 +188,8 @@
404 188 *
405 189 * @since 3.06.04
406 190 *
407 191 * @param FrmSettings $settings_list
408 - *
409 192 * @return array
410 193 */
411 194 private function permissions( $settings_list ) {
412 195 $permissions = array();
@@ -422,16 +205,15 @@
422 205 }
423 206
424 207 /**
425 208 * @since 3.06.04
426 - *
427 209 * @return array
428 210 */
429 211 private function forms() {
430 212 $s_query = array(
431 213 array(
432 - 'or' => 1,
433 - 'parent_form_id' => null,
214 + 'or' => 1,
215 + 'parent_form_id' => null,
434 216 'parent_form_id <' => 1,
435 217 ),
436 218 );
437 219
@@ -439,10 +221,10 @@
439 221 $forms = array();
440 222 $settings = array(
441 223 'form_class',
442 224 'akismet',
225 + 'honeypot',
443 226 'antispam',
444 - 'stopforumspam',
445 227 'custom_style',
446 228 'success_action',
447 229 'show_form',
448 230 'no_save',
@@ -471,48 +253,28 @@
471 253 'prev_value',
472 254 'submit_conditions',
473 255 );
474 256
475 - $style = new FrmStyle();
476 -
477 257 foreach ( $saved_forms as $form ) {
478 258 $new_form = array(
479 - 'form_id' => $form->id,
480 - 'description' => $form->description,
481 - 'logged_in' => $form->logged_in,
482 - 'editable' => $form->editable,
483 - 'is_template' => $form->is_template,
484 - 'entry_count' => FrmEntry::getRecordCount( $form->id ),
485 - '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 ),
486 266 'form_action_count' => $this->form_action_count( $form->id ),
487 267 );
488 268
489 269 foreach ( $settings as $setting ) {
490 - if ( ! isset( $form->options[ $setting ] ) ) {
491 - continue;
492 - }
493 -
494 - if ( 'custom_style' !== $setting ) {
270 + if ( isset( $form->options[ $setting ] ) ) {
495 271 $new_form[ $setting ] = $this->maybe_json( $form->options[ $setting ] );
496 - continue;
497 272 }
273 + }
498 274
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';
508 - }
509 -
510 - $new_form[ $setting ] = $style_name;
511 - }//end foreach
512 -
513 275 $forms[] = apply_filters( 'frm_usage_form', $new_form, compact( 'form' ) );
514 - }//end foreach
276 + }
515 277
516 278 // If the array uses numeric keys, reset them.
517 279 return $forms;
518 280 }
@@ -518,17 +280,14 @@
518 280 }
519 281
520 282 /**
521 283 * @since 3.06.04
522 - *
523 - * @param int|string $form_id Form ID.
524 - *
525 284 * @return int
526 285 */
527 286 private function form_field_count( $form_id ) {
528 287 global $wpdb;
529 288
530 - $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)';
531 290
532 291 $field_query = array(
533 292 'or' => 1,
534 293 'fi.form_id' => $form_id,
@@ -539,11 +298,8 @@
539 298 }
540 299
541 300 /**
542 301 * @since 3.06.04
543 - *
544 - * @param int|string $form_id Form ID.
545 - *
546 302 * @return int
547 303 */
548 304 private function form_action_count( $form_id ) {
549 305 $args = array(
@@ -559,30 +315,26 @@
559 315 /**
560 316 * Get the last 100 fields created.
561 317 *
562 318 * @since 3.06.04
563 - *
564 319 * @return array
565 320 */
566 321 private function fields() {
567 - $args = array(
322 + $args = array(
568 323 'limit' => 50,
569 324 'order_by' => 'id DESC',
570 325 );
571 326
572 - $fields = FrmDb::get_results( 'frm_fields', array(), 'id, form_id, name, type, field_options', $args );
573 -
327 + $fields = FrmDb::get_results( 'frm_fields', array(), 'form_id, name, type, field_options', $args );
574 328 foreach ( $fields as $k => $field ) {
575 329 FrmAppHelper::unserialize_or_decode( $field->field_options );
576 - $fields[ $k ]->field_options = $field->field_options;
330 + $fields[ $k ]->field_options = json_encode( $field->field_options );
577 331 }
578 -
579 332 return $fields;
580 333 }
581 334
582 335 /**
583 336 * @since 3.06.04
584 - *
585 337 * @return array
586 338 */
587 339 private function actions() {
588 340 $args = array(
@@ -589,17 +341,17 @@
589 341 'post_type' => FrmFormActionsController::$action_post_type,
590 342 'numberposts' => 100,
591 343 );
592 344
593 - $actions = array();
345 + $actions = array();
346 +
594 347 $saved_actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
595 -
596 348 foreach ( $saved_actions as $action ) {
597 349 $actions[] = array(
598 350 'form_id' => $action->menu_order,
599 351 'type' => $action->post_excerpt,
600 352 'status' => $action->post_status,
601 - 'settings' => FrmAppHelper::maybe_json_decode( $action->post_content ),
353 + 'settings' => $action->post_content,
602 354 );
603 355 }
604 356
605 357 return $actions;
@@ -606,20 +358,17 @@
606 358 }
607 359
608 360 /**
609 361 * @since 3.06.04
610 - *
611 362 * @return bool
612 363 */
613 364 private function tracking_allowed() {
614 - return FrmUsageController::tracking_allowed();
365 + $settings = FrmAppHelper::get_settings();
366 + return $settings->tracking;
615 367 }
616 368
617 369 /**
618 370 * @since 3.06.04
619 - *
620 - * @param mixed $value Value.
621 - *
622 371 * @return string
623 372 */
624 373 private function maybe_json( $value ) {
625 374 return is_array( $value ) ? json_encode( $value ) : $value;
@@ -624,4 +373,5 @@
624 373 private function maybe_json( $value ) {
625 374 return is_array( $value ) ? json_encode( $value ) : $value;
626 375 }
627 376 }
377 +