芝麻web文件管理V1.00
编辑当前文件:/var/www/cognitio.in/wp-content/plugins/wp-mail-smtp/src/Admin/DebugEvents/Table.php
'event', 'plural' => 'events', 'ajax' => false, ] ); // Include polyfill if mbstring PHP extension is not enabled. if ( ! function_exists( 'mb_substr' ) || ! function_exists( 'mb_strlen' ) ) { Helpers::include_mbstring_polyfill(); } } /** * Get the debug event types for filtering purpose. * * @since 3.0.0 * * @return array Associative array of debug event types StatusCode=>Name. */ public function get_types() { return Event::get_types(); } /** * Get the items counts for various types of debug logs. * * @since 3.0.0 */ public function get_counts() { $this->counts = []; // Base params with applied filters. $base_params = $this->get_filters_query_params(); $total_params = $base_params; unset( $total_params['type'] ); $this->counts['total'] = ( new EventsCollection( $total_params ) )->get_count(); foreach ( $this->get_types() as $type => $name ) { $collection = new EventsCollection( array_merge( $base_params, [ 'type' => $type ] ) ); $this->counts[ 'type_' . $type ] = $collection->get_count(); } /** * Filters items counts by various types of debug events. * * @since 3.0.0 * * @param array $counts { * Items counts by types. * * @type integer $total Total items count. * @type integer $status_{$type_key} Items count by type. * } */ $this->counts = apply_filters( 'wp_mail_smtp_admin_debug_events_table_get_counts', $this->counts ); } /** * Retrieve the view types. * * @since 3.0.0 */ public function get_views() { $base_url = $this->get_filters_base_url(); $current_type = $this->get_filtered_types(); $views = []; $views['all'] = sprintf( '
%3$s
(%4$d)
', esc_url( remove_query_arg( 'type', $base_url ) ), $current_type === false ? 'class="current"' : '', esc_html__( 'All', 'wp-mail-smtp' ), intval( $this->counts['total'] ) ); foreach ( $this->get_types() as $type => $type_label ) { $count = intval( $this->counts[ 'type_' . $type ] ); // Skipping types with no events. if ( $count === 0 && $current_type !== $type ) { continue; } $views[ $type ] = sprintf( '
%3$s
(%4$d)
', esc_url( add_query_arg( 'type', $type, $base_url ) ), $current_type === $type ? 'class="current"' : '', esc_html( $type_label ), $count ); } /** * Filters debug event item views. * * @since 3.0.0 * * @param array $views { * Debug event items views by types. * * @type string $all Total items view. * @type integer $status_key Items views by type. * } * @param array $counts { * Items counts by types. * * @type integer $total Total items count. * @type integer $status_{$status_key} Items count by types. * } */ return apply_filters( 'wp_mail_smtp_admin_debug_events_table_get_views', $views, $this->counts ); } /** * Define the table columns. * * @since 3.0.0 * * @return array Associative array of slug=>Name columns data. */ public function get_columns() { return [ 'event' => esc_html__( 'Event', 'wp-mail-smtp' ), 'type' => esc_html__( 'Type', 'wp-mail-smtp' ), 'content' => esc_html__( 'Content', 'wp-mail-smtp' ), 'initiator' => esc_html__( 'Source', 'wp-mail-smtp' ), 'created_at' => esc_html__( 'Date', 'wp-mail-smtp' ), ]; } /** * Display the main event title with a link to open event details. * * @since 3.0.0 * * @param Event $item Event object. * * @return string */ public function column_event( $item ) { return '
' . '
' . esc_html( $item->get_title() ) . '
' . '
'; } /** * Display event's type. * * @since 3.0.0 * * @param Event $item Event object. * * @return string */ public function column_type( $item ) { return esc_html( $item->get_type_name() ); } /** * Display event's content. * * @since 3.0.0 * * @param Event $item Event object. * * @return string */ public function column_content( $item ) { $content = $item->get_content(); if ( mb_strlen( $content ) > 100 ) { $content = mb_substr( $content, 0, 100 ) . '...'; } return wp_kses_post( $content ); } /** * Display event's wp_mail initiator. * * @since 3.0.0 * * @param Event $item Event object. * * @return string */ public function column_initiator( $item ) { return esc_html( $item->get_initiator() ); } /** * Display event's created date. * * @since 3.0.0 * * @param Event $item Event object. * * @return string */ public function column_created_at( $item ) { return $item->get_created_at_formatted(); } /** * Return type filter value or FALSE. * * @since 3.0.0 * * @return bool|integer */ public function get_filtered_types() { if ( ! isset( $_REQUEST['type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended return false; } return intval( $_REQUEST['type'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended } /** * Return date filter value or FALSE. * * @since 3.0.0 * * @return bool|array */ public function get_filtered_dates() { if ( empty( $_REQUEST['date'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended return false; } $dates = (array) explode( ' - ', sanitize_text_field( wp_unslash( $_REQUEST['date'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended return array_map( 'sanitize_text_field', $dates ); } /** * Return search filter values or FALSE. * * @since 3.0.0 * * @return bool|array */ public function get_filtered_search() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( empty( $_REQUEST['search'] ) ) { return false; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended return sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ); } /** * Whether the event log is filtered or not. * * @since 3.0.0 * * @return bool */ public function is_filtered() { $is_filtered = false; if ( $this->get_filtered_search() !== false || $this->get_filtered_dates() !== false || $this->get_filtered_types() !== false ) { $is_filtered = true; } return $is_filtered; } /** * Get current filters query parameters. * * @since 3.0.0 * * @return array */ public function get_filters_query_params() { $params = [ 'search' => $this->get_filtered_search(), 'type' => $this->get_filtered_types(), 'date' => $this->get_filtered_dates(), ]; return array_filter( $params, function ( $v ) { return $v !== false; } ); } /** * Get current filters base url. * * @since 3.0.0 * * @return string */ public function get_filters_base_url() { $base_url = DebugEvents::get_page_url(); $filters_params = $this->get_filters_query_params(); if ( isset( $filters_params['search'] ) ) { $base_url = add_query_arg( 'search', $filters_params['search'], $base_url ); } if ( isset( $filters_params['type'] ) ) { $base_url = add_query_arg( 'type', $filters_params['type'], $base_url ); } if ( isset( $filters_params['date'] ) ) { $base_url = add_query_arg( 'date', implode( ' - ', $filters_params['date'] ), $base_url ); } return $base_url; } /** * Get the data, prepare pagination, process bulk actions. * Prepare columns for display. * * @since 3.0.0 */ public function prepare_items() { // Retrieve count. $this->get_counts(); // Prepare all the params to pass to our Collection. All sanitization is done in that class. $params = $this->get_filters_query_params(); // Total amount for pagination with WHERE clause - super quick count DB request. $total_items = ( new EventsCollection( $params ) )->get_count(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( ! empty( $_REQUEST['orderby'] ) && in_array( $_REQUEST['orderby'], [ 'event', 'type', 'content', 'initiator', 'created_at' ], true ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $params['orderby'] = sanitize_key( $_REQUEST['orderby'] ); } // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( ! empty( $_REQUEST['order'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $params['order'] = strtoupper( sanitize_text_field( wp_unslash( $_REQUEST['order'] ) ) ) === 'DESC' ? 'DESC' : 'ASC'; } $params['offset'] = ( $this->get_pagenum() - 1 ) * EventsCollection::$per_page; // Get the data from the DB using parameters defined above. $collection = new EventsCollection( $params ); $this->items = $collection->get(); /* * Register our pagination options & calculations. */ $this->set_pagination_args( [ 'total_items' => $total_items, 'per_page' => EventsCollection::$per_page, ] ); } /** * Display the search box. * * @since 1.7.0 * * @param string $text The 'submit' button label. * @param string $input_id ID attribute value for the search input field. */ public function search_box( $text, $input_id ) { if ( ! $this->is_filtered() && ! $this->has_items() ) { return; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended $search = ! empty( $_REQUEST['search'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['search'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( ! empty( $_REQUEST['orderby'] ) && in_array( $_REQUEST['orderby'], [ 'event', 'type', 'content', 'initiator', 'created_at' ], true ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $order_by = sanitize_text_field( wp_unslash( $_REQUEST['orderby'] ) ); echo '
'; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( ! empty( $_REQUEST['order'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $order = strtoupper( sanitize_text_field( wp_unslash( $_REQUEST['order'] ) ) ) === 'DESC' ? 'DESC' : 'ASC'; echo '
'; } ?>
:
'search-submit' ] ); ?>
items ) > 0; } /** * Message to be displayed when there are no items. * * @since 3.0.0 */ public function no_items() { if ( $this->is_filtered() ) { esc_html_e( 'No events found.', 'wp-mail-smtp' ); } else { esc_html_e( 'No events have been logged for now.', 'wp-mail-smtp' ); } } /** * Displays the table. * * @since 3.0.0 */ public function display() { $this->_column_headers = [ $this->get_columns(), [], [] ]; parent::display(); } /** * Hide the tablenav if there are no items in the table. * And remove the bulk action nonce and code. * * @since 3.0.0 * * @param string $which Which tablenav: top or bottom. */ protected function display_tablenav( $which ) { if ( ! $this->has_items() ) { return; } ?>
extra_tablenav( $which ); $this->pagination( $which ); ?>
has_items() ) { return; } $date = $this->get_filtered_dates() !== false ? implode( ' - ', $this->get_filtered_dates() ) : ''; ?>
%s', esc_html__( 'Delete All Events', 'wp-mail-smtp' ) ); } } /** * Get the name of the primary column. * Important for the mobile view. * * @since 3.0.0 * * @return string The name of the primary column. */ protected function get_primary_column_name() { return 'event'; } }