PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 3.06.06
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v3.06.06
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 +54 -202 6.263.06.06 View file →
@@ -9,10 +9,8 @@
9 9 class FrmUsage {
10 10
11 11 /**
12 12 * @since 3.06.04
13 - *
14 - * @return void
15 13 */
16 14 public function send_snapshot() {
17 15 if ( ! $this->tracking_allowed() ) {
18 16 return;
@@ -17,38 +15,27 @@
17 15 if ( ! $this->tracking_allowed() ) {
18 16 return;
19 17 }
20 18
21 - $ep = 'aHR0cHM6Ly91c2FnZTIuZm9ybWlkYWJsZWZvcm1zLmNvbS9zbmFwc2hvdA==';
22 - // $ep = base64_encode( 'http://localhost:4567/snapshot' ); // Uncomment for testing
19 + $ep = 'aHR0cHM6Ly9mcm0tdXNlci10cmFja2luZy5oZXJva3VhcHAuY29tL3NuYXBzaG90';
23 20 $body = json_encode( $this->snapshot() );
24 21
25 22 // Setup variable for wp_remote_request.
26 23 $post = array(
27 - 'method' => 'POST',
28 - 'headers' => array(
24 + 'method' => 'POST',
25 + 'headers' => array(
29 26 'Accept' => 'application/json',
30 27 'Content-Type' => 'application/json',
31 28 'Content-Length' => strlen( $body ),
32 29 ),
33 - 'body' => $body,
34 - // Without this, Debug Log catches the `http_request_failed` error.
35 - 'timeout' => 45,
30 + 'body' => $body,
36 31 );
37 32
38 - // Remove time limit to execute this function.
39 - if ( function_exists( 'set_time_limit' ) ) {
40 - set_time_limit( 0 );
41 - }
42 -
43 33 wp_remote_request( base64_decode( $ep ), $post );
44 34 }
45 35
46 36 /**
47 37 * @since 3.06.04
48 - *
49 - * @param bool $regenerate
50 - *
51 38 * @return string
52 39 */
53 40 public function uuid( $regenerate = false ) {
54 41 $uuid_key = 'frm-usage-uuid';
@@ -65,9 +52,8 @@
65 52 }
66 53
67 54 /**
68 55 * @since 3.06.04
69 - *
70 56 * @return array
71 57 */
72 58 public function snapshot() {
73 59 global $wpdb, $wp_version;
@@ -75,127 +61,48 @@
75 61 $theme_data = wp_get_theme();
76 62 $form_counts = FrmForm::get_count();
77 63
78 64 $snap = array(
79 - 'uuid' => $this->uuid(),
80 - // Let's keep it anonymous.
81 - 'admin_email' => '',
82 - 'wp_version' => $wp_version,
83 - 'php_version' => phpversion(),
84 - 'mysql_version' => $wpdb->db_version(),
85 - 'os' => FrmAppHelper::get_server_os(),
86 - 'locale' => get_locale(),
65 + 'uuid' => $this->uuid(),
66 + 'admin_email' => '', // Let's keep it anonymous.
67 + 'wp_version' => $wp_version,
68 + 'php_version' => phpversion(),
69 + 'mysql_version' => $wpdb->db_version(),
70 + 'os' => php_uname( 's' ),
71 + 'locale' => get_locale(),
87 72
88 - 'active_license' => FrmAppHelper::pro_is_installed(),
89 - 'form_count' => $form_counts->published,
90 - 'entry_count' => FrmEntry::getRecordCount(),
91 - 'timestamp' => gmdate( 'c' ),
73 + 'active_license' => FrmAppHelper::pro_is_installed(),
74 + 'form_count' => $form_counts->published,
75 + 'entry_count' => FrmEntry::getRecordCount(),
76 + 'timestamp' => gmdate( 'c' ),
92 77
93 - 'theme_name' => is_object( $theme_data ) ? $theme_data->Name : '', // phpcs:ignore WordPress.NamingConventions
94 - 'plugins' => $this->plugins(),
95 - 'settings' => array(
78 + 'theme_name' => $theme_data->Name, // phpcs:ignore WordPress.NamingConventions
79 + 'plugins' => $this->plugins(),
80 + 'settings' => array(
96 81 $this->settings(),
97 82 ),
98 - 'forms' => $this->forms(),
99 - 'fields' => $this->fields(),
100 - 'actions' => $this->actions(),
101 -
102 - 'onboarding-wizard' => $this->onboarding_wizard(),
103 - 'welcome-tour' => FrmWelcomeTourController::get_usage_data(),
104 - 'flows' => FrmUsageController::get_flows_data(),
105 - 'payments' => $this->payments(),
106 - 'subscriptions' => $this->payments( 'frm_subscriptions' ),
83 + 'forms' => $this->forms(),
84 + 'fields' => $this->fields(),
85 + 'actions' => $this->actions(),
107 86 );
108 87
109 - if ( method_exists( 'FrmProAddonsController', 'get_readable_license_type' ) ) {
110 - $snap['active_license'] = FrmProAddonsController::get_readable_license_type();
111 - }
112 -
113 88 return apply_filters( 'frm_usage_snapshot', $snap );
114 89 }
115 90
116 91 /**
117 - * Gets onboarding wizard data.
118 - *
119 - * @since 6.16.1
120 - *
121 - * @return array
122 - */
123 - private function onboarding_wizard() {
124 - $data = FrmOnboardingWizardController::get_usage_data();
125 - $skipped_keys = array(
126 - 'default_email',
127 - 'is_subscribed',
128 - 'allows_tracking',
129 - 'summary_emails',
130 - 'installed_addons',
131 - );
132 -
133 - foreach ( $skipped_keys as $skipped_key ) {
134 - unset( $data[ $skipped_key ] );
135 - }
136 -
137 - return $data;
138 - }
139 -
140 - /**
141 - * Gets payments data.
142 - *
143 - * @since 6.16.1
144 - *
145 - * @param string $table Database table name.
146 - *
147 - * @return array
148 - */
149 - private function payments( $table = 'frm_payments' ) {
150 - $allowed_tables = array( 'frm_payments', 'frm_subscriptions' );
151 -
152 - if ( ! in_array( $table, $allowed_tables, true ) ) {
153 - return array();
154 - }
155 -
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 -
168 - $payments = array();
169 -
170 - foreach ( $rows as $row ) {
171 - $payments[] = array(
172 - 'amount' => (float) $row->amount,
173 - 'status' => $row->status,
174 - 'gateway' => $row->paysys,
175 - 'created_at' => $row->created_at,
176 - );
177 - }
178 -
179 - return $payments;
180 - }
181 -
182 - /**
183 92 * @since 3.06.04
184 - *
185 93 * @return array
186 94 */
187 95 private function plugins() {
188 - $plugin_list = FrmAppHelper::get_plugins();
96 + $plugin_list = get_plugins();
189 97
190 98 $plugins = array();
191 -
192 99 foreach ( $plugin_list as $slug => $info ) {
193 100 $plugins[] = array(
194 - 'name' => $info['Name'],
195 - 'slug' => $slug,
196 - 'version' => $info['Version'],
197 - 'active' => is_plugin_active( $slug ),
101 + 'name' => $info['Name'],
102 + 'slug' => $slug,
103 + 'version' => $info['Version'],
104 + 'active' => is_plugin_active( $slug ),
198 105 );
199 106 }
200 107
201 108 return $plugins;
@@ -204,20 +111,22 @@
204 111 /**
205 112 * Add global settings to tracking data.
206 113 *
207 114 * @since 3.06.04
208 - *
209 115 * @return array
210 116 */
211 117 private function settings() {
212 - $settings_list = FrmAppHelper::get_settings();
213 - $settings = array(
118 + $settings_list = FrmAppHelper::get_settings();
119 + $settings = array(
214 120 'messages' => $this->messages( $settings_list ),
215 121 'permissions' => $this->permissions( $settings_list ),
216 122 );
217 123 $pass_settings = array(
218 124 'load_style',
125 + 'use_html',
126 + 'old_css',
219 127 'fade_form',
128 + 'jquery_css',
220 129 're_type',
221 130 're_lang',
222 131 're_multi',
223 132 'menu',
@@ -222,20 +131,10 @@
222 131 're_multi',
223 132 'menu',
224 133 'mu_menu',
225 134 'no_ips',
226 - 'custom_header_ip',
227 - 'enable_gdpr',
228 - 'no_gdpr_cookies',
229 135 'btsp_css',
230 - 'btsp_version',
231 - 'admin_bar',
232 - 'summary_emails',
233 - 'active_captcha',
234 - 'honeypot',
235 - 'wp_spam_check',
236 - 'denylist_check',
237 - 'email_style',
136 + 'btsp_errors',
238 137 );
239 138
240 139 foreach ( $pass_settings as $setting ) {
241 140 if ( isset( $settings_list->$setting ) ) {
@@ -254,11 +153,8 @@
254 153 /**
255 154 * Include the permissions settings for each capability.
256 155 *
257 156 * @since 3.06.04
258 - *
259 - * @param FrmSettings $settings_list
260 - *
261 157 * @return array
262 158 */
263 159 private function messages( $settings_list ) {
264 160 $messages = array(
@@ -271,14 +167,11 @@
271 167 'login_msg',
272 168 'admin_permission',
273 169 );
274 170
275 - $default = $settings_list->default_options();
276 -
277 171 $message_settings = array();
278 -
279 172 foreach ( $messages as $message ) {
280 - $message_settings[ 'changed-' . $message ] = $settings_list->$message === $default[ $message ] ? 0 : 1;
173 + $message_settings[ $message ] = $settings_list->$message;
281 174 }
282 175
283 176 return $message_settings;
284 177 }
@@ -286,11 +179,8 @@
286 179 /**
287 180 * Include the permissions settings for each capability.
288 181 *
289 182 * @since 3.06.04
290 - *
291 - * @param FrmSettings $settings_list
292 - *
293 183 * @return array
294 184 */
295 185 private function permissions( $settings_list ) {
296 186 $permissions = array();
@@ -306,16 +196,15 @@
306 196 }
307 197
308 198 /**
309 199 * @since 3.06.04
310 - *
311 200 * @return array
312 201 */
313 202 private function forms() {
314 203 $s_query = array(
315 204 array(
316 - 'or' => 1,
317 - 'parent_form_id' => null,
205 + 'or' => 1,
206 + 'parent_form_id' => null,
318 207 'parent_form_id <' => 1,
319 208 ),
320 209 );
321 210
@@ -323,10 +212,8 @@
323 212 $forms = array();
324 213 $settings = array(
325 214 'form_class',
326 215 'akismet',
327 - 'antispam',
328 - 'stopforumspam',
329 216 'custom_style',
330 217 'success_action',
331 218 'show_form',
332 219 'no_save',
@@ -344,9 +231,8 @@
344 231 'save_draft',
345 232 'draft_msg',
346 233 'submit_align',
347 234 'protect_files',
348 - 'protect_files_role',
349 235 'max_entries',
350 236 'open_status',
351 237 'closed_msg',
352 238 'open_date',
@@ -355,45 +241,28 @@
355 241 'prev_value',
356 242 'submit_conditions',
357 243 );
358 244
359 - $style = new FrmStyle();
360 -
361 245 foreach ( $saved_forms as $form ) {
362 246 $new_form = array(
363 - 'form_id' => $form->id,
364 - 'description' => $form->description,
365 - 'logged_in' => $form->logged_in,
366 - 'editable' => $form->editable,
367 - 'is_template' => $form->is_template,
368 - 'entry_count' => FrmEntry::getRecordCount( $form->id ),
369 - 'field_count' => $this->form_field_count( $form->id ),
247 + 'form_id' => $form->id,
248 + 'description' => $form->description,
249 + 'logged_in' => $form->logged_in,
250 + 'editable' => $form->editable,
251 + 'is_template' => $form->is_template,
252 + 'entry_count' => FrmEntry::getRecordCount( $form->id ),
253 + 'field_count' => $this->form_field_count( $form->id ),
370 254 'form_action_count' => $this->form_action_count( $form->id ),
371 255 );
372 256
373 257 foreach ( $settings as $setting ) {
374 258 if ( isset( $form->options[ $setting ] ) ) {
375 - if ( 'custom_style' === $setting ) {
376 - $style->id = $form->options[ $setting ];
377 -
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 - }
386 -
387 - $new_form[ $setting ] = $style_name;
388 - } else {
389 - $new_form[ $setting ] = $this->maybe_json( $form->options[ $setting ] );
390 - }
259 + $new_form[ $setting ] = $this->maybe_json( $form->options[ $setting ] );
391 260 }
392 261 }
393 262
394 263 $forms[] = apply_filters( 'frm_usage_form', $new_form, compact( 'form' ) );
395 - }//end foreach
264 + }
396 265
397 266 // If the array uses numeric keys, reset them.
398 267 return $forms;
399 268 }
@@ -399,21 +268,18 @@
399 268 }
400 269
401 270 /**
402 271 * @since 3.06.04
403 - *
404 - * @param int|string $form_id Form ID.
405 - *
406 272 * @return int
407 273 */
408 274 private function form_field_count( $form_id ) {
409 275 global $wpdb;
410 276
411 - $join = $wpdb->prefix . 'frm_fields fi JOIN ' . $wpdb->prefix . 'frm_forms fo ON (fi.form_id=fo.id)';
277 + $join = $wpdb->prefix . 'frm_fields fi LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fo ON (fi.form_id=fo.id)';
412 278
413 279 $field_query = array(
414 280 'or' => 1,
415 - 'fi.form_id' => $form_id,
281 + 'form_id' => $form_id,
416 282 'parent_form_id' => $form_id,
417 283 );
418 284
419 285 return FrmDb::get_count( $join, $field_query );
@@ -420,11 +286,8 @@
420 286 }
421 287
422 288 /**
423 289 * @since 3.06.04
424 - *
425 - * @param int|string $form_id Form ID.
426 - *
427 290 * @return int
428 291 */
429 292 private function form_action_count( $form_id ) {
430 293 $args = array(
@@ -432,9 +295,9 @@
432 295 'menu_order' => $form_id,
433 296 'fields' => 'ids',
434 297 );
435 298
436 - $actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
299 + $actions = FrmDb::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' );
437 300 return count( $actions );
438 301 }
439 302
440 303 /**
@@ -440,29 +303,21 @@
440 303 /**
441 304 * Get the last 100 fields created.
442 305 *
443 306 * @since 3.06.04
444 - *
445 307 * @return array
446 308 */
447 309 private function fields() {
448 - $args = array(
449 - 'limit' => 50,
310 + $args = array(
311 + 'limit' => 100,
450 312 'order_by' => 'id DESC',
451 313 );
452 314
453 - $fields = FrmDb::get_results( 'frm_fields', array(), 'id, form_id, name, type, field_options', $args );
454 -
455 - foreach ( $fields as $k => $field ) {
456 - FrmAppHelper::unserialize_or_decode( $field->field_options );
457 - $fields[ $k ]->field_options = json_encode( $field->field_options );
458 - }
459 - return $fields;
315 + return FrmDb::get_results( 'frm_fields', array(), 'form_id, name, type', $args );
460 316 }
461 317
462 318 /**
463 319 * @since 3.06.04
464 - *
465 320 * @return array
466 321 */
467 322 private function actions() {
468 323 $args = array(
@@ -471,10 +326,9 @@
471 326 );
472 327
473 328 $actions = array();
474 329
475 - $saved_actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
476 -
330 + $saved_actions = FrmDb::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' );
477 331 foreach ( $saved_actions as $action ) {
478 332 $actions[] = array(
479 333 'form_id' => $action->menu_order,
480 334 'type' => $action->post_excerpt,
@@ -487,20 +341,17 @@
487 341 }
488 342
489 343 /**
490 344 * @since 3.06.04
491 - *
492 345 * @return bool
493 346 */
494 347 private function tracking_allowed() {
495 - return FrmUsageController::tracking_allowed();
348 + $settings = FrmAppHelper::get_settings();
349 + return $settings->tracking;
496 350 }
497 351
498 352 /**
499 353 * @since 3.06.04
500 - *
501 - * @param mixed $value Value.
502 - *
503 354 * @return string
504 355 */
505 356 private function maybe_json( $value ) {
506 357 return is_array( $value ) ? json_encode( $value ) : $value;
@@ -505,4 +356,5 @@
505 356 private function maybe_json( $value ) {
506 357 return is_array( $value ) ? json_encode( $value ) : $value;
507 358 }
508 359 }
360 +