PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.23
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.23
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 +15 -34 6.356.23 View file →
@@ -13,9 +13,9 @@
13 13 */
14 14 class FrmFormState {
15 15
16 16 /**
17 - * @var FrmFormState|null
17 + * @var FrmFormState
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' ) ) {
@@ -46,9 +45,9 @@
46 45 /**
47 46 * @return bool true if just initialized.
48 47 */
49 48 private static function maybe_initialize() {
50 - if ( ! self::$instance ) {
49 + if ( empty( self::$instance ) ) {
51 50 self::$instance = new self();
52 51 return true;
53 52 }
54 53 return false;
@@ -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,9 +95,9 @@
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 ( ! self::$instance && ! self::get_state_from_request() ) {
99 + if ( empty( self::$instance ) && ! self::get_state_from_request() ) {
107 100 return;
108 101 }
109 102
110 103 $honeypot_field_id = self::$instance->get( 'honeypot_field_id', 0 );
@@ -131,30 +124,23 @@
131 124 * @return bool true if there is valid state data in the request.
132 125 */
133 126 private static function get_state_from_request() {
134 127 $encrypted_state = FrmAppHelper::get_post_param( 'frm_state', '', 'sanitize_text_field' );
135 -
136 128 if ( ! $encrypted_state ) {
137 129 return false;
138 130 }
139 -
140 131 $secret = self::get_encryption_secret();
141 132 $decrypted_state = openssl_decrypt( $encrypted_state, 'AES-128-ECB', $secret );
142 -
143 133 if ( false === $decrypted_state ) {
144 134 return false;
145 135 }
146 -
147 136 $decoded_state = json_decode( $decrypted_state, true );
148 -
149 137 if ( ! is_array( $decoded_state ) ) {
150 138 return false;
151 139 }
152 -
153 140 foreach ( $decoded_state as $key => $value ) {
154 141 self::set_initial_value( self::decompressed_key( $key ), $value );
155 142 }
156 -
157 143 return true;
158 144 }
159 145
160 146 /**
@@ -163,14 +149,13 @@
163 149 public function render_state_field() {
164 150 if ( ! self::open_ssl_is_installed() ) {
165 151 return;
166 152 }
167 -
168 153 if ( ! $this->state && ! self::get_state_from_request() ) {
169 154 return;
170 155 }
171 -
172 - echo '<input name="frm_state" type="hidden" value="' . esc_attr( $this->get_state_string() ) . '" />';
156 + $state_string = $this->get_state_string();
157 + echo '<input name="frm_state" type="hidden" value="' . esc_attr( $state_string ) . '" />';
173 158 }
174 159
175 160 /**
176 161 * @return string
@@ -178,12 +163,13 @@
178 163 private function get_state_string() {
179 164 if ( ! self::open_ssl_is_installed() ) {
180 165 return '';
181 166 }
182 -
183 - $secret = self::get_encryption_secret();
184 - $json_encoded = json_encode( $this->compressed_state() );
185 - return openssl_encrypt( $json_encoded, 'AES-128-ECB', $secret );
167 + $secret = self::get_encryption_secret();
168 + $compressed_state = $this->compressed_state();
169 + $json_encoded = json_encode( $compressed_state );
170 + $encrypted = openssl_encrypt( $json_encoded, 'AES-128-ECB', $secret );
171 + return $encrypted;
186 172 }
187 173
188 174 /**
189 175 * Returns true if open SSL is installed.
@@ -188,9 +174,8 @@
188 174 /**
189 175 * Returns true if open SSL is installed.
190 176 *
191 177 * @since 6.12
192 - *
193 178 * @return bool
194 179 */
195 180 private static function open_ssl_is_installed() {
196 181 return function_exists( 'openssl_encrypt' );
@@ -202,13 +187,11 @@
202 187 * @return array
203 188 */
204 189 private function compressed_state() {
205 190 $compressed = array();
206 -
207 191 foreach ( $this->state as $key => $value ) {
208 192 $compressed[ self::compressed_key( $key ) ] = $value;
209 193 }
210 -
211 194 return $compressed;
212 195 }
213 196
214 197 /**
@@ -216,9 +199,8 @@
216 199 * "title" => "t".
217 200 * "description" => "d".
218 201 *
219 202 * @param string $key
220 - *
221 203 * @return string
222 204 */
223 205 private static function compressed_key( $key ) {
224 206 return $key[0];
@@ -229,9 +211,8 @@
229 211 * Pro supports additional keys include "i" for include_fields and "g" for get params.
230 212 * To avoid conflicts, we should not add "i" or "g" in Lite for another state property.
231 213 *
232 214 * @param string $key
233 - *
234 215 * @return string The full key name if one is found. If nothing is found, the $key param is passed back.
235 216 */
236 217 private static function decompressed_key( $key ) {
237 218 switch ( $key ) {
@@ -257,9 +238,9 @@
257 238 }
258 239
259 240 // We don't have a secret, so let's generate one.
260 241 $secret_key = is_callable( 'sodium_crypto_secretbox_keygen' ) ? sodium_crypto_secretbox_keygen() : wp_generate_password( 32, true, true );
261 - update_option( 'frm_form_state_key', base64_encode( $secret_key ), false ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
242 + update_option( 'frm_form_state_key', base64_encode( $secret_key ), 'no' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
262 243
263 244 return $secret_key;
264 245 }
265 246 }