| @@ -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(); |
| @@ -347,12 +219,8 @@ | ||
| 347 | 219 | 'btsp_version', |
| 348 | 220 | 'admin_bar', |
| 349 | 221 | 'summary_emails', |
| 350 | 222 | 'active_captcha', |
| 351 | - 'honeypot', | |
| 352 | - 'wp_spam_check', | |
| 353 | - 'denylist_check', | |
| 354 | - 'email_style', | |
| 355 | 223 | ); |
| 356 | 224 | |
| 357 | 225 | foreach ( $pass_settings as $setting ) { |
| 358 | 226 | if ( isset( $settings_list->$setting ) ) { |
| @@ -373,9 +241,8 @@ | ||
| 373 | 241 | * |
| 374 | 242 | * @since 3.06.04 |
| 375 | 243 | * |
| 376 | 244 | * @param FrmSettings $settings_list |
| 377 | - * | |
| 378 | 245 | * @return array |
| 379 | 246 | */ |
| 380 | 247 | private function messages( $settings_list ) { |
| 381 | 248 | $messages = array( |
| @@ -388,11 +255,11 @@ | ||
| 388 | 255 | 'login_msg', |
| 389 | 256 | 'admin_permission', |
| 390 | 257 | ); |
| 391 | 258 | |
| 392 | - $default = $settings_list->default_options(); | |
| 259 | + $default = $settings_list->default_options(); | |
| 260 | + | |
| 393 | 261 | $message_settings = array(); |
| 394 | - | |
| 395 | 262 | foreach ( $messages as $message ) { |
| 396 | 263 | $message_settings[ 'changed-' . $message ] = $settings_list->$message === $default[ $message ] ? 0 : 1; |
| 397 | 264 | } |
| 398 | 265 | |
| @@ -404,9 +271,8 @@ | ||
| 404 | 271 | * |
| 405 | 272 | * @since 3.06.04 |
| 406 | 273 | * |
| 407 | 274 | * @param FrmSettings $settings_list |
| 408 | - * | |
| 409 | 275 | * @return array |
| 410 | 276 | */ |
| 411 | 277 | private function permissions( $settings_list ) { |
| 412 | 278 | $permissions = array(); |
| @@ -422,9 +288,8 @@ | ||
| 422 | 288 | } |
| 423 | 289 | |
| 424 | 290 | /** |
| 425 | 291 | * @since 3.06.04 |
| 426 | - * | |
| 427 | 292 | * @return array |
| 428 | 293 | */ |
| 429 | 294 | private function forms() { |
| 430 | 295 | $s_query = array( |
| @@ -439,10 +304,10 @@ | ||
| 439 | 304 | $forms = array(); |
| 440 | 305 | $settings = array( |
| 441 | 306 | 'form_class', |
| 442 | 307 | 'akismet', |
| 308 | + 'honeypot', | |
| 443 | 309 | 'antispam', |
| 444 | - 'stopforumspam', | |
| 445 | 310 | 'custom_style', |
| 446 | 311 | 'success_action', |
| 447 | 312 | 'show_form', |
| 448 | 313 | 'no_save', |
| @@ -472,9 +337,8 @@ | ||
| 472 | 337 | 'submit_conditions', |
| 473 | 338 | ); |
| 474 | 339 | |
| 475 | 340 | $style = new FrmStyle(); |
| 476 | - | |
| 477 | 341 | foreach ( $saved_forms as $form ) { |
| 478 | 342 | $new_form = array( |
| 479 | 343 | 'form_id' => $form->id, |
| 480 | 344 | 'description' => $form->description, |
| @@ -486,31 +350,28 @@ | ||
| 486 | 350 | 'form_action_count' => $this->form_action_count( $form->id ), |
| 487 | 351 | ); |
| 488 | 352 | |
| 489 | 353 | foreach ( $settings as $setting ) { |
| 490 | - if ( ! isset( $form->options[ $setting ] ) ) { | |
| 491 | - continue; | |
| 492 | - } | |
| 354 | + if ( isset( $form->options[ $setting ] ) ) { | |
| 355 | + if ( 'custom_style' === $setting ) { | |
| 356 | + $style->id = $form->options[ $setting ]; | |
| 493 | 357 | |
| 494 | - if ( 'custom_style' !== $setting ) { | |
| 495 | - $new_form[ $setting ] = $this->maybe_json( $form->options[ $setting ] ); | |
| 496 | - continue; | |
| 497 | - } | |
| 358 | + if ( ! $style->id ) { | |
| 359 | + $style_name = 0; | |
| 360 | + } elseif ( 1 === intval( $style->id ) ) { | |
| 361 | + $style_name = 'formidable-style'; | |
| 362 | + } else { | |
| 363 | + $style_post = $style->get_one(); | |
| 364 | + $style_name = $style_post ? $style_post->post_name : 'formidable-style'; | |
| 365 | + } | |
| 498 | 366 | |
| 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'; | |
| 367 | + $new_form[ $setting ] = $style_name; | |
| 368 | + } else { | |
| 369 | + $new_form[ $setting ] = $this->maybe_json( $form->options[ $setting ] ); | |
| 370 | + } | |
| 508 | 371 | } |
| 372 | + } | |
| 509 | 373 | |
| 510 | - $new_form[ $setting ] = $style_name; | |
| 511 | - }//end foreach | |
| 512 | - | |
| 513 | 374 | $forms[] = apply_filters( 'frm_usage_form', $new_form, compact( 'form' ) ); |
| 514 | 375 | }//end foreach |
| 515 | 376 | |
| 516 | 377 | // If the array uses numeric keys, reset them. |
| @@ -518,11 +379,8 @@ | ||
| 518 | 379 | } |
| 519 | 380 | |
| 520 | 381 | /** |
| 521 | 382 | * @since 3.06.04 |
| 522 | - * | |
| 523 | - * @param int|string $form_id Form ID. | |
| 524 | - * | |
| 525 | 383 | * @return int |
| 526 | 384 | */ |
| 527 | 385 | private function form_field_count( $form_id ) { |
| 528 | 386 | global $wpdb; |
| @@ -539,11 +397,8 @@ | ||
| 539 | 397 | } |
| 540 | 398 | |
| 541 | 399 | /** |
| 542 | 400 | * @since 3.06.04 |
| 543 | - * | |
| 544 | - * @param int|string $form_id Form ID. | |
| 545 | - * | |
| 546 | 401 | * @return int |
| 547 | 402 | */ |
| 548 | 403 | private function form_action_count( $form_id ) { |
| 549 | 404 | $args = array( |
| @@ -559,9 +414,8 @@ | ||
| 559 | 414 | /** |
| 560 | 415 | * Get the last 100 fields created. |
| 561 | 416 | * |
| 562 | 417 | * @since 3.06.04 |
| 563 | - * | |
| 564 | 418 | * @return array |
| 565 | 419 | */ |
| 566 | 420 | private function fields() { |
| 567 | 421 | $args = array( |
| @@ -569,20 +423,17 @@ | ||
| 569 | 423 | 'order_by' => 'id DESC', |
| 570 | 424 | ); |
| 571 | 425 | |
| 572 | 426 | $fields = FrmDb::get_results( 'frm_fields', array(), 'id, form_id, name, type, field_options', $args ); |
| 573 | - | |
| 574 | 427 | foreach ( $fields as $k => $field ) { |
| 575 | 428 | FrmAppHelper::unserialize_or_decode( $field->field_options ); |
| 576 | - $fields[ $k ]->field_options = $field->field_options; | |
| 429 | + $fields[ $k ]->field_options = json_encode( $field->field_options ); | |
| 577 | 430 | } |
| 578 | - | |
| 579 | 431 | return $fields; |
| 580 | 432 | } |
| 581 | 433 | |
| 582 | 434 | /** |
| 583 | 435 | * @since 3.06.04 |
| 584 | - * | |
| 585 | 436 | * @return array |
| 586 | 437 | */ |
| 587 | 438 | private function actions() { |
| 588 | 439 | $args = array( |
| @@ -589,17 +440,17 @@ | ||
| 589 | 440 | 'post_type' => FrmFormActionsController::$action_post_type, |
| 590 | 441 | 'numberposts' => 100, |
| 591 | 442 | ); |
| 592 | 443 | |
| 593 | - $actions = array(); | |
| 444 | + $actions = array(); | |
| 445 | + | |
| 594 | 446 | $saved_actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' ); |
| 595 | - | |
| 596 | 447 | foreach ( $saved_actions as $action ) { |
| 597 | 448 | $actions[] = array( |
| 598 | 449 | 'form_id' => $action->menu_order, |
| 599 | 450 | 'type' => $action->post_excerpt, |
| 600 | 451 | 'status' => $action->post_status, |
| 601 | - 'settings' => FrmAppHelper::maybe_json_decode( $action->post_content ), | |
| 452 | + 'settings' => $action->post_content, | |
| 602 | 453 | ); |
| 603 | 454 | } |
| 604 | 455 | |
| 605 | 456 | return $actions; |
| @@ -606,9 +457,8 @@ | ||
| 606 | 457 | } |
| 607 | 458 | |
| 608 | 459 | /** |
| 609 | 460 | * @since 3.06.04 |
| 610 | - * | |
| 611 | 461 | * @return bool |
| 612 | 462 | */ |
| 613 | 463 | private function tracking_allowed() { |
| 614 | 464 | return FrmUsageController::tracking_allowed(); |
| @@ -615,11 +465,8 @@ | ||
| 615 | 465 | } |
| 616 | 466 | |
| 617 | 467 | /** |
| 618 | 468 | * @since 3.06.04 |
| 619 | - * | |
| 620 | - * @param mixed $value Value. | |
| 621 | - * | |
| 622 | 469 | * @return string |
| 623 | 470 | */ |
| 624 | 471 | private function maybe_json( $value ) { |
| 625 | 472 | return is_array( $value ) ? json_encode( $value ) : $value; |