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

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