| @@ -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(), |
| @@ -89,9 +84,8 @@ | ||
| 89 | 84 | 'active_license' => FrmAppHelper::pro_is_installed(), |
| 90 | 85 | 'form_count' => $form_counts->published, |
| 91 | 86 | 'entry_count' => FrmEntry::getRecordCount(), |
| 92 | 87 | 'timestamp' => gmdate( 'c' ), |
| 93 | - 'misc' => array(), | |
| 94 | 88 | |
| 95 | 89 | 'theme_name' => is_object( $theme_data ) ? $theme_data->Name : '', // phpcs:ignore WordPress.NamingConventions |
| 96 | 90 | 'plugins' => $this->plugins(), |
| 97 | 91 | 'settings' => array( |
| @@ -101,9 +95,8 @@ | ||
| 101 | 95 | 'fields' => $this->fields(), |
| 102 | 96 | 'actions' => $this->actions(), |
| 103 | 97 | |
| 104 | 98 | 'onboarding-wizard' => $this->onboarding_wizard(), |
| 105 | - 'welcome-tour' => FrmWelcomeTourController::get_usage_data(), | |
| 106 | 99 | 'flows' => FrmUsageController::get_flows_data(), |
| 107 | 100 | 'payments' => $this->payments(), |
| 108 | 101 | 'subscriptions' => $this->payments( 'frm_subscriptions' ), |
| 109 | 102 | ); |
| @@ -115,125 +108,8 @@ | ||
| 115 | 108 | return apply_filters( 'frm_usage_snapshot', $snap ); |
| 116 | 109 | } |
| 117 | 110 | |
| 118 | 111 | /** |
| 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' ) || str_contains( $value, '@' ) ) { | |
| 229 | - // Replace it with a placeholder. | |
| 230 | - $value = '{{contain_email}}'; | |
| 231 | - } | |
| 232 | - }//end foreach | |
| 233 | - } | |
| 234 | - | |
| 235 | - /** | |
| 236 | 112 | * Gets onboarding wizard data. |
| 237 | 113 | * |
| 238 | 114 | * @since 6.16.1 |
| 239 | 115 | * |
| @@ -261,21 +137,29 @@ | ||
| 261 | 137 | * |
| 262 | 138 | * @since 6.16.1 |
| 263 | 139 | * |
| 264 | 140 | * @param string $table Database table name. |
| 265 | - * | |
| 266 | 141 | * @return array |
| 267 | 142 | */ |
| 268 | 143 | private function payments( $table = 'frm_payments' ) { |
| 269 | 144 | $allowed_tables = array( 'frm_payments', 'frm_subscriptions' ); |
| 145 | + if ( ! in_array( $table, $allowed_tables, true ) ) { | |
| 146 | + return array(); | |
| 147 | + } | |
| 270 | 148 | |
| 271 | - if ( ! in_array( $table, $allowed_tables, true ) || ! FrmTransLiteAppHelper::payments_table_exists() ) { | |
| 149 | + if ( ! FrmTransLiteAppHelper::payments_table_exists() ) { | |
| 272 | 150 | return array(); |
| 273 | 151 | } |
| 274 | 152 | |
| 275 | - $rows = $this->get_payment_db_rows( $table ); | |
| 153 | + global $wpdb; | |
| 154 | + $rows = $wpdb->get_results( | |
| 155 | + $wpdb->prepare( | |
| 156 | + 'SELECT amount, status, paysys, created_at FROM %1$s', | |
| 157 | + $wpdb->prefix . $table | |
| 158 | + ) | |
| 159 | + ); | |
| 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, |
| @@ -287,44 +171,15 @@ | ||
| 287 | 171 | return $payments; |
| 288 | 172 | } |
| 289 | 173 | |
| 290 | 174 | /** |
| 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 | - /** | |
| 319 | 175 | * @since 3.06.04 |
| 320 | - * | |
| 321 | 176 | * @return array |
| 322 | 177 | */ |
| 323 | 178 | private function plugins() { |
| 324 | 179 | $plugin_list = FrmAppHelper::get_plugins(); |
| 325 | - $plugins = array(); | |
| 326 | 180 | |
| 181 | + $plugins = array(); | |
| 327 | 182 | foreach ( $plugin_list as $slug => $info ) { |
| 328 | 183 | $plugins[] = array( |
| 329 | 184 | 'name' => $info['Name'], |
| 330 | 185 | 'slug' => $slug, |
| @@ -339,9 +194,8 @@ | ||
| 339 | 194 | /** |
| 340 | 195 | * Add global settings to tracking data. |
| 341 | 196 | * |
| 342 | 197 | * @since 3.06.04 |
| 343 | - * | |
| 344 | 198 | * @return array |
| 345 | 199 | */ |
| 346 | 200 | private function settings() { |
| 347 | 201 | $settings_list = FrmAppHelper::get_settings(); |
| @@ -368,9 +222,8 @@ | ||
| 368 | 222 | 'active_captcha', |
| 369 | 223 | 'honeypot', |
| 370 | 224 | 'wp_spam_check', |
| 371 | 225 | 'denylist_check', |
| 372 | - 'email_style', | |
| 373 | 226 | ); |
| 374 | 227 | |
| 375 | 228 | foreach ( $pass_settings as $setting ) { |
| 376 | 229 | if ( isset( $settings_list->$setting ) ) { |
| @@ -391,9 +244,8 @@ | ||
| 391 | 244 | * |
| 392 | 245 | * @since 3.06.04 |
| 393 | 246 | * |
| 394 | 247 | * @param FrmSettings $settings_list |
| 395 | - * | |
| 396 | 248 | * @return array |
| 397 | 249 | */ |
| 398 | 250 | private function messages( $settings_list ) { |
| 399 | 251 | $messages = array( |
| @@ -406,11 +258,11 @@ | ||
| 406 | 258 | 'login_msg', |
| 407 | 259 | 'admin_permission', |
| 408 | 260 | ); |
| 409 | 261 | |
| 410 | - $default = $settings_list->default_options(); | |
| 262 | + $default = $settings_list->default_options(); | |
| 263 | + | |
| 411 | 264 | $message_settings = array(); |
| 412 | - | |
| 413 | 265 | foreach ( $messages as $message ) { |
| 414 | 266 | $message_settings[ 'changed-' . $message ] = $settings_list->$message === $default[ $message ] ? 0 : 1; |
| 415 | 267 | } |
| 416 | 268 | |
| @@ -422,9 +274,8 @@ | ||
| 422 | 274 | * |
| 423 | 275 | * @since 3.06.04 |
| 424 | 276 | * |
| 425 | 277 | * @param FrmSettings $settings_list |
| 426 | - * | |
| 427 | 278 | * @return array |
| 428 | 279 | */ |
| 429 | 280 | private function permissions( $settings_list ) { |
| 430 | 281 | $permissions = array(); |
| @@ -440,9 +291,8 @@ | ||
| 440 | 291 | } |
| 441 | 292 | |
| 442 | 293 | /** |
| 443 | 294 | * @since 3.06.04 |
| 444 | - * | |
| 445 | 295 | * @return array |
| 446 | 296 | */ |
| 447 | 297 | private function forms() { |
| 448 | 298 | $s_query = array( |
| @@ -490,9 +340,8 @@ | ||
| 490 | 340 | 'submit_conditions', |
| 491 | 341 | ); |
| 492 | 342 | |
| 493 | 343 | $style = new FrmStyle(); |
| 494 | - | |
| 495 | 344 | foreach ( $saved_forms as $form ) { |
| 496 | 345 | $new_form = array( |
| 497 | 346 | 'form_id' => $form->id, |
| 498 | 347 | 'description' => $form->description, |
| @@ -504,31 +353,28 @@ | ||
| 504 | 353 | 'form_action_count' => $this->form_action_count( $form->id ), |
| 505 | 354 | ); |
| 506 | 355 | |
| 507 | 356 | foreach ( $settings as $setting ) { |
| 508 | - if ( ! isset( $form->options[ $setting ] ) ) { | |
| 509 | - continue; | |
| 510 | - } | |
| 357 | + if ( isset( $form->options[ $setting ] ) ) { | |
| 358 | + if ( 'custom_style' === $setting ) { | |
| 359 | + $style->id = $form->options[ $setting ]; | |
| 511 | 360 | |
| 512 | - if ( 'custom_style' !== $setting ) { | |
| 513 | - $new_form[ $setting ] = $this->maybe_json( $form->options[ $setting ] ); | |
| 514 | - continue; | |
| 515 | - } | |
| 361 | + if ( ! $style->id ) { | |
| 362 | + $style_name = 0; | |
| 363 | + } elseif ( 1 === intval( $style->id ) ) { | |
| 364 | + $style_name = 'formidable-style'; | |
| 365 | + } else { | |
| 366 | + $style_post = $style->get_one(); | |
| 367 | + $style_name = $style_post ? $style_post->post_name : 'formidable-style'; | |
| 368 | + } | |
| 516 | 369 | |
| 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'; | |
| 370 | + $new_form[ $setting ] = $style_name; | |
| 371 | + } else { | |
| 372 | + $new_form[ $setting ] = $this->maybe_json( $form->options[ $setting ] ); | |
| 373 | + } | |
| 526 | 374 | } |
| 375 | + } | |
| 527 | 376 | |
| 528 | - $new_form[ $setting ] = $style_name; | |
| 529 | - }//end foreach | |
| 530 | - | |
| 531 | 377 | $forms[] = apply_filters( 'frm_usage_form', $new_form, compact( 'form' ) ); |
| 532 | 378 | }//end foreach |
| 533 | 379 | |
| 534 | 380 | // If the array uses numeric keys, reset them. |
| @@ -536,11 +382,8 @@ | ||
| 536 | 382 | } |
| 537 | 383 | |
| 538 | 384 | /** |
| 539 | 385 | * @since 3.06.04 |
| 540 | - * | |
| 541 | - * @param int|string $form_id Form ID. | |
| 542 | - * | |
| 543 | 386 | * @return int |
| 544 | 387 | */ |
| 545 | 388 | private function form_field_count( $form_id ) { |
| 546 | 389 | global $wpdb; |
| @@ -557,11 +400,8 @@ | ||
| 557 | 400 | } |
| 558 | 401 | |
| 559 | 402 | /** |
| 560 | 403 | * @since 3.06.04 |
| 561 | - * | |
| 562 | - * @param int|string $form_id Form ID. | |
| 563 | - * | |
| 564 | 404 | * @return int |
| 565 | 405 | */ |
| 566 | 406 | private function form_action_count( $form_id ) { |
| 567 | 407 | $args = array( |
| @@ -577,9 +417,8 @@ | ||
| 577 | 417 | /** |
| 578 | 418 | * Get the last 100 fields created. |
| 579 | 419 | * |
| 580 | 420 | * @since 3.06.04 |
| 581 | - * | |
| 582 | 421 | * @return array |
| 583 | 422 | */ |
| 584 | 423 | private function fields() { |
| 585 | 424 | $args = array( |
| @@ -587,20 +426,17 @@ | ||
| 587 | 426 | 'order_by' => 'id DESC', |
| 588 | 427 | ); |
| 589 | 428 | |
| 590 | 429 | $fields = FrmDb::get_results( 'frm_fields', array(), 'id, form_id, name, type, field_options', $args ); |
| 591 | - | |
| 592 | 430 | foreach ( $fields as $k => $field ) { |
| 593 | 431 | FrmAppHelper::unserialize_or_decode( $field->field_options ); |
| 594 | - $fields[ $k ]->field_options = $field->field_options; | |
| 432 | + $fields[ $k ]->field_options = json_encode( $field->field_options ); | |
| 595 | 433 | } |
| 596 | - | |
| 597 | 434 | return $fields; |
| 598 | 435 | } |
| 599 | 436 | |
| 600 | 437 | /** |
| 601 | 438 | * @since 3.06.04 |
| 602 | - * | |
| 603 | 439 | * @return array |
| 604 | 440 | */ |
| 605 | 441 | private function actions() { |
| 606 | 442 | $args = array( |
| @@ -607,17 +443,17 @@ | ||
| 607 | 443 | 'post_type' => FrmFormActionsController::$action_post_type, |
| 608 | 444 | 'numberposts' => 100, |
| 609 | 445 | ); |
| 610 | 446 | |
| 611 | - $actions = array(); | |
| 447 | + $actions = array(); | |
| 448 | + | |
| 612 | 449 | $saved_actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' ); |
| 613 | - | |
| 614 | 450 | foreach ( $saved_actions as $action ) { |
| 615 | 451 | $actions[] = array( |
| 616 | 452 | 'form_id' => $action->menu_order, |
| 617 | 453 | 'type' => $action->post_excerpt, |
| 618 | 454 | 'status' => $action->post_status, |
| 619 | - 'settings' => FrmAppHelper::maybe_json_decode( $action->post_content ), | |
| 455 | + 'settings' => $action->post_content, | |
| 620 | 456 | ); |
| 621 | 457 | } |
| 622 | 458 | |
| 623 | 459 | return $actions; |
| @@ -624,9 +460,8 @@ | ||
| 624 | 460 | } |
| 625 | 461 | |
| 626 | 462 | /** |
| 627 | 463 | * @since 3.06.04 |
| 628 | - * | |
| 629 | 464 | * @return bool |
| 630 | 465 | */ |
| 631 | 466 | private function tracking_allowed() { |
| 632 | 467 | return FrmUsageController::tracking_allowed(); |
| @@ -633,11 +468,8 @@ | ||
| 633 | 468 | } |
| 634 | 469 | |
| 635 | 470 | /** |
| 636 | 471 | * @since 3.06.04 |
| 637 | - * | |
| 638 | - * @param mixed $value Value. | |
| 639 | - * | |
| 640 | 472 | * @return string |
| 641 | 473 | */ |
| 642 | 474 | private function maybe_json( $value ) { |
| 643 | 475 | return is_array( $value ) ? json_encode( $value ) : $value; |