'entry', 'plural' => 'entries', 'ajax' => false, ) ); } /** * Columns. * * @return array */ public function get_columns() { return array( 'cb' => '', 'summary' => __( 'Submission', 'alpeg-forms' ), 'form_title' => __( 'Form', 'alpeg-forms' ), 'created_at' => __( 'Received', 'alpeg-forms' ), ); } /** * Sortierbare Columns. * * @return array */ protected function get_sortable_columns() { return array( 'form_title' => array( 'form_title', false ), 'created_at' => array( 'created_at', true ), ); } /** * Bulk actions. * * @return array */ protected function get_bulk_actions() { return array( 'read' => __( 'Mark as read', 'alpeg-forms' ), 'unread' => __( 'Mark as unread', 'alpeg-forms' ), 'delete' => __( 'Delete', 'alpeg-forms' ), ); } /** * Views: All / Unread. * * @return array */ protected function get_views() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $current = isset( $_GET['status'] ) ? sanitize_key( wp_unslash( $_GET['status'] ) ) : ''; $base = admin_url( 'admin.php?page=alpeg-forms' ); $all = Entries::count(); $unread = Entries::count( array( 'status' => 'unread' ) ); return array( 'all' => sprintf( '%s (%d)', esc_url( $base ), '' === $current ? ' class="current" aria-current="page"' : '', esc_html__( 'All', 'alpeg-forms' ), $all ), 'unread' => sprintf( '%s (%d)', esc_url( add_query_arg( 'status', 'unread', $base ) ), 'unread' === $current ? ' class="current" aria-current="page"' : '', esc_html__( 'Unread', 'alpeg-forms' ), $unread ), ); } /** * Form filter and export above the table. * * @param string $which top|bottom. */ protected function extra_tablenav( $which ) { if ( 'top' !== $which ) { return; } $forms = Entries::forms(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $current = isset( $_GET['form_id'] ) ? sanitize_key( wp_unslash( $_GET['form_id'] ) ) : ''; echo '
'; if ( count( $forms ) > 1 ) { echo ''; echo ''; submit_button( __( 'Filter', 'alpeg-forms' ), '', 'filter_action', false ); } $export = wp_nonce_url( add_query_arg( array( 'action' => 'alpeg_forms_export', 'form_id' => $current ), admin_url( 'admin-post.php' ) ), 'alpeg_forms_export' ); echo ' ' . esc_html__( 'CSV export', 'alpeg-forms' ) . ''; echo '
'; } /** * Load data. */ public function prepare_items() { // phpcs:disable WordPress.Security.NonceVerification.Recommended -- read only. $per_page = $this->get_items_per_page( 'alpeg_forms_per_page', 20 ); $args = array( 'form_id' => isset( $_GET['form_id'] ) ? sanitize_key( wp_unslash( $_GET['form_id'] ) ) : '', 'status' => isset( $_GET['status'] ) && 'unread' === $_GET['status'] ? 'unread' : '', 'search' => isset( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : '', 'orderby' => isset( $_GET['orderby'] ) ? sanitize_key( wp_unslash( $_GET['orderby'] ) ) : 'created_at', 'order' => isset( $_GET['order'] ) ? sanitize_key( wp_unslash( $_GET['order'] ) ) : 'desc', 'per_page' => $per_page, 'page' => $this->get_pagenum(), ); // phpcs:enable $this->items = Entries::query( $args ); $this->set_pagination_args( array( 'total_items' => Entries::count( $args ), 'per_page' => $per_page, ) ); $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns(), 'summary' ); } /** * Checkbox. * * @param object $item Zeile. * @return string */ protected function column_cb( $item ) { return ''; } /** * Short preview of the first values. * * @param object $item Zeile. * @return string */ protected function column_summary( $item ) { $view = wp_nonce_url( admin_url( 'admin.php?page=alpeg-forms&view=' . $item->id ), 'alpeg_forms_read_' . $item->id ); $parts = array(); foreach ( $item->data as $row ) { if ( in_array( $row['type'], array( 'consent', 'file' ), true ) || '' === $row['value'] ) { continue; } $parts[] = $row['value']; if ( count( $parts ) >= 2 ) { break; } } $title = $parts ? implode( ' · ', $parts ) : __( '(empty)', 'alpeg-forms' ); $title = wp_html_excerpt( $title, 90, '…' ); $preview = ''; foreach ( $item->data as $row ) { if ( 'textarea' === $row['type'] && '' !== $row['value'] ) { $preview = '

' . esc_html( wp_html_excerpt( $row['value'], 140, '…' ) ) . '

'; break; } } $icons = ''; if ( wp_list_filter( $item->data, array( 'type' => 'file' ) ) ) { $icons .= ' '; } if ( 'failed' === $item->mail_status ) { $icons .= ' '; } $unread = 'unread' === $item->status ? '' : ''; $del = wp_nonce_url( admin_url( 'admin-post.php?action=alpeg_forms_entry&do=delete&id=' . $item->id ), 'alpeg_forms_entry_' . $item->id ); $actions = array( 'view' => '' . esc_html__( 'View', 'alpeg-forms' ) . '', 'delete' => '' . esc_html__( 'Delete', 'alpeg-forms' ) . '', ); return $unread . '' . esc_html( $title ) . '' . $icons . $preview . $this->row_actions( $actions ); } /** * Form. * * @param object $item Zeile. * @return string */ protected function column_form_title( $item ) { return esc_html( $item->form_title ); } /** * Date. * * @param object $item Zeile. * @return string */ protected function column_created_at( $item ) { $ts = strtotime( $item->created_at . ' UTC' ); $diff = time() - $ts; $text = $diff < DAY_IN_SECONDS /* translators: %s: time span, e.g. "5 minutes" */ ? sprintf( __( '%s ago', 'alpeg-forms' ), human_time_diff( $ts ) ) : wp_date( get_option( 'date_format' ) . ', ' . get_option( 'time_format' ), $ts ); return ''; } /** * Text for an empty list (e.g. search without results). */ public function no_items() { esc_html_e( 'No matching submissions found.', 'alpeg-forms' ); } /** * Process bulk actions (runs before output). */ public static function process_bulk_action() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'alpeg-forms' ), 403 ); } // phpcs:disable WordPress.Security.NonceVerification.Recommended $action = ''; if ( isset( $_GET['action'] ) && '-1' !== $_GET['action'] ) { $action = sanitize_key( wp_unslash( $_GET['action'] ) ); } elseif ( isset( $_GET['action2'] ) && '-1' !== $_GET['action2'] ) { $action = sanitize_key( wp_unslash( $_GET['action2'] ) ); } if ( ! in_array( $action, array( 'read', 'unread', 'delete' ), true ) || empty( $_GET['entry'] ) ) { return; } // phpcs:enable check_admin_referer( 'bulk-entries' ); $ids = array_map( 'absint', (array) wp_unslash( $_GET['entry'] ) ); if ( 'delete' === $action ) { $n = Entries::delete( $ids ); } else { Entries::set_status( $ids, $action ); $n = count( $ids ); } wp_safe_redirect( add_query_arg( array( 'page' => 'alpeg-forms', 'af_done' => 'delete' === $action ? 'deleted' : $action, 'af_n' => $n, ), admin_url( 'admin.php' ) ) ); exit; } }