| @@ -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,115 +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 || 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 | 112 | * Gets onboarding wizard data. |
| 226 | 113 | * |
| 227 | 114 | * @since 6.16.1 |
| 228 | 115 | * |
| @@ -250,14 +137,12 @@ | ||
| 250 | 137 | * |
| 251 | 138 | * @since 6.16.1 |
| 252 | 139 | * |
| 253 | 140 | * @param string $table Database table name. |
| 254 | - * | |
| 255 | 141 | * @return array |
| 256 | 142 | */ |
| 257 | 143 | private function payments( $table = 'frm_payments' ) { |
| 258 | 144 | $allowed_tables = array( 'frm_payments', 'frm_subscriptions' ); |
| 259 | - | |
| 260 | 145 | if ( ! in_array( $table, $allowed_tables, true ) ) { |
| 261 | 146 | return array(); |
| 262 | 147 | } |
| 263 | 148 | |
| @@ -273,9 +158,8 @@ | ||
| 273 | 158 | ) |
| 274 | 159 | ); |
| 275 | 160 | |
| 276 | 161 | $payments = array(); |
| 277 | - | |
| 278 | 162 | foreach ( $rows as $row ) { |
| 279 | 163 | $payments[] = array( |
| 280 | 164 | 'amount' => (float) $row->amount, |
| 281 | 165 | 'status' => $row->status, |
| @@ -288,15 +172,14 @@ | ||
| 288 | 172 | } |
| 289 | 173 | |
| 290 | 174 | /** |
| 291 | 175 | * @since 3.06.04 |
| 292 | - * | |
| 293 | 176 | * @return array |
| 294 | 177 | */ |
| 295 | 178 | private function plugins() { |
| 296 | 179 | $plugin_list = FrmAppHelper::get_plugins(); |
| 297 | - $plugins = array(); | |
| 298 | 180 | |
| 181 | + $plugins = array(); | |
| 299 | 182 | foreach ( $plugin_list as $slug => $info ) { |
| 300 | 183 | $plugins[] = array( |
| 301 | 184 | 'name' => $info['Name'], |
| 302 | 185 | 'slug' => $slug, |
| @@ -311,9 +194,8 @@ | ||
| 311 | 194 | /** |
| 312 | 195 | * Add global settings to tracking data. |
| 313 | 196 | * |
| 314 | 197 | * @since 3.06.04 |
| 315 | - * | |
| 316 | 198 | * @return array |
| 317 | 199 | */ |
| 318 | 200 | private function settings() { |
| 319 | 201 | $settings_list = FrmAppHelper::get_settings(); |
| @@ -340,9 +222,8 @@ | ||
| 340 | 222 | 'active_captcha', |
| 341 | 223 | 'honeypot', |
| 342 | 224 | 'wp_spam_check', |
| 343 | 225 | 'denylist_check', |
| 344 | - 'email_style', | |
| 345 | 226 | ); |
| 346 | 227 | |
| 347 | 228 | foreach ( $pass_settings as $setting ) { |
| 348 | 229 | if ( isset( $settings_list->$setting ) ) { |
| @@ -363,9 +244,8 @@ | ||
| 363 | 244 | * |
| 364 | 245 | * @since 3.06.04 |
| 365 | 246 | * |
| 366 | 247 | * @param FrmSettings $settings_list |
| 367 | - * | |
| 368 | 248 | * @return array |
| 369 | 249 | */ |
| 370 | 250 | private function messages( $settings_list ) { |
| 371 | 251 | $messages = array( |
| @@ -378,11 +258,11 @@ | ||
| 378 | 258 | 'login_msg', |
| 379 | 259 | 'admin_permission', |
| 380 | 260 | ); |
| 381 | 261 | |
| 382 | - $default = $settings_list->default_options(); | |
| 262 | + $default = $settings_list->default_options(); | |
| 263 | + | |
| 383 | 264 | $message_settings = array(); |
| 384 | - | |
| 385 | 265 | foreach ( $messages as $message ) { |
| 386 | 266 | $message_settings[ 'changed-' . $message ] = $settings_list->$message === $default[ $message ] ? 0 : 1; |
| 387 | 267 | } |
| 388 | 268 | |
| @@ -394,9 +274,8 @@ | ||
| 394 | 274 | * |
| 395 | 275 | * @since 3.06.04 |
| 396 | 276 | * |
| 397 | 277 | * @param FrmSettings $settings_list |
| 398 | - * | |
| 399 | 278 | * @return array |
| 400 | 279 | */ |
| 401 | 280 | private function permissions( $settings_list ) { |
| 402 | 281 | $permissions = array(); |
| @@ -412,9 +291,8 @@ | ||
| 412 | 291 | } |
| 413 | 292 | |
| 414 | 293 | /** |
| 415 | 294 | * @since 3.06.04 |
| 416 | - * | |
| 417 | 295 | * @return array |
| 418 | 296 | */ |
| 419 | 297 | private function forms() { |
| 420 | 298 | $s_query = array( |
| @@ -462,9 +340,8 @@ | ||
| 462 | 340 | 'submit_conditions', |
| 463 | 341 | ); |
| 464 | 342 | |
| 465 | 343 | $style = new FrmStyle(); |
| 466 | - | |
| 467 | 344 | foreach ( $saved_forms as $form ) { |
| 468 | 345 | $new_form = array( |
| 469 | 346 | 'form_id' => $form->id, |
| 470 | 347 | 'description' => $form->description, |
| @@ -505,11 +382,8 @@ | ||
| 505 | 382 | } |
| 506 | 383 | |
| 507 | 384 | /** |
| 508 | 385 | * @since 3.06.04 |
| 509 | - * | |
| 510 | - * @param int|string $form_id Form ID. | |
| 511 | - * | |
| 512 | 386 | * @return int |
| 513 | 387 | */ |
| 514 | 388 | private function form_field_count( $form_id ) { |
| 515 | 389 | global $wpdb; |
| @@ -526,11 +400,8 @@ | ||
| 526 | 400 | } |
| 527 | 401 | |
| 528 | 402 | /** |
| 529 | 403 | * @since 3.06.04 |
| 530 | - * | |
| 531 | - * @param int|string $form_id Form ID. | |
| 532 | - * | |
| 533 | 404 | * @return int |
| 534 | 405 | */ |
| 535 | 406 | private function form_action_count( $form_id ) { |
| 536 | 407 | $args = array( |
| @@ -546,9 +417,8 @@ | ||
| 546 | 417 | /** |
| 547 | 418 | * Get the last 100 fields created. |
| 548 | 419 | * |
| 549 | 420 | * @since 3.06.04 |
| 550 | - * | |
| 551 | 421 | * @return array |
| 552 | 422 | */ |
| 553 | 423 | private function fields() { |
| 554 | 424 | $args = array( |
| @@ -556,20 +426,17 @@ | ||
| 556 | 426 | 'order_by' => 'id DESC', |
| 557 | 427 | ); |
| 558 | 428 | |
| 559 | 429 | $fields = FrmDb::get_results( 'frm_fields', array(), 'id, form_id, name, type, field_options', $args ); |
| 560 | - | |
| 561 | 430 | foreach ( $fields as $k => $field ) { |
| 562 | 431 | FrmAppHelper::unserialize_or_decode( $field->field_options ); |
| 563 | - $fields[ $k ]->field_options = $field->field_options; | |
| 432 | + $fields[ $k ]->field_options = json_encode( $field->field_options ); | |
| 564 | 433 | } |
| 565 | - | |
| 566 | 434 | return $fields; |
| 567 | 435 | } |
| 568 | 436 | |
| 569 | 437 | /** |
| 570 | 438 | * @since 3.06.04 |
| 571 | - * | |
| 572 | 439 | * @return array |
| 573 | 440 | */ |
| 574 | 441 | private function actions() { |
| 575 | 442 | $args = array( |
| @@ -576,17 +443,17 @@ | ||
| 576 | 443 | 'post_type' => FrmFormActionsController::$action_post_type, |
| 577 | 444 | 'numberposts' => 100, |
| 578 | 445 | ); |
| 579 | 446 | |
| 580 | - $actions = array(); | |
| 447 | + $actions = array(); | |
| 448 | + | |
| 581 | 449 | $saved_actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' ); |
| 582 | - | |
| 583 | 450 | foreach ( $saved_actions as $action ) { |
| 584 | 451 | $actions[] = array( |
| 585 | 452 | 'form_id' => $action->menu_order, |
| 586 | 453 | 'type' => $action->post_excerpt, |
| 587 | 454 | 'status' => $action->post_status, |
| 588 | - 'settings' => FrmAppHelper::maybe_json_decode( $action->post_content ), | |
| 455 | + 'settings' => $action->post_content, | |
| 589 | 456 | ); |
| 590 | 457 | } |
| 591 | 458 | |
| 592 | 459 | return $actions; |
| @@ -593,9 +460,8 @@ | ||
| 593 | 460 | } |
| 594 | 461 | |
| 595 | 462 | /** |
| 596 | 463 | * @since 3.06.04 |
| 597 | - * | |
| 598 | 464 | * @return bool |
| 599 | 465 | */ |
| 600 | 466 | private function tracking_allowed() { |
| 601 | 467 | return FrmUsageController::tracking_allowed(); |
| @@ -602,11 +468,8 @@ | ||
| 602 | 468 | } |
| 603 | 469 | |
| 604 | 470 | /** |
| 605 | 471 | * @since 3.06.04 |
| 606 | - * | |
| 607 | - * @param mixed $value Value. | |
| 608 | - * | |
| 609 | 472 | * @return string |
| 610 | 473 | */ |
| 611 | 474 | private function maybe_json( $value ) { |
| 612 | 475 | return is_array( $value ) ? json_encode( $value ) : $value; |