| @@ -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 | */ |
| @@ -51,13 +48,9 @@ | ||
| 51 | 48 | * @param int|string $entry_id |
| 52 | 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,23 +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 | - * @return stdClass | |
| 91 | - */ | |
| 92 | - public function get_entry() { | |
| 93 | - return $this->entry; | |
| 94 | - } | |
| 95 | - | |
| 96 | - /** | |
| 97 | 78 | * Set the form_id property |
| 98 | 79 | * |
| 99 | 80 | * @since 2.04 |
| 100 | - * | |
| 101 | - * @return void | |
| 102 | 81 | */ |
| 103 | 82 | protected function init_form_id() { |
| 104 | 83 | $this->form_id = (int) $this->entry->form_id; |
| 105 | 84 | } |
| @@ -109,10 +88,8 @@ | ||
| 109 | 88 | * |
| 110 | 89 | * @since 2.04 |
| 111 | 90 | * |
| 112 | 91 | * @param array $atts |
| 113 | - * | |
| 114 | - * @return void | |
| 115 | 92 | */ |
| 116 | 93 | protected function init_include_fields( $atts ) { |
| 117 | 94 | |
| 118 | 95 | // For reverse compatibility with the fields parameter |
| @@ -134,18 +111,8 @@ | ||
| 134 | 111 | } |
| 135 | 112 | } |
| 136 | 113 | |
| 137 | 114 | $this->include_fields = $this->prepare_array_property( 'include_fields', $atts ); |
| 138 | - | |
| 139 | - /** | |
| 140 | - * Allows modifying the IDs of include_fields used in the entry values. | |
| 141 | - * | |
| 142 | - * @since 5.0.04 | |
| 143 | - * | |
| 144 | - * @param array $field_ids The list of field IDs. | |
| 145 | - * @param array $atts The arguments. See {@see FrmEntriesController::show_entry_shortcode()}. | |
| 146 | - */ | |
| 147 | - $this->include_fields = apply_filters( 'frm_entry_values_include_fields', $this->include_fields, $atts ); | |
| 148 | 115 | } |
| 149 | 116 | |
| 150 | 117 | /** |
| 151 | 118 | * Set the exclude_fields property |
| @@ -152,23 +119,11 @@ | ||
| 152 | 119 | * |
| 153 | 120 | * @since 2.04 |
| 154 | 121 | * |
| 155 | 122 | * @param array $atts |
| 156 | - * | |
| 157 | - * @return void | |
| 158 | 123 | */ |
| 159 | 124 | protected function init_exclude_fields( $atts ) { |
| 160 | 125 | $this->exclude_fields = $this->prepare_array_property( 'exclude_fields', $atts ); |
| 161 | - | |
| 162 | - /** | |
| 163 | - * Allows modifying the IDs of exclude_fields used in the entry values. | |
| 164 | - * | |
| 165 | - * @since 5.0.04 | |
| 166 | - * | |
| 167 | - * @param array $field_ids The list of field IDs. | |
| 168 | - * @param array $atts The arguments. See {@see FrmEntriesController::show_entry_shortcode()}. | |
| 169 | - */ | |
| 170 | - $this->exclude_fields = apply_filters( 'frm_entry_values_exclude_fields', $this->exclude_fields, $atts ); | |
| 171 | 126 | } |
| 172 | 127 | |
| 173 | 128 | /** |
| 174 | 129 | * Prepare an array property value, such as include_fields and exclude_fields |
| @@ -198,30 +153,11 @@ | ||
| 198 | 153 | /** |
| 199 | 154 | * Set the fields property |
| 200 | 155 | * |
| 201 | 156 | * @since 2.04 |
| 202 | - * | |
| 203 | - * @return void | |
| 204 | 157 | */ |
| 205 | 158 | protected function init_fields() { |
| 206 | 159 | $this->fields = FrmField::get_all_for_form( $this->form_id, '', 'exclude', 'exclude' ); |
| 207 | - | |
| 208 | - /** | |
| 209 | - * Allows modifying the list of all field in the form that is used in the entry values. | |
| 210 | - * | |
| 211 | - * @since 5.0.04 | |
| 212 | - * | |
| 213 | - * @param array $fields The list of fields. | |
| 214 | - * @param array $args The arguments. Contains `form_id`, `entry`. | |
| 215 | - */ | |
| 216 | - $this->fields = apply_filters( | |
| 217 | - 'frm_entry_values_fields', | |
| 218 | - $this->fields, | |
| 219 | - array( | |
| 220 | - 'form_id' => $this->form_id, | |
| 221 | - 'entry' => $this->entry, | |
| 222 | - ) | |
| 223 | - ); | |
| 224 | 160 | } |
| 225 | 161 | |
| 226 | 162 | /** |
| 227 | 163 | * Set the field_values property |
| @@ -226,10 +162,8 @@ | ||
| 226 | 162 | /** |
| 227 | 163 | * Set the field_values property |
| 228 | 164 | * |
| 229 | 165 | * @since 2.04 |
| 230 | - * | |
| 231 | - * @return void | |
| 232 | 166 | */ |
| 233 | 167 | protected function init_field_values() { |
| 234 | 168 | foreach ( $this->fields as $field ) { |
| 235 | 169 | if ( $this->is_field_included( $field ) ) { |
| @@ -252,47 +186,37 @@ | ||
| 252 | 186 | /** |
| 253 | 187 | * Set the user_info property |
| 254 | 188 | * |
| 255 | 189 | * @since 2.04 |
| 256 | - * | |
| 257 | - * @return void | |
| 258 | 190 | */ |
| 259 | 191 | protected function init_user_info() { |
| 260 | 192 | if ( isset( $this->entry->description ) ) { |
| 261 | - $entry_description = (array) $this->entry->description; | |
| 193 | + $entry_description = (array) maybe_unserialize( $this->entry->description ); | |
| 262 | 194 | } else { |
| 263 | 195 | $entry_description = array( |
| 264 | - 'browser' => '', | |
| 196 | + 'browser' => '', | |
| 265 | 197 | 'referrer' => '', |
| 266 | 198 | ); |
| 267 | 199 | } |
| 268 | 200 | |
| 269 | - $ip = array( | |
| 201 | + $ip = array( | |
| 270 | 202 | 'label' => __( 'IP Address', 'formidable' ), |
| 271 | 203 | 'value' => $this->entry->ip, |
| 272 | 204 | ); |
| 205 | + | |
| 273 | 206 | $browser = array( |
| 274 | 207 | 'label' => __( 'User-Agent (Browser/OS)', 'formidable' ), |
| 275 | - 'value' => isset( $entry_description['browser'] ) ? FrmEntriesHelper::get_browser( $entry_description['browser'] ) : '', | |
| 208 | + 'value' => FrmEntriesHelper::get_browser( $entry_description['browser'] ), | |
| 276 | 209 | ); |
| 210 | + | |
| 277 | 211 | $referrer = array( |
| 278 | 212 | 'label' => __( 'Referrer', 'formidable' ), |
| 279 | - 'value' => isset( $entry_description['referrer'] ) ? $entry_description['referrer'] : '', | |
| 213 | + 'value' => $entry_description['referrer'], | |
| 280 | 214 | ); |
| 281 | 215 | |
| 282 | - /** | |
| 283 | - * Allow the referrer to be modified. | |
| 284 | - * | |
| 285 | - * @since 5.5.1 | |
| 286 | - * | |
| 287 | - * @param array $referrer | |
| 288 | - * @param array @entry_description | |
| 289 | - */ | |
| 290 | - $referrer = apply_filters( 'frm_user_info_referrer', $referrer, $entry_description, $this->entry ); | |
| 291 | - | |
| 292 | 216 | $this->user_info = array( |
| 293 | - 'ip' => $ip, | |
| 294 | - 'browser' => $browser, | |
| 217 | + 'ip' => $ip, | |
| 218 | + 'browser' => $browser, | |
| 295 | 219 | 'referrer' => $referrer, |
| 296 | 220 | ); |
| 297 | 221 | } |
| 298 | 222 | |
| @@ -316,20 +240,16 @@ | ||
| 316 | 240 | * |
| 317 | 241 | * @return bool |
| 318 | 242 | */ |
| 319 | 243 | protected function is_field_included( $field ) { |
| 320 | - $is_included = true; | |
| 321 | 244 | if ( ! empty( $this->include_fields ) ) { |
| 322 | 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; | |
| 323 | 250 | } |
| 324 | 251 | |
| 325 | - if ( ! empty( $this->exclude_fields ) ) { | |
| 326 | - $is_excluded = $this->is_field_in_array( $field, $this->exclude_fields ); | |
| 327 | - if ( $is_excluded ) { | |
| 328 | - $is_included = false; | |
| 329 | - } | |
| 330 | - } | |
| 331 | - | |
| 332 | 252 | return $is_included; |
| 333 | 253 | } |
| 334 | 254 | |
| 335 | 255 | /** |
| @@ -342,9 +262,9 @@ | ||
| 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 | } |