PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8.2
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
formidable / classes / models / FrmUsage.php

FrmUsage.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.8.2, at classes/models/FrmUsage.php

377 lines 8.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 /**
7 * @since 3.06.04
8 */
9 class FrmUsage {
10
11 /**
12 * @since 3.06.04
13 *
14 * @return void
15 */
16 public function send_snapshot() {
17 if ( ! $this->tracking_allowed() ) {
18 return;
19 }
20
21 $ep = 'aHR0cHM6Ly91c2FnZS5mb3JtaWRhYmxlZm9ybXMuY29tL2FwcC9zbmFwc2hvdAo=';
22 // $ep = base64_encode( 'http://localhost:4567/snapshot' ); // Uncomment for testing
23 $body = json_encode( $this->snapshot() );
24
25 // Setup variable for wp_remote_request.
26 $post = array(
27 'method' => 'POST',
28 'headers' => array(
29 'Accept' => 'application/json',
30 'Content-Type' => 'application/json',
31 'Content-Length' => strlen( $body ),
32 ),
33 'body' => $body,
34 );
35
36 wp_remote_request( base64_decode( $ep ), $post );
37 }
38
39 /**
40 * @since 3.06.04
41 * @return string
42 */
43 public function uuid( $regenerate = false ) {
44 $uuid_key = 'frm-usage-uuid';
45 $uuid = get_option( $uuid_key );
46
47 if ( $regenerate || empty( $uuid ) ) {
48 // Definitely not cryptographically secure but
49 // close enough to provide an unique id
50 $uuid = md5( uniqid() . site_url() );
51 update_option( $uuid_key, $uuid, 'no' );
52 }
53
54 return $uuid;
55 }
56
57 /**
58 * @since 3.06.04
59 * @return array
60 */
61 public function snapshot() {
62 global $wpdb, $wp_version;
63
64 $theme_data = wp_get_theme();
65 $form_counts = FrmForm::get_count();
66
67 $snap = array(
68 'uuid' => $this->uuid(),
69 // Let's keep it anonymous.
70 'admin_email' => '',
71 'wp_version' => $wp_version,
72 'php_version' => phpversion(),
73 'mysql_version' => $wpdb->db_version(),
74 'os' => FrmAppHelper::get_server_os(),
75 'locale' => get_locale(),
76
77 'active_license' => FrmAppHelper::pro_is_installed(),
78 'form_count' => $form_counts->published,
79 'entry_count' => FrmEntry::getRecordCount(),
80 'timestamp' => gmdate( 'c' ),
81
82 'theme_name' => is_object( $theme_data ) ? $theme_data->Name : '', // phpcs:ignore WordPress.NamingConventions
83 'plugins' => $this->plugins(),
84 'settings' => array(
85 $this->settings(),
86 ),
87 'forms' => $this->forms(),
88 'fields' => $this->fields(),
89 'actions' => $this->actions(),
90 );
91
92 return apply_filters( 'frm_usage_snapshot', $snap );
93 }
94
95 /**
96 * @since 3.06.04
97 * @return array
98 */
99 private function plugins() {
100 $plugin_list = FrmAppHelper::get_plugins();
101
102 $plugins = array();
103 foreach ( $plugin_list as $slug => $info ) {
104 $plugins[] = array(
105 'name' => $info['Name'],
106 'slug' => $slug,
107 'version' => $info['Version'],
108 'active' => is_plugin_active( $slug ),
109 );
110 }
111
112 return $plugins;
113 }
114
115 /**
116 * Add global settings to tracking data.
117 *
118 * @since 3.06.04
119 * @return array
120 */
121 private function settings() {
122 $settings_list = FrmAppHelper::get_settings();
123 $settings = array(
124 'messages' => $this->messages( $settings_list ),
125 'permissions' => $this->permissions( $settings_list ),
126 );
127 $pass_settings = array(
128 'load_style',
129 'use_html',
130 'fade_form',
131 'jquery_css',
132 're_type',
133 're_lang',
134 're_multi',
135 'menu',
136 'mu_menu',
137 'no_ips',
138 'btsp_css',
139 'btsp_errors',
140 'admin_bar',
141 );
142
143 foreach ( $pass_settings as $setting ) {
144 if ( isset( $settings_list->$setting ) ) {
145 $settings[ $setting ] = $this->maybe_json( $settings_list->$setting );
146 }
147 }
148
149 $settings = apply_filters( 'frm_usage_settings', $settings );
150
151 $settings['messages'] = $this->maybe_json( $settings['messages'] );
152 $settings['permissions'] = $this->maybe_json( $settings['permissions'] );
153
154 return $settings;
155 }
156
157 /**
158 * Include the permissions settings for each capability.
159 *
160 * @since 3.06.04
161 *
162 * @param FrmSettings $settings_list
163 * @return array
164 */
165 private function messages( $settings_list ) {
166 $messages = array(
167 'success_msg',
168 'blank_msg',
169 'unique_msg',
170 'invalid_msg',
171 'failed_msg',
172 'submit_value',
173 'login_msg',
174 'admin_permission',
175 );
176
177 $message_settings = array();
178 foreach ( $messages as $message ) {
179 $message_settings[ $message ] = $settings_list->$message;
180 }
181
182 return $message_settings;
183 }
184
185 /**
186 * Include the permissions settings for each capability.
187 *
188 * @since 3.06.04
189 *
190 * @param FrmSettings $settings_list
191 * @return array
192 */
193 private function permissions( $settings_list ) {
194 $permissions = array();
195 $frm_roles = FrmAppHelper::frm_capabilities();
196
197 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
198 if ( isset( $settings_list->$frm_role ) ) {
199 $permissions[ $frm_role ] = $settings_list->$frm_role;
200 }
201 }
202
203 return $permissions;
204 }
205
206 /**
207 * @since 3.06.04
208 * @return array
209 */
210 private function forms() {
211 $s_query = array(
212 array(
213 'or' => 1,
214 'parent_form_id' => null,
215 'parent_form_id <' => 1,
216 ),
217 );
218
219 $saved_forms = FrmForm::getAll( $s_query );
220 $forms = array();
221 $settings = array(
222 'form_class',
223 'akismet',
224 'honeypot',
225 'antispam',
226 'custom_style',
227 'success_action',
228 'show_form',
229 'no_save',
230 'ajax_load',
231 'ajax_submit',
232 'js_validate',
233 'logged_in_role',
234 'single_entry',
235 'single_entry_type',
236 'editable_role',
237 'open_editable_role',
238 'edit_action',
239 'edit_value',
240 'edit_msg',
241 'save_draft',
242 'draft_msg',
243 'submit_align',
244 'protect_files',
245 'protect_files_role',
246 'max_entries',
247 'open_status',
248 'closed_msg',
249 'open_date',
250 'close_date',
251 'copy',
252 'prev_value',
253 'submit_conditions',
254 );
255
256 foreach ( $saved_forms as $form ) {
257 $new_form = array(
258 'form_id' => $form->id,
259 'description' => $form->description,
260 'logged_in' => $form->logged_in,
261 'editable' => $form->editable,
262 'is_template' => $form->is_template,
263 'entry_count' => FrmEntry::getRecordCount( $form->id ),
264 'field_count' => $this->form_field_count( $form->id ),
265 'form_action_count' => $this->form_action_count( $form->id ),
266 );
267
268 foreach ( $settings as $setting ) {
269 if ( isset( $form->options[ $setting ] ) ) {
270 $new_form[ $setting ] = $this->maybe_json( $form->options[ $setting ] );
271 }
272 }
273
274 $forms[] = apply_filters( 'frm_usage_form', $new_form, compact( 'form' ) );
275 }
276
277 // If the array uses numeric keys, reset them.
278 return $forms;
279 }
280
281 /**
282 * @since 3.06.04
283 * @return int
284 */
285 private function form_field_count( $form_id ) {
286 global $wpdb;
287
288 $join = $wpdb->prefix . 'frm_fields fi LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fo ON (fi.form_id=fo.id)';
289
290 $field_query = array(
291 'or' => 1,
292 'fi.form_id' => $form_id,
293 'parent_form_id' => $form_id,
294 );
295
296 return FrmDb::get_count( $join, $field_query );
297 }
298
299 /**
300 * @since 3.06.04
301 * @return int
302 */
303 private function form_action_count( $form_id ) {
304 $args = array(
305 'post_type' => FrmFormActionsController::$action_post_type,
306 'menu_order' => $form_id,
307 'fields' => 'ids',
308 );
309
310 $actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
311 return count( $actions );
312 }
313
314 /**
315 * Get the last 100 fields created.
316 *
317 * @since 3.06.04
318 * @return array
319 */
320 private function fields() {
321 $args = array(
322 'limit' => 50,
323 'order_by' => 'id DESC',
324 );
325
326 $fields = FrmDb::get_results( 'frm_fields', array(), 'form_id, name, type, field_options', $args );
327 foreach ( $fields as $k => $field ) {
328 FrmAppHelper::unserialize_or_decode( $field->field_options );
329 $fields[ $k ]->field_options = json_encode( $field->field_options );
330 }
331 return $fields;
332 }
333
334 /**
335 * @since 3.06.04
336 * @return array
337 */
338 private function actions() {
339 $args = array(
340 'post_type' => FrmFormActionsController::$action_post_type,
341 'numberposts' => 100,
342 );
343
344 $actions = array();
345
346 $saved_actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
347 foreach ( $saved_actions as $action ) {
348 $actions[] = array(
349 'form_id' => $action->menu_order,
350 'type' => $action->post_excerpt,
351 'status' => $action->post_status,
352 'settings' => $action->post_content,
353 );
354 }
355
356 return $actions;
357 }
358
359 /**
360 * @since 3.06.04
361 * @return bool
362 */
363 private function tracking_allowed() {
364 $settings = FrmAppHelper::get_settings();
365 return $settings->tracking;
366 }
367
368 /**
369 * @since 3.06.04
370 * @return string
371 */
372 private function maybe_json( $value ) {
373 return is_array( $value ) ? json_encode( $value ) : $value;
374 }
375 }
376
377