PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0.14
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0.14
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 5.0.14, at classes/models/FrmUsage.php

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