| @@ -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 false|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,38 +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 | - // 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 | 94 | |
| 123 | - foreach ( $atts['fields'] as $included_field ) { | |
| 124 | - $atts['include_fields'] .= $included_field->id . ','; | |
| 95 | + // For reverse compatibility with the fields parameter | |
| 96 | + if ( ! isset( $atts['include_fields'] ) || empty( $atts['include_fields'] ) ) { | |
| 97 | + | |
| 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'], ',' ); | |
| 125 | 110 | } |
| 126 | - | |
| 127 | - $atts['include_fields'] = rtrim( $atts['include_fields'], ',' ); | |
| 128 | - } else { | |
| 129 | - $atts['include_fields'] = $atts['fields']; | |
| 130 | 111 | } |
| 131 | 112 | } |
| 132 | 113 | |
| 133 | 114 | $this->include_fields = $this->prepare_array_property( 'include_fields', $atts ); |
| 134 | - | |
| 135 | - /** | |
| 136 | - * Allows modifying the IDs of include_fields used in the entry values. | |
| 137 | - * | |
| 138 | - * @since 5.0.04 | |
| 139 | - * | |
| 140 | - * @param array $field_ids The list of field IDs. | |
| 141 | - * @param array $atts The arguments. See {@see FrmEntriesController::show_entry_shortcode()}. | |
| 142 | - */ | |
| 143 | - $this->include_fields = apply_filters( 'frm_entry_values_include_fields', $this->include_fields, $atts ); | |
| 144 | 115 | } |
| 145 | 116 | |
| 146 | 117 | /** |
| 147 | 118 | * Set the exclude_fields property |
| @@ -148,23 +119,11 @@ | ||
| 148 | 119 | * |
| 149 | 120 | * @since 2.04 |
| 150 | 121 | * |
| 151 | 122 | * @param array $atts |
| 152 | - * | |
| 153 | - * @return void | |
| 154 | 123 | */ |
| 155 | 124 | protected function init_exclude_fields( $atts ) { |
| 156 | 125 | $this->exclude_fields = $this->prepare_array_property( 'exclude_fields', $atts ); |
| 157 | - | |
| 158 | - /** | |
| 159 | - * Allows modifying the IDs of exclude_fields used in the entry values. | |
| 160 | - * | |
| 161 | - * @since 5.0.04 | |
| 162 | - * | |
| 163 | - * @param array $field_ids The list of field IDs. | |
| 164 | - * @param array $atts The arguments. See {@see FrmEntriesController::show_entry_shortcode()}. | |
| 165 | - */ | |
| 166 | - $this->exclude_fields = apply_filters( 'frm_entry_values_exclude_fields', $this->exclude_fields, $atts ); | |
| 167 | 126 | } |
| 168 | 127 | |
| 169 | 128 | /** |
| 170 | 129 | * Prepare an array property value, such as include_fields and exclude_fields |
| @@ -171,18 +130,25 @@ | ||
| 171 | 130 | * |
| 172 | 131 | * @since 2.04 |
| 173 | 132 | * |
| 174 | 133 | * @param string $index |
| 175 | - * @param array $atts | |
| 134 | + * @param array $atts | |
| 176 | 135 | * |
| 177 | 136 | * @return array |
| 178 | 137 | */ |
| 179 | 138 | private function prepare_array_property( $index, $atts ) { |
| 180 | - if ( ! empty( $atts[ $index ] ) ) { | |
| 181 | - return is_array( $atts[ $index ] ) ? $atts[ $index ] : explode( ',', $atts[ $index ] ); | |
| 139 | + if ( isset( $atts[ $index ] ) && ! empty( $atts[ $index ] ) ) { | |
| 140 | + | |
| 141 | + if ( is_array( $atts[ $index ] ) ) { | |
| 142 | + $property = $atts[ $index ]; | |
| 143 | + } else { | |
| 144 | + $property = explode( ',', $atts[ $index ] ); | |
| 145 | + } | |
| 146 | + } else { | |
| 147 | + $property = array(); | |
| 182 | 148 | } |
| 183 | 149 | |
| 184 | - return array(); | |
| 150 | + return $property; | |
| 185 | 151 | } |
| 186 | 152 | |
| 187 | 153 | /** |
| 188 | 154 | * Set the fields property |
| @@ -187,30 +153,11 @@ | ||
| 187 | 153 | /** |
| 188 | 154 | * Set the fields property |
| 189 | 155 | * |
| 190 | 156 | * @since 2.04 |
| 191 | - * | |
| 192 | - * @return void | |
| 193 | 157 | */ |
| 194 | 158 | protected function init_fields() { |
| 195 | 159 | $this->fields = FrmField::get_all_for_form( $this->form_id, '', 'exclude', 'exclude' ); |
| 196 | - | |
| 197 | - /** | |
| 198 | - * Allows modifying the list of all field in the form that is used in the entry values. | |
| 199 | - * | |
| 200 | - * @since 5.0.04 | |
| 201 | - * | |
| 202 | - * @param array $fields The list of fields. | |
| 203 | - * @param array $args The arguments. Contains `form_id`, `entry`. | |
| 204 | - */ | |
| 205 | - $this->fields = apply_filters( | |
| 206 | - 'frm_entry_values_fields', | |
| 207 | - $this->fields, | |
| 208 | - array( | |
| 209 | - 'form_id' => $this->form_id, | |
| 210 | - 'entry' => $this->entry, | |
| 211 | - ) | |
| 212 | - ); | |
| 213 | 160 | } |
| 214 | 161 | |
| 215 | 162 | /** |
| 216 | 163 | * Set the field_values property |
| @@ -215,10 +162,8 @@ | ||
| 215 | 162 | /** |
| 216 | 163 | * Set the field_values property |
| 217 | 164 | * |
| 218 | 165 | * @since 2.04 |
| 219 | - * | |
| 220 | - * @return void | |
| 221 | 166 | */ |
| 222 | 167 | protected function init_field_values() { |
| 223 | 168 | foreach ( $this->fields as $field ) { |
| 224 | 169 | if ( $this->is_field_included( $field ) ) { |
| @@ -241,48 +186,37 @@ | ||
| 241 | 186 | /** |
| 242 | 187 | * Set the user_info property |
| 243 | 188 | * |
| 244 | 189 | * @since 2.04 |
| 245 | - * | |
| 246 | - * @return void | |
| 247 | 190 | */ |
| 248 | 191 | protected function init_user_info() { |
| 249 | 192 | if ( isset( $this->entry->description ) ) { |
| 250 | - $entry_description = (array) $this->entry->description; | |
| 193 | + $entry_description = (array) maybe_unserialize( $this->entry->description ); | |
| 251 | 194 | } else { |
| 252 | 195 | $entry_description = array( |
| 253 | - 'browser' => '', | |
| 196 | + 'browser' => '', | |
| 254 | 197 | 'referrer' => '', |
| 255 | 198 | ); |
| 256 | 199 | } |
| 257 | 200 | |
| 258 | - $ip = array( | |
| 201 | + $ip = array( | |
| 259 | 202 | 'label' => __( 'IP Address', 'formidable' ), |
| 260 | 203 | 'value' => $this->entry->ip, |
| 261 | 204 | ); |
| 262 | - $browser = array( | |
| 205 | + | |
| 206 | + $browser = array( | |
| 263 | 207 | 'label' => __( 'User-Agent (Browser/OS)', 'formidable' ), |
| 264 | - 'value' => isset( $entry_description['browser'] ) ? FrmEntriesHelper::get_browser( $entry_description['browser'] ) : '', | |
| 208 | + 'value' => FrmEntriesHelper::get_browser( $entry_description['browser'] ), | |
| 265 | 209 | ); |
| 210 | + | |
| 266 | 211 | $referrer = array( |
| 267 | 212 | 'label' => __( 'Referrer', 'formidable' ), |
| 268 | - 'value' => $entry_description['referrer'] ?? '', | |
| 213 | + 'value' => $entry_description['referrer'], | |
| 269 | 214 | ); |
| 270 | 215 | |
| 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 | 216 | $this->user_info = array( |
| 283 | - 'ip' => $ip, | |
| 284 | - 'browser' => $browser, | |
| 217 | + 'ip' => $ip, | |
| 218 | + 'browser' => $browser, | |
| 285 | 219 | 'referrer' => $referrer, |
| 286 | 220 | ); |
| 287 | 221 | } |
| 288 | 222 | |
| @@ -306,22 +240,16 @@ | ||
| 306 | 240 | * |
| 307 | 241 | * @return bool |
| 308 | 242 | */ |
| 309 | 243 | protected function is_field_included( $field ) { |
| 310 | - $is_included = true; | |
| 311 | - | |
| 312 | - if ( $this->include_fields ) { | |
| 244 | + if ( ! empty( $this->include_fields ) ) { | |
| 313 | 245 | $is_included = $this->is_field_in_array( $field, $this->include_fields ); |
| 246 | + } else if ( ! empty( $this->exclude_fields ) ) { | |
| 247 | + $is_included = ! $this->is_field_in_array( $field, $this->exclude_fields ); | |
| 248 | + } else { | |
| 249 | + $is_included = true; | |
| 314 | 250 | } |
| 315 | 251 | |
| 316 | - if ( $this->exclude_fields ) { | |
| 317 | - $is_excluded = $this->is_field_in_array( $field, $this->exclude_fields ); | |
| 318 | - | |
| 319 | - if ( $is_excluded ) { | |
| 320 | - $is_included = false; | |
| 321 | - } | |
| 322 | - } | |
| 323 | - | |
| 324 | 252 | return $is_included; |
| 325 | 253 | } |
| 326 | 254 | |
| 327 | 255 | /** |
| @@ -329,15 +257,14 @@ | ||
| 329 | 257 | * |
| 330 | 258 | * @since 2.04 |
| 331 | 259 | * |
| 332 | 260 | * @param stdClass $field |
| 333 | - * @param array $array | |
| 261 | + * @param array $array | |
| 334 | 262 | * |
| 335 | 263 | * @return bool |
| 336 | 264 | */ |
| 337 | 265 | protected function is_field_in_array( $field, $array ) { |
| 338 | - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict | |
| 339 | - 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 ); | |
| 340 | 267 | } |
| 341 | 268 | |
| 342 | 269 | /** |
| 343 | 270 | * Add a field's values to the field_values property |
| @@ -344,10 +271,8 @@ | ||
| 344 | 271 | * |
| 345 | 272 | * @since 2.04 |
| 346 | 273 | * |
| 347 | 274 | * @param stdClass $field |
| 348 | - * | |
| 349 | - * @return void | |
| 350 | 275 | */ |
| 351 | 276 | protected function add_field_values( $field ) { |
| 352 | 277 | $this->field_values[ $field->id ] = new FrmFieldValue( $field, $this->entry ); |
| 353 | 278 | } |