PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.16.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.16.1
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
← All changes | classes/controllers/FrmUsageController.php +103 -4 6.36.16.1 View file →
@@ -9,8 +9,17 @@
9 9 */
10 10 class FrmUsageController {
11 11
12 12 /**
13 + * Option name of flows data.
14 + *
15 + * @since 6.16.1
16 + *
17 + * @var string
18 + */
19 + const FLOWS_ACTION_NAME = 'frm_usage_tracking_flows';
20 +
21 + /**
13 22 * Randomize the first send to prevent our servers from crashing.
14 23 *
15 24 * @since 3.06.04
16 25 *
@@ -21,12 +30,12 @@
21 30 return;
22 31 }
23 32
24 33 $tracking = array(
25 - 'day' => rand( 0, 6 ) * DAY_IN_SECONDS,
26 - 'hour' => rand( 0, 23 ) * HOUR_IN_SECONDS,
27 - 'minute' => rand( 0, 59 ) * MINUTE_IN_SECONDS,
28 - 'second' => rand( 0, 59 ),
34 + 'day' => rand( 0, 6 ) * DAY_IN_SECONDS,
35 + 'hour' => rand( 0, 23 ) * HOUR_IN_SECONDS,
36 + 'minute' => rand( 0, 59 ) * MINUTE_IN_SECONDS,
37 + 'second' => rand( 0, 59 ),
29 38 );
30 39
31 40 $offset = array_sum( $tracking );
32 41 $init_send = strtotime( 'next sunday' ) + $offset;
@@ -54,6 +63,96 @@
54 63 */
55 64 public static function send_snapshot() {
56 65 $usage = new FrmUsage();
57 66 $usage->send_snapshot();
67 + }
68 +
69 + /**
70 + * Loads scripts.
71 + *
72 + * @since 6.16.1
73 + */
74 + public static function load_scripts() {
75 + if ( self::is_forms_list_page() || FrmAppHelper::is_admin_page( 'formidable-form-templates' ) ) {
76 + wp_enqueue_script( 'frm-usage-tracking', FrmAppHelper::plugin_url() . '/js/admin/usage-tracking.js', array( 'formidable_dom' ), FrmAppHelper::$plug_version, true );
77 + }
78 + }
79 +
80 + /**
81 + * Checks if is forms list page.
82 + *
83 + * @since 6.16.1
84 + *
85 + * @return bool
86 + */
87 + private static function is_forms_list_page() {
88 + if ( ! FrmAppHelper::is_admin_page() ) {
89 + return false;
90 + }
91 +
92 + // Check Trash page.
93 + $form_type = FrmAppHelper::simple_get( 'form_type' );
94 + if ( $form_type && 'published' !== $form_type ) {
95 + return false;
96 + }
97 +
98 + // Check edit or settings page.
99 + return ! FrmAppHelper::simple_get( 'frm_action' );
100 + }
101 +
102 + /**
103 + * AJAX handler to track flows.
104 + *
105 + * @since 6.16.1
106 + */
107 + public static function ajax_track_flows() {
108 + FrmAppHelper::permission_check( 'frm_view_forms' );
109 + check_ajax_referer( 'frm_ajax', 'nonce' );
110 +
111 + $key = FrmAppHelper::get_post_param( 'key', '', 'sanitize_text_field' );
112 + $value = FrmAppHelper::get_post_param( 'value', '', 'sanitize_text_field' );
113 +
114 + self::update_flows_data( $key, $value );
115 +
116 + wp_send_json_success();
117 + }
118 +
119 + /**
120 + * Updates flows data.
121 + *
122 + * @since 6.16.1
123 + *
124 + * @param string $key Flow key.
125 + * @param string $value Flow value.
126 + *
127 + * @return void
128 + */
129 + public static function update_flows_data( $key, $value ) {
130 + $flows_data = self::get_flows_data();
131 +
132 + if ( '' === $key || '' === $value ) {
133 + return;
134 + }
135 +
136 + if ( ! isset( $flows_data[ $key ] ) ) {
137 + $flows_data[ $key ] = array();
138 + }
139 +
140 + if ( ! isset( $flows_data[ $key ][ $value ] ) ) {
141 + $flows_data[ $key ][ $value ] = 0;
142 + }
143 +
144 + $flows_data[ $key ][ $value ]++;
145 + update_option( self::FLOWS_ACTION_NAME, $flows_data );
146 + }
147 +
148 + /**
149 + * Get flows data.
150 + *
151 + * @since 6.16.1
152 + *
153 + * @return array
154 + */
155 + public static function get_flows_data() {
156 + return get_option( self::FLOWS_ACTION_NAME, array() );
58 157 }
59 158 }