| @@ -17,11 +17,14 @@ | ||
| 17 | 17 | if ( ! $this->tracking_allowed() ) { |
| 18 | 18 | return; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | + $snapshot = $this->snapshot(); | |
| 22 | + $this->clean_before_send( $snapshot ); | |
| 23 | + | |
| 21 | 24 | $ep = 'aHR0cHM6Ly91c2FnZTIuZm9ybWlkYWJsZWZvcm1zLmNvbS9zbmFwc2hvdA=='; |
| 22 | 25 | // $ep = base64_encode( 'http://localhost:4567/snapshot' ); // Uncomment for testing |
| 23 | - $body = json_encode( $this->snapshot() ); | |
| 26 | + $body = json_encode( $snapshot ); | |
| 24 | 27 | |
| 25 | 28 | // Setup variable for wp_remote_request. |
| 26 | 29 | $post = array( |
| 27 | 30 | 'method' => 'POST', |
| @@ -53,13 +56,13 @@ | ||
| 53 | 56 | public function uuid( $regenerate = false ) { |
| 54 | 57 | $uuid_key = 'frm-usage-uuid'; |
| 55 | 58 | $uuid = get_option( $uuid_key ); |
| 56 | 59 | |
| 57 | - if ( $regenerate || empty( $uuid ) ) { | |
| 60 | + if ( $regenerate || ! $uuid ) { | |
| 58 | 61 | // Definitely not cryptographically secure but |
| 59 | - // close enough to provide an unique id | |
| 62 | + // close enough to provide a unique id | |
| 60 | 63 | $uuid = md5( uniqid() . site_url() ); |
| 61 | - update_option( $uuid_key, $uuid, 'no' ); | |
| 64 | + update_option( $uuid_key, $uuid, false ); | |
| 62 | 65 | } |
| 63 | 66 | |
| 64 | 67 | return $uuid; |
| 65 | 68 | } |
| @@ -76,10 +79,8 @@ | ||
| 76 | 79 | $form_counts = FrmForm::get_count(); |
| 77 | 80 | |
| 78 | 81 | $snap = array( |
| 79 | 82 | 'uuid' => $this->uuid(), |
| 80 | - // Let's keep it anonymous. | |
| 81 | - 'admin_email' => '', | |
| 82 | 83 | 'wp_version' => $wp_version, |
| 83 | 84 | 'php_version' => phpversion(), |
| 84 | 85 | 'mysql_version' => $wpdb->db_version(), |
| 85 | 86 | 'os' => FrmAppHelper::get_server_os(), |
| @@ -88,8 +89,9 @@ | ||
| 88 | 89 | 'active_license' => FrmAppHelper::pro_is_installed(), |
| 89 | 90 | 'form_count' => $form_counts->published, |
| 90 | 91 | 'entry_count' => FrmEntry::getRecordCount(), |
| 91 | 92 | 'timestamp' => gmdate( 'c' ), |
| 93 | + 'misc' => array(), | |
| 92 | 94 | |
| 93 | 95 | 'theme_name' => is_object( $theme_data ) ? $theme_data->Name : '', // phpcs:ignore WordPress.NamingConventions |
| 94 | 96 | 'plugins' => $this->plugins(), |
| 95 | 97 | 'settings' => array( |
| @@ -113,8 +115,125 @@ | ||
| 113 | 115 | return apply_filters( 'frm_usage_snapshot', $snap ); |
| 114 | 116 | } |
| 115 | 117 | |
| 116 | 118 | /** |
| 119 | + * Cleans the snapshot data before sending. | |
| 120 | + * | |
| 121 | + * @param array $data Snapshot data. | |
| 122 | + * | |
| 123 | + * @return void | |
| 124 | + */ | |
| 125 | + private function clean_before_send( &$data ) { | |
| 126 | + $skip_keys = array( | |
| 127 | + 'plan_id', | |
| 128 | + 'paypal_item_name', | |
| 129 | + 'account_num', | |
| 130 | + 'routing_num', | |
| 131 | + 'bank_name', | |
| 132 | + 'business_email', | |
| 133 | + | |
| 134 | + // Form action settings. | |
| 135 | + 'quiz', | |
| 136 | + 'email_to', | |
| 137 | + 'cc', | |
| 138 | + 'bcc', | |
| 139 | + 'from', | |
| 140 | + 'email_subject', | |
| 141 | + 'email_msg', | |
| 142 | + 'email_message', | |
| 143 | + 'success_msg', | |
| 144 | + 'success_url', | |
| 145 | + 'success_page_id', | |
| 146 | + 'redirect_msg', | |
| 147 | + 'conditions', | |
| 148 | + 'list_id', | |
| 149 | + 'api_key', | |
| 150 | + 'url', | |
| 151 | + 'data_fields', | |
| 152 | + 'reg_email_msg', | |
| 153 | + | |
| 154 | + // Form settings. | |
| 155 | + 'form_id', | |
| 156 | + 'description', | |
| 157 | + 'submit_conditions-hide_field', | |
| 158 | + 'submit_conditions-hide_field_cond', | |
| 159 | + 'submit_conditions-hide_opt', | |
| 160 | + 'submit_conditions-show_hide', | |
| 161 | + 'submit_conditions-any_all', | |
| 162 | + | |
| 163 | + // Field settings. | |
| 164 | + 'show_hide', | |
| 165 | + 'any_all', | |
| 166 | + 'hide_field', | |
| 167 | + 'hide_field_cond', | |
| 168 | + 'hide_opt', | |
| 169 | + 'custom_html', | |
| 170 | + 'blank', | |
| 171 | + 'required_indicator', | |
| 172 | + 'invalid', | |
| 173 | + 'unique_msg', | |
| 174 | + 'edit_text', | |
| 175 | + 'start_over_label', | |
| 176 | + 'add_label', | |
| 177 | + 'remove_label', | |
| 178 | + 'draft', | |
| 179 | + ); | |
| 180 | + | |
| 181 | + /** | |
| 182 | + * Filter the keys to skip when cleaning the snapshot data before sending. | |
| 183 | + * | |
| 184 | + * @since 6.28 | |
| 185 | + * | |
| 186 | + * @param array $skip_keys Data keys. | |
| 187 | + */ | |
| 188 | + $skip_keys = apply_filters( 'frm_usage_skip_keys', $skip_keys ); | |
| 189 | + | |
| 190 | + $long_text_keys = array( 'description' ); | |
| 191 | + | |
| 192 | + /** | |
| 193 | + * Filter the keys to replace with a long text placeholder before sending. | |
| 194 | + * | |
| 195 | + * @since 6.28 | |
| 196 | + * | |
| 197 | + * @paramm array $long_text_keys Data keys. | |
| 198 | + */ | |
| 199 | + $long_text_keys = apply_filters( 'frm_usage_long_text_keys', $long_text_keys ); | |
| 200 | + | |
| 201 | + foreach ( $data as $key => &$value ) { | |
| 202 | + if ( ! $value ) { | |
| 203 | + continue; | |
| 204 | + } | |
| 205 | + | |
| 206 | + if ( in_array( $key, $skip_keys, true ) || str_ends_with( $key, '_url' ) ) { | |
| 207 | + unset( $data[ $key ] ); | |
| 208 | + continue; | |
| 209 | + } | |
| 210 | + | |
| 211 | + if ( is_object( $value ) ) { | |
| 212 | + $value = '{{object}}'; | |
| 213 | + continue; | |
| 214 | + } | |
| 215 | + | |
| 216 | + if ( is_array( $value ) ) { | |
| 217 | + $this->clean_before_send( $value ); | |
| 218 | + continue; | |
| 219 | + } | |
| 220 | + | |
| 221 | + if ( in_array( $key, $long_text_keys, true ) || str_ends_with( $key, '_msg' ) ) { | |
| 222 | + // Replace it with a placeholder. | |
| 223 | + $value = '{{long_text}}'; | |
| 224 | + continue; | |
| 225 | + } | |
| 226 | + | |
| 227 | + // If key ends with `_email`, or value contains `@`, this might contain an email address. | |
| 228 | + if ( str_ends_with( $key, '_email' ) || ( is_string( $value ) && str_contains( $value, '@' ) ) ) { | |
| 229 | + // Replace it with a placeholder. | |
| 230 | + $value = '{{contain_email}}'; | |
| 231 | + } | |
| 232 | + }//end foreach | |
| 233 | + } | |
| 234 | + | |
| 235 | + /** | |
| 117 | 236 | * Gets onboarding wizard data. |
| 118 | 237 | * |
| 119 | 238 | * @since 6.16.1 |
| 120 | 239 | * |
| @@ -148,24 +267,13 @@ | ||
| 148 | 267 | */ |
| 149 | 268 | private function payments( $table = 'frm_payments' ) { |
| 150 | 269 | $allowed_tables = array( 'frm_payments', 'frm_subscriptions' ); |
| 151 | 270 | |
| 152 | - if ( ! in_array( $table, $allowed_tables, true ) ) { | |
| 271 | + if ( ! in_array( $table, $allowed_tables, true ) || ! FrmTransLiteAppHelper::payments_table_exists() ) { | |
| 153 | 272 | return array(); |
| 154 | 273 | } |
| 155 | 274 | |
| 156 | - if ( ! FrmTransLiteAppHelper::payments_table_exists() ) { | |
| 157 | - return array(); | |
| 158 | - } | |
| 159 | - | |
| 160 | - global $wpdb; | |
| 161 | - $rows = $wpdb->get_results( | |
| 162 | - $wpdb->prepare( | |
| 163 | - 'SELECT amount, status, paysys, created_at FROM %1$s', | |
| 164 | - $wpdb->prefix . $table | |
| 165 | - ) | |
| 166 | - ); | |
| 167 | - | |
| 275 | + $rows = $this->get_payment_db_rows( $table ); | |
| 168 | 276 | $payments = array(); |
| 169 | 277 | |
| 170 | 278 | foreach ( $rows as $row ) { |
| 171 | 279 | $payments[] = array( |
| @@ -179,8 +287,36 @@ | ||
| 179 | 287 | return $payments; |
| 180 | 288 | } |
| 181 | 289 | |
| 182 | 290 | /** |
| 291 | + * @since 6.30 | |
| 292 | + * | |
| 293 | + * @param string $table | |
| 294 | + * | |
| 295 | + * @return array | |
| 296 | + */ | |
| 297 | + private function get_payment_db_rows( $table ) { | |
| 298 | + global $wpdb; | |
| 299 | + | |
| 300 | + if ( FrmDb::db_column_exists( $table, 'test' ) ) { | |
| 301 | + return $wpdb->get_results( | |
| 302 | + $wpdb->prepare( | |
| 303 | + 'SELECT amount, status, paysys, created_at FROM %i WHERE test IS NULL OR test != 1', | |
| 304 | + $wpdb->prefix . $table | |
| 305 | + ) | |
| 306 | + ); | |
| 307 | + } | |
| 308 | + | |
| 309 | + // Fallback for PayPal add-on where this column does not exist. | |
| 310 | + return $wpdb->get_results( | |
| 311 | + $wpdb->prepare( | |
| 312 | + 'SELECT amount, status, paysys, created_at FROM %i', | |
| 313 | + $wpdb->prefix . $table | |
| 314 | + ) | |
| 315 | + ); | |
| 316 | + } | |
| 317 | + | |
| 318 | + /** | |
| 183 | 319 | * @since 3.06.04 |
| 184 | 320 | * |
| 185 | 321 | * @return array |
| 186 | 322 | */ |
| @@ -185,11 +321,10 @@ | ||
| 185 | 321 | * @return array |
| 186 | 322 | */ |
| 187 | 323 | private function plugins() { |
| 188 | 324 | $plugin_list = FrmAppHelper::get_plugins(); |
| 325 | + $plugins = array(); | |
| 189 | 326 | |
| 190 | - $plugins = array(); | |
| 191 | - | |
| 192 | 327 | foreach ( $plugin_list as $slug => $info ) { |
| 193 | 328 | $plugins[] = array( |
| 194 | 329 | 'name' => $info['Name'], |
| 195 | 330 | 'slug' => $slug, |
| @@ -271,10 +406,9 @@ | ||
| 271 | 406 | 'login_msg', |
| 272 | 407 | 'admin_permission', |
| 273 | 408 | ); |
| 274 | 409 | |
| 275 | - $default = $settings_list->default_options(); | |
| 276 | - | |
| 410 | + $default = $settings_list->default_options(); | |
| 277 | 411 | $message_settings = array(); |
| 278 | 412 | |
| 279 | 413 | foreach ( $messages as $message ) { |
| 280 | 414 | $message_settings[ 'changed-' . $message ] = $settings_list->$message === $default[ $message ] ? 0 : 1; |
| @@ -370,28 +504,31 @@ | ||
| 370 | 504 | 'form_action_count' => $this->form_action_count( $form->id ), |
| 371 | 505 | ); |
| 372 | 506 | |
| 373 | 507 | foreach ( $settings as $setting ) { |
| 374 | - if ( isset( $form->options[ $setting ] ) ) { | |
| 375 | - if ( 'custom_style' === $setting ) { | |
| 376 | - $style->id = $form->options[ $setting ]; | |
| 508 | + if ( ! isset( $form->options[ $setting ] ) ) { | |
| 509 | + continue; | |
| 510 | + } | |
| 377 | 511 | |
| 378 | - if ( ! $style->id ) { | |
| 379 | - $style_name = 0; | |
| 380 | - } elseif ( 1 === intval( $style->id ) ) { | |
| 381 | - $style_name = 'formidable-style'; | |
| 382 | - } else { | |
| 383 | - $style_post = $style->get_one(); | |
| 384 | - $style_name = $style_post ? $style_post->post_name : 'formidable-style'; | |
| 385 | - } | |
| 512 | + if ( 'custom_style' !== $setting ) { | |
| 513 | + $new_form[ $setting ] = $this->maybe_json( $form->options[ $setting ] ); | |
| 514 | + continue; | |
| 515 | + } | |
| 386 | 516 | |
| 387 | - $new_form[ $setting ] = $style_name; | |
| 388 | - } else { | |
| 389 | - $new_form[ $setting ] = $this->maybe_json( $form->options[ $setting ] ); | |
| 390 | - } | |
| 517 | + $style->id = $form->options[ $setting ]; | |
| 518 | + | |
| 519 | + if ( ! $style->id ) { | |
| 520 | + $style_name = 0; | |
| 521 | + } elseif ( 1 === intval( $style->id ) ) { | |
| 522 | + $style_name = 'formidable-style'; | |
| 523 | + } else { | |
| 524 | + $style_post = $style->get_one(); | |
| 525 | + $style_name = $style_post ? $style_post->post_name : 'formidable-style'; | |
| 391 | 526 | } |
| 392 | - } | |
| 393 | 527 | |
| 528 | + $new_form[ $setting ] = $style_name; | |
| 529 | + }//end foreach | |
| 530 | + | |
| 394 | 531 | $forms[] = apply_filters( 'frm_usage_form', $new_form, compact( 'form' ) ); |
| 395 | 532 | }//end foreach |
| 396 | 533 | |
| 397 | 534 | // If the array uses numeric keys, reset them. |
| @@ -453,10 +590,11 @@ | ||
| 453 | 590 | $fields = FrmDb::get_results( 'frm_fields', array(), 'id, form_id, name, type, field_options', $args ); |
| 454 | 591 | |
| 455 | 592 | foreach ( $fields as $k => $field ) { |
| 456 | 593 | FrmAppHelper::unserialize_or_decode( $field->field_options ); |
| 457 | - $fields[ $k ]->field_options = json_encode( $field->field_options ); | |
| 594 | + $fields[ $k ]->field_options = $field->field_options; | |
| 458 | 595 | } |
| 596 | + | |
| 459 | 597 | return $fields; |
| 460 | 598 | } |
| 461 | 599 | |
| 462 | 600 | /** |
| @@ -464,25 +602,43 @@ | ||
| 464 | 602 | * |
| 465 | 603 | * @return array |
| 466 | 604 | */ |
| 467 | 605 | private function actions() { |
| 468 | - $args = array( | |
| 469 | - 'post_type' => FrmFormActionsController::$action_post_type, | |
| 470 | - 'numberposts' => 100, | |
| 471 | - ); | |
| 606 | + $actions = array(); | |
| 607 | + $offset = 0; | |
| 608 | + $limit = 100; | |
| 609 | + $limit_plus_one = $limit + 1; | |
| 472 | 610 | |
| 473 | - $actions = array(); | |
| 611 | + do { | |
| 612 | + $args = array( | |
| 613 | + 'post_type' => FrmFormActionsController::$action_post_type, | |
| 614 | + 'numberposts' => $limit_plus_one, | |
| 615 | + 'offset' => $offset, | |
| 616 | + ); | |
| 617 | + $saved_actions = get_posts( $args ); | |
| 618 | + $has_more = count( $saved_actions ) === $limit_plus_one; | |
| 474 | 619 | |
| 475 | - $saved_actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' ); | |
| 620 | + if ( $has_more ) { | |
| 621 | + // Pop off the last item as it is only queried to determine if there are more results. | |
| 622 | + array_pop( $saved_actions ); | |
| 623 | + } | |
| 476 | 624 | |
| 477 | - foreach ( $saved_actions as $action ) { | |
| 478 | - $actions[] = array( | |
| 479 | - 'form_id' => $action->menu_order, | |
| 480 | - 'type' => $action->post_excerpt, | |
| 481 | - 'status' => $action->post_status, | |
| 482 | - 'settings' => $action->post_content, | |
| 483 | - ); | |
| 484 | - } | |
| 625 | + foreach ( $saved_actions as $action ) { | |
| 626 | + $actions[] = array( | |
| 627 | + 'form_id' => $action->menu_order, | |
| 628 | + 'type' => $action->post_excerpt, | |
| 629 | + 'status' => $action->post_status, | |
| 630 | + 'settings' => FrmAppHelper::maybe_json_decode( $action->post_content ), | |
| 631 | + ); | |
| 632 | + unset( $action ); | |
| 633 | + } | |
| 634 | + | |
| 635 | + $offset += $limit; | |
| 636 | + | |
| 637 | + unset( $saved_actions ); | |
| 638 | + | |
| 639 | + gc_collect_cycles(); | |
| 640 | + } while ( $has_more ); | |
| 485 | 641 | |
| 486 | 642 | return $actions; |
| 487 | 643 | } |
| 488 | 644 | |