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

369 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 'old_css',
128 'fade_form',
129 'jquery_css',
130 're_type',
131 're_lang',
132 're_multi',
133 'menu',
134 'mu_menu',
135 'no_ips',
136 'btsp_css',
137 'btsp_errors',
138 'admin_bar',
139 );
140
141 foreach ( $pass_settings as $setting ) {
142 if ( isset( $settings_list->$setting ) ) {
143 $settings[ $setting ] = $this->maybe_json( $settings_list->$setting );
144 }
145 }
146
147 $settings = apply_filters( 'frm_usage_settings', $settings );
148
149 $settings['messages'] = $this->maybe_json( $settings['messages'] );
150 $settings['permissions'] = $this->maybe_json( $settings['permissions'] );
151
152 return $settings;
153 }
154
155 /**
156 * Include the permissions settings for each capability.
157 *
158 * @since 3.06.04
159 * @return array
160 */
161 private function messages( $settings_list ) {
162 $messages = array(
163 'success_msg',
164 'blank_msg',
165 'unique_msg',
166 'invalid_msg',
167 'failed_msg',
168 'submit_value',
169 'login_msg',
170 'admin_permission',
171 );
172
173 $message_settings = array();
174 foreach ( $messages as $message ) {
175 $message_settings[ $message ] = $settings_list->$message;
176 }
177
178 return $message_settings;
179 }
180
181 /**
182 * Include the permissions settings for each capability.
183 *
184 * @since 3.06.04
185 * @return array
186 */
187 private function permissions( $settings_list ) {
188 $permissions = array();
189 $frm_roles = FrmAppHelper::frm_capabilities();
190
191 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
192 if ( isset( $settings_list->$frm_role ) ) {
193 $permissions[ $frm_role ] = $settings_list->$frm_role;
194 }
195 }
196
197 return $permissions;
198 }
199
200 /**
201 * @since 3.06.04
202 * @return array
203 */
204 private function forms() {
205 $s_query = array(
206 array(
207 'or' => 1,
208 'parent_form_id' => null,
209 'parent_form_id <' => 1,
210 ),
211 );
212
213 $saved_forms = FrmForm::getAll( $s_query );
214 $forms = array();
215 $settings = array(
216 'form_class',
217 'akismet',
218 'custom_style',
219 'success_action',
220 'show_form',
221 'no_save',
222 'ajax_load',
223 'ajax_submit',
224 'js_validate',
225 'logged_in_role',
226 'single_entry',
227 'single_entry_type',
228 'editable_role',
229 'open_editable_role',
230 'edit_action',
231 'edit_value',
232 'edit_msg',
233 'save_draft',
234 'draft_msg',
235 'submit_align',
236 'protect_files',
237 'protect_files_role',
238 'max_entries',
239 'open_status',
240 'closed_msg',
241 'open_date',
242 'close_date',
243 'copy',
244 'prev_value',
245 'submit_conditions',
246 );
247
248 foreach ( $saved_forms as $form ) {
249 $new_form = array(
250 'form_id' => $form->id,
251 'description' => $form->description,
252 'logged_in' => $form->logged_in,
253 'editable' => $form->editable,
254 'is_template' => $form->is_template,
255 'entry_count' => FrmEntry::getRecordCount( $form->id ),
256 'field_count' => $this->form_field_count( $form->id ),
257 'form_action_count' => $this->form_action_count( $form->id ),
258 );
259
260 foreach ( $settings as $setting ) {
261 if ( isset( $form->options[ $setting ] ) ) {
262 $new_form[ $setting ] = $this->maybe_json( $form->options[ $setting ] );
263 }
264 }
265
266 $forms[] = apply_filters( 'frm_usage_form', $new_form, compact( 'form' ) );
267 }
268
269 // If the array uses numeric keys, reset them.
270 return $forms;
271 }
272
273 /**
274 * @since 3.06.04
275 * @return int
276 */
277 private function form_field_count( $form_id ) {
278 global $wpdb;
279
280 $join = $wpdb->prefix . 'frm_fields fi LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fo ON (fi.form_id=fo.id)';
281
282 $field_query = array(
283 'or' => 1,
284 'fi.form_id' => $form_id,
285 'parent_form_id' => $form_id,
286 );
287
288 return FrmDb::get_count( $join, $field_query );
289 }
290
291 /**
292 * @since 3.06.04
293 * @return int
294 */
295 private function form_action_count( $form_id ) {
296 $args = array(
297 'post_type' => FrmFormActionsController::$action_post_type,
298 'menu_order' => $form_id,
299 'fields' => 'ids',
300 );
301
302 $actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
303 return count( $actions );
304 }
305
306 /**
307 * Get the last 100 fields created.
308 *
309 * @since 3.06.04
310 * @return array
311 */
312 private function fields() {
313 $args = array(
314 'limit' => 50,
315 'order_by' => 'id DESC',
316 );
317
318 $fields = FrmDb::get_results( 'frm_fields', array(), 'form_id, name, type, field_options', $args );
319 foreach ( $fields as $k => $field ) {
320 FrmAppHelper::unserialize_or_decode( $field->field_options );
321 $fields[ $k ]->field_options = json_encode( $field->field_options );
322 }
323 return $fields;
324 }
325
326 /**
327 * @since 3.06.04
328 * @return array
329 */
330 private function actions() {
331 $args = array(
332 'post_type' => FrmFormActionsController::$action_post_type,
333 'numberposts' => 100,
334 );
335
336 $actions = array();
337
338 $saved_actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
339 foreach ( $saved_actions as $action ) {
340 $actions[] = array(
341 'form_id' => $action->menu_order,
342 'type' => $action->post_excerpt,
343 'status' => $action->post_status,
344 'settings' => $action->post_content,
345 );
346 }
347
348 return $actions;
349 }
350
351 /**
352 * @since 3.06.04
353 * @return bool
354 */
355 private function tracking_allowed() {
356 $settings = FrmAppHelper::get_settings();
357 return $settings->tracking;
358 }
359
360 /**
361 * @since 3.06.04
362 * @return string
363 */
364 private function maybe_json( $value ) {
365 return is_array( $value ) ? json_encode( $value ) : $value;
366 }
367 }
368
369