| @@ -8,11 +8,11 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | class FrmEntryValues { |
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | - * @var false|stdClass|null | |
| 12 | + * @var stdClass | |
| 13 | 13 | */ |
| 14 | - protected $entry; | |
| 14 | + protected $entry = null; | |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | 17 | * @var int |
| 18 | 18 | */ |
| @@ -48,9 +48,9 @@ | ||
| 48 | 48 | * |
| 49 | 49 | * @since 2.04 |
| 50 | 50 | * |
| 51 | 51 | * @param int|string $entry_id |
| 52 | - * @param array $atts | |
| 52 | + * @param array $atts | |
| 53 | 53 | */ |
| 54 | 54 | public function __construct( $entry_id, $atts = array() ) { |
| 55 | 55 | if ( isset( $atts['entry'] ) && is_object( $atts['entry'] ) && ! empty( $atts['entry']->metas ) ) { |
| 56 | 56 | $this->entry = $atts['entry']; |
| @@ -75,10 +75,8 @@ | ||
| 75 | 75 | * |
| 76 | 76 | * @since 2.04 |
| 77 | 77 | * |
| 78 | 78 | * @param int|string $entry_id |
| 79 | - * | |
| 80 | - * @return void | |
| 81 | 79 | */ |
| 82 | 80 | protected function init_entry( $entry_id ) { |
| 83 | 81 | $this->entry = FrmEntry::getOne( $entry_id, true ); |
| 84 | 82 | } |
| @@ -86,9 +84,8 @@ | ||
| 86 | 84 | /** |
| 87 | 85 | * Gets entry property. |
| 88 | 86 | * |
| 89 | 87 | * @since 5.0.16 |
| 90 | - * | |
| 91 | 88 | * @return stdClass |
| 92 | 89 | */ |
| 93 | 90 | public function get_entry() { |
| 94 | 91 | return $this->entry; |
| @@ -97,10 +94,8 @@ | ||
| 97 | 94 | /** |
| 98 | 95 | * Set the form_id property |
| 99 | 96 | * |
| 100 | 97 | * @since 2.04 |
| 101 | - * | |
| 102 | - * @return void | |
| 103 | 98 | */ |
| 104 | 99 | protected function init_form_id() { |
| 105 | 100 | $this->form_id = (int) $this->entry->form_id; |
| 106 | 101 | } |
| @@ -110,24 +105,27 @@ | ||
| 110 | 105 | * |
| 111 | 106 | * @since 2.04 |
| 112 | 107 | * |
| 113 | 108 | * @param array $atts |
| 114 | - * | |
| 115 | - * @return void | |
| 116 | 109 | */ |
| 117 | 110 | protected function init_include_fields( $atts ) { |
| 118 | - // For reverse compatibility with the fields parameter. | |
| 119 | - if ( empty( $atts['include_fields'] ) && ! empty( $atts['fields'] ) ) { | |
| 120 | - if ( is_array( $atts['fields'] ) ) { | |
| 121 | - $atts['include_fields'] = ''; | |
| 122 | 111 | |
| 123 | - foreach ( $atts['fields'] as $included_field ) { | |
| 124 | - $atts['include_fields'] .= $included_field->id . ','; | |
| 112 | + // For reverse compatibility with the fields parameter | |
| 113 | + if ( ! isset( $atts['include_fields'] ) || empty( $atts['include_fields'] ) ) { | |
| 114 | + | |
| 115 | + if ( isset( $atts['fields'] ) && ! empty( $atts['fields'] ) ) { | |
| 116 | + | |
| 117 | + if ( ! is_array( $atts['fields'] ) ) { | |
| 118 | + $atts['include_fields'] = $atts['fields']; | |
| 119 | + } else { | |
| 120 | + $atts['include_fields'] = ''; | |
| 121 | + | |
| 122 | + foreach ( $atts['fields'] as $included_field ) { | |
| 123 | + $atts['include_fields'] .= $included_field->id . ','; | |
| 124 | + } | |
| 125 | + | |
| 126 | + $atts['include_fields'] = rtrim( $atts['include_fields'], ',' ); | |
| 125 | 127 | } |
| 126 | - | |
| 127 | - $atts['include_fields'] = rtrim( $atts['include_fields'], ',' ); | |
| 128 | - } else { | |
| 129 | - $atts['include_fields'] = $atts['fields']; | |
| 130 | 128 | } |
| 131 | 129 | } |
| 132 | 130 | |
| 133 | 131 | $this->include_fields = $this->prepare_array_property( 'include_fields', $atts ); |
| @@ -148,10 +146,8 @@ | ||
| 148 | 146 | * |
| 149 | 147 | * @since 2.04 |
| 150 | 148 | * |
| 151 | 149 | * @param array $atts |
| 152 | - * | |
| 153 | - * @return void | |
| 154 | 150 | */ |
| 155 | 151 | protected function init_exclude_fields( $atts ) { |
| 156 | 152 | $this->exclude_fields = $this->prepare_array_property( 'exclude_fields', $atts ); |
| 157 | 153 | |
| @@ -171,18 +167,25 @@ | ||
| 171 | 167 | * |
| 172 | 168 | * @since 2.04 |
| 173 | 169 | * |
| 174 | 170 | * @param string $index |
| 175 | - * @param array $atts | |
| 171 | + * @param array $atts | |
| 176 | 172 | * |
| 177 | 173 | * @return array |
| 178 | 174 | */ |
| 179 | 175 | private function prepare_array_property( $index, $atts ) { |
| 180 | - if ( ! empty( $atts[ $index ] ) ) { | |
| 181 | - return is_array( $atts[ $index ] ) ? $atts[ $index ] : explode( ',', $atts[ $index ] ); | |
| 176 | + if ( isset( $atts[ $index ] ) && ! empty( $atts[ $index ] ) ) { | |
| 177 | + | |
| 178 | + if ( is_array( $atts[ $index ] ) ) { | |
| 179 | + $property = $atts[ $index ]; | |
| 180 | + } else { | |
| 181 | + $property = explode( ',', $atts[ $index ] ); | |
| 182 | + } | |
| 183 | + } else { | |
| 184 | + $property = array(); | |
| 182 | 185 | } |
| 183 | 186 | |
| 184 | - return array(); | |
| 187 | + return $property; | |
| 185 | 188 | } |
| 186 | 189 | |
| 187 | 190 | /** |
| 188 | 191 | * Set the fields property |
| @@ -187,10 +190,8 @@ | ||
| 187 | 190 | /** |
| 188 | 191 | * Set the fields property |
| 189 | 192 | * |
| 190 | 193 | * @since 2.04 |
| 191 | - * | |
| 192 | - * @return void | |
| 193 | 194 | */ |
| 194 | 195 | protected function init_fields() { |
| 195 | 196 | $this->fields = FrmField::get_all_for_form( $this->form_id, '', 'exclude', 'exclude' ); |
| 196 | 197 | |
| @@ -215,10 +216,8 @@ | ||
| 215 | 216 | /** |
| 216 | 217 | * Set the field_values property |
| 217 | 218 | * |
| 218 | 219 | * @since 2.04 |
| 219 | - * | |
| 220 | - * @return void | |
| 221 | 220 | */ |
| 222 | 221 | protected function init_field_values() { |
| 223 | 222 | foreach ( $this->fields as $field ) { |
| 224 | 223 | if ( $this->is_field_included( $field ) ) { |
| @@ -241,10 +240,8 @@ | ||
| 241 | 240 | /** |
| 242 | 241 | * Set the user_info property |
| 243 | 242 | * |
| 244 | 243 | * @since 2.04 |
| 245 | - * | |
| 246 | - * @return void | |
| 247 | 244 | */ |
| 248 | 245 | protected function init_user_info() { |
| 249 | 246 | if ( isset( $this->entry->description ) ) { |
| 250 | 247 | $entry_description = (array) $this->entry->description; |
| @@ -254,32 +251,23 @@ | ||
| 254 | 251 | 'referrer' => '', |
| 255 | 252 | ); |
| 256 | 253 | } |
| 257 | 254 | |
| 258 | - $ip = array( | |
| 255 | + $ip = array( | |
| 259 | 256 | 'label' => __( 'IP Address', 'formidable' ), |
| 260 | 257 | 'value' => $this->entry->ip, |
| 261 | 258 | ); |
| 262 | - $browser = array( | |
| 259 | + | |
| 260 | + $browser = array( | |
| 263 | 261 | 'label' => __( 'User-Agent (Browser/OS)', 'formidable' ), |
| 264 | - 'value' => isset( $entry_description['browser'] ) ? FrmEntriesHelper::get_browser( $entry_description['browser'] ) : '', | |
| 262 | + 'value' => FrmEntriesHelper::get_browser( $entry_description['browser'] ), | |
| 265 | 263 | ); |
| 264 | + | |
| 266 | 265 | $referrer = array( |
| 267 | 266 | 'label' => __( 'Referrer', 'formidable' ), |
| 268 | - 'value' => $entry_description['referrer'] ?? '', | |
| 267 | + 'value' => $entry_description['referrer'], | |
| 269 | 268 | ); |
| 270 | 269 | |
| 271 | - /** | |
| 272 | - * Allow the referrer to be modified. | |
| 273 | - * | |
| 274 | - * @since 5.5.1 | |
| 275 | - * | |
| 276 | - * @param array $referrer | |
| 277 | - * @param array $entry_description | |
| 278 | - * @param object $entry | |
| 279 | - */ | |
| 280 | - $referrer = apply_filters( 'frm_user_info_referrer', $referrer, $entry_description, $this->entry ); | |
| 281 | - | |
| 282 | 270 | $this->user_info = array( |
| 283 | 271 | 'ip' => $ip, |
| 284 | 272 | 'browser' => $browser, |
| 285 | 273 | 'referrer' => $referrer, |
| @@ -307,16 +295,14 @@ | ||
| 307 | 295 | * @return bool |
| 308 | 296 | */ |
| 309 | 297 | protected function is_field_included( $field ) { |
| 310 | 298 | $is_included = true; |
| 311 | - | |
| 312 | - if ( $this->include_fields ) { | |
| 299 | + if ( ! empty( $this->include_fields ) ) { | |
| 313 | 300 | $is_included = $this->is_field_in_array( $field, $this->include_fields ); |
| 314 | 301 | } |
| 315 | 302 | |
| 316 | - if ( $this->exclude_fields ) { | |
| 303 | + if ( ! empty( $this->exclude_fields ) ) { | |
| 317 | 304 | $is_excluded = $this->is_field_in_array( $field, $this->exclude_fields ); |
| 318 | - | |
| 319 | 305 | if ( $is_excluded ) { |
| 320 | 306 | $is_included = false; |
| 321 | 307 | } |
| 322 | 308 | } |
| @@ -329,14 +315,13 @@ | ||
| 329 | 315 | * |
| 330 | 316 | * @since 2.04 |
| 331 | 317 | * |
| 332 | 318 | * @param stdClass $field |
| 333 | - * @param array $array | |
| 319 | + * @param array $array | |
| 334 | 320 | * |
| 335 | 321 | * @return bool |
| 336 | 322 | */ |
| 337 | 323 | protected function is_field_in_array( $field, $array ) { |
| 338 | - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict | |
| 339 | 324 | return in_array( $field->id, $array ) || in_array( (string) $field->field_key, $array, true ); |
| 340 | 325 | } |
| 341 | 326 | |
| 342 | 327 | /** |
| @@ -344,10 +329,8 @@ | ||
| 344 | 329 | * |
| 345 | 330 | * @since 2.04 |
| 346 | 331 | * |
| 347 | 332 | * @param stdClass $field |
| 348 | - * | |
| 349 | - * @return void | |
| 350 | 333 | */ |
| 351 | 334 | protected function add_field_values( $field ) { |
| 352 | 335 | $this->field_values[ $field->id ] = new FrmFieldValue( $field, $this->entry ); |
| 353 | 336 | } |