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

368 lines 8.1 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 'max_entries',
238 'open_status',
239 'closed_msg',
240 'open_date',
241 'close_date',
242 'copy',
243 'prev_value',
244 'submit_conditions',
245 );
246
247 foreach ( $saved_forms as $form ) {
248 $new_form = array(
249 'form_id' => $form->id,
250 'description' => $form->description,
251 'logged_in' => $form->logged_in,
252 'editable' => $form->editable,
253 'is_template' => $form->is_template,
254 'entry_count' => FrmEntry::getRecordCount( $form->id ),
255 'field_count' => $this->form_field_count( $form->id ),
256 'form_action_count' => $this->form_action_count( $form->id ),
257 );
258
259 foreach ( $settings as $setting ) {
260 if ( isset( $form->options[ $setting ] ) ) {
261 $new_form[ $setting ] = $this->maybe_json( $form->options[ $setting ] );
262 }
263 }
264
265 $forms[] = apply_filters( 'frm_usage_form', $new_form, compact( 'form' ) );
266 }
267
268 // If the array uses numeric keys, reset them.
269 return $forms;
270 }
271
272 /**
273 * @since 3.06.04
274 * @return int
275 */
276 private function form_field_count( $form_id ) {
277 global $wpdb;
278
279 $join = $wpdb->prefix . 'frm_fields fi LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fo ON (fi.form_id=fo.id)';
280
281 $field_query = array(
282 'or' => 1,
283 'fi.form_id' => $form_id,
284 'parent_form_id' => $form_id,
285 );
286
287 return FrmDb::get_count( $join, $field_query );
288 }
289
290 /**
291 * @since 3.06.04
292 * @return int
293 */
294 private function form_action_count( $form_id ) {
295 $args = array(
296 'post_type' => FrmFormActionsController::$action_post_type,
297 'menu_order' => $form_id,
298 'fields' => 'ids',
299 );
300
301 $actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
302 return count( $actions );
303 }
304
305 /**
306 * Get the last 100 fields created.
307 *
308 * @since 3.06.04
309 * @return array
310 */
311 private function fields() {
312 $args = array(
313 'limit' => 50,
314 'order_by' => 'id DESC',
315 );
316
317 $fields = FrmDb::get_results( 'frm_fields', array(), 'form_id, name, type, field_options', $args );
318 foreach ( $fields as $k => $field ) {
319 FrmAppHelper::unserialize_or_decode( $field->field_options );
320 $fields[ $k ]->field_options = json_encode( $field->field_options );
321 }
322 return $fields;
323 }
324
325 /**
326 * @since 3.06.04
327 * @return array
328 */
329 private function actions() {
330 $args = array(
331 'post_type' => FrmFormActionsController::$action_post_type,
332 'numberposts' => 100,
333 );
334
335 $actions = array();
336
337 $saved_actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
338 foreach ( $saved_actions as $action ) {
339 $actions[] = array(
340 'form_id' => $action->menu_order,
341 'type' => $action->post_excerpt,
342 'status' => $action->post_status,
343 'settings' => $action->post_content,
344 );
345 }
346
347 return $actions;
348 }
349
350 /**
351 * @since 3.06.04
352 * @return bool
353 */
354 private function tracking_allowed() {
355 $settings = FrmAppHelper::get_settings();
356 return $settings->tracking;
357 }
358
359 /**
360 * @since 3.06.04
361 * @return string
362 */
363 private function maybe_json( $value ) {
364 return is_array( $value ) ? json_encode( $value ) : $value;
365 }
366 }
367
368