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