Completed
Branch uploads (08d8c9)
by Stephanie
04:20
created

FrmEntriesController::entry_sidebar()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
class FrmEntriesController {
4
5
    public static function menu() {
6
		FrmAppHelper::force_capability( 'frm_view_entries' );
7
8
        add_submenu_page('formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' );
9
10
		if ( ! in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show' ) ) ) {
11
			$menu_name = FrmAppHelper::get_menu_name();
12
			add_filter( 'manage_' . sanitize_title( $menu_name ) . '_page_formidable-entries_columns', 'FrmEntriesController::manage_columns' );
13
			add_filter( 'get_user_option_manage' . sanitize_title( $menu_name ) . '_page_formidable-entriescolumnshidden', 'FrmEntriesController::hidden_columns' );
14
			add_filter( 'manage_' . sanitize_title( $menu_name ) . '_page_formidable-entries_sortable_columns', 'FrmEntriesController::sortable_columns' );
15
        }
16
    }
17
18
    /* Display in Back End */
19
    public static function route() {
20
		$action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' );
21
22
        switch ( $action ) {
23
            case 'show':
24
            case 'destroy':
25
            case 'destroy_all':
26
                return self::$action();
27
28
            default:
29
                do_action( 'frm_entry_action_route', $action );
30
                if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) {
31
                    return;
32
                }
33
34
                return self::display_list();
35
        }
36
    }
37
38
	public static function contextual_help( $help, $screen_id, $screen ) {
39
        // Only add to certain screens. add_help_tab was introduced in WordPress 3.3
40
        if ( ! method_exists( $screen, 'add_help_tab' ) ) {
41
            return $help;
42
        }
43
44
		$action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
45
		$page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
46
		if ( $page != 'formidable-entries' || ( ! empty( $action ) && $action != 'list' ) ) {
47
            return $help;
48
        }
49
50
		unset( $action, $page );
51
52
        $screen->add_help_tab( array(
53
            'id'      => 'formidable-entries-tab',
54
            'title'   => __( 'Overview', 'formidable' ),
55
			'content' => '<p>' . esc_html__( 'This screen provides access to all of your entries. You can customize the display of this screen to suit your workflow.', 'formidable' ) . '</p> <p>' . esc_html__( 'Hovering over a row in the entries list will display action links that allow you to manage your entry.', 'formidable' ) . '</p>',
56
        ));
57
58
        $screen->set_help_sidebar(
59
			'<p><strong>' . esc_html__( 'For more information:', 'formidable' ) . '</strong></p>' .
60
			'<p><a href="' . esc_url( FrmAppHelper::make_affiliate_url( 'http://formidablepro.com/knowledgebase/manage-entries-from-the-back-end/' ) ) . '" target="_blank">' . esc_html__( 'Documentation on Entries', 'formidable' ) . '</a></p>' .
61
			'<p><a href="' . esc_url( FrmAppHelper::make_affiliate_url( 'http://formidablepro.com/help-desk/' ) ) . '" target="_blank">' . esc_html__( 'Support', 'formidable' ) . '</a></p>'
62
    	);
63
64
        return $help;
65
    }
66
67
	public static function manage_columns( $columns ) {
68
        global $frm_vars;
69
		$form_id = FrmForm::get_current_form_id();
70
71
		$columns[ $form_id . '_id' ] = 'ID';
72
		$columns[ $form_id . '_item_key' ] = esc_html__( 'Entry Key', 'formidable' );
73
74
		if ( $form_id ) {
75
			self::get_columns_for_form( $form_id, $columns );
76
		} else {
77
			$columns[ $form_id . '_form_id' ] = __( 'Form', 'formidable' );
78
			$columns[ $form_id . '_name' ] = __( 'Entry Name', 'formidable' );
79
			$columns[ $form_id . '_user_id' ] = __( 'Created By', 'formidable' );
80
		}
81
82
		$columns[ $form_id . '_created_at' ] = __( 'Entry creation date', 'formidable' );
83
		$columns[ $form_id . '_updated_at' ] = __( 'Entry update date', 'formidable' );
84
		$columns[ $form_id . '_ip' ] = 'IP';
85
86
        $frm_vars['cols'] = $columns;
87
88
		$action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
89
		if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ) ) ) {
90
			add_screen_option( 'per_page', array( 'label' => __( 'Entries', 'formidable' ), 'default' => 20, 'option' => 'formidable_page_formidable_entries_per_page' ) );
91
        }
92
93
        return $columns;
94
    }
95
96
	private static function get_columns_for_form( $form_id, &$columns ) {
97
		$form_cols = FrmField::get_all_for_form( $form_id, '', 'include' );
98
99
		foreach ( $form_cols as $form_col ) {
100
			if ( FrmField::is_no_save_field( $form_col->type ) ) {
101
				continue;
102
			}
103
104
			if ( $form_col->type == 'form' && isset( $form_col->field_options['form_select'] ) && ! empty( $form_col->field_options['form_select'] ) ) {
105
				$sub_form_cols = FrmField::get_all_for_form( $form_col->field_options['form_select'] );
106
107
				if ( $sub_form_cols ) {
108
					foreach ( $sub_form_cols as $k => $sub_form_col ) {
109
						if ( FrmField::is_no_save_field( $sub_form_col->type ) ) {
110
							unset( $sub_form_cols[ $k ] );
111
							continue;
112
						}
113
						$columns[ $form_id . '_' . $sub_form_col->field_key . '-_-' . $form_col->id ] = FrmAppHelper::truncate( $sub_form_col->name, 35 );
114
						unset($sub_form_col);
115
					}
116
				}
117
				unset($sub_form_cols);
118
			} else {
119
				$col_id = $form_col->field_key;
120
				if ( $form_col->form_id != $form_id ) {
121
					$col_id .= '-_-form' . $form_col->form_id;
122
				}
123
124
				if ( isset($form_col->field_options['separate_value']) && $form_col->field_options['separate_value'] ) {
125
					$columns[ $form_id . '_frmsep_' . $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 );
126
				}
127
				$columns[ $form_id . '_' . $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 );
128
			}
129
		}
130
	}
131
132
	public static function check_hidden_cols( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
133
		$menu_name = FrmAppHelper::get_menu_name();
134
		$this_page_name = 'manage' . sanitize_title( $menu_name ) . '_page_formidable-entriescolumnshidden';
135
		if ( $meta_key != $this_page_name || $meta_value == $prev_value ) {
136
            return $check;
137
        }
138
139
		if ( empty( $prev_value ) ) {
140
			$prev_value = get_metadata( 'user', $object_id, $meta_key, true );
141
		}
142
143
        global $frm_vars;
144
        //add a check so we don't create a loop
145
        $frm_vars['prev_hidden_cols'] = ( isset($frm_vars['prev_hidden_cols']) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value;
146
147
        return $check;
148
    }
149
150
    //add hidden columns back from other forms
151
	public static function update_hidden_cols( $meta_id, $object_id, $meta_key, $meta_value ) {
152
		$menu_name = FrmAppHelper::get_menu_name();
153
		$sanitized = sanitize_title( $menu_name );
154
		$this_page_name = 'manage' . $sanitized . '_page_formidable-entriescolumnshidden';
155
		if ( $meta_key != $this_page_name ) {
156
            return;
157
        }
158
159
        global $frm_vars;
160
        if ( ! isset($frm_vars['prev_hidden_cols']) || ! $frm_vars['prev_hidden_cols'] ) {
161
            return; //don't continue if there's no previous value
162
        }
163
164
        foreach ( $meta_value as $mk => $mv ) {
165
            //remove blank values
166
            if ( empty( $mv )  ) {
167
                unset( $meta_value[ $mk ] );
168
            }
169
        }
170
171
        $cur_form_prefix = reset($meta_value);
172
        $cur_form_prefix = explode('_', $cur_form_prefix);
173
        $cur_form_prefix = $cur_form_prefix[0];
174
        $save = false;
175
176
        foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) {
177
			if ( empty( $prev_hidden ) || in_array( $prev_hidden, $meta_value ) ) {
178
                //don't add blank cols or process included cols
179
                continue;
180
            }
181
182
			$form_prefix = explode( '_', $prev_hidden );
183
            $form_prefix = $form_prefix[0];
184
            if ( $form_prefix == $cur_form_prefix ) {
185
                //don't add back columns that are meant to be hidden
186
                continue;
187
            }
188
189
            $meta_value[] = $prev_hidden;
190
            $save = true;
191
            unset($form_prefix);
192
        }
193
194
		if ( $save ) {
195
            $user = wp_get_current_user();
196
			update_user_option( $user->ID, $this_page_name, $meta_value, true );
197
        }
198
    }
199
200
	public static function save_per_page( $save, $option, $value ) {
201
        if ( $option == 'formidable_page_formidable_entries_per_page' ) {
202
            $save = (int) $value;
203
        }
204
        return $save;
205
    }
206
207
	public static function sortable_columns() {
208
		$form_id = FrmForm::get_current_form_id();
209
		$fields = FrmField::get_all_for_form( $form_id );
210
211
		$columns = array(
212
			$form_id . '_id'         => 'id',
213
			$form_id . '_created_at' => 'created_at',
214
			$form_id . '_updated_at' => 'updated_at',
215
			$form_id . '_ip'         => 'ip',
216
			$form_id . '_item_key'   => 'item_key',
217
			$form_id . '_is_draft'   => 'is_draft',
218
		);
219
220
		foreach ( $fields as $field ) {
221
			if ( $field->type != 'checkbox' && ( ! isset( $field->field_options['post_field'] ) || $field->field_options['post_field'] == '' ) ) {
222
				// Can't sort on checkboxes because they are stored serialized, or post fields
223
				$columns[ $form_id . '_' . $field->field_key ] = 'meta_' . $field->id;
224
			}
225
		}
226
227
		return $columns;
228
	}
229
230
	public static function hidden_columns( $result ) {
231
        global $frm_vars;
232
233
		$form_id = FrmForm::get_current_form_id();
234
235
        $return = false;
236
        foreach ( (array) $result as $r ) {
237
            if ( ! empty( $r ) ) {
238
                $form_prefix = explode( '_', $r );
239
                $form_prefix = $form_prefix[0];
240
241
                if ( (int) $form_prefix == (int) $form_id ) {
242
                    $return = true;
243
                    break;
244
                }
245
246
                unset($form_prefix);
247
            }
248
        }
249
250
        if ( $return ) {
251
			return $result;
252
		}
253
254
        $i = isset($frm_vars['cols']) ? count($frm_vars['cols']) : 0;
255
        $max_columns = 8;
256
        if ( $i <= $max_columns ) {
257
			return $result;
258
		}
259
260
        global $frm_vars;
261
        if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] ) {
262
            $frm_vars['current_form']->options = maybe_unserialize($frm_vars['current_form']->options);
263
        }
264
265
		$has_custom_hidden_columns = ( isset( $frm_vars['current_form'] ) && $frm_vars['current_form'] && isset( $frm_vars['current_form']->options['hidden_cols'] ) && ! empty( $frm_vars['current_form']->options['hidden_cols'] ) );
266
		if ( $has_custom_hidden_columns ) {
267
            $result = $frm_vars['current_form']->options['hidden_cols'];
268
        } else {
269
            $cols = $frm_vars['cols'];
270
            $cols = array_reverse($cols, true);
271
272
			if ( $form_id ) {
273
				$result[] = $form_id . '_id';
274
				$i--;
275
			}
276
277
			$result[] = $form_id . '_item_key';
278
            $i--;
279
280
			foreach ( $cols as $col_key => $col ) {
281
                if ( $i > $max_columns ) {
282
					$result[] = $col_key;
283
				}
284
                //remove some columns by default
285
                $i--;
286
                unset($col_key, $col);
287
            }
288
        }
289
290
        return $result;
291
    }
292
293
	public static function display_list( $message = '', $errors = array() ) {
294
        global $wpdb, $frm_vars;
295
296
		$form = FrmForm::maybe_get_current_form();
297
		$params = FrmForm::get_admin_params( $form );
298
299
        if ( $form ) {
300
            $params['form'] = $form->id;
301
            $frm_vars['current_form'] = $form;
302
303
			self::get_delete_form_time( $form, $errors );
304
		}
305
306
        $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
307
308
        $wp_list_table = new $table_class( array( 'params' => $params ) );
309
310
        $pagenum = $wp_list_table->get_pagenum();
311
312
        $wp_list_table->prepare_items();
313
314
        $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
315
        if ( $pagenum > $total_pages && $total_pages > 0 ) {
316
			$url = add_query_arg( 'paged', $total_pages );
317
            if ( headers_sent() ) {
318
                echo FrmAppHelper::js_redirect($url);
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'FrmAppHelper'
Loading history...
319
            } else {
320
                wp_redirect( esc_url_raw( $url ) );
321
            }
322
            die();
323
        }
324
325
        if ( empty($message) && isset($_GET['import-message']) ) {
326
            $message = __( 'Your import is complete', 'formidable' );
327
        }
328
329
		require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php' );
330
    }
331
332
	private static function get_delete_form_time( $form, &$errors ) {
333
		if ( 'trash' == $form->status ) {
334
			$delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
335
			$time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? ( $form->options['trash_time'] ) : time() ) );
336
			$errors['trash'] = sprintf( __( 'This form is in the trash and is scheduled to be deleted permanently in %s along with any entries.', 'formidable' ), $time_to_delete );
337
		}
338
	}
339
340
    /* Back End CRUD */
341
	public static function show( $id = 0 ) {
342
        FrmAppHelper::permission_check('frm_view_entries');
343
344
        if ( ! $id ) {
345
			$id = FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
346
347
            if ( ! $id ) {
348
				$id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'absint' );
349
            }
350
        }
351
352
        $entry = FrmEntry::getOne($id, true);
353
		if ( ! $entry ) {
354
			echo '<div id="form_show_entry_page" class="wrap">' .
355
				__( 'You are trying to view an entry that does not exist.', 'formidable' ) .
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw '__'
Loading history...
356
				'</div>';
357
			return;
358
		}
359
360
        $data = maybe_unserialize($entry->description);
361
		if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) {
362
			$data = array( 'referrer' => $data );
363
		}
364
365
		$fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' );
366
        $to_emails = array();
367
368
		include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php' );
369
    }
370
371
    public static function destroy() {
372
        FrmAppHelper::permission_check('frm_delete_entries');
373
374
		$params = FrmForm::get_admin_params();
375
376
        if ( isset($params['keep_post']) && $params['keep_post'] ) {
377
            //unlink entry from post
378
            global $wpdb;
379
			$wpdb->update( $wpdb->prefix . 'frm_items', array( 'post_id' => '' ), array( 'id' => $params['id'] ) );
380
        }
381
382
        $message = '';
383
        if ( FrmEntry::destroy( $params['id'] ) ) {
384
            $message = __( 'Entry was Successfully Destroyed', 'formidable' );
385
        }
386
387
        self::display_list( $message );
388
    }
389
390
    public static function destroy_all() {
391
        if ( ! current_user_can( 'frm_delete_entries' ) ) {
392
            $frm_settings = FrmAppHelper::get_settings();
393
            wp_die( $frm_settings->admin_permission );
394
        }
395
396
        global $wpdb;
397
		$params = FrmForm::get_admin_params();
398
        $message = '';
399
        $errors = array();
400
        $form_id = (int) $params['form'];
401
402
        if ( $form_id ) {
403
            $entry_ids = FrmDb::get_col( 'frm_items', array( 'form_id' => $form_id ) );
404
			$action = FrmFormAction::get_action_for_form( $form_id, 'wppost', 1 );
405
406
            if ( $action ) {
407
                // this action takes a while, so only trigger it if there are posts to delete
408
                foreach ( $entry_ids as $entry_id ) {
0 ignored issues
show
Bug introduced by
The expression $entry_ids of type array|null|string|object is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
409
                    do_action( 'frm_before_destroy_entry', $entry_id );
410
                    unset( $entry_id );
411
                }
412
            }
413
414
            $wpdb->query( $wpdb->prepare( "DELETE em.* FROM {$wpdb->prefix}frm_item_metas as em INNER JOIN {$wpdb->prefix}frm_items as e on (em.item_id=e.id) and form_id=%d", $form_id ) );
415
            $results = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id ) );
416
            if ( $results ) {
417
				FrmEntry::clear_cache();
418
                $message = __( 'Entries were Successfully Destroyed', 'formidable' );
419
            }
420
        } else {
421
            $errors = __( 'No entries were specified', 'formidable' );
422
        }
423
424
        self::display_list( $message, $errors );
425
    }
426
427
    public static function show_form( $id = '', $key = '', $title = false, $description = false ) {
428
        _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::show_form()' );
429
        return FrmFormsController::show_form( $id, $key, $title, $description );
430
    }
431
432
    public static function get_form( $filename, $form, $title, $description ) {
433
        _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form()' );
434
        return FrmFormsController::get_form( $form, $title, $description );
435
    }
436
437
    public static function process_entry( $errors = '', $ajax = false ) {
438
		$form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
439
		if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) {
1 ignored issue
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
440
            return;
441
        }
442
443
        global $frm_vars;
444
445
		$form = FrmForm::getOne( $form_id );
446
        if ( ! $form ) {
447
            return;
448
        }
449
450
		$params = FrmForm::get_params( $form );
451
452
        if ( ! isset( $frm_vars['form_params'] ) ) {
453
            $frm_vars['form_params'] = array();
454
        }
455
		$frm_vars['form_params'][ $form->id ] = $params;
456
457
		if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) {
458
            return;
459
        }
460
461
        if ( $errors == '' && ! $ajax ) {
462
			$errors = FrmEntryValidate::validate( $_POST );
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
463
        }
464
465
		/**
466
		 * Use this filter to add trigger actions and add errors after
467
		 * all other errors have been processed
468
		 * @since 2.0.6
469
		 */
470
		$errors = apply_filters( 'frm_entries_before_create', $errors, $form );
471
472
		$frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors );
473
474
        if ( empty( $errors ) ) {
475
			$_POST['frm_skip_cookie'] = 1;
476
            if ( $params['action'] == 'create' ) {
477
				if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) {
478
					$frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST );
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
479
                }
480
            }
481
482
            do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) );
483
			unset( $_POST['frm_skip_cookie'] );
1 ignored issue
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
484
        }
485
    }
486
487
    public static function delete_entry_before_redirect( $url, $form, $atts ) {
488
        self::_delete_entry( $atts['id'], $form );
489
        return $url;
490
    }
491
492
    //Delete entry if not redirected
493
    public static function delete_entry_after_save( $atts ) {
494
        self::_delete_entry( $atts['entry_id'], $atts['form'] );
495
    }
496
497
    private static function _delete_entry( $entry_id, $form ) {
498
        if ( ! $form ) {
499
            return;
500
        }
501
502
        $form->options = maybe_unserialize( $form->options );
503
        if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) {
504
            FrmEntry::destroy( $entry_id );
505
        }
506
    }
507
508
	public static function show_entry_shortcode( $atts ) {
509
		return FrmEntryFormat::show_entry( $atts );
510
	}
511
512
    public static function &filter_email_value( $value, $meta, $entry, $atts = array() ) {
513 View Code Duplication
		if ( isset( $atts['field'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
514
			$field = $atts['field'];
515
		} else {
516
			$field = FrmField::getOne( $meta->field_id );
517
		}
518
        if ( ! $field ) {
519
            return $value;
520
        }
521
522
        $value = self::filter_display_value($value, $field, $atts);
523
        return $value;
524
    }
525
526
	public static function &filter_shortcode_value( $value, $tag, $atts, $field ) {
527
        $plain_text = add_filter('frm_plain_text_email', true);
528
		FrmEntryFormat::textarea_display_value( $field->type, $plain_text, $value );
529
530
        if ( isset($atts['show']) && $atts['show'] == 'value' ) {
531
            return $value;
532
        }
533
534
        return self::filter_display_value($value, $field, $atts);
535
    }
536
537
    public static function &filter_display_value( $value, $field, $atts = array() ) {
538
        $saved_value = ( isset($atts['saved_value']) && $atts['saved_value'] ) ? true : false;
539
		if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'radio', 'select' ) ) || ! FrmField::is_option_true( $field, 'separate_value' ) || $saved_value ) {
540
            return $value;
541
        }
542
543
        $f_values = $f_labels = array();
544
545
        foreach ( $field->options as $opt_key => $opt ) {
546
            if ( ! is_array($opt) ) {
547
                continue;
548
            }
549
550
            $f_labels[ $opt_key ] = isset( $opt['label'] ) ? $opt['label'] : reset($opt);
551
            $f_values[ $opt_key ] = isset( $opt['value'] ) ? $opt['value'] : $f_labels[ $opt_key ];
552
            if ( $f_labels[ $opt_key ] == $f_values[ $opt_key ] ) {
553
                unset( $f_values[ $opt_key ], $f_labels[ $opt_key ] );
554
            }
555
            unset($opt_key, $opt);
556
        }
557
558
        if ( ! empty($f_values) ) {
559
            foreach ( (array) $value as $v_key => $val ) {
560
                if ( in_array($val, $f_values) ) {
561
                    $opt = array_search($val, $f_values);
562
                    if ( is_array($value) ) {
563
                        $value[ $v_key ] = $f_labels[ $opt ];
564
                    } else {
565
                        $value = $f_labels[ $opt ];
566
                    }
567
                }
568
                unset($v_key, $val);
569
            }
570
        }
571
572
        return $value;
573
    }
574
575
	public static function get_params( $form = null ) {
576
		_deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::get_params' );
577
		return FrmForm::get_params( $form );
578
	}
579
580
	public static function entry_sidebar( $entry ) {
581
        $data = maybe_unserialize($entry->description);
582
        $date_format = get_option('date_format');
583
        $time_format = get_option('time_format');
584
		if ( isset( $data['browser'] ) ) {
585
			$browser = FrmEntryFormat::get_browser( $data['browser'] );
586
		}
587
588
		include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php' );
589
    }
590
}
591