| @@ -4,23 +4,16 @@ | ||
| 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' ); |
| 15 | 12 | |
| 16 | - $views_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) && FrmProAppHelper::views_is_installed(); | |
| 17 | - | |
| 13 | + $views_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) ? FrmProAppHelper::views_is_installed() : FrmAppHelper::pro_is_installed(); | |
| 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 | - self::maybe_redirect_to_views_upsell(); | |
| 21 | - } else { | |
| 22 | - self::maybe_redirect_to_views_index(); | |
| 23 | 16 | } |
| 24 | 17 | |
| 25 | 18 | if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) { |
| 26 | 19 | self::load_manage_entries_hooks(); |
| @@ -27,82 +20,12 @@ | ||
| 27 | 20 | } |
| 28 | 21 | } |
| 29 | 22 | |
| 30 | 23 | /** |
| 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 | 24 | * @since 2.05.07 |
| 100 | - * | |
| 101 | - * @return void | |
| 102 | 25 | */ |
| 103 | 26 | private static function load_manage_entries_hooks() { |
| 104 | - if ( ! in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show', 'new', 'duplicate' ), true ) ) { | |
| 27 | + if ( ! in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show', 'new' ) ) ) { | |
| 105 | 28 | $menu_name = FrmAppHelper::get_menu_name(); |
| 106 | 29 | $base = self::base_column_key( $menu_name ); |
| 107 | 30 | |
| 108 | 31 | add_filter( 'manage_' . $base . '_columns', 'FrmEntriesController::manage_columns' ); |
| @@ -108,17 +31,13 @@ | ||
| 108 | 31 | add_filter( 'manage_' . $base . '_columns', 'FrmEntriesController::manage_columns' ); |
| 109 | 32 | add_filter( 'get_user_option_' . self::hidden_column_key( $menu_name ), 'FrmEntriesController::hidden_columns' ); |
| 110 | 33 | add_filter( 'manage_' . $base . '_sortable_columns', 'FrmEntriesController::sortable_columns' ); |
| 111 | 34 | } else { |
| 112 | - add_filter( 'screen_options_show_screen', self::class . '::remove_screen_options', 10, 2 ); | |
| 35 | + add_filter( 'screen_options_show_screen', __CLASS__ . '::remove_screen_options', 10, 2 ); | |
| 113 | 36 | } |
| 114 | 37 | } |
| 115 | 38 | |
| 116 | - /** | |
| 117 | - * Display in Back End. | |
| 118 | - * | |
| 119 | - * @return mixed | |
| 120 | - */ | |
| 39 | + /* Display in Back End */ | |
| 121 | 40 | public static function route() { |
| 122 | 41 | $action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' ); |
| 123 | 42 | FrmAppHelper::include_svg(); |
| 124 | 43 | |
| @@ -128,15 +47,13 @@ | ||
| 128 | 47 | return self::$action(); |
| 129 | 48 | |
| 130 | 49 | default: |
| 131 | 50 | do_action( 'frm_entry_action_route', $action ); |
| 132 | - | |
| 133 | 51 | if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) { |
| 134 | 52 | return; |
| 135 | 53 | } |
| 136 | 54 | |
| 137 | - self::display_list(); | |
| 138 | - return; | |
| 55 | + return self::display_list(); | |
| 139 | 56 | } |
| 140 | 57 | } |
| 141 | 58 | |
| 142 | 59 | /** |
| @@ -143,19 +60,12 @@ | ||
| 143 | 60 | * Prevent the "screen options" tab from showing when |
| 144 | 61 | * editing or creating an entry |
| 145 | 62 | * |
| 146 | 63 | * @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 | 64 | */ |
| 153 | 65 | 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' ) { | |
| 66 | + $menu_name = sanitize_title( FrmAppHelper::get_menu_name() ); | |
| 67 | + if ( $screen->id == $menu_name . '_page_formidable-entries' ) { | |
| 158 | 68 | $show_screen = false; |
| 159 | 69 | } |
| 160 | 70 | |
| 161 | 71 | return $show_screen; |
| @@ -160,13 +70,8 @@ | ||
| 160 | 70 | |
| 161 | 71 | return $show_screen; |
| 162 | 72 | } |
| 163 | 73 | |
| 164 | - /** | |
| 165 | - * @param array $columns | |
| 166 | - * | |
| 167 | - * @return array | |
| 168 | - */ | |
| 169 | 74 | public static function manage_columns( $columns ) { |
| 170 | 75 | global $frm_vars; |
| 171 | 76 | $form_id = FrmForm::get_current_form_id(); |
| 172 | 77 | |
| @@ -175,14 +80,13 @@ | ||
| 175 | 80 | |
| 176 | 81 | if ( $form_id ) { |
| 177 | 82 | self::get_columns_for_form( $form_id, $columns ); |
| 178 | 83 | } 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' ); | |
| 84 | + $columns[ $form_id . '_form_id' ] = __( 'Form', 'formidable' ); | |
| 85 | + $columns[ $form_id . '_name' ] = __( 'Entry Name', 'formidable' ); | |
| 86 | + $columns[ $form_id . '_user_id' ] = __( 'Created By', 'formidable' ); | |
| 182 | 87 | } |
| 183 | 88 | |
| 184 | - $columns[ $form_id . '_is_draft' ] = esc_html__( 'Entry Status', 'formidable' ); | |
| 185 | 89 | $columns[ $form_id . '_created_at' ] = __( 'Entry creation date', 'formidable' ); |
| 186 | 90 | $columns[ $form_id . '_updated_at' ] = __( 'Entry update date', 'formidable' ); |
| 187 | 91 | self::maybe_add_ip_col( $form_id, $columns ); |
| 188 | 92 | |
| @@ -188,14 +92,13 @@ | ||
| 188 | 92 | |
| 189 | 93 | $frm_vars['cols'] = $columns; |
| 190 | 94 | |
| 191 | 95 | $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); |
| 192 | - | |
| 193 | 96 | if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ) ) ) { |
| 194 | 97 | add_screen_option( |
| 195 | 98 | 'per_page', |
| 196 | 99 | array( |
| 197 | - 'label' => esc_html__( 'Entries', 'formidable' ), | |
| 100 | + 'label' => __( 'Entries', 'formidable' ), | |
| 198 | 101 | 'default' => 20, |
| 199 | 102 | 'option' => 'formidable_page_formidable_entries_per_page', |
| 200 | 103 | ) |
| 201 | 104 | ); |
| @@ -203,14 +106,8 @@ | ||
| 203 | 106 | |
| 204 | 107 | return $columns; |
| 205 | 108 | } |
| 206 | 109 | |
| 207 | - /** | |
| 208 | - * @param int|string $form_id | |
| 209 | - * @param array $columns | |
| 210 | - * | |
| 211 | - * @return void | |
| 212 | - */ | |
| 213 | 110 | private static function get_columns_for_form( $form_id, &$columns ) { |
| 214 | 111 | $form_cols = FrmField::get_all_for_form( $form_id, '', 'include' ); |
| 215 | 112 | |
| 216 | 113 | /** |
| @@ -227,10 +124,9 @@ | ||
| 227 | 124 | if ( FrmField::is_no_save_field( $form_col->type ) ) { |
| 228 | 125 | continue; |
| 229 | 126 | } |
| 230 | 127 | |
| 231 | - $has_child_fields = $form_col->type === 'form' && ! empty( $form_col->field_options['form_select'] ); | |
| 232 | - | |
| 128 | + $has_child_fields = $form_col->type == 'form' && isset( $form_col->field_options['form_select'] ) && ! empty( $form_col->field_options['form_select'] ); | |
| 233 | 129 | if ( $has_child_fields ) { |
| 234 | 130 | self::add_subform_cols( $form_col, $form_id, $columns ); |
| 235 | 131 | } else { |
| 236 | 132 | self::add_field_cols( $form_col, $form_id, $columns ); |
| @@ -239,18 +135,11 @@ | ||
| 239 | 135 | } |
| 240 | 136 | |
| 241 | 137 | /** |
| 242 | 138 | * @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 | 139 | */ |
| 250 | 140 | private static function add_subform_cols( $field, $form_id, &$columns ) { |
| 251 | 141 | $sub_form_cols = FrmField::get_all_for_form( $field->field_options['form_select'] ); |
| 252 | - | |
| 253 | 142 | if ( empty( $sub_form_cols ) ) { |
| 254 | 143 | return; |
| 255 | 144 | } |
| 256 | 145 | |
| @@ -265,62 +154,24 @@ | ||
| 265 | 154 | } |
| 266 | 155 | |
| 267 | 156 | /** |
| 268 | 157 | * @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 | 158 | */ |
| 276 | 159 | private static function add_field_cols( $field, $form_id, &$columns ) { |
| 277 | 160 | $col_id = $field->field_key; |
| 278 | - | |
| 279 | 161 | if ( $field->form_id != $form_id ) { |
| 280 | 162 | $col_id .= '-_-form' . $field->form_id; |
| 281 | 163 | } |
| 282 | 164 | |
| 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 ); | |
| 165 | + $has_separate_value = ! FrmField::is_option_empty( $field, 'separate_value' ); | |
| 166 | + $is_post_status = FrmField::is_option_true( $field, 'post_field' ) && $field->field_options['post_field'] == 'post_status'; | |
| 167 | + if ( $has_separate_value && ! $is_post_status ) { | |
| 168 | + $columns[ $form_id . '_frmsep_' . $col_id ] = FrmAppHelper::truncate( $field->name, 35 ); | |
| 289 | 169 | } |
| 290 | 170 | |
| 291 | - $columns[ $form_id . '_' . $col_id ] = self::maybe_format_field_name_for_column_title( $field, $include_column_for_sep_val, false ); | |
| 171 | + $columns[ $form_id . '_' . $col_id ] = FrmAppHelper::truncate( $field->name, 35 ); | |
| 292 | 172 | } |
| 293 | 173 | |
| 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 | 174 | private static function maybe_add_ip_col( $form_id, &$columns ) { |
| 324 | 175 | if ( FrmAppHelper::ips_saved() ) { |
| 325 | 176 | $columns[ $form_id . '_ip' ] = 'IP'; |
| 326 | 177 | } |
| @@ -325,20 +176,10 @@ | ||
| 325 | 176 | $columns[ $form_id . '_ip' ] = 'IP'; |
| 326 | 177 | } |
| 327 | 178 | } |
| 328 | 179 | |
| 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 | 180 | public static function check_hidden_cols( $check, $object_id, $meta_key, $meta_value, $prev_value ) { |
| 339 | 181 | $this_page_name = self::hidden_column_key(); |
| 340 | - | |
| 341 | 182 | if ( $meta_key != $this_page_name || $meta_value == $prev_value ) { |
| 342 | 183 | return $check; |
| 343 | 184 | } |
| 344 | 185 | |
| @@ -346,10 +187,10 @@ | ||
| 346 | 187 | $prev_value = get_metadata( 'user', $object_id, $meta_key, true ); |
| 347 | 188 | } |
| 348 | 189 | |
| 349 | 190 | 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; | |
| 191 | + //add a check so we don't create a loop | |
| 192 | + $frm_vars['prev_hidden_cols'] = ( isset( $frm_vars['prev_hidden_cols'] ) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value; | |
| 352 | 193 | |
| 353 | 194 | return $check; |
| 354 | 195 | } |
| 355 | 196 | |
| @@ -354,28 +195,18 @@ | ||
| 354 | 195 | } |
| 355 | 196 | |
| 356 | 197 | /** |
| 357 | 198 | * 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 | 199 | */ |
| 366 | 200 | public static function update_hidden_cols( $meta_id, $object_id, $meta_key, $meta_value ) { |
| 367 | 201 | $this_page_name = self::hidden_column_key(); |
| 368 | - | |
| 369 | 202 | if ( $meta_key != $this_page_name ) { |
| 370 | 203 | return; |
| 371 | 204 | } |
| 372 | 205 | |
| 373 | 206 | global $frm_vars; |
| 374 | - | |
| 375 | 207 | if ( ! isset( $frm_vars['prev_hidden_cols'] ) || ! $frm_vars['prev_hidden_cols'] ) { |
| 376 | - // Don't continue if there's no previous value. | |
| 377 | - return; | |
| 208 | + return; // Don't continue if there's no previous value. | |
| 378 | 209 | } |
| 379 | 210 | |
| 380 | 211 | foreach ( $meta_value as $mk => $mv ) { |
| 381 | 212 | // Remove blank values. |
| @@ -396,10 +227,9 @@ | ||
| 396 | 227 | } |
| 397 | 228 | |
| 398 | 229 | $form_prefix = explode( '_', $prev_hidden ); |
| 399 | 230 | $form_prefix = $form_prefix[0]; |
| 400 | - | |
| 401 | - if ( $form_prefix === $cur_form_prefix ) { | |
| 231 | + if ( $form_prefix == $cur_form_prefix ) { | |
| 402 | 232 | // Don't add back columns that are meant to be hidden. |
| 403 | 233 | continue; |
| 404 | 234 | } |
| 405 | 235 | |
| @@ -415,12 +245,8 @@ | ||
| 415 | 245 | } |
| 416 | 246 | |
| 417 | 247 | /** |
| 418 | 248 | * @since 2.05.07 |
| 419 | - * | |
| 420 | - * @param string $menu_name | |
| 421 | - * | |
| 422 | - * @return string | |
| 423 | 249 | */ |
| 424 | 250 | private static function hidden_column_key( $menu_name = '' ) { |
| 425 | 251 | $base = self::base_column_key( $menu_name ); |
| 426 | 252 | |
| @@ -428,12 +254,8 @@ | ||
| 428 | 254 | } |
| 429 | 255 | |
| 430 | 256 | /** |
| 431 | 257 | * @since 2.05.07 |
| 432 | - * | |
| 433 | - * @param string $menu_name | |
| 434 | - * | |
| 435 | - * @return string | |
| 436 | 258 | */ |
| 437 | 259 | private static function base_column_key( $menu_name = '' ) { |
| 438 | 260 | if ( empty( $menu_name ) ) { |
| 439 | 261 | $menu_name = FrmAppHelper::get_menu_name(); |
| @@ -438,22 +260,13 @@ | ||
| 438 | 260 | if ( empty( $menu_name ) ) { |
| 439 | 261 | $menu_name = FrmAppHelper::get_menu_name(); |
| 440 | 262 | } |
| 441 | 263 | |
| 442 | - $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count(); | |
| 443 | - | |
| 444 | - return sanitize_title( $menu_name ) . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-entries'; | |
| 264 | + return sanitize_title( $menu_name ) . '_page_formidable-entries'; | |
| 445 | 265 | } |
| 446 | 266 | |
| 447 | - /** | |
| 448 | - * @param int $save | |
| 449 | - * @param string $option | |
| 450 | - * @param string $value | |
| 451 | - * | |
| 452 | - * @return int | |
| 453 | - */ | |
| 454 | 267 | public static function save_per_page( $save, $option, $value ) { |
| 455 | - if ( $option === 'formidable_page_formidable_entries_per_page' ) { | |
| 268 | + if ( $option == 'formidable_page_formidable_entries_per_page' ) { | |
| 456 | 269 | $save = (int) $value; |
| 457 | 270 | } |
| 458 | 271 | |
| 459 | 272 | return $save; |
| @@ -458,11 +271,8 @@ | ||
| 458 | 271 | |
| 459 | 272 | return $save; |
| 460 | 273 | } |
| 461 | 274 | |
| 462 | - /** | |
| 463 | - * @return array | |
| 464 | - */ | |
| 465 | 275 | public static function sortable_columns() { |
| 466 | 276 | $form_id = FrmForm::get_current_form_id(); |
| 467 | 277 | $fields = FrmField::get_all_for_form( $form_id ); |
| 468 | 278 | |
| @@ -474,14 +284,8 @@ | ||
| 474 | 284 | $form_id . '_item_key' => 'item_key', |
| 475 | 285 | $form_id . '_is_draft' => 'is_draft', |
| 476 | 286 | ); |
| 477 | 287 | |
| 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 | 288 | foreach ( $fields as $field ) { |
| 485 | 289 | if ( self::field_supports_sorting( $field ) ) { |
| 486 | 290 | $columns[ $form_id . '_' . $field->field_key ] = 'meta_' . $field->id; |
| 487 | 291 | } |
| @@ -494,9 +298,8 @@ | ||
| 494 | 298 | * Can't sort on checkboxes because they are sorted serialized. |
| 495 | 299 | * Some post content can be sorted but not everything. |
| 496 | 300 | * |
| 497 | 301 | * @param stdClass $field |
| 498 | - * | |
| 499 | 302 | * @return bool |
| 500 | 303 | */ |
| 501 | 304 | private static function field_supports_sorting( $field ) { |
| 502 | 305 | $is_sortable = 'checkbox' !== $field->type && empty( $field->field_options['post_field'] ); |
| @@ -502,31 +305,22 @@ | ||
| 502 | 305 | $is_sortable = 'checkbox' !== $field->type && empty( $field->field_options['post_field'] ); |
| 503 | 306 | return apply_filters( 'frm_field_column_is_sortable', $is_sortable, $field ); |
| 504 | 307 | } |
| 505 | 308 | |
| 506 | - /** | |
| 507 | - * @param mixed $result Option value from database for hidden columns in entries table. | |
| 508 | - * | |
| 509 | - * @return array | |
| 510 | - */ | |
| 511 | 309 | public static function hidden_columns( $result ) { |
| 512 | - global $frm_vars; | |
| 310 | + $form_id = FrmForm::get_current_form_id(); | |
| 513 | 311 | |
| 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 | - } | |
| 312 | + $hidden = self::user_hidden_columns_for_form( $form_id, $result ); | |
| 520 | 313 | |
| 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; | |
| 314 | + global $frm_vars; | |
| 315 | + $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0; | |
| 525 | 316 | |
| 526 | 317 | if ( ! empty( $hidden ) ) { |
| 527 | - $result = $hidden; | |
| 528 | - $i = $i - count( $result ); | |
| 318 | + $result = $hidden; | |
| 319 | + $i = $i - count( $result ); | |
| 320 | + $max_columns = 11; | |
| 321 | + } else { | |
| 322 | + $max_columns = 8; | |
| 529 | 323 | } |
| 530 | 324 | |
| 531 | 325 | if ( $i <= $max_columns ) { |
| 532 | 326 | return $result; |
| @@ -538,22 +332,16 @@ | ||
| 538 | 332 | } |
| 539 | 333 | |
| 540 | 334 | /** |
| 541 | 335 | * @since 2.05.07 |
| 542 | - * | |
| 543 | - * @param int|string $form_id | |
| 544 | - * @param mixed $result | |
| 545 | - * | |
| 546 | - * @return array | |
| 547 | 336 | */ |
| 548 | 337 | private static function user_hidden_columns_for_form( $form_id, $result ) { |
| 549 | 338 | $hidden = array(); |
| 550 | - | |
| 551 | 339 | foreach ( (array) $result as $r ) { |
| 552 | 340 | if ( ! empty( $r ) ) { |
| 553 | 341 | list( $form_prefix, $field_key ) = explode( '_', $r ); |
| 554 | 342 | |
| 555 | - if ( (int) $form_prefix === (int) $form_id ) { | |
| 343 | + if ( (int) $form_prefix == (int) $form_id ) { | |
| 556 | 344 | $hidden[] = $r; |
| 557 | 345 | } |
| 558 | 346 | |
| 559 | 347 | unset( $form_prefix ); |
| @@ -566,13 +354,8 @@ | ||
| 566 | 354 | /** |
| 567 | 355 | * Remove some columns by default when there are too many |
| 568 | 356 | * |
| 569 | 357 | * @since 2.05.07 |
| 570 | - * | |
| 571 | - * @param array $atts | |
| 572 | - * @param array $result | |
| 573 | - * | |
| 574 | - * @return void | |
| 575 | 358 | */ |
| 576 | 359 | private static function remove_excess_cols( $atts, &$result ) { |
| 577 | 360 | global $frm_vars; |
| 578 | 361 | |
| @@ -590,9 +373,9 @@ | ||
| 590 | 373 | } |
| 591 | 374 | |
| 592 | 375 | if ( empty( $result ) || ! in_array( $col_key, $result, true ) ) { |
| 593 | 376 | $result[] = $col_key; |
| 594 | - --$i; | |
| 377 | + $i--; | |
| 595 | 378 | } |
| 596 | 379 | |
| 597 | 380 | unset( $col_key, $col ); |
| 598 | 381 | } |
| @@ -597,14 +380,8 @@ | ||
| 597 | 380 | unset( $col_key, $col ); |
| 598 | 381 | } |
| 599 | 382 | } |
| 600 | 383 | |
| 601 | - /** | |
| 602 | - * @param string $message | |
| 603 | - * @param array $errors | |
| 604 | - * | |
| 605 | - * @return void | |
| 606 | - */ | |
| 607 | 384 | public static function display_list( $message = '', $errors = array() ) { |
| 608 | 385 | global $wpdb, $frm_vars; |
| 609 | 386 | |
| 610 | 387 | $form = FrmForm::maybe_get_current_form(); |
| @@ -625,12 +402,10 @@ | ||
| 625 | 402 | |
| 626 | 403 | $wp_list_table->prepare_items(); |
| 627 | 404 | |
| 628 | 405 | $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); |
| 629 | - | |
| 630 | 406 | if ( $pagenum > $total_pages && $total_pages > 0 ) { |
| 631 | 407 | $url = add_query_arg( 'paged', $total_pages ); |
| 632 | - | |
| 633 | 408 | if ( headers_sent() ) { |
| 634 | 409 | FrmAppHelper::js_redirect( $url, true ); |
| 635 | 410 | } else { |
| 636 | 411 | wp_redirect( esc_url_raw( $url ) ); |
| @@ -644,31 +419,19 @@ | ||
| 644 | 419 | |
| 645 | 420 | require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php'; |
| 646 | 421 | } |
| 647 | 422 | |
| 648 | - /** | |
| 649 | - * @param object $form | |
| 650 | - * @param array $errors | |
| 651 | - * | |
| 652 | - * @return void | |
| 653 | - */ | |
| 654 | 423 | private static function get_delete_form_time( $form, &$errors ) { |
| 655 | - if ( 'trash' === $form->status ) { | |
| 424 | + if ( 'trash' == $form->status ) { | |
| 656 | 425 | $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); |
| 657 | - $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( $form->options['trash_time'] ?? time() ) ); | |
| 426 | + $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? ( $form->options['trash_time'] ) : time() ) ); | |
| 658 | 427 | |
| 659 | 428 | /* 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 ); | |
| 429 | + $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 | 430 | } |
| 662 | 431 | } |
| 663 | 432 | |
| 664 | - /** | |
| 665 | - * Back End CRUD. | |
| 666 | - * | |
| 667 | - * @param int $id | |
| 668 | - * | |
| 669 | - * @return void | |
| 670 | - */ | |
| 433 | + /* Back End CRUD */ | |
| 671 | 434 | public static function show( $id = 0 ) { |
| 672 | 435 | FrmAppHelper::permission_check( 'frm_view_entries' ); |
| 673 | 436 | |
| 674 | 437 | if ( ! $id ) { |
| @@ -679,22 +442,17 @@ | ||
| 679 | 442 | } |
| 680 | 443 | } |
| 681 | 444 | |
| 682 | 445 | $entry = FrmEntry::getOne( $id, true ); |
| 446 | + if ( ! $entry ) { | |
| 447 | + echo '<div id="form_show_entry_page" class="wrap">' . | |
| 448 | + esc_html__( 'You are trying to view an entry that does not exist.', 'formidable' ) . | |
| 449 | + '</div>'; | |
| 683 | 450 | |
| 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 | 451 | return; |
| 693 | 452 | } |
| 694 | 453 | |
| 695 | 454 | $data = $entry->description; |
| 696 | - | |
| 697 | 455 | if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) { |
| 698 | 456 | $data = array( 'referrer' => $data ); |
| 699 | 457 | } |
| 700 | 458 | |
| @@ -700,30 +458,14 @@ | ||
| 700 | 458 | |
| 701 | 459 | $fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' ); |
| 702 | 460 | $form = FrmForm::getOne( $entry->form_id ); |
| 703 | 461 | |
| 704 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php'; | |
| 462 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php' ); | |
| 705 | 463 | } |
| 706 | 464 | |
| 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 | 465 | public static function destroy() { |
| 714 | - $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_entries', '_wpnonce', -1 ); | |
| 466 | + FrmAppHelper::permission_check( 'frm_delete_entries' ); | |
| 715 | 467 | |
| 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 | 468 | $params = FrmForm::get_admin_params(); |
| 727 | 469 | |
| 728 | 470 | if ( isset( $params['keep_post'] ) && $params['keep_post'] ) { |
| 729 | 471 | self::unlink_post( $params['id'] ); |
| @@ -729,11 +471,10 @@ | ||
| 729 | 471 | self::unlink_post( $params['id'] ); |
| 730 | 472 | } |
| 731 | 473 | |
| 732 | 474 | $message = ''; |
| 733 | - | |
| 734 | 475 | if ( FrmEntry::destroy( $params['id'] ) ) { |
| 735 | - $message = __( 'Entry was successfully deleted', 'formidable' ); | |
| 476 | + $message = __( 'Entry was Successfully Deleted', 'formidable' ); | |
| 736 | 477 | } |
| 737 | 478 | |
| 738 | 479 | self::display_list( $message ); |
| 739 | 480 | } |
| @@ -738,16 +479,19 @@ | ||
| 738 | 479 | self::display_list( $message ); |
| 739 | 480 | } |
| 740 | 481 | |
| 741 | 482 | /** |
| 742 | - * @param array|string $errors | |
| 743 | - * @param bool $ajax | |
| 744 | - * | |
| 745 | - * @return void | |
| 483 | + * @deprecated 4.02.04 - Moved to Pro since it was unused in Lite. | |
| 746 | 484 | */ |
| 485 | + public static function destroy_all() { | |
| 486 | + _deprecated_function( __METHOD__, '4.02.04', 'FrmProEntriesController::destroy_all' ); | |
| 487 | + if ( is_callable( 'FrmProEntriesController::destroy_all' ) ) { | |
| 488 | + FrmProEntriesController::destroy_all(); | |
| 489 | + } | |
| 490 | + } | |
| 491 | + | |
| 747 | 492 | public static function process_entry( $errors = '', $ajax = false ) { |
| 748 | 493 | $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' ); |
| 749 | - | |
| 750 | 494 | if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 751 | 495 | return; |
| 752 | 496 | } |
| 753 | 497 | |
| @@ -753,19 +497,12 @@ | ||
| 753 | 497 | |
| 754 | 498 | global $frm_vars; |
| 755 | 499 | |
| 756 | 500 | $form = FrmForm::getOne( $form_id ); |
| 757 | - | |
| 758 | 501 | if ( ! $form ) { |
| 759 | 502 | return; |
| 760 | 503 | } |
| 761 | 504 | |
| 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 | 505 | $params = FrmForm::get_params( $form ); |
| 769 | 506 | |
| 770 | 507 | if ( ! isset( $frm_vars['form_params'] ) ) { |
| 771 | 508 | $frm_vars['form_params'] = array(); |
| @@ -792,9 +529,8 @@ | ||
| 792 | 529 | |
| 793 | 530 | if ( empty( $errors ) ) { |
| 794 | 531 | $_POST['frm_skip_cookie'] = 1; |
| 795 | 532 | $do_success = false; |
| 796 | - | |
| 797 | 533 | if ( $params['action'] === 'create' ) { |
| 798 | 534 | if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) { |
| 799 | 535 | $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 800 | 536 | |
| @@ -803,9 +539,8 @@ | ||
| 803 | 539 | } |
| 804 | 540 | } |
| 805 | 541 | |
| 806 | 542 | do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) ); |
| 807 | - | |
| 808 | 543 | if ( $do_success ) { |
| 809 | 544 | FrmFormsController::maybe_trigger_redirect( $form, $params, array( 'ajax' => $ajax ) ); |
| 810 | 545 | } |
| 811 | 546 | unset( $_POST['frm_skip_cookie'] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| @@ -824,17 +559,8 @@ | ||
| 824 | 559 | public static function prepare_redirect_url( $url ) { |
| 825 | 560 | return str_replace( array( ' ', '[', ']', '|', '@' ), array( '%20', '%5B', '%5D', '%7C', '%40' ), $url ); |
| 826 | 561 | } |
| 827 | 562 | |
| 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 | 563 | public static function delete_entry_before_redirect( $url, $form, $atts ) { |
| 838 | 564 | self::_delete_entry( $atts['id'], $form ); |
| 839 | 565 | |
| 840 | 566 | return $url; |
| @@ -843,23 +569,13 @@ | ||
| 843 | 569 | /** |
| 844 | 570 | * Delete entry if not redirected. |
| 845 | 571 | * |
| 846 | 572 | * @param array $atts |
| 847 | - * | |
| 848 | - * @return void | |
| 849 | 573 | */ |
| 850 | 574 | public static function delete_entry_after_save( $atts ) { |
| 851 | 575 | self::_delete_entry( $atts['entry_id'], $atts['form'] ); |
| 852 | 576 | } |
| 853 | 577 | |
| 854 | - /** | |
| 855 | - * Delete entry if not redirected. | |
| 856 | - * | |
| 857 | - * @param int $entry_id | |
| 858 | - * @param object $form | |
| 859 | - * | |
| 860 | - * @return void | |
| 861 | - */ | |
| 862 | 578 | private static function _delete_entry( $entry_id, $form ) { |
| 863 | 579 | if ( ! $form ) { |
| 864 | 580 | return; |
| 865 | 581 | } |
| @@ -864,9 +580,8 @@ | ||
| 864 | 580 | return; |
| 865 | 581 | } |
| 866 | 582 | |
| 867 | 583 | FrmAppHelper::unserialize_or_decode( $form->options ); |
| 868 | - | |
| 869 | 584 | if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) { |
| 870 | 585 | self::unlink_post( $entry_id ); |
| 871 | 586 | FrmEntry::destroy( $entry_id ); |
| 872 | 587 | } |
| @@ -873,12 +588,8 @@ | ||
| 873 | 588 | } |
| 874 | 589 | |
| 875 | 590 | /** |
| 876 | 591 | * Unlink entry from post |
| 877 | - * | |
| 878 | - * @param int $entry_id | |
| 879 | - * | |
| 880 | - * @return void | |
| 881 | 592 | */ |
| 882 | 593 | private static function unlink_post( $entry_id ) { |
| 883 | 594 | global $wpdb; |
| 884 | 595 | $wpdb->update( $wpdb->prefix . 'frm_items', array( 'post_id' => '' ), array( 'id' => $entry_id ) ); |
| @@ -885,9 +596,9 @@ | ||
| 885 | 596 | FrmEntry::clear_cache(); |
| 886 | 597 | } |
| 887 | 598 | |
| 888 | 599 | /** |
| 889 | - * @param array $atts | |
| 600 | + * @param $atts | |
| 890 | 601 | * |
| 891 | 602 | * @return array|string |
| 892 | 603 | */ |
| 893 | 604 | public static function show_entry_shortcode( $atts ) { |
| @@ -914,11 +625,9 @@ | ||
| 914 | 625 | 'exclude_fields' => '', |
| 915 | 626 | 'include_fields' => '', |
| 916 | 627 | 'include_extras' => '', |
| 917 | 628 | 'inline_style' => 1, |
| 918 | - 'table_style' => '', | |
| 919 | - // Return embedded fields as nested array. | |
| 920 | - 'child_array' => false, | |
| 629 | + 'child_array' => false, // return embedded fields as nested array | |
| 921 | 630 | 'line_breaks' => true, |
| 922 | 631 | 'array_separator' => ', ', |
| 923 | 632 | ); |
| 924 | 633 | $defaults = apply_filters( 'frm_show_entry_defaults', $defaults ); |
| @@ -943,13 +652,8 @@ | ||
| 943 | 652 | |
| 944 | 653 | return $formatted_entry; |
| 945 | 654 | } |
| 946 | 655 | |
| 947 | - /** | |
| 948 | - * @param false|object $entry | |
| 949 | - * | |
| 950 | - * @return void | |
| 951 | - */ | |
| 952 | 656 | public static function entry_sidebar( $entry = false ) { |
| 953 | 657 | $data = array(); |
| 954 | 658 | $id = 0; |
| 955 | 659 | |
| @@ -958,22 +662,36 @@ | ||
| 958 | 662 | |
| 959 | 663 | if ( $entry ) { |
| 960 | 664 | $id = $entry->id; |
| 961 | 665 | $data = $entry->description; |
| 962 | - | |
| 963 | 666 | if ( isset( $data['browser'] ) ) { |
| 964 | 667 | $browser = FrmEntriesHelper::get_browser( $data['browser'] ); |
| 965 | 668 | } |
| 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 | 669 | } |
| 976 | 670 | |
| 977 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php'; | |
| 671 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php' ); | |
| 672 | + } | |
| 673 | + | |
| 674 | + /** | |
| 675 | + * @deprecated 4.0 | |
| 676 | + */ | |
| 677 | + public static function contextual_help( $help, $screen_id, $screen ) { | |
| 678 | + _deprecated_function( __METHOD__, '4.0' ); | |
| 679 | + return $help; | |
| 680 | + } | |
| 681 | + | |
| 682 | + /** | |
| 683 | + * @deprecated 1.07.05 | |
| 684 | + * @codeCoverageIgnore | |
| 685 | + */ | |
| 686 | + public static function show_form( $id = '', $key = '', $title = false, $description = false ) { | |
| 687 | + return FrmDeprecated::show_form( $id, $key, $title, $description ); | |
| 688 | + } | |
| 689 | + | |
| 690 | + /** | |
| 691 | + * @deprecated 1.07.05 | |
| 692 | + * @codeCoverageIgnore | |
| 693 | + */ | |
| 694 | + public static function get_form( $filename, $form, $title, $description ) { | |
| 695 | + return FrmDeprecated::get_form( $filename, $form, $title, $description ); | |
| 978 | 696 | } |
| 979 | 697 | } |