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