| @@ -4,11 +4,8 @@ | ||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmEntriesController { |
| 7 | 7 | |
| 8 | - /** | |
| 9 | - * @return void | |
| 10 | - */ | |
| 11 | 8 | public static function menu() { |
| 12 | 9 | FrmAppHelper::force_capability( 'frm_view_entries' ); |
| 13 | 10 | |
| 14 | 11 | add_submenu_page( 'formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' ); |
| @@ -13,9 +10,8 @@ | ||
| 13 | 10 | |
| 14 | 11 | add_submenu_page( 'formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' ); |
| 15 | 12 | |
| 16 | 13 | $views_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) && FrmProAppHelper::views_is_installed(); |
| 17 | - | |
| 18 | 14 | if ( ! $views_installed ) { |
| 19 | 15 | add_submenu_page( 'formidable', 'Formidable | ' . __( 'Views', 'formidable' ), __( 'Views', 'formidable' ), 'frm_view_entries', 'formidable-views', 'FrmFormsController::no_views' ); |
| 20 | 16 | self::maybe_redirect_to_views_upsell(); |
| 21 | 17 | } else { |
| @@ -61,9 +57,8 @@ | ||
| 61 | 57 | * @return void |
| 62 | 58 | */ |
| 63 | 59 | private static function maybe_redirect_to_views_upsell() { |
| 64 | 60 | global $pagenow; |
| 65 | - | |
| 66 | 61 | if ( 'edit.php' !== $pagenow || 'frm_display' !== FrmAppHelper::simple_get( 'post_type' ) ) { |
| 67 | 62 | return; |
| 68 | 63 | } |
| 69 | 64 | |
| @@ -79,9 +74,8 @@ | ||
| 79 | 74 | /** |
| 80 | 75 | * @since 6.14.1 |
| 81 | 76 | * |
| 82 | 77 | * @param array $query_args |
| 83 | - * | |
| 84 | 78 | * @return array |
| 85 | 79 | */ |
| 86 | 80 | private static function add_url_params_to_views_redirect_query_args( $query_args ) { |
| 87 | 81 | $query_args['show_nav'] = FrmAppHelper::simple_get( 'show_nav', 'absint', 0 ); |
| @@ -86,9 +80,8 @@ | ||
| 86 | 80 | private static function add_url_params_to_views_redirect_query_args( $query_args ) { |
| 87 | 81 | $query_args['show_nav'] = FrmAppHelper::simple_get( 'show_nav', 'absint', 0 ); |
| 88 | 82 | |
| 89 | 83 | $form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 ); |
| 90 | - | |
| 91 | 84 | if ( $form_id ) { |
| 92 | 85 | $query_args['form'] = $form_id; |
| 93 | 86 | } |
| 94 | 87 | |
| @@ -96,10 +89,8 @@ | ||
| 96 | 89 | } |
| 97 | 90 | |
| 98 | 91 | /** |
| 99 | 92 | * @since 2.05.07 |
| 100 | - * | |
| 101 | - * @return void | |
| 102 | 93 | */ |
| 103 | 94 | private static function load_manage_entries_hooks() { |
| 104 | 95 | if ( ! in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show', 'new', 'duplicate' ), true ) ) { |
| 105 | 96 | $menu_name = FrmAppHelper::get_menu_name(); |
| @@ -108,16 +99,14 @@ | ||
| 108 | 99 | add_filter( 'manage_' . $base . '_columns', 'FrmEntriesController::manage_columns' ); |
| 109 | 100 | add_filter( 'get_user_option_' . self::hidden_column_key( $menu_name ), 'FrmEntriesController::hidden_columns' ); |
| 110 | 101 | add_filter( 'manage_' . $base . '_sortable_columns', 'FrmEntriesController::sortable_columns' ); |
| 111 | 102 | } else { |
| 112 | - add_filter( 'screen_options_show_screen', self::class . '::remove_screen_options', 10, 2 ); | |
| 103 | + add_filter( 'screen_options_show_screen', __CLASS__ . '::remove_screen_options', 10, 2 ); | |
| 113 | 104 | } |
| 114 | 105 | } |
| 115 | 106 | |
| 116 | 107 | /** |
| 117 | 108 | * Display in Back End. |
| 118 | - * | |
| 119 | - * @return mixed | |
| 120 | 109 | */ |
| 121 | 110 | public static function route() { |
| 122 | 111 | $action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' ); |
| 123 | 112 | FrmAppHelper::include_svg(); |
| @@ -128,15 +117,13 @@ | ||
| 128 | 117 | return self::$action(); |
| 129 | 118 | |
| 130 | 119 | default: |
| 131 | 120 | do_action( 'frm_entry_action_route', $action ); |
| 132 | - | |
| 133 | 121 | if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) { |
| 134 | 122 | return; |
| 135 | 123 | } |
| 136 | 124 | |
| 137 | - self::display_list(); | |
| 138 | - return; | |
| 125 | + return self::display_list(); | |
| 139 | 126 | } |
| 140 | 127 | } |
| 141 | 128 | |
| 142 | 129 | /** |
| @@ -143,19 +130,12 @@ | ||
| 143 | 130 | * Prevent the "screen options" tab from showing when |
| 144 | 131 | * editing or creating an entry |
| 145 | 132 | * |
| 146 | 133 | * @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 | 134 | */ |
| 153 | 135 | 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(); | |
| 156 | - | |
| 157 | - if ( $screen->id === $menu_name . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-entries' ) { | |
| 136 | + $menu_name = sanitize_title( FrmAppHelper::get_menu_name() ); | |
| 137 | + if ( $screen->id == $menu_name . '_page_formidable-entries' ) { | |
| 158 | 138 | $show_screen = false; |
| 159 | 139 | } |
| 160 | 140 | |
| 161 | 141 | return $show_screen; |
| @@ -160,13 +140,8 @@ | ||
| 160 | 140 | |
| 161 | 141 | return $show_screen; |
| 162 | 142 | } |
| 163 | 143 | |
| 164 | - /** | |
| 165 | - * @param array $columns | |
| 166 | - * | |
| 167 | - * @return array | |
| 168 | - */ | |
| 169 | 144 | public static function manage_columns( $columns ) { |
| 170 | 145 | global $frm_vars; |
| 171 | 146 | $form_id = FrmForm::get_current_form_id(); |
| 172 | 147 | |
| @@ -188,9 +163,8 @@ | ||
| 188 | 163 | |
| 189 | 164 | $frm_vars['cols'] = $columns; |
| 190 | 165 | |
| 191 | 166 | $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); |
| 192 | - | |
| 193 | 167 | if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ) ) ) { |
| 194 | 168 | add_screen_option( |
| 195 | 169 | 'per_page', |
| 196 | 170 | array( |
| @@ -203,14 +177,8 @@ | ||
| 203 | 177 | |
| 204 | 178 | return $columns; |
| 205 | 179 | } |
| 206 | 180 | |
| 207 | - /** | |
| 208 | - * @param int|string $form_id | |
| 209 | - * @param array $columns | |
| 210 | - * | |
| 211 | - * @return void | |
| 212 | - */ | |
| 213 | 181 | private static function get_columns_for_form( $form_id, &$columns ) { |
| 214 | 182 | $form_cols = FrmField::get_all_for_form( $form_id, '', 'include' ); |
| 215 | 183 | |
| 216 | 184 | /** |
| @@ -228,9 +196,8 @@ | ||
| 228 | 196 | continue; |
| 229 | 197 | } |
| 230 | 198 | |
| 231 | 199 | $has_child_fields = $form_col->type === 'form' && ! empty( $form_col->field_options['form_select'] ); |
| 232 | - | |
| 233 | 200 | if ( $has_child_fields ) { |
| 234 | 201 | self::add_subform_cols( $form_col, $form_id, $columns ); |
| 235 | 202 | } else { |
| 236 | 203 | self::add_field_cols( $form_col, $form_id, $columns ); |
| @@ -239,18 +206,11 @@ | ||
| 239 | 206 | } |
| 240 | 207 | |
| 241 | 208 | /** |
| 242 | 209 | * @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 | 210 | */ |
| 250 | 211 | private static function add_subform_cols( $field, $form_id, &$columns ) { |
| 251 | 212 | $sub_form_cols = FrmField::get_all_for_form( $field->field_options['form_select'] ); |
| 252 | - | |
| 253 | 213 | if ( empty( $sub_form_cols ) ) { |
| 254 | 214 | return; |
| 255 | 215 | } |
| 256 | 216 | |
| @@ -265,62 +225,24 @@ | ||
| 265 | 225 | } |
| 266 | 226 | |
| 267 | 227 | /** |
| 268 | 228 | * @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 | 229 | */ |
| 276 | 230 | private static function add_field_cols( $field, $form_id, &$columns ) { |
| 277 | 231 | $col_id = $field->field_key; |
| 278 | - | |
| 279 | 232 | if ( $field->form_id != $form_id ) { |
| 280 | 233 | $col_id .= '-_-form' . $field->form_id; |
| 281 | 234 | } |
| 282 | 235 | |
| 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 ); | |
| 236 | + $has_separate_value = ! FrmField::is_option_empty( $field, 'separate_value' ); | |
| 237 | + $is_post_status = FrmField::is_option_true( $field, 'post_field' ) && $field->field_options['post_field'] === 'post_status'; | |
| 238 | + if ( $has_separate_value && ! $is_post_status ) { | |
| 239 | + $columns[ $form_id . '_frmsep_' . $col_id ] = FrmAppHelper::truncate( $field->name, 35 ); | |
| 289 | 240 | } |
| 290 | 241 | |
| 291 | - $columns[ $form_id . '_' . $col_id ] = self::maybe_format_field_name_for_column_title( $field, $include_column_for_sep_val, false ); | |
| 242 | + $columns[ $form_id . '_' . $col_id ] = FrmAppHelper::truncate( $field->name, 35 ); | |
| 292 | 243 | } |
| 293 | 244 | |
| 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 | 245 | private static function maybe_add_ip_col( $form_id, &$columns ) { |
| 324 | 246 | if ( FrmAppHelper::ips_saved() ) { |
| 325 | 247 | $columns[ $form_id . '_ip' ] = 'IP'; |
| 326 | 248 | } |
| @@ -325,20 +247,10 @@ | ||
| 325 | 247 | $columns[ $form_id . '_ip' ] = 'IP'; |
| 326 | 248 | } |
| 327 | 249 | } |
| 328 | 250 | |
| 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 | 251 | public static function check_hidden_cols( $check, $object_id, $meta_key, $meta_value, $prev_value ) { |
| 339 | 252 | $this_page_name = self::hidden_column_key(); |
| 340 | - | |
| 341 | 253 | if ( $meta_key != $this_page_name || $meta_value == $prev_value ) { |
| 342 | 254 | return $check; |
| 343 | 255 | } |
| 344 | 256 | |
| @@ -354,25 +266,16 @@ | ||
| 354 | 266 | } |
| 355 | 267 | |
| 356 | 268 | /** |
| 357 | 269 | * 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 | 270 | */ |
| 366 | 271 | public static function update_hidden_cols( $meta_id, $object_id, $meta_key, $meta_value ) { |
| 367 | 272 | $this_page_name = self::hidden_column_key(); |
| 368 | - | |
| 369 | 273 | if ( $meta_key != $this_page_name ) { |
| 370 | 274 | return; |
| 371 | 275 | } |
| 372 | 276 | |
| 373 | 277 | global $frm_vars; |
| 374 | - | |
| 375 | 278 | if ( ! isset( $frm_vars['prev_hidden_cols'] ) || ! $frm_vars['prev_hidden_cols'] ) { |
| 376 | 279 | // Don't continue if there's no previous value. |
| 377 | 280 | return; |
| 378 | 281 | } |
| @@ -396,10 +299,9 @@ | ||
| 396 | 299 | } |
| 397 | 300 | |
| 398 | 301 | $form_prefix = explode( '_', $prev_hidden ); |
| 399 | 302 | $form_prefix = $form_prefix[0]; |
| 400 | - | |
| 401 | - if ( $form_prefix === $cur_form_prefix ) { | |
| 303 | + if ( $form_prefix == $cur_form_prefix ) { | |
| 402 | 304 | // Don't add back columns that are meant to be hidden. |
| 403 | 305 | continue; |
| 404 | 306 | } |
| 405 | 307 | |
| @@ -415,12 +317,8 @@ | ||
| 415 | 317 | } |
| 416 | 318 | |
| 417 | 319 | /** |
| 418 | 320 | * @since 2.05.07 |
| 419 | - * | |
| 420 | - * @param string $menu_name | |
| 421 | - * | |
| 422 | - * @return string | |
| 423 | 321 | */ |
| 424 | 322 | private static function hidden_column_key( $menu_name = '' ) { |
| 425 | 323 | $base = self::base_column_key( $menu_name ); |
| 426 | 324 | |
| @@ -428,12 +326,8 @@ | ||
| 428 | 326 | } |
| 429 | 327 | |
| 430 | 328 | /** |
| 431 | 329 | * @since 2.05.07 |
| 432 | - * | |
| 433 | - * @param string $menu_name | |
| 434 | - * | |
| 435 | - * @return string | |
| 436 | 330 | */ |
| 437 | 331 | private static function base_column_key( $menu_name = '' ) { |
| 438 | 332 | if ( empty( $menu_name ) ) { |
| 439 | 333 | $menu_name = FrmAppHelper::get_menu_name(); |
| @@ -443,15 +337,8 @@ | ||
| 443 | 337 | |
| 444 | 338 | return sanitize_title( $menu_name ) . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-entries'; |
| 445 | 339 | } |
| 446 | 340 | |
| 447 | - /** | |
| 448 | - * @param int $save | |
| 449 | - * @param string $option | |
| 450 | - * @param string $value | |
| 451 | - * | |
| 452 | - * @return int | |
| 453 | - */ | |
| 454 | 341 | public static function save_per_page( $save, $option, $value ) { |
| 455 | 342 | if ( $option === 'formidable_page_formidable_entries_per_page' ) { |
| 456 | 343 | $save = (int) $value; |
| 457 | 344 | } |
| @@ -458,11 +345,8 @@ | ||
| 458 | 345 | |
| 459 | 346 | return $save; |
| 460 | 347 | } |
| 461 | 348 | |
| 462 | - /** | |
| 463 | - * @return array | |
| 464 | - */ | |
| 465 | 349 | public static function sortable_columns() { |
| 466 | 350 | $form_id = FrmForm::get_current_form_id(); |
| 467 | 351 | $fields = FrmField::get_all_for_form( $form_id ); |
| 468 | 352 | |
| @@ -494,9 +378,8 @@ | ||
| 494 | 378 | * Can't sort on checkboxes because they are sorted serialized. |
| 495 | 379 | * Some post content can be sorted but not everything. |
| 496 | 380 | * |
| 497 | 381 | * @param stdClass $field |
| 498 | - * | |
| 499 | 382 | * @return bool |
| 500 | 383 | */ |
| 501 | 384 | private static function field_supports_sorting( $field ) { |
| 502 | 385 | $is_sortable = 'checkbox' !== $field->type && empty( $field->field_options['post_field'] ); |
| @@ -504,14 +387,11 @@ | ||
| 504 | 387 | } |
| 505 | 388 | |
| 506 | 389 | /** |
| 507 | 390 | * @param mixed $result Option value from database for hidden columns in entries table. |
| 508 | - * | |
| 509 | 391 | * @return array |
| 510 | 392 | */ |
| 511 | 393 | public static function hidden_columns( $result ) { |
| 512 | - global $frm_vars; | |
| 513 | - | |
| 514 | 394 | if ( ! is_array( $result ) ) { |
| 515 | 395 | // Force an unexpected value to be an array. |
| 516 | 396 | // Since $result is a filtered option and gets saved to the database, it's possible it could be a string. |
| 517 | 397 | // Since this code expects an array it would break with a "Uncaught Error: [] operator not supported for strings" error. |
| @@ -517,16 +397,21 @@ | ||
| 517 | 397 | // Since this code expects an array it would break with a "Uncaught Error: [] operator not supported for strings" error. |
| 518 | 398 | $result = array(); |
| 519 | 399 | } |
| 520 | 400 | |
| 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; | |
| 401 | + $form_id = FrmForm::get_current_form_id(); | |
| 525 | 402 | |
| 403 | + $hidden = self::user_hidden_columns_for_form( $form_id, $result ); | |
| 404 | + | |
| 405 | + global $frm_vars; | |
| 406 | + $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0; | |
| 407 | + | |
| 526 | 408 | if ( ! empty( $hidden ) ) { |
| 527 | - $result = $hidden; | |
| 528 | - $i = $i - count( $result ); | |
| 409 | + $result = $hidden; | |
| 410 | + $i = $i - count( $result ); | |
| 411 | + $max_columns = 11; | |
| 412 | + } else { | |
| 413 | + $max_columns = 8; | |
| 529 | 414 | } |
| 530 | 415 | |
| 531 | 416 | if ( $i <= $max_columns ) { |
| 532 | 417 | return $result; |
| @@ -538,17 +423,11 @@ | ||
| 538 | 423 | } |
| 539 | 424 | |
| 540 | 425 | /** |
| 541 | 426 | * @since 2.05.07 |
| 542 | - * | |
| 543 | - * @param int|string $form_id | |
| 544 | - * @param mixed $result | |
| 545 | - * | |
| 546 | - * @return array | |
| 547 | 427 | */ |
| 548 | 428 | private static function user_hidden_columns_for_form( $form_id, $result ) { |
| 549 | 429 | $hidden = array(); |
| 550 | - | |
| 551 | 430 | foreach ( (array) $result as $r ) { |
| 552 | 431 | if ( ! empty( $r ) ) { |
| 553 | 432 | list( $form_prefix, $field_key ) = explode( '_', $r ); |
| 554 | 433 | |
| @@ -566,13 +445,8 @@ | ||
| 566 | 445 | /** |
| 567 | 446 | * Remove some columns by default when there are too many |
| 568 | 447 | * |
| 569 | 448 | * @since 2.05.07 |
| 570 | - * | |
| 571 | - * @param array $atts | |
| 572 | - * @param array $result | |
| 573 | - * | |
| 574 | - * @return void | |
| 575 | 449 | */ |
| 576 | 450 | private static function remove_excess_cols( $atts, &$result ) { |
| 577 | 451 | global $frm_vars; |
| 578 | 452 | |
| @@ -597,14 +471,8 @@ | ||
| 597 | 471 | unset( $col_key, $col ); |
| 598 | 472 | } |
| 599 | 473 | } |
| 600 | 474 | |
| 601 | - /** | |
| 602 | - * @param string $message | |
| 603 | - * @param array $errors | |
| 604 | - * | |
| 605 | - * @return void | |
| 606 | - */ | |
| 607 | 475 | public static function display_list( $message = '', $errors = array() ) { |
| 608 | 476 | global $wpdb, $frm_vars; |
| 609 | 477 | |
| 610 | 478 | $form = FrmForm::maybe_get_current_form(); |
| @@ -625,12 +493,10 @@ | ||
| 625 | 493 | |
| 626 | 494 | $wp_list_table->prepare_items(); |
| 627 | 495 | |
| 628 | 496 | $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); |
| 629 | - | |
| 630 | 497 | if ( $pagenum > $total_pages && $total_pages > 0 ) { |
| 631 | 498 | $url = add_query_arg( 'paged', $total_pages ); |
| 632 | - | |
| 633 | 499 | if ( headers_sent() ) { |
| 634 | 500 | FrmAppHelper::js_redirect( $url, true ); |
| 635 | 501 | } else { |
| 636 | 502 | wp_redirect( esc_url_raw( $url ) ); |
| @@ -644,18 +510,12 @@ | ||
| 644 | 510 | |
| 645 | 511 | require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php'; |
| 646 | 512 | } |
| 647 | 513 | |
| 648 | - /** | |
| 649 | - * @param object $form | |
| 650 | - * @param array $errors | |
| 651 | - * | |
| 652 | - * @return void | |
| 653 | - */ | |
| 654 | 514 | private static function get_delete_form_time( $form, &$errors ) { |
| 655 | 515 | if ( 'trash' === $form->status ) { |
| 656 | 516 | $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); |
| 657 | - $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( $form->options['trash_time'] ?? time() ) ); | |
| 517 | + $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? $form->options['trash_time'] : time() ) ); | |
| 658 | 518 | |
| 659 | 519 | /* translators: %1$s: Time string */ |
| 660 | 520 | $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 | 521 | } |
| @@ -662,12 +522,8 @@ | ||
| 662 | 522 | } |
| 663 | 523 | |
| 664 | 524 | /** |
| 665 | 525 | * Back End CRUD. |
| 666 | - * | |
| 667 | - * @param int $id | |
| 668 | - * | |
| 669 | - * @return void | |
| 670 | 526 | */ |
| 671 | 527 | public static function show( $id = 0 ) { |
| 672 | 528 | FrmAppHelper::permission_check( 'frm_view_entries' ); |
| 673 | 529 | |
| @@ -679,9 +535,8 @@ | ||
| 679 | 535 | } |
| 680 | 536 | } |
| 681 | 537 | |
| 682 | 538 | $entry = FrmEntry::getOne( $id, true ); |
| 683 | - | |
| 684 | 539 | if ( ! $entry ) { |
| 685 | 540 | FrmAppController::show_error_modal( |
| 686 | 541 | array( |
| 687 | 542 | 'title' => __( 'You can\'t view the entry', 'formidable' ), |
| @@ -692,9 +547,8 @@ | ||
| 692 | 547 | return; |
| 693 | 548 | } |
| 694 | 549 | |
| 695 | 550 | $data = $entry->description; |
| 696 | - | |
| 697 | 551 | if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) { |
| 698 | 552 | $data = array( 'referrer' => $data ); |
| 699 | 553 | } |
| 700 | 554 | |
| @@ -711,9 +565,8 @@ | ||
| 711 | 565 | * @return void |
| 712 | 566 | */ |
| 713 | 567 | public static function destroy() { |
| 714 | 568 | $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_entries', '_wpnonce', -1 ); |
| 715 | - | |
| 716 | 569 | if ( false !== $permission_error ) { |
| 717 | 570 | $error_args = array( |
| 718 | 571 | 'title' => __( 'Verification failed', 'formidable' ), |
| 719 | 572 | 'body' => $permission_error, |
| @@ -729,9 +582,8 @@ | ||
| 729 | 582 | self::unlink_post( $params['id'] ); |
| 730 | 583 | } |
| 731 | 584 | |
| 732 | 585 | $message = ''; |
| 733 | - | |
| 734 | 586 | if ( FrmEntry::destroy( $params['id'] ) ) { |
| 735 | 587 | $message = __( 'Entry was successfully deleted', 'formidable' ); |
| 736 | 588 | } |
| 737 | 589 | |
| @@ -737,17 +589,10 @@ | ||
| 737 | 589 | |
| 738 | 590 | self::display_list( $message ); |
| 739 | 591 | } |
| 740 | 592 | |
| 741 | - /** | |
| 742 | - * @param array|string $errors | |
| 743 | - * @param bool $ajax | |
| 744 | - * | |
| 745 | - * @return void | |
| 746 | - */ | |
| 747 | 593 | public static function process_entry( $errors = '', $ajax = false ) { |
| 748 | 594 | $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' ); |
| 749 | - | |
| 750 | 595 | if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 751 | 596 | return; |
| 752 | 597 | } |
| 753 | 598 | |
| @@ -753,19 +598,12 @@ | ||
| 753 | 598 | |
| 754 | 599 | global $frm_vars; |
| 755 | 600 | |
| 756 | 601 | $form = FrmForm::getOne( $form_id ); |
| 757 | - | |
| 758 | 602 | if ( ! $form ) { |
| 759 | 603 | return; |
| 760 | 604 | } |
| 761 | 605 | |
| 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 | 606 | $params = FrmForm::get_params( $form ); |
| 769 | 607 | |
| 770 | 608 | if ( ! isset( $frm_vars['form_params'] ) ) { |
| 771 | 609 | $frm_vars['form_params'] = array(); |
| @@ -792,9 +630,8 @@ | ||
| 792 | 630 | |
| 793 | 631 | if ( empty( $errors ) ) { |
| 794 | 632 | $_POST['frm_skip_cookie'] = 1; |
| 795 | 633 | $do_success = false; |
| 796 | - | |
| 797 | 634 | if ( $params['action'] === 'create' ) { |
| 798 | 635 | if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) { |
| 799 | 636 | $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 800 | 637 | |
| @@ -803,9 +640,8 @@ | ||
| 803 | 640 | } |
| 804 | 641 | } |
| 805 | 642 | |
| 806 | 643 | do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) ); |
| 807 | - | |
| 808 | 644 | if ( $do_success ) { |
| 809 | 645 | FrmFormsController::maybe_trigger_redirect( $form, $params, array( 'ajax' => $ajax ) ); |
| 810 | 646 | } |
| 811 | 647 | unset( $_POST['frm_skip_cookie'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| @@ -824,17 +660,8 @@ | ||
| 824 | 660 | public static function prepare_redirect_url( $url ) { |
| 825 | 661 | return str_replace( array( ' ', '[', ']', '|', '@' ), array( '%20', '%5B', '%5D', '%7C', '%40' ), $url ); |
| 826 | 662 | } |
| 827 | 663 | |
| 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 | 664 | public static function delete_entry_before_redirect( $url, $form, $atts ) { |
| 838 | 665 | self::_delete_entry( $atts['id'], $form ); |
| 839 | 666 | |
| 840 | 667 | return $url; |
| @@ -843,23 +670,13 @@ | ||
| 843 | 670 | /** |
| 844 | 671 | * Delete entry if not redirected. |
| 845 | 672 | * |
| 846 | 673 | * @param array $atts |
| 847 | - * | |
| 848 | - * @return void | |
| 849 | 674 | */ |
| 850 | 675 | public static function delete_entry_after_save( $atts ) { |
| 851 | 676 | self::_delete_entry( $atts['entry_id'], $atts['form'] ); |
| 852 | 677 | } |
| 853 | 678 | |
| 854 | - /** | |
| 855 | - * Delete entry if not redirected. | |
| 856 | - * | |
| 857 | - * @param int $entry_id | |
| 858 | - * @param object $form | |
| 859 | - * | |
| 860 | - * @return void | |
| 861 | - */ | |
| 862 | 679 | private static function _delete_entry( $entry_id, $form ) { |
| 863 | 680 | if ( ! $form ) { |
| 864 | 681 | return; |
| 865 | 682 | } |
| @@ -864,9 +681,8 @@ | ||
| 864 | 681 | return; |
| 865 | 682 | } |
| 866 | 683 | |
| 867 | 684 | FrmAppHelper::unserialize_or_decode( $form->options ); |
| 868 | - | |
| 869 | 685 | if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) { |
| 870 | 686 | self::unlink_post( $entry_id ); |
| 871 | 687 | FrmEntry::destroy( $entry_id ); |
| 872 | 688 | } |
| @@ -873,12 +689,8 @@ | ||
| 873 | 689 | } |
| 874 | 690 | |
| 875 | 691 | /** |
| 876 | 692 | * Unlink entry from post |
| 877 | - * | |
| 878 | - * @param int $entry_id | |
| 879 | - * | |
| 880 | - * @return void | |
| 881 | 693 | */ |
| 882 | 694 | private static function unlink_post( $entry_id ) { |
| 883 | 695 | global $wpdb; |
| 884 | 696 | $wpdb->update( $wpdb->prefix . 'frm_items', array( 'post_id' => '' ), array( 'id' => $entry_id ) ); |
| @@ -914,9 +726,8 @@ | ||
| 914 | 726 | 'exclude_fields' => '', |
| 915 | 727 | 'include_fields' => '', |
| 916 | 728 | 'include_extras' => '', |
| 917 | 729 | 'inline_style' => 1, |
| 918 | - 'table_style' => '', | |
| 919 | 730 | // Return embedded fields as nested array. |
| 920 | 731 | 'child_array' => false, |
| 921 | 732 | 'line_breaks' => true, |
| 922 | 733 | 'array_separator' => ', ', |
| @@ -943,13 +754,8 @@ | ||
| 943 | 754 | |
| 944 | 755 | return $formatted_entry; |
| 945 | 756 | } |
| 946 | 757 | |
| 947 | - /** | |
| 948 | - * @param false|object $entry | |
| 949 | - * | |
| 950 | - * @return void | |
| 951 | - */ | |
| 952 | 758 | public static function entry_sidebar( $entry = false ) { |
| 953 | 759 | $data = array(); |
| 954 | 760 | $id = 0; |
| 955 | 761 | |
| @@ -958,9 +764,8 @@ | ||
| 958 | 764 | |
| 959 | 765 | if ( $entry ) { |
| 960 | 766 | $id = $entry->id; |
| 961 | 767 | $data = $entry->description; |
| 962 | - | |
| 963 | 768 | if ( isset( $data['browser'] ) ) { |
| 964 | 769 | $browser = FrmEntriesHelper::get_browser( $data['browser'] ); |
| 965 | 770 | } |
| 966 | 771 | /** |