PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.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 +55 -191 6.275.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 - $plugin_list = FrmAppHelper::get_plugins();
189 - $plugins = array();
97 + $plugin_list = get_plugins();
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,22 @@
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',
127 + 'old_css',
218 128 'fade_form',
129 + 'jquery_css',
219 130 're_type',
220 131 're_lang',
221 132 're_multi',
222 133 'menu',
@@ -221,20 +132,11 @@
221 132 're_multi',
222 133 'menu',
223 134 'mu_menu',
224 135 'no_ips',
225 - 'custom_header_ip',
226 - 'enable_gdpr',
227 - 'no_gdpr_cookies',
228 136 'btsp_css',
229 - 'btsp_version',
137 + 'btsp_errors',
230 138 'admin_bar',
231 - 'summary_emails',
232 - 'active_captcha',
233 - 'honeypot',
234 - 'wp_spam_check',
235 - 'denylist_check',
236 - 'email_style',
237 139 );
238 140
239 141 foreach ( $pass_settings as $setting ) {
240 142 if ( isset( $settings_list->$setting ) ) {
@@ -253,11 +155,8 @@
253 155 /**
254 156 * Include the permissions settings for each capability.
255 157 *
256 158 * @since 3.06.04
257 - *
258 - * @param FrmSettings $settings_list
259 - *
260 159 * @return array
261 160 */
262 161 private function messages( $settings_list ) {
263 162 $messages = array(
@@ -270,13 +169,11 @@
270 169 'login_msg',
271 170 'admin_permission',
272 171 );
273 172
274 - $default = $settings_list->default_options();
275 173 $message_settings = array();
276 -
277 174 foreach ( $messages as $message ) {
278 - $message_settings[ 'changed-' . $message ] = $settings_list->$message === $default[ $message ] ? 0 : 1;
175 + $message_settings[ $message ] = $settings_list->$message;
279 176 }
280 177
281 178 return $message_settings;
282 179 }
@@ -284,11 +181,8 @@
284 181 /**
285 182 * Include the permissions settings for each capability.
286 183 *
287 184 * @since 3.06.04
288 - *
289 - * @param FrmSettings $settings_list
290 - *
291 185 * @return array
292 186 */
293 187 private function permissions( $settings_list ) {
294 188 $permissions = array();
@@ -304,16 +198,15 @@
304 198 }
305 199
306 200 /**
307 201 * @since 3.06.04
308 - *
309 202 * @return array
310 203 */
311 204 private function forms() {
312 205 $s_query = array(
313 206 array(
314 - 'or' => 1,
315 - 'parent_form_id' => null,
207 + 'or' => 1,
208 + 'parent_form_id' => null,
316 209 'parent_form_id <' => 1,
317 210 ),
318 211 );
319 212
@@ -321,10 +214,10 @@
321 214 $forms = array();
322 215 $settings = array(
323 216 'form_class',
324 217 'akismet',
218 + 'honeypot',
325 219 'antispam',
326 - 'stopforumspam',
327 220 'custom_style',
328 221 'success_action',
329 222 'show_form',
330 223 'no_save',
@@ -353,45 +246,28 @@
353 246 'prev_value',
354 247 'submit_conditions',
355 248 );
356 249
357 - $style = new FrmStyle();
358 -
359 250 foreach ( $saved_forms as $form ) {
360 251 $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 ),
252 + 'form_id' => $form->id,
253 + 'description' => $form->description,
254 + 'logged_in' => $form->logged_in,
255 + 'editable' => $form->editable,
256 + 'is_template' => $form->is_template,
257 + 'entry_count' => FrmEntry::getRecordCount( $form->id ),
258 + 'field_count' => $this->form_field_count( $form->id ),
368 259 'form_action_count' => $this->form_action_count( $form->id ),
369 260 );
370 261
371 262 foreach ( $settings as $setting ) {
372 263 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 - }
264 + $new_form[ $setting ] = $this->maybe_json( $form->options[ $setting ] );
389 265 }
390 266 }
391 267
392 268 $forms[] = apply_filters( 'frm_usage_form', $new_form, compact( 'form' ) );
393 - }//end foreach
269 + }
394 270
395 271 // If the array uses numeric keys, reset them.
396 272 return $forms;
397 273 }
@@ -397,17 +273,14 @@
397 273 }
398 274
399 275 /**
400 276 * @since 3.06.04
401 - *
402 - * @param int|string $form_id Form ID.
403 - *
404 277 * @return int
405 278 */
406 279 private function form_field_count( $form_id ) {
407 280 global $wpdb;
408 281
409 - $join = $wpdb->prefix . 'frm_fields fi JOIN ' . $wpdb->prefix . 'frm_forms fo ON (fi.form_id=fo.id)';
282 + $join = $wpdb->prefix . 'frm_fields fi LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fo ON (fi.form_id=fo.id)';
410 283
411 284 $field_query = array(
412 285 'or' => 1,
413 286 'fi.form_id' => $form_id,
@@ -418,11 +291,8 @@
418 291 }
419 292
420 293 /**
421 294 * @since 3.06.04
422 - *
423 - * @param int|string $form_id Form ID.
424 - *
425 295 * @return int
426 296 */
427 297 private function form_action_count( $form_id ) {
428 298 $args = array(
@@ -438,30 +308,26 @@
438 308 /**
439 309 * Get the last 100 fields created.
440 310 *
441 311 * @since 3.06.04
442 - *
443 312 * @return array
444 313 */
445 314 private function fields() {
446 - $args = array(
315 + $args = array(
447 316 'limit' => 50,
448 317 'order_by' => 'id DESC',
449 318 );
450 319
451 - $fields = FrmDb::get_results( 'frm_fields', array(), 'id, form_id, name, type, field_options', $args );
452 -
320 + $fields = FrmDb::get_results( 'frm_fields', array(), 'form_id, name, type, field_options', $args );
453 321 foreach ( $fields as $k => $field ) {
454 322 FrmAppHelper::unserialize_or_decode( $field->field_options );
455 323 $fields[ $k ]->field_options = json_encode( $field->field_options );
456 324 }
457 -
458 325 return $fields;
459 326 }
460 327
461 328 /**
462 329 * @since 3.06.04
463 - *
464 330 * @return array
465 331 */
466 332 private function actions() {
467 333 $args = array(
@@ -468,11 +334,11 @@
468 334 'post_type' => FrmFormActionsController::$action_post_type,
469 335 'numberposts' => 100,
470 336 );
471 337
472 - $actions = array();
338 + $actions = array();
339 +
473 340 $saved_actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
474 -
475 341 foreach ( $saved_actions as $action ) {
476 342 $actions[] = array(
477 343 'form_id' => $action->menu_order,
478 344 'type' => $action->post_excerpt,
@@ -485,20 +351,17 @@
485 351 }
486 352
487 353 /**
488 354 * @since 3.06.04
489 - *
490 355 * @return bool
491 356 */
492 357 private function tracking_allowed() {
493 - return FrmUsageController::tracking_allowed();
358 + $settings = FrmAppHelper::get_settings();
359 + return $settings->tracking;
494 360 }
495 361
496 362 /**
497 363 * @since 3.06.04
498 - *
499 - * @param mixed $value Value.
500 - *
501 364 * @return string
502 365 */
503 366 private function maybe_json( $value ) {
504 367 return is_array( $value ) ? json_encode( $value ) : $value;
@@ -503,4 +366,5 @@
503 366 private function maybe_json( $value ) {
504 367 return is_array( $value ) ? json_encode( $value ) : $value;
505 368 }
506 369 }
370 +