PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.01.02
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.01.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
← All changes | classes/models/FrmEntryValues.php +33 -115 6.264.01.02 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -if ( ! defined( 'ABSPATH' ) ) {
3 - die( 'You are not allowed to call this page directly.' );
4 -}
5 2
6 3 /**
7 4 * @since 2.04
8 5 */
@@ -8,11 +5,11 @@
8 5 */
9 6 class FrmEntryValues {
10 7
11 8 /**
12 - * @var stdClass|null
9 + * @var stdClass
13 10 */
14 - protected $entry;
11 + protected $entry = null;
15 12
16 13 /**
17 14 * @var int
18 15 */
@@ -48,16 +45,12 @@
48 45 *
49 46 * @since 2.04
50 47 *
51 48 * @param int|string $entry_id
52 - * @param array $atts
49 + * @param array $atts
53 50 */
54 51 public function __construct( $entry_id, $atts = array() ) {
55 - if ( isset( $atts['entry'] ) && is_object( $atts['entry'] ) && ! empty( $atts['entry']->metas ) ) {
56 - $this->entry = $atts['entry'];
57 - } else {
58 - $this->init_entry( $entry_id );
59 - }
52 + $this->init_entry( $entry_id );
60 53
61 54 if ( $this->entry === null || $this->entry === false ) {
62 55 return;
63 56 }
@@ -75,10 +68,8 @@
75 68 *
76 69 * @since 2.04
77 70 *
78 71 * @param int|string $entry_id
79 - *
80 - * @return void
81 72 */
82 73 protected function init_entry( $entry_id ) {
83 74 $this->entry = FrmEntry::getOne( $entry_id, true );
84 75 }
@@ -83,24 +74,11 @@
83 74 $this->entry = FrmEntry::getOne( $entry_id, true );
84 75 }
85 76
86 77 /**
87 - * Gets entry property.
88 - *
89 - * @since 5.0.16
90 - *
91 - * @return stdClass
92 - */
93 - public function get_entry() {
94 - return $this->entry;
95 - }
96 -
97 - /**
98 78 * Set the form_id property
99 79 *
100 80 * @since 2.04
101 - *
102 - * @return void
103 81 */
104 82 protected function init_form_id() {
105 83 $this->form_id = (int) $this->entry->form_id;
106 84 }
@@ -110,39 +88,31 @@
110 88 *
111 89 * @since 2.04
112 90 *
113 91 * @param array $atts
114 - *
115 - * @return void
116 92 */
117 93 protected function init_include_fields( $atts ) {
118 94
119 - // For reverse compatibility with the fields parameter.
120 - if ( empty( $atts['include_fields'] ) && ! empty( $atts['fields'] ) ) {
121 - if ( ! is_array( $atts['fields'] ) ) {
122 - $atts['include_fields'] = $atts['fields'];
123 - } else {
124 - $atts['include_fields'] = '';
95 + // For reverse compatibility with the fields parameter
96 + if ( ! isset( $atts['include_fields'] ) || empty( $atts['include_fields'] ) ) {
125 97
126 - foreach ( $atts['fields'] as $included_field ) {
127 - $atts['include_fields'] .= $included_field->id . ',';
98 + if ( isset( $atts['fields'] ) && ! empty( $atts['fields'] ) ) {
99 +
100 + if ( ! is_array( $atts['fields'] ) ) {
101 + $atts['include_fields'] = $atts['fields'];
102 + } else {
103 + $atts['include_fields'] = '';
104 +
105 + foreach ( $atts['fields'] as $included_field ) {
106 + $atts['include_fields'] .= $included_field->id . ',';
107 + }
108 +
109 + $atts['include_fields'] = rtrim( $atts['include_fields'], ',' );
128 110 }
129 -
130 - $atts['include_fields'] = rtrim( $atts['include_fields'], ',' );
131 111 }
132 112 }
133 113
134 114 $this->include_fields = $this->prepare_array_property( 'include_fields', $atts );
135 -
136 - /**
137 - * Allows modifying the IDs of include_fields used in the entry values.
138 - *
139 - * @since 5.0.04
140 - *
141 - * @param array $field_ids The list of field IDs.
142 - * @param array $atts The arguments. See {@see FrmEntriesController::show_entry_shortcode()}.
143 - */
144 - $this->include_fields = apply_filters( 'frm_entry_values_include_fields', $this->include_fields, $atts );
145 115 }
146 116
147 117 /**
148 118 * Set the exclude_fields property
@@ -149,23 +119,11 @@
149 119 *
150 120 * @since 2.04
151 121 *
152 122 * @param array $atts
153 - *
154 - * @return void
155 123 */
156 124 protected function init_exclude_fields( $atts ) {
157 125 $this->exclude_fields = $this->prepare_array_property( 'exclude_fields', $atts );
158 -
159 - /**
160 - * Allows modifying the IDs of exclude_fields used in the entry values.
161 - *
162 - * @since 5.0.04
163 - *
164 - * @param array $field_ids The list of field IDs.
165 - * @param array $atts The arguments. See {@see FrmEntriesController::show_entry_shortcode()}.
166 - */
167 - $this->exclude_fields = apply_filters( 'frm_entry_values_exclude_fields', $this->exclude_fields, $atts );
168 126 }
169 127
170 128 /**
171 129 * Prepare an array property value, such as include_fields and exclude_fields
@@ -172,14 +130,14 @@
172 130 *
173 131 * @since 2.04
174 132 *
175 133 * @param string $index
176 - * @param array $atts
134 + * @param array $atts
177 135 *
178 136 * @return array
179 137 */
180 138 private function prepare_array_property( $index, $atts ) {
181 - if ( ! empty( $atts[ $index ] ) ) {
139 + if ( isset( $atts[ $index ] ) && ! empty( $atts[ $index ] ) ) {
182 140
183 141 if ( is_array( $atts[ $index ] ) ) {
184 142 $property = $atts[ $index ];
185 143 } else {
@@ -195,30 +153,11 @@
195 153 /**
196 154 * Set the fields property
197 155 *
198 156 * @since 2.04
199 - *
200 - * @return void
201 157 */
202 158 protected function init_fields() {
203 159 $this->fields = FrmField::get_all_for_form( $this->form_id, '', 'exclude', 'exclude' );
204 -
205 - /**
206 - * Allows modifying the list of all field in the form that is used in the entry values.
207 - *
208 - * @since 5.0.04
209 - *
210 - * @param array $fields The list of fields.
211 - * @param array $args The arguments. Contains `form_id`, `entry`.
212 - */
213 - $this->fields = apply_filters(
214 - 'frm_entry_values_fields',
215 - $this->fields,
216 - array(
217 - 'form_id' => $this->form_id,
218 - 'entry' => $this->entry,
219 - )
220 - );
221 160 }
222 161
223 162 /**
224 163 * Set the field_values property
@@ -223,10 +162,8 @@
223 162 /**
224 163 * Set the field_values property
225 164 *
226 165 * @since 2.04
227 - *
228 - * @return void
229 166 */
230 167 protected function init_field_values() {
231 168 foreach ( $this->fields as $field ) {
232 169 if ( $this->is_field_included( $field ) ) {
@@ -249,14 +186,12 @@
249 186 /**
250 187 * Set the user_info property
251 188 *
252 189 * @since 2.04
253 - *
254 - * @return void
255 190 */
256 191 protected function init_user_info() {
257 192 if ( isset( $this->entry->description ) ) {
258 - $entry_description = (array) $this->entry->description;
193 + $entry_description = (array) maybe_unserialize( $this->entry->description );
259 194 } else {
260 195 $entry_description = array(
261 196 'browser' => '',
262 197 'referrer' => '',
@@ -262,32 +197,23 @@
262 197 'referrer' => '',
263 198 );
264 199 }
265 200
266 - $ip = array(
201 + $ip = array(
267 202 'label' => __( 'IP Address', 'formidable' ),
268 203 'value' => $this->entry->ip,
269 204 );
270 - $browser = array(
205 +
206 + $browser = array(
271 207 'label' => __( 'User-Agent (Browser/OS)', 'formidable' ),
272 - 'value' => isset( $entry_description['browser'] ) ? FrmEntriesHelper::get_browser( $entry_description['browser'] ) : '',
208 + 'value' => FrmEntriesHelper::get_browser( $entry_description['browser'] ),
273 209 );
210 +
274 211 $referrer = array(
275 212 'label' => __( 'Referrer', 'formidable' ),
276 - 'value' => $entry_description['referrer'] ?? '',
213 + 'value' => $entry_description['referrer'],
277 214 );
278 215
279 - /**
280 - * Allow the referrer to be modified.
281 - *
282 - * @since 5.5.1
283 - *
284 - * @param array $referrer
285 - * @param array $entry_description
286 - * @param object $entry
287 - */
288 - $referrer = apply_filters( 'frm_user_info_referrer', $referrer, $entry_description, $this->entry );
289 -
290 216 $this->user_info = array(
291 217 'ip' => $ip,
292 218 'browser' => $browser,
293 219 'referrer' => $referrer,
@@ -314,22 +240,16 @@
314 240 *
315 241 * @return bool
316 242 */
317 243 protected function is_field_included( $field ) {
318 - $is_included = true;
319 -
320 244 if ( ! empty( $this->include_fields ) ) {
321 245 $is_included = $this->is_field_in_array( $field, $this->include_fields );
246 + } elseif ( ! empty( $this->exclude_fields ) ) {
247 + $is_included = ! $this->is_field_in_array( $field, $this->exclude_fields );
248 + } else {
249 + $is_included = true;
322 250 }
323 251
324 - if ( ! empty( $this->exclude_fields ) ) {
325 - $is_excluded = $this->is_field_in_array( $field, $this->exclude_fields );
326 -
327 - if ( $is_excluded ) {
328 - $is_included = false;
329 - }
330 - }
331 -
332 252 return $is_included;
333 253 }
334 254
335 255 /**
@@ -337,14 +257,14 @@
337 257 *
338 258 * @since 2.04
339 259 *
340 260 * @param stdClass $field
341 - * @param array $array
261 + * @param array $array
342 262 *
343 263 * @return bool
344 264 */
345 265 protected function is_field_in_array( $field, $array ) {
346 - return in_array( $field->id, $array ) || in_array( (string) $field->field_key, $array, true );
266 + return in_array( $field->id, $array ) || in_array( $field->field_key, $array );
347 267 }
348 268
349 269 /**
350 270 * Add a field's values to the field_values property
@@ -351,10 +271,8 @@
351 271 *
352 272 * @since 2.04
353 273 *
354 274 * @param stdClass $field
355 - *
356 - * @return void
357 275 */
358 276 protected function add_field_values( $field ) {
359 277 $this->field_values[ $field->id ] = new FrmFieldValue( $field, $this->entry );
360 278 }