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