PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 1.07.11
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v1.07.11
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/controllers/FrmEntriesController.php +427 -966 6.261.07.11 View file →
@@ -1,979 +1,440 @@
1 1 <?php
2 -if ( ! defined( 'ABSPATH' ) ) {
3 - die( 'You are not allowed to call this page directly.' );
4 -}
2 +/**
3 + * @package Formidable
4 + */
5 +
6 +if(!defined('ABSPATH')) die('You are not allowed to call this page directly.');
5 7
6 -class FrmEntriesController {
8 +if(class_exists('FrmEntriesController'))
9 + return;
7 10
8 - /**
9 - * @return void
10 - */
11 - public static function menu() {
12 - FrmAppHelper::force_capability( 'frm_view_entries' );
11 +class FrmEntriesController{
12 +
13 + public static function load_hooks(){
14 + add_action('admin_menu', 'FrmEntriesController::menu', 11);
15 + add_action('wp', 'FrmEntriesController::process_entry', 10, 0);
16 + add_action('frm_wp', 'FrmEntriesController::process_entry', 10, 0);
17 + add_filter('frm_redirect_url', 'FrmEntriesController::delete_entry_before_redirect', 50, 3);
18 + add_action('frm_after_entry_processed', 'FrmEntriesController::delete_entry_after_save', 100);
19 + add_filter('frm_email_value', 'FrmEntriesController::filter_email_value', 10, 3);
20 + }
21 +
22 + public static function menu(){
23 + global $frm_vars;
24 + if(!$frm_vars['pro_is_installed']){
25 + add_submenu_page('formidable', 'Formidable |'. __('Entries', 'formidable'), '<span style="opacity:.5;filter:alpha(opacity=50);">'. __('Entries', 'formidable') .'</span>', 'administrator', 'formidable-entries', 'FrmEntriesController::list_entries');
26 + }
27 + }
28 +
29 + public static function list_entries(){
30 + global $frm_entry;
31 + $frm_form = new FrmForm();
32 + $form_select = $frm_form->getAll("is_template=0 AND (status is NULL OR status = '' OR status = 'published')", ' ORDER BY name');
33 + $form_id = FrmAppHelper::get_param('form', false);
34 + if($form_id)
35 + $form = $frm_form->getOne($form_id);
36 + else
37 + $form = (isset($form_select[0])) ? $form_select[0] : 0;
38 +
39 + if($form)
40 + $entry_count = $frm_entry->getRecordCount($form->id);
41 +
42 + include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/list.php');
43 + }
44 +
45 + public static function show_form($id='', $key='', $title=false, $description=false){
46 + _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::show_form()' );
47 + return FrmFormsController::show_form($id, $key, $title, $description);
48 + }
49 +
50 + public static function get_form($filename, $form, $title, $description) {
51 + _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form()' );
52 + return FrmFormsController::get_form($form, $title, $description);
53 + }
54 +
55 + public static function process_entry($errors='', $ajax=false){
56 + if((is_admin() and !defined('DOING_AJAX')) or !isset($_POST) or !isset($_POST['form_id']) or !is_numeric($_POST['form_id']) or !isset($_POST['item_key']))
57 + return;
13 58
14 - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' );
59 + global $frm_entry, $frm_vars;
60 +
61 + $frm_form = new FrmForm();
62 + $form = $frm_form->getOne($_POST['form_id']);
63 + if(!$form)
64 + return;
65 +
66 + $params = FrmEntriesController::get_params($form);
67 +
68 + if(!isset($frm_vars['form_params']))
69 + $frm_vars['form_params'] = array();
70 + $frm_vars['form_params'][$form->id] = $params;
71 +
72 + if(isset($frm_vars['created_entries'][$_POST['form_id']]))
73 + return;
74 +
75 + if($errors == '')
76 + $errors = $frm_entry->validate($_POST);
77 + $frm_vars['created_entries'][$_POST['form_id']] = array('errors' => $errors);
78 +
79 + if( empty($errors) ){
80 + $_POST['frm_skip_cookie'] = 1;
81 + if($params['action'] == 'create'){
82 + if (apply_filters('frm_continue_to_create', true, $_POST['form_id']) and !isset($frm_vars['created_entries'][$_POST['form_id']]['entry_id']))
83 + $frm_vars['created_entries'][$_POST['form_id']]['entry_id'] = $frm_entry->create( $_POST );
84 + }
85 +
86 + do_action('frm_process_entry', $params, $errors, $form, array('ajax' => $ajax));
87 + unset($_POST['frm_skip_cookie']);
88 + }
89 + }
90 +
91 + public static function delete_entry_before_redirect($url, $form, $atts){
92 + self::_delete_entry($atts['id'], $form);
93 + return $url;
94 + }
95 +
96 + //Delete entry if not redirected
97 + public static function delete_entry_after_save($atts){
98 + self::_delete_entry($atts['entry_id'], $atts['form']);
99 + }
100 +
101 + private static function _delete_entry($entry_id, $form){
102 + if(!$form)
103 + return;
104 +
105 + $form->options = maybe_unserialize($form->options);
106 + if(isset($form->options['no_save']) and $form->options['no_save']){
107 + global $frm_entry;
108 + $frm_entry->destroy( $entry_id );
109 + }
110 + }
111 +
112 + public static function show_entry_shortcode($atts){
113 + $atts = shortcode_atts(array(
114 + 'id' => false, 'entry' => false, 'fields' => false, 'plain_text' => false,
115 + 'user_info' => false, 'include_blank' => false, 'default_email' => false,
116 + 'form_id' => false, 'format' => 'text', 'direction' => 'ltr',
117 + 'font_size' => '', 'text_color' => '',
118 + 'border_width' => '', 'border_color' => '',
119 + 'bg_color' => '', 'alt_bg_color' => '',
120 + ), $atts);
121 + extract($atts);
122 +
123 + if ( $format != 'text' ) {
124 + //format options are text, array, or json
125 + $plain_text = true;
126 + }
127 +
128 + global $frm_entry;
129 +
130 + if ( !$entry || !is_object($entry) ) {
131 + if ( !$id && !$default_email ) {
132 + return '';
133 + }
134 +
135 + if($id)
136 + $entry = $frm_entry->getOne($id, true);
137 + }
138 +
139 + if ( $entry ) {
140 + $form_id = $entry->form_id;
141 + $id = $entry->id;
142 + }
143 +
144 + if ( !$fields || !is_array($fields) ) {
145 + global $frm_field;
146 + $fields = $frm_field->getAll(array('fi.form_id' => $form_id), 'field_order');
147 + }
148 +
149 + $content = ( $format != 'text' ) ? array() : '';
150 + $odd = true;
151 +
152 + if ( !$plain_text ) {
153 + global $frmpro_settings;
154 +
155 + $default_settings = array(
156 + 'border_color' => 'dddddd',
157 + 'bg_color' => 'f7f7f7',
158 + 'text_color' => '444444',
159 + 'font_size' => '12px',
160 + 'border_width' => '1px',
161 + 'alt_bg_color' => 'ffffff',
162 + );
163 +
164 + // merge defaults, global settings, and shortcode options
165 + foreach ( $default_settings as $key => $setting ) {
166 + if ( $atts[$key] != '' ) {
167 + continue;
168 + }
169 +
170 + if ( $frmpro_settings ) {
171 + if ( 'alt_bg_color' == $key ) {
172 + $atts[$key] = $frmpro_settings->bg_color_active;
173 + } else if ( 'border_width' == $key ) {
174 + $atts[$key] = $frmpro_settings->field_border_width;
175 + } else {
176 + $atts[$key] = $frmpro_settings->{$key};
177 + }
178 + } else {
179 + $atts[$key] = $setting;
180 + }
181 + unset($key, $setting);
182 + }
183 +
184 + unset($default_settings);
185 +
186 + $content .= "<table cellspacing='0' style='font-size:{$atts['font_size']};line-height:135%; border-bottom:{$atts['border_width']} solid #{$atts['border_color']};'><tbody>\r\n";
187 + $bg_color = " style='background-color:#{$atts['bg_color']};'";
188 + $bg_color_alt = " style='background-color:#{$atts['alt_bg_color']};'";
189 + $row_style = "style='text-align:". ( $direction == 'rtl' ? 'right' : 'left' ) .";color:#{$atts['text_color']};padding:7px 9px;border-top:{$atts['border_width']} solid #{$atts['border_color']}'";
190 + }
191 +
192 + foreach ( $fields as $f ) {
193 + if ( in_array($f->type, array('divider', 'captcha', 'break', 'html')) )
194 + continue;
195 +
196 + if ( $entry && !isset($entry->metas[$f->id]) ) {
197 + if ( $entry->post_id && ( $f->type == 'tag' || (isset($f->field_options['post_field']) && $f->field_options['post_field'])) ) {
198 + $p_val = FrmProEntryMetaHelper::get_post_value($entry->post_id, $f->field_options['post_field'], $f->field_options['custom_field'], array(
199 + 'truncate' => (($f->field_options['post_field'] == 'post_category') ? true : false),
200 + 'form_id' => $entry->form_id, 'field' => $f, 'type' => $f->type,
201 + 'exclude_cat' => (isset($f->field_options['exclude_cat']) ? $f->field_options['exclude_cat'] : 0)
202 + ));
203 + if ( $p_val != '' ) {
204 + $entry->metas[$f->id] = $p_val;
205 + }
206 + }
207 +
208 + if ( !isset($entry->metas[$f->id]) && !$include_blank && !$default_email ) {
209 + continue;
210 + }
211 +
212 + $entry->metas[$f->id] = $default_email ? '['. $f->id .']' : '';
213 + }
214 +
215 + $val = '';
216 + if ( $entry ) {
217 + $prev_val = maybe_unserialize($entry->metas[$f->id]);
218 + $meta = array('item_id' => $id, 'field_id' => $f->id, 'meta_value' => $prev_val, 'field_type' => $f->type);
15 219
16 - $views_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) && FrmProAppHelper::views_is_installed();
220 + $val = $default_email ? $prev_val : apply_filters('frm_email_value', $prev_val, (object) $meta, $entry);
221 + } else if ( $default_email ) {
222 + $val = '['. $f->id .']';
223 + }
17 224
18 - if ( ! $views_installed ) {
19 - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Views', 'formidable' ), __( 'Views', 'formidable' ), 'frm_view_entries', 'formidable-views', 'FrmFormsController::no_views' );
20 - self::maybe_redirect_to_views_upsell();
21 - } else {
22 - self::maybe_redirect_to_views_index();
23 - }
24 -
25 - if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) {
26 - self::load_manage_entries_hooks();
27 - }
28 - }
29 -
30 - /**
31 - * This function is called when views is installed.
32 - * The Views add-on uses a different URL for the Views tab than the upsell page.
33 - * If the user is on the upsell page, instead of showing a permission error on reload,
34 - * redirect to the views index page.
35 - *
36 - * @since 6.14.1
37 - *
38 - * @return void
39 - */
40 - private static function maybe_redirect_to_views_index() {
41 - if ( ! FrmAppHelper::is_admin_page( 'formidable-views' ) ) {
42 - return;
43 - }
44 -
45 - $query_args = array(
46 - 'post_type' => 'frm_display',
47 - );
48 - $query_args = self::add_url_params_to_views_redirect_query_args( $query_args );
49 -
50 - wp_safe_redirect( add_query_arg( $query_args, admin_url( 'edit.php' ) ) );
51 - die();
52 - }
53 -
54 - /**
55 - * This function is called when views is inactive.
56 - * A user may deactivate views but then try to reload the views index.
57 - * Instead of showing a permission error, redirect to the views upsell page.
58 - *
59 - * @since 6.14.1
60 - *
61 - * @return void
62 - */
63 - private static function maybe_redirect_to_views_upsell() {
64 - global $pagenow;
65 -
66 - if ( 'edit.php' !== $pagenow || 'frm_display' !== FrmAppHelper::simple_get( 'post_type' ) ) {
67 - return;
68 - }
69 -
70 - $query_args = array(
71 - 'page' => 'formidable-views',
72 - );
73 - $query_args = self::add_url_params_to_views_redirect_query_args( $query_args );
74 -
75 - wp_safe_redirect( add_query_arg( $query_args, admin_url( 'admin.php' ) ) );
76 - die();
77 - }
78 -
79 - /**
80 - * @since 6.14.1
81 - *
82 - * @param array $query_args
83 - *
84 - * @return array
85 - */
86 - private static function add_url_params_to_views_redirect_query_args( $query_args ) {
87 - $query_args['show_nav'] = FrmAppHelper::simple_get( 'show_nav', 'absint', 0 );
88 -
89 - $form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 );
90 -
91 - if ( $form_id ) {
92 - $query_args['form'] = $form_id;
93 - }
94 -
95 - return $query_args;
96 - }
97 -
98 - /**
99 - * @since 2.05.07
100 - *
101 - * @return void
102 - */
103 - private static function load_manage_entries_hooks() {
104 - if ( ! in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show', 'new', 'duplicate' ), true ) ) {
105 - $menu_name = FrmAppHelper::get_menu_name();
106 - $base = self::base_column_key( $menu_name );
107 -
108 - add_filter( 'manage_' . $base . '_columns', 'FrmEntriesController::manage_columns' );
109 - add_filter( 'get_user_option_' . self::hidden_column_key( $menu_name ), 'FrmEntriesController::hidden_columns' );
110 - add_filter( 'manage_' . $base . '_sortable_columns', 'FrmEntriesController::sortable_columns' );
111 - } else {
112 - add_filter( 'screen_options_show_screen', self::class . '::remove_screen_options', 10, 2 );
113 - }
114 - }
115 -
116 - /**
117 - * Display in Back End.
118 - *
119 - * @return mixed
120 - */
121 - public static function route() {
122 - $action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' );
123 - FrmAppHelper::include_svg();
124 -
125 - switch ( $action ) {
126 - case 'show':
127 - case 'destroy':
128 - return self::$action();
129 -
130 - default:
131 - do_action( 'frm_entry_action_route', $action );
132 -
133 - if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) {
134 - return;
225 + if ( $f->type == 'textarea' and !$plain_text ) {
226 + $val = str_replace(array("\r\n", "\r", "\n"), ' <br/>', $val);
227 + }
228 +
229 + //Remove signature from default-message shortcode
230 + if ( $f->type == 'signature' && !$default_email ) {
231 + continue;
232 + }
233 +
234 + if ( is_array($val) && $format == 'text' ) {
235 + $val = implode(', ', $val);
236 + }
237 +
238 + $fname = $default_email ? '['. $f->id .' show=field_label]' : $f->name;
239 +
240 + if ( $format != 'text' ){
241 + $content[$f->field_key] = $val;
242 + } else if ( $plain_text ) {
243 + if ( 'rtl' == $direction ) {
244 + $content .= $val . ' :' . $fname . "\r\n\r\n";
245 + } else {
246 + $content .= $fname . ': ' . $val . "\r\n\r\n";
247 + }
248 + } else {
249 + if (!$default_email){
250 + $content .= '<tr'. ( $odd ? $bg_color : $bg_color_alt ) .'>';
251 + if ( 'rtl' == $direction ) {
252 + $content .= "<td $row_style>$val</td><th $row_style>" . $fname ."</th>";
253 + } else {
254 + $content .= "<th $row_style>" . $fname ."</th><td $row_style>$val</td>";
255 + }
256 + $content .= '</tr>'. "\r\n";
257 + $odd = ($odd) ? false : true;
258 + }else{
259 + $content .= '[if '. $f->id .']<tr style="[frm-alt-color]">';
260 + if ( 'rtl' == $direction ) {
261 + $content .= "<td $row_style>$val</td><th $row_style>" . $fname ."</th>";
262 + } else {
263 + $content .= "<th $row_style>" . $fname ."</th><td $row_style>$val</td>";
264 + }
265 + $content .= "</tr>\r\n[/if $f->id]";
135 266 }
267 +
268 + }
269 +
270 + unset($fname, $f);
271 + }
272 +
273 + if ( $user_info ) {
274 + if ( isset($entry->description) ) {
275 + $data = maybe_unserialize($entry->description);
276 + } else if ( $default_email ) {
277 + $entry->ip = '[ip]';
278 + $data = array(
279 + 'browser' => '[browser]',
280 + 'referrer' => '[referrer]',
281 + );
282 + }
283 + if ( $format != 'text' ) {
284 + $content['ip'] = $entry->ip;
285 + $content['browser'] = $data['browser'];
286 + $content['referrer'] = $data['referrer'];
287 + } else if ( $plain_text ) {
288 + $content .= "\r\n\r\n" . __('User Information', 'formidable') ."\r\n";
289 + if ( 'rtl' == $direction ) {
290 + $content .= $entry->ip . ' :'. __('IP Address', 'formidable') ."\r\n";
291 + $content .= $data['browser'] .' :'. __('User-Agent (Browser/OS)', 'formidable') ."\r\n";
292 + $content .= $data['referrer'] .' :'. __('Referrer', 'formidable') ."\r\n";
293 + } else {
294 + $content .= __('IP Address', 'formidable') . ': '. $entry->ip ."\r\n";
295 + $content .= __('User-Agent (Browser/OS)', 'formidable') . ': '. $data['browser']."\r\n";
296 + $content .= __('Referrer', 'formidable') . ': '. $data['referrer']."\r\n";
297 + }
298 + } else {
299 + $content .= '<tr'. ($odd ? $bg_color : $bg_color_alt) .'>';
300 + if ( 'rtl' == $direction ) {
301 + $content .= "<td $row_style>". $entry->ip ."</td><th $row_style>". __('IP Address', 'formidable') . "</th>";
302 + } else {
303 + $content .= "<th $row_style>". __('IP Address', 'formidable') . "</th><td $row_style>". $entry->ip ."</td>";
304 + }
305 + $content .= '</tr>'. "\r\n";
306 + $odd = ($odd) ? false : true;
307 +
308 + if ( isset($data['browser']) ) {
309 + $content .= '<tr'. ($odd ? $bg_color : $bg_color_alt) .'>';
310 + if ( 'rtl' == $direction ) {
311 + $content .= "<td $row_style>". $data['browser']."</td><th $row_style>". __('User-Agent (Browser/OS)', 'formidable') . "</th>";
312 + } else {
313 + $content .= "<th $row_style>". __('User-Agent (Browser/OS)', 'formidable') . "</th><td $row_style>". $data['browser']."</td>";
314 + }
315 + $content .= '</tr>'. "\r\n";
316 + }
317 + $odd = ($odd) ? false : true;
318 +
319 + if ( isset($data['referrer']) ) {
320 + $content .= '<tr'. ($odd ? $bg_color : $bg_color_alt) .'>';
321 + if ( 'rtl' == $direction ) {
322 + $content .= "<td $row_style>". str_replace("\r\n", '<br/>', $data['referrer']) ."</td><th $row_style>".__('Referrer', 'formidable') . "</th>";
323 + } else {
324 + $content .= "<th $row_style>".__('Referrer', 'formidable') . "</th><td $row_style>". str_replace("\r\n", '<br/>', $data['referrer']) ."</td>";
325 + }
326 + $content .= '</tr>'. "\r\n";
327 + }
328 + }
329 + }
136 330
137 - self::display_list();
138 - return;
139 - }
140 - }
331 + if ( ! $plain_text ) {
332 + $content .= '</tbody></table>';
333 + }
334 +
335 + if ( $format == 'json' ) {
336 + $content = json_encode($content);
337 + }
338 +
339 + return $content;
340 + }
341 +
342 + public static function &filter_email_value($value, $meta, $entry, $atts=array()){
343 + $frm_field = new FrmField();
344 + $field = $frm_field->getOne($meta->field_id);
345 + if(!$field)
346 + return $value;
347 +
348 + $value = self::filter_display_value($value, $field, $atts);
349 + return $value;
350 + }
351 +
352 + public static function &filter_display_value($value, $field, $atts=array()){
353 + $field->field_options = maybe_unserialize($field->field_options);
354 +
355 + $saved_value = (isset($atts['saved_value']) and $atts['saved_value']) ? true : false;
356 + if(!in_array($field->type, array('radio', 'checkbox', 'radio', 'select')) or !isset($field->field_options['separate_value']) or !$field->field_options['separate_value'] or $saved_value)
357 + return $value;
358 +
359 + $field->options = maybe_unserialize($field->options);
360 + $f_values = array();
361 + $f_labels = array();
362 + foreach($field->options as $opt_key => $opt){
363 + if(!is_array($opt))
364 + continue;
365 +
366 + $f_labels[$opt_key] = isset($opt['label']) ? $opt['label'] : reset($opt);
367 + $f_values[$opt_key] = isset($opt['value']) ? $opt['value'] : $f_labels[$opt_key];
368 + if($f_labels[$opt_key] == $f_values[$opt_key]){
369 + unset($f_values[$opt_key]);
370 + unset($f_labels[$opt_key]);
371 + }
372 + unset($opt_key);
373 + unset($opt);
374 + }
141 375
142 - /**
143 - * Prevent the "screen options" tab from showing when
144 - * editing or creating an entry
145 - *
146 - * @since 3.0
147 - *
148 - * @param bool $show_screen Whether to show the screen options tab.
149 - * @param object $screen The current screen object.
150 - *
151 - * @return bool
152 - */
153 - public static function remove_screen_options( $show_screen, $screen ) {
154 - $menu_name = sanitize_title( FrmAppHelper::get_menu_name() );
155 - $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count();
376 + if(!empty($f_values)){
377 + foreach((array)$value as $v_key => $val){
378 + if(in_array($val, $f_values)){
379 + $opt = array_search($val, $f_values);
380 + if(is_array($value))
381 + $value[$v_key] = $f_labels[$opt];
382 + else
383 + $value = $f_labels[$opt];
384 + }
385 + unset($v_key);
386 + unset($val);
387 + }
388 + }
389 +
390 + return $value;
391 + }
392 +
393 + public static function get_params($form=null){
394 + global $frm_vars;
395 +
396 + $frm_form = new FrmForm();
397 + if(!$form)
398 + $form = $frm_form->getAll(array(), 'name', 1);
399 + else if(!is_object($form))
400 + $form = $frm_form->getOne($form);
401 +
402 + if(isset($frm_vars['form_params']) && is_array($frm_vars['form_params']) && isset($frm_vars['form_params'][$form->id]))
403 + return $frm_vars['form_params'][$form->id];
404 +
405 + $action_var = isset($_REQUEST['frm_action']) ? 'frm_action' : 'action';
406 + $action = apply_filters('frm_show_new_entry_page', FrmAppHelper::get_param($action_var, 'new'), $form);
407 +
408 + $default_values = array(
409 + 'id' => '', 'form_name' => '', 'paged' => 1, 'form' => $form->id, 'form_id' => $form->id,
410 + 'field_id' => '', 'search' => '', 'sort' => '', 'sdir' => '', 'action' => $action
411 + );
412 +
413 + $values['posted_form_id'] = FrmAppHelper::get_param('form_id');
414 + if (!is_numeric($values['posted_form_id']))
415 + $values['posted_form_id'] = FrmAppHelper::get_param('form');
156 416
157 - if ( $screen->id === $menu_name . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-entries' ) {
158 - $show_screen = false;
159 - }
417 + if ($form->id == $values['posted_form_id']){ //if there are two forms on the same page, make sure not to submit both
418 + foreach ($default_values as $var => $default){
419 + if($var == 'action')
420 + $values[$var] = FrmAppHelper::get_param($action_var, $default);
421 + else
422 + $values[$var] = FrmAppHelper::get_param($var, $default);
423 + unset($var);
424 + unset($default);
425 + }
426 + }else{
427 + foreach ($default_values as $var => $default){
428 + $values[$var] = $default;
429 + unset($var);
430 + unset($default);
431 + }
432 + }
160 433
161 - return $show_screen;
162 - }
434 + if(in_array($values['action'], array('create', 'update')) and (!isset($_POST) or (!isset($_POST['action']) and !isset($_POST['frm_action']))))
435 + $values['action'] = 'new';
163 436
164 - /**
165 - * @param array $columns
166 - *
167 - * @return array
168 - */
169 - public static function manage_columns( $columns ) {
170 - global $frm_vars;
171 - $form_id = FrmForm::get_current_form_id();
172 -
173 - $columns[ $form_id . '_id' ] = 'ID';
174 - $columns[ $form_id . '_item_key' ] = esc_html__( 'Entry Key', 'formidable' );
175 -
176 - if ( $form_id ) {
177 - self::get_columns_for_form( $form_id, $columns );
178 - } else {
179 - $columns[ $form_id . '_form_id' ] = esc_html__( 'Form', 'formidable' );
180 - $columns[ $form_id . '_name' ] = esc_html__( 'Entry Name', 'formidable' );
181 - $columns[ $form_id . '_user_id' ] = esc_html__( 'Created By', 'formidable' );
182 - }
183 -
184 - $columns[ $form_id . '_is_draft' ] = esc_html__( 'Entry Status', 'formidable' );
185 - $columns[ $form_id . '_created_at' ] = __( 'Entry creation date', 'formidable' );
186 - $columns[ $form_id . '_updated_at' ] = __( 'Entry update date', 'formidable' );
187 - self::maybe_add_ip_col( $form_id, $columns );
188 -
189 - $frm_vars['cols'] = $columns;
190 -
191 - $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
192 -
193 - if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ) ) ) {
194 - add_screen_option(
195 - 'per_page',
196 - array(
197 - 'label' => esc_html__( 'Entries', 'formidable' ),
198 - 'default' => 20,
199 - 'option' => 'formidable_page_formidable_entries_per_page',
200 - )
201 - );
202 - }
203 -
204 - return $columns;
205 - }
206 -
207 - /**
208 - * @param int|string $form_id
209 - * @param array $columns
210 - *
211 - * @return void
212 - */
213 - private static function get_columns_for_form( $form_id, &$columns ) {
214 - $form_cols = FrmField::get_all_for_form( $form_id, '', 'include' );
215 -
216 - /**
217 - * Allows changing fields in the Entries list table heading.
218 - *
219 - * @since 5.0.04
220 - *
221 - * @param array $fields Array of fields.
222 - * @param array $args The arguments. Contains `form_id`.
223 - */
224 - $form_cols = apply_filters( 'frm_fields_in_entries_list_table', $form_cols, compact( 'form_id' ) );
225 -
226 - foreach ( $form_cols as $form_col ) {
227 - if ( FrmField::is_no_save_field( $form_col->type ) ) {
228 - continue;
229 - }
230 -
231 - $has_child_fields = $form_col->type === 'form' && ! empty( $form_col->field_options['form_select'] );
232 -
233 - if ( $has_child_fields ) {
234 - self::add_subform_cols( $form_col, $form_id, $columns );
235 - } else {
236 - self::add_field_cols( $form_col, $form_id, $columns );
237 - }
238 - }
239 - }
240 -
241 - /**
242 - * @since 3.01
243 - *
244 - * @param object $field The field object.
245 - * @param int|string $form_id The form ID.
246 - * @param array $columns The columns array.
247 - *
248 - * @return void
249 - */
250 - private static function add_subform_cols( $field, $form_id, &$columns ) {
251 - $sub_form_cols = FrmField::get_all_for_form( $field->field_options['form_select'] );
252 -
253 - if ( empty( $sub_form_cols ) ) {
254 - return;
255 - }
256 -
257 - foreach ( $sub_form_cols as $k => $sub_form_col ) {
258 - if ( FrmField::is_no_save_field( $sub_form_col->type ) ) {
259 - unset( $sub_form_cols[ $k ] );
260 - continue;
261 - }
262 - $columns[ $form_id . '_' . $sub_form_col->field_key . '-_-' . $field->id ] = FrmAppHelper::truncate( $sub_form_col->name, 35 );
263 - unset( $sub_form_col );
264 - }
265 - }
266 -
267 - /**
268 - * @since 3.01
269 - *
270 - * @param object $field The field object.
271 - * @param int|string $form_id The form ID.
272 - * @param array $columns The columns array.
273 - *
274 - * @return void
275 - */
276 - private static function add_field_cols( $field, $form_id, &$columns ) {
277 - $col_id = $field->field_key;
278 -
279 - if ( $field->form_id != $form_id ) {
280 - $col_id .= '-_-form' . $field->form_id;
281 - }
282 -
283 - $has_separate_value = ! FrmField::is_option_empty( $field, 'separate_value' );
284 - $is_post_status = FrmField::is_option_true( $field, 'post_field' ) && $field->field_options['post_field'] === 'post_status';
285 - $include_column_for_sep_val = $has_separate_value && ! $is_post_status;
286 -
287 - if ( $include_column_for_sep_val ) {
288 - $columns[ $form_id . '_frmsep_' . $col_id ] = self::maybe_format_field_name_for_column_title( $field, $include_column_for_sep_val );
289 - }
290 -
291 - $columns[ $form_id . '_' . $col_id ] = self::maybe_format_field_name_for_column_title( $field, $include_column_for_sep_val, false );
292 - }
293 -
294 - /**
295 - * Appends "(Value)" or "(Label)" to the field name if it's an option field that has a separate value/label.
296 - *
297 - * @since 6.25.1
298 - *
299 - * @param object $field
300 - * @param bool $include_column_for_sep_val
301 - * @param bool $is_value
302 - *
303 - * @return string
304 - */
305 - private static function maybe_format_field_name_for_column_title( $field, $include_column_for_sep_val, $is_value = true ) {
306 - $field_name = FrmAppHelper::truncate( $field->name, 35 );
307 -
308 - if ( ! $include_column_for_sep_val || ! in_array( $field->type, array( 'select', 'radio', 'checkbox' ), true ) ) {
309 - return $field_name;
310 - }
311 -
312 - $append_text = $is_value ? esc_html__( 'value', 'formidable' ) : esc_html__( 'label', 'formidable' );
313 -
314 - return sprintf( '%s (%s)', $field_name, $append_text );
315 - }
316 -
317 - /**
318 - * @param int|string $form_id The form ID.
319 - * @param array $columns The columns array.
320 - *
321 - * @return void
322 - */
323 - private static function maybe_add_ip_col( $form_id, &$columns ) {
324 - if ( FrmAppHelper::ips_saved() ) {
325 - $columns[ $form_id . '_ip' ] = 'IP';
326 - }
327 - }
328 -
329 - /**
330 - * @param bool $check The check value.
331 - * @param int $object_id The object ID.
332 - * @param string $meta_key The meta key.
333 - * @param mixed $meta_value The meta value.
334 - * @param mixed $prev_value The previous value.
335 - *
336 - * @return bool
337 - */
338 - public static function check_hidden_cols( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
339 - $this_page_name = self::hidden_column_key();
340 -
341 - if ( $meta_key != $this_page_name || $meta_value == $prev_value ) {
342 - return $check;
343 - }
344 -
345 - if ( empty( $prev_value ) ) {
346 - $prev_value = get_metadata( 'user', $object_id, $meta_key, true );
347 - }
348 -
349 - global $frm_vars;
350 - // Add a check so we don't create a loop.
351 - $frm_vars['prev_hidden_cols'] = ! empty( $frm_vars['prev_hidden_cols'] ) ? false : $prev_value;
352 -
353 - return $check;
354 - }
355 -
356 - /**
357 - * Add hidden columns back from other forms
358 - *
359 - * @param int $meta_id The meta ID.
360 - * @param int $object_id The object ID.
361 - * @param string $meta_key The meta key.
362 - * @param array $meta_value The meta value.
363 - *
364 - * @return void
365 - */
366 - public static function update_hidden_cols( $meta_id, $object_id, $meta_key, $meta_value ) {
367 - $this_page_name = self::hidden_column_key();
368 -
369 - if ( $meta_key != $this_page_name ) {
370 - return;
371 - }
372 -
373 - global $frm_vars;
374 -
375 - if ( ! isset( $frm_vars['prev_hidden_cols'] ) || ! $frm_vars['prev_hidden_cols'] ) {
376 - // Don't continue if there's no previous value.
377 - return;
378 - }
379 -
380 - foreach ( $meta_value as $mk => $mv ) {
381 - // Remove blank values.
382 - if ( empty( $mv ) ) {
383 - unset( $meta_value[ $mk ] );
384 - }
385 - }
386 -
387 - $cur_form_prefix = reset( $meta_value );
388 - $cur_form_prefix = explode( '_', $cur_form_prefix );
389 - $cur_form_prefix = $cur_form_prefix[0];
390 - $save = false;
391 -
392 - foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) {
393 - if ( empty( $prev_hidden ) || in_array( $prev_hidden, $meta_value ) ) {
394 - // Don't add blank cols or process included cols.
395 - continue;
396 - }
397 -
398 - $form_prefix = explode( '_', $prev_hidden );
399 - $form_prefix = $form_prefix[0];
400 -
401 - if ( $form_prefix === $cur_form_prefix ) {
402 - // Don't add back columns that are meant to be hidden.
403 - continue;
404 - }
405 -
406 - $meta_value[] = $prev_hidden;
407 - $save = true;
408 - unset( $form_prefix );
409 - }
410 -
411 - if ( $save ) {
412 - $user_id = get_current_user_id();
413 - update_user_option( $user_id, $this_page_name, $meta_value, true );
414 - }
415 - }
416 -
417 - /**
418 - * @since 2.05.07
419 - *
420 - * @param string $menu_name
421 - *
422 - * @return string
423 - */
424 - private static function hidden_column_key( $menu_name = '' ) {
425 - $base = self::base_column_key( $menu_name );
426 -
427 - return 'manage' . $base . 'columnshidden';
428 - }
429 -
430 - /**
431 - * @since 2.05.07
432 - *
433 - * @param string $menu_name
434 - *
435 - * @return string
436 - */
437 - private static function base_column_key( $menu_name = '' ) {
438 - if ( empty( $menu_name ) ) {
439 - $menu_name = FrmAppHelper::get_menu_name();
440 - }
441 -
442 - $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count();
443 -
444 - return sanitize_title( $menu_name ) . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-entries';
445 - }
446 -
447 - /**
448 - * @param int $save
449 - * @param string $option
450 - * @param string $value
451 - *
452 - * @return int
453 - */
454 - public static function save_per_page( $save, $option, $value ) {
455 - if ( $option === 'formidable_page_formidable_entries_per_page' ) {
456 - $save = (int) $value;
457 - }
458 -
459 - return $save;
460 - }
461 -
462 - /**
463 - * @return array
464 - */
465 - public static function sortable_columns() {
466 - $form_id = FrmForm::get_current_form_id();
467 - $fields = FrmField::get_all_for_form( $form_id );
468 -
469 - $columns = array(
470 - $form_id . '_id' => 'id',
471 - $form_id . '_created_at' => 'created_at',
472 - $form_id . '_updated_at' => 'updated_at',
473 - $form_id . '_ip' => 'ip',
474 - $form_id . '_item_key' => 'item_key',
475 - $form_id . '_is_draft' => 'is_draft',
476 - );
477 -
478 - if ( ! $form_id ) {
479 - $columns[ $form_id . '_user_id' ] = 'user_id';
480 - $columns[ $form_id . '_name' ] = 'name';
481 - $columns[ $form_id . '_form_id' ] = 'form_id';
482 - }
483 -
484 - foreach ( $fields as $field ) {
485 - if ( self::field_supports_sorting( $field ) ) {
486 - $columns[ $form_id . '_' . $field->field_key ] = 'meta_' . $field->id;
487 - }
488 - }
489 -
490 - return $columns;
491 - }
492 -
493 - /**
494 - * Can't sort on checkboxes because they are sorted serialized.
495 - * Some post content can be sorted but not everything.
496 - *
497 - * @param stdClass $field
498 - *
499 - * @return bool
500 - */
501 - private static function field_supports_sorting( $field ) {
502 - $is_sortable = 'checkbox' !== $field->type && empty( $field->field_options['post_field'] );
503 - return apply_filters( 'frm_field_column_is_sortable', $is_sortable, $field );
504 - }
505 -
506 - /**
507 - * @param mixed $result Option value from database for hidden columns in entries table.
508 - *
509 - * @return array
510 - */
511 - public static function hidden_columns( $result ) {
512 - global $frm_vars;
513 -
514 - if ( ! is_array( $result ) ) {
515 - // Force an unexpected value to be an array.
516 - // Since $result is a filtered option and gets saved to the database, it's possible it could be a string.
517 - // Since this code expects an array it would break with a "Uncaught Error: [] operator not supported for strings" error.
518 - $result = array();
519 - }
520 -
521 - $form_id = FrmForm::get_current_form_id();
522 - $hidden = self::user_hidden_columns_for_form( $form_id, $result );
523 - $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0;
524 - $max_columns = 11;
525 -
526 - if ( ! empty( $hidden ) ) {
527 - $result = $hidden;
528 - $i = $i - count( $result );
529 - }
530 -
531 - if ( $i <= $max_columns ) {
532 - return $result;
533 - }
534 -
535 - self::remove_excess_cols( compact( 'i', 'max_columns', 'form_id' ), $result );
536 -
537 - return $result;
538 - }
539 -
540 - /**
541 - * @since 2.05.07
542 - *
543 - * @param int|string $form_id
544 - * @param mixed $result
545 - *
546 - * @return array
547 - */
548 - private static function user_hidden_columns_for_form( $form_id, $result ) {
549 - $hidden = array();
550 -
551 - foreach ( (array) $result as $r ) {
552 - if ( ! empty( $r ) ) {
553 - list( $form_prefix, $field_key ) = explode( '_', $r );
554 -
555 - if ( (int) $form_prefix === (int) $form_id ) {
556 - $hidden[] = $r;
557 - }
558 -
559 - unset( $form_prefix );
560 - }
561 - }
562 -
563 - return $hidden;
564 - }
565 -
566 - /**
567 - * Remove some columns by default when there are too many
568 - *
569 - * @since 2.05.07
570 - *
571 - * @param array $atts
572 - * @param array $result
573 - *
574 - * @return void
575 - */
576 - private static function remove_excess_cols( $atts, &$result ) {
577 - global $frm_vars;
578 -
579 - $remove_first = array(
580 - $atts['form_id'] . '_item_key' => '',
581 - $atts['form_id'] . '_id' => '',
582 - );
583 - $cols = $remove_first + array_reverse( $frm_vars['cols'], true );
584 -
585 - $i = $atts['i'];
586 -
587 - foreach ( $cols as $col_key => $col ) {
588 - if ( $i <= $atts['max_columns'] ) {
589 - break;
590 - }
591 -
592 - if ( empty( $result ) || ! in_array( $col_key, $result, true ) ) {
593 - $result[] = $col_key;
594 - --$i;
595 - }
596 -
597 - unset( $col_key, $col );
598 - }
599 - }
600 -
601 - /**
602 - * @param string $message
603 - * @param array $errors
604 - *
605 - * @return void
606 - */
607 - public static function display_list( $message = '', $errors = array() ) {
608 - global $wpdb, $frm_vars;
609 -
610 - $form = FrmForm::maybe_get_current_form();
611 - $params = FrmForm::get_admin_params( $form );
612 -
613 - if ( $form ) {
614 - $params['form'] = $form->id;
615 - $frm_vars['current_form'] = $form;
616 -
617 - self::get_delete_form_time( $form, $errors );
618 - }
619 -
620 - $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' );
621 -
622 - $wp_list_table = new $table_class( array( 'params' => $params ) );
623 -
624 - $pagenum = $wp_list_table->get_pagenum();
625 -
626 - $wp_list_table->prepare_items();
627 -
628 - $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
629 -
630 - if ( $pagenum > $total_pages && $total_pages > 0 ) {
631 - $url = add_query_arg( 'paged', $total_pages );
632 -
633 - if ( headers_sent() ) {
634 - FrmAppHelper::js_redirect( $url, true );
635 - } else {
636 - wp_redirect( esc_url_raw( $url ) );
637 - }
638 - die();
639 - }
640 -
641 - if ( empty( $message ) && isset( $_GET['import-message'] ) ) {
642 - $message = __( 'Your import is complete', 'formidable' );
643 - }
644 -
645 - require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php';
646 - }
647 -
648 - /**
649 - * @param object $form
650 - * @param array $errors
651 - *
652 - * @return void
653 - */
654 - private static function get_delete_form_time( $form, &$errors ) {
655 - if ( 'trash' === $form->status ) {
656 - $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
657 - $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( $form->options['trash_time'] ?? time() ) );
658 -
659 - /* translators: %1$s: Time string */
660 - $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 );
661 - }
662 - }
663 -
664 - /**
665 - * Back End CRUD.
666 - *
667 - * @param int $id
668 - *
669 - * @return void
670 - */
671 - public static function show( $id = 0 ) {
672 - FrmAppHelper::permission_check( 'frm_view_entries' );
673 -
674 - if ( ! $id ) {
675 - $id = FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
676 -
677 - if ( ! $id ) {
678 - $id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'absint' );
679 - }
680 - }
681 -
682 - $entry = FrmEntry::getOne( $id, true );
683 -
684 - if ( ! $entry ) {
685 - FrmAppController::show_error_modal(
686 - array(
687 - 'title' => __( 'You can\'t view the entry', 'formidable' ),
688 - 'body' => __( 'You are trying to view an entry that does not exist', 'formidable' ),
689 - 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
690 - )
691 - );
692 - return;
693 - }
694 -
695 - $data = $entry->description;
696 -
697 - if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) {
698 - $data = array( 'referrer' => $data );
699 - }
700 -
701 - $fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' );
702 - $form = FrmForm::getOne( $entry->form_id );
703 -
704 - include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php';
705 - }
706 -
707 - /**
708 - * Destroy an entry from the admin page.
709 - * This is triggered from the entries list from the "Delete" row action, and also from the "Delete Entry" trigger in the view/edit entry sidebar.
710 - *
711 - * @return void
712 - */
713 - public static function destroy() {
714 - $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_entries', '_wpnonce', -1 );
715 -
716 - if ( false !== $permission_error ) {
717 - $error_args = array(
718 - 'title' => __( 'Verification failed', 'formidable' ),
719 - 'body' => $permission_error,
720 - 'cancel_url' => admin_url( 'admin.php?page=formidable-entries' ),
721 - );
722 - FrmAppController::show_error_modal( $error_args );
723 - return;
724 - }
725 -
726 - $params = FrmForm::get_admin_params();
727 -
728 - if ( isset( $params['keep_post'] ) && $params['keep_post'] ) {
729 - self::unlink_post( $params['id'] );
730 - }
731 -
732 - $message = '';
733 -
734 - if ( FrmEntry::destroy( $params['id'] ) ) {
735 - $message = __( 'Entry was successfully deleted', 'formidable' );
736 - }
737 -
738 - self::display_list( $message );
739 - }
740 -
741 - /**
742 - * @param array|string $errors
743 - * @param bool $ajax
744 - *
745 - * @return void
746 - */
747 - public static function process_entry( $errors = '', $ajax = false ) {
748 - $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' );
749 -
750 - if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
751 - return;
752 - }
753 -
754 - global $frm_vars;
755 -
756 - $form = FrmForm::getOne( $form_id );
757 -
758 - if ( ! $form ) {
759 - return;
760 - }
761 -
762 - $is_preview = 'frm_forms_preview' === FrmAppHelper::simple_get( 'action' );
763 -
764 - if ( $is_preview && FrmFormsHelper::should_block_preview( $form->form_key ) ) {
765 - return;
766 - }
767 -
768 - $params = FrmForm::get_params( $form );
769 -
770 - if ( ! isset( $frm_vars['form_params'] ) ) {
771 - $frm_vars['form_params'] = array();
772 - }
773 - $frm_vars['form_params'][ $form->id ] = $params;
774 -
775 - if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) {
776 - return;
777 - }
778 -
779 - if ( $errors == '' && ! $ajax ) {
780 - $errors = FrmEntryValidate::validate( wp_unslash( $_POST ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
781 - }
782 -
783 - /**
784 - * Use this filter to add trigger actions and add errors after
785 - * all other errors have been processed
786 - *
787 - * @since 2.0.6
788 - */
789 - $errors = apply_filters( 'frm_entries_before_create', $errors, $form );
790 -
791 - $frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors );
792 -
793 - if ( empty( $errors ) ) {
794 - $_POST['frm_skip_cookie'] = 1;
795 - $do_success = false;
796 -
797 - if ( $params['action'] === 'create' ) {
798 - if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) {
799 - $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
800 -
801 - $params['id'] = $frm_vars['created_entries'][ $form_id ]['entry_id'];
802 - $do_success = true;
803 - }
804 - }
805 -
806 - do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) );
807 -
808 - if ( $do_success ) {
809 - FrmFormsController::maybe_trigger_redirect( $form, $params, array( 'ajax' => $ajax ) );
810 - }
811 - unset( $_POST['frm_skip_cookie'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
812 - }
813 - }
814 -
815 - /**
816 - * Escape url entities before redirect
817 - *
818 - * @since 3.0
819 - *
820 - * @param string $url
821 - *
822 - * @return string
823 - */
824 - public static function prepare_redirect_url( $url ) {
825 - return str_replace( array( ' ', '[', ']', '|', '@' ), array( '%20', '%5B', '%5D', '%7C', '%40' ), $url );
826 - }
827 -
828 - /**
829 - * Delete entry if redirected.
830 - *
831 - * @param string $url
832 - * @param object $form
833 - * @param array $atts
834 - *
835 - * @return string
836 - */
837 - public static function delete_entry_before_redirect( $url, $form, $atts ) {
838 - self::_delete_entry( $atts['id'], $form );
839 -
840 - return $url;
841 - }
842 -
843 - /**
844 - * Delete entry if not redirected.
845 - *
846 - * @param array $atts
847 - *
848 - * @return void
849 - */
850 - public static function delete_entry_after_save( $atts ) {
851 - self::_delete_entry( $atts['entry_id'], $atts['form'] );
852 - }
853 -
854 - /**
855 - * Delete entry if not redirected.
856 - *
857 - * @param int $entry_id
858 - * @param object $form
859 - *
860 - * @return void
861 - */
862 - private static function _delete_entry( $entry_id, $form ) {
863 - if ( ! $form ) {
864 - return;
865 - }
866 -
867 - FrmAppHelper::unserialize_or_decode( $form->options );
868 -
869 - if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) {
870 - self::unlink_post( $entry_id );
871 - FrmEntry::destroy( $entry_id );
872 - }
873 - }
874 -
875 - /**
876 - * Unlink entry from post
877 - *
878 - * @param int $entry_id
879 - *
880 - * @return void
881 - */
882 - private static function unlink_post( $entry_id ) {
883 - global $wpdb;
884 - $wpdb->update( $wpdb->prefix . 'frm_items', array( 'post_id' => '' ), array( 'id' => $entry_id ) );
885 - FrmEntry::clear_cache();
886 - }
887 -
888 - /**
889 - * @param array $atts
890 - *
891 - * @return array|string
892 - */
893 - public static function show_entry_shortcode( $atts ) {
894 - $defaults = array(
895 - 'id' => false,
896 - 'entry' => false,
897 - 'fields' => false,
898 - 'plain_text' => false,
899 - 'user_info' => false,
900 - 'include_blank' => false,
901 - 'default_email' => false,
902 - 'form_id' => false,
903 - 'format' => 'text',
904 - 'array_key' => 'key',
905 - 'direction' => 'ltr',
906 - 'font_size' => '',
907 - 'text_color' => '',
908 - 'border_width' => '',
909 - 'border_color' => '',
910 - 'bg_color' => '',
911 - 'alt_bg_color' => '',
912 - 'class' => '',
913 - 'clickable' => false,
914 - 'exclude_fields' => '',
915 - 'include_fields' => '',
916 - 'include_extras' => '',
917 - 'inline_style' => 1,
918 - 'table_style' => '',
919 - // Return embedded fields as nested array.
920 - 'child_array' => false,
921 - 'line_breaks' => true,
922 - 'array_separator' => ', ',
923 - );
924 - $defaults = apply_filters( 'frm_show_entry_defaults', $defaults );
925 -
926 - $atts = shortcode_atts( $defaults, $atts );
927 -
928 - if ( $atts['default_email'] ) {
929 - $shortcode_atts = array(
930 - 'format' => $atts['format'],
931 - 'plain_text' => $atts['plain_text'],
932 - );
933 -
934 - $entry_formatter = FrmEntryFactory::entry_shortcode_formatter_instance( $atts['form_id'], $shortcode_atts );
935 - $formatted_entry = $entry_formatter->content();
936 -
937 - } else {
938 -
939 - $entry_formatter = FrmEntryFactory::entry_formatter_instance( $atts );
940 - $formatted_entry = $entry_formatter->get_formatted_entry_values();
941 -
942 - }
943 -
944 - return $formatted_entry;
945 - }
946 -
947 - /**
948 - * @param false|object $entry
949 - *
950 - * @return void
951 - */
952 - public static function entry_sidebar( $entry = false ) {
953 - $data = array();
954 - $id = 0;
955 -
956 - $date_format = get_option( 'date_format' );
957 - $time_format = get_option( 'time_format' );
958 -
959 - if ( $entry ) {
960 - $id = $entry->id;
961 - $data = $entry->description;
962 -
963 - if ( isset( $data['browser'] ) ) {
964 - $browser = FrmEntriesHelper::get_browser( $data['browser'] );
965 - }
966 - /**
967 - * Add or remove information in the entry sidebar.
968 - *
969 - * @since 5.5.2
970 - *
971 - * @param array $data
972 - * @param array{entry:\stdClass} $entry
973 - */
974 - $data = apply_filters( 'frm_sidebar_data', $data, compact( 'entry' ) );
975 - }
976 -
977 - include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php';
978 - }
437 + return $values;
438 + }
439 +
979 440 }