PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8
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/models/FrmFormState.php +10 -50 6.266.8 View file →
@@ -13,9 +13,9 @@
13 13 */
14 14 class FrmFormState {
15 15
16 16 /**
17 - * @var FrmFormState
17 + * @var FrmFormState $instance
18 18 */
19 19 private static $instance;
20 20
21 21 /**
@@ -29,9 +29,8 @@
29 29
30 30 /**
31 31 * @param string $key
32 32 * @param mixed $value
33 - *
34 33 * @return void
35 34 */
36 35 public static function set_initial_value( $key, $value ) {
37 36 if ( is_callable( 'FrmProFormState::set_initial_value' ) ) {
@@ -56,9 +55,8 @@
56 55
57 56 /**
58 57 * @param string $key
59 58 * @param mixed $value
60 - *
61 59 * @return void
62 60 */
63 61 public function set( $key, $value ) {
64 62 $this->state[ $key ] = $value;
@@ -66,9 +64,8 @@
66 64
67 65 /**
68 66 * @param string $key
69 67 * @param mixed $default
70 - *
71 68 * @return mixed
72 69 */
73 70 public static function get_from_request( $key, $default ) {
74 71 if ( self::maybe_initialize() ) {
@@ -76,16 +73,13 @@
76 73 }
77 74 return self::$instance->get( $key, $default );
78 75 }
79 76
80 - /**
81 - * @param string $key
82 - * @param mixed $default
83 - *
84 - * @return mixed
85 - */
86 77 public function get( $key, $default ) {
87 - return $this->state[ $key ] ?? $default;
78 + if ( isset( $this->state[ $key ] ) ) {
79 + return $this->state[ $key ];
80 + }
81 + return $default;
88 82 }
89 83
90 84 /**
91 85 * Render a basic version of the state field from Pro.
@@ -92,9 +86,8 @@
92 86 * This is required only when submitting with AJAX.
93 87 * It is used to track the value of a title=1|0 or description=1|0 option in a [formidable] shortcode.
94 88 *
95 89 * @param stdClass $form
96 - *
97 90 * @return void
98 91 */
99 92 public static function maybe_render_state_field( $form ) {
100 93 if ( is_callable( 'FrmProFormState::maybe_render_state_field' ) ) {
@@ -102,16 +95,14 @@
102 95 // This way we can also avoid duplicate state fields if Pro isn't up to date.
103 96 return;
104 97 }
105 98
106 - if ( empty( self::$instance ) && ! self::get_state_from_request() ) {
99 + if ( empty( $form->options['ajax_submit'] ) ) {
100 + // This is only required for AJAX submit.
107 101 return;
108 102 }
109 103
110 - $honeypot_field_id = self::$instance->get( 'honeypot_field_id', 0 );
111 -
112 - if ( empty( $form->options['ajax_submit'] ) && ! $honeypot_field_id ) {
113 - // This is only required for AJAX submit, or when the honeypot field is on the page.
104 + if ( empty( self::$instance ) && ! self::get_state_from_request() ) {
114 105 return;
115 106 }
116 107
117 108 $state_title = ! empty( self::$instance->state['title'] ) ? 1 : 0;
@@ -118,10 +109,10 @@
118 109 $state_description = ! empty( self::$instance->state['description'] ) ? 1 : 0;
119 110 $settings_title = ! empty( $form->options['show_title'] ) ? 1 : 0;
120 111 $settings_description = ! empty( $form->options['show_description'] ) ? 1 : 0;
121 112
122 - if ( $state_title === $settings_title && $state_description === $settings_description && ! $honeypot_field_id ) {
123 - // Avoid state field if it matches form settings and there is no honeypot.
113 + if ( $state_title === $settings_title && $state_description === $settings_description ) {
114 + // Avoid state field if it matches form settings.
124 115 return;
125 116 }
126 117
127 118 self::$instance->render_state_field();
@@ -131,26 +122,20 @@
131 122 * @return bool true if there is valid state data in the request.
132 123 */
133 124 private static function get_state_from_request() {
134 125 $encrypted_state = FrmAppHelper::get_post_param( 'frm_state', '', 'sanitize_text_field' );
135 -
136 126 if ( ! $encrypted_state ) {
137 127 return false;
138 128 }
139 -
140 129 $secret = self::get_encryption_secret();
141 130 $decrypted_state = openssl_decrypt( $encrypted_state, 'AES-128-ECB', $secret );
142 -
143 131 if ( false === $decrypted_state ) {
144 132 return false;
145 133 }
146 -
147 134 $decoded_state = json_decode( $decrypted_state, true );
148 -
149 135 if ( ! is_array( $decoded_state ) ) {
150 136 return false;
151 137 }
152 -
153 138 foreach ( $decoded_state as $key => $value ) {
154 139 self::set_initial_value( self::decompressed_key( $key ), $value );
155 140 }
156 141 return true;
@@ -159,16 +144,11 @@
159 144 /**
160 145 * @return void
161 146 */
162 147 public function render_state_field() {
163 - if ( ! self::open_ssl_is_installed() ) {
164 - return;
165 - }
166 -
167 148 if ( ! $this->state && ! self::get_state_from_request() ) {
168 149 return;
169 150 }
170 -
171 151 $state_string = $this->get_state_string();
172 152 echo '<input name="frm_state" type="hidden" value="' . esc_attr( $state_string ) . '" />';
173 153 }
174 154
@@ -175,12 +155,8 @@
175 155 /**
176 156 * @return string
177 157 */
178 158 private function get_state_string() {
179 - if ( ! self::open_ssl_is_installed() ) {
180 - return '';
181 - }
182 -
183 159 $secret = self::get_encryption_secret();
184 160 $compressed_state = $this->compressed_state();
185 161 $json_encoded = json_encode( $compressed_state );
186 162 $encrypted = openssl_encrypt( $json_encoded, 'AES-128-ECB', $secret );
@@ -187,19 +163,8 @@
187 163 return $encrypted;
188 164 }
189 165
190 166 /**
191 - * Returns true if open SSL is installed.
192 - *
193 - * @since 6.12
194 - *
195 - * @return bool
196 - */
197 - private static function open_ssl_is_installed() {
198 - return function_exists( 'openssl_encrypt' );
199 - }
200 -
201 - /**
202 167 * Return state but with shorter keys to use for the state string.
203 168 *
204 169 * @return array
205 170 */
@@ -204,9 +169,8 @@
204 169 * @return array
205 170 */
206 171 private function compressed_state() {
207 172 $compressed = array();
208 -
209 173 foreach ( $this->state as $key => $value ) {
210 174 $compressed[ self::compressed_key( $key ) ] = $value;
211 175 }
212 176 return $compressed;
@@ -217,9 +181,8 @@
217 181 * "title" => "t".
218 182 * "description" => "d".
219 183 *
220 184 * @param string $key
221 - *
222 185 * @return string
223 186 */
224 187 private static function compressed_key( $key ) {
225 188 return $key[0];
@@ -230,9 +193,8 @@
230 193 * Pro supports additional keys include "i" for include_fields and "g" for get params.
231 194 * To avoid conflicts, we should not add "i" or "g" in Lite for another state property.
232 195 *
233 196 * @param string $key
234 - *
235 197 * @return string The full key name if one is found. If nothing is found, the $key param is passed back.
236 198 */
237 199 private static function decompressed_key( $key ) {
238 200 switch ( $key ) {
@@ -239,10 +201,8 @@
239 201 case 'd':
240 202 return 'description';
241 203 case 't':
242 204 return 'title';
243 - case 'h':
244 - return 'honeypot_field_id';
245 205 }
246 206 return $key;
247 207 }
248 208