芝麻web文件管理V1.00
编辑当前文件:/var/www/cognitio.in/wp-content/plugins/woocommerce/includes/admin/reports/class-wc-report-downloads.php
'download', 'plural' => 'downloads', 'ajax' => false, ) ); } /** * Don't need this. * * @param string $position Top or bottom. */ public function display_tablenav( $position ) { if ( 'top' !== $position ) { parent::display_tablenav( $position ); } } /** * Output the report. */ public function output_report() { $this->prepare_items(); // Subtitle for permission if set. if ( ! empty( $_GET['permission_id'] ) ) { // WPCS: input var ok. $permission_id = absint( $_GET['permission_id'] ); // WPCS: input var ok. // Load the permission, order, etc. so we can render more information. $permission = null; $product = null; try { $permission = new WC_Customer_Download( $permission_id ); $product = wc_get_product( $permission->product_id ); } catch ( Exception $e ) { wp_die( sprintf( esc_html__( 'Permission #%d not found.', 'woocommerce' ), esc_html( $permission_id ) ) ); } } echo '
' . esc_html__( 'Customer downloads', 'woocommerce' ); $filters = $this->get_filter_vars(); $filter_list = array(); $filter_names = array( 'product_id' => __( 'Product', 'woocommerce' ), 'download_id' => __( 'File ID', 'woocommerce' ), 'permission_id' => __( 'Permission ID', 'woocommerce' ), 'order_id' => __( 'Order', 'woocommerce' ), 'user_id' => __( 'User', 'woocommerce' ), 'user_ip_address' => __( 'IP address', 'woocommerce' ), ); foreach ( $filters as $key => $value ) { if ( is_null( $value ) ) { continue; } switch ( $key ) { case 'order_id': $order = wc_get_order( $value ); if ( $order ) { $display_value = _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number(); } else { break 2; } break; case 'product_id': $product = wc_get_product( $value ); if ( $product ) { $display_value = $product->get_formatted_name(); } else { break 2; } break; default: $display_value = $value; break; } $filter_list[] = $filter_names[ $key ] . ' ' . $display_value . '
×
'; } echo '
'; echo '
'; echo esc_html__( 'Active filters', 'woocommerce' ) . ': '; echo $filter_list ? wp_kses_post( implode( ', ', $filter_list ) ) : ''; echo '
'; echo '
'; $this->display(); echo '
'; } /** * Get column value. * * @param mixed $item Item being displayed. * @param string $column_name Column name. */ public function column_default( $item, $column_name ) { $permission = null; $product = null; try { $permission = new WC_Customer_Download( $item->permission_id ); $product = wc_get_product( $permission->product_id ); } catch ( Exception $e ) { // Ok to continue rendering other information even if permission and/or product is not found. return; } switch ( $column_name ) { case 'timestamp': echo esc_html( $item->timestamp ); break; case 'product': if ( ! empty( $product ) ) { edit_post_link( esc_html( $product->get_formatted_name() ), '', '', $product->get_id(), 'view-link' ); echo '
'; echo '
' . esc_html__( 'Filter by product', 'woocommerce' ) . '
'; echo '
'; } break; case 'file': if ( ! empty( $permission ) && ! empty( $product ) ) { // File information. $file = $product->get_file( $permission->get_download_id() ); if ( false === $file ) { echo esc_html__( 'File does not exist', 'woocommerce' ); } else { echo esc_html( $file->get_name() . ' - ' . basename( $file->get_file() ) ); echo '
'; echo '
' . esc_html__( 'Filter by file', 'woocommerce' ) . '
'; echo '
'; } } break; case 'order': if ( ! empty( $permission ) && ( $order = wc_get_order( $permission->order_id ) ) ) { edit_post_link( esc_html( _x( '#', 'hash before order number', 'woocommerce' ) . $order->get_order_number() ), '', '', $permission->order_id, 'view-link' ); echo '
'; echo '
' . esc_html__( 'Filter by order', 'woocommerce' ) . '
'; echo '
'; } break; case 'user': if ( $item->user_id > 0 ) { $user = get_user_by( 'id', $item->user_id ); if ( ! empty( $user ) ) { echo '
' . esc_html( $user->display_name ) . '
'; echo '
'; echo '
' . esc_html__( 'Filter by user', 'woocommerce' ) . '
'; echo '
'; } } else { esc_html_e( 'Guest', 'woocommerce' ); } break; case 'user_ip_address': echo esc_html( $item->user_ip_address ); echo '
'; echo '
' . esc_html__( 'Filter by IP address', 'woocommerce' ) . '
'; echo '
'; break; } } /** * Get columns. * * @return array */ public function get_columns() { $columns = array( 'timestamp' => __( 'Timestamp', 'woocommerce' ), 'product' => __( 'Product', 'woocommerce' ), 'file' => __( 'File', 'woocommerce' ), 'order' => __( 'Order', 'woocommerce' ), 'user' => __( 'User', 'woocommerce' ), 'user_ip_address' => __( 'IP address', 'woocommerce' ), ); return $columns; } /** * Prepare download list items. */ public function prepare_items() { $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns() ); $current_page = absint( $this->get_pagenum() ); // Allow filtering per_page value, but ensure it's at least 1. $per_page = max( 1, apply_filters( 'woocommerce_admin_downloads_report_downloads_per_page', 20 ) ); $this->get_items( $current_page, $per_page ); /** * Pagination. */ $this->set_pagination_args( array( 'total_items' => $this->max_items, 'per_page' => $per_page, 'total_pages' => ceil( $this->max_items / $per_page ), ) ); } /** * No items found text. */ public function no_items() { esc_html_e( 'No customer downloads found.', 'woocommerce' ); } /** * Get filters from querystring. * * @return object */ protected function get_filter_vars() { $product_id = ! empty( $_GET['product_id'] ) ? absint( wp_unslash( $_GET['product_id'] ) ) : null; // WPCS: input var ok. $download_id = ! empty( $_GET['download_id'] ) ? wc_clean( wp_unslash( $_GET['download_id'] ) ) : null; // WPCS: input var ok. $permission_id = ! empty( $_GET['permission_id'] ) ? absint( wp_unslash( $_GET['permission_id'] ) ) : null; // WPCS: input var ok. $order_id = ! empty( $_GET['order_id'] ) ? absint( wp_unslash( $_GET['order_id'] ) ) : null; // WPCS: input var ok. $user_id = ! empty( $_GET['user_id'] ) ? absint( wp_unslash( $_GET['user_id'] ) ) : null; // WPCS: input var ok. $user_ip_address = ! empty( $_GET['user_ip_address'] ) ? wc_clean( wp_unslash( $_GET['user_ip_address'] ) ) : null; // WPCS: input var ok. return (object) array( 'product_id' => $product_id, 'download_id' => $download_id, 'permission_id' => $permission_id, 'order_id' => $order_id, 'user_id' => $user_id, 'user_ip_address' => $user_ip_address, ); } /** * Get downloads matching criteria. * * @param int $current_page Current viewed page. * @param int $per_page How many results to show per page. */ public function get_items( $current_page, $per_page ) { global $wpdb; $this->max_items = 0; $this->items = array(); $filters = $this->get_filter_vars(); // Get downloads from database. $table = $wpdb->prefix . WC_Customer_Download_Log_Data_Store::get_table_name(); $query_from = " FROM {$table} as downloads "; if ( ! is_null( $filters->product_id ) || ! is_null( $filters->download_id ) || ! is_null( $filters->order_id ) ) { $query_from .= " LEFT JOIN {$wpdb->prefix}woocommerce_downloadable_product_permissions as permissions on downloads.permission_id = permissions.permission_id "; } $query_from .= ' WHERE 1=1 '; if ( ! is_null( $filters->product_id ) ) { $query_from .= $wpdb->prepare( ' AND product_id = %d ', $filters->product_id ); } if ( ! is_null( $filters->download_id ) ) { $query_from .= $wpdb->prepare( ' AND download_id = %s ', $filters->download_id ); } if ( ! is_null( $filters->order_id ) ) { $query_from .= $wpdb->prepare( ' AND order_id = %d ', $filters->order_id ); } if ( ! is_null( $filters->permission_id ) ) { $query_from .= $wpdb->prepare( ' AND downloads.permission_id = %d ', $filters->permission_id ); } if ( ! is_null( $filters->user_id ) ) { $query_from .= $wpdb->prepare( ' AND downloads.user_id = %d ', $filters->user_id ); } if ( ! is_null( $filters->user_ip_address ) ) { $query_from .= $wpdb->prepare( ' AND user_ip_address = %s ', $filters->user_ip_address ); } $query_from = apply_filters( 'woocommerce_report_downloads_query_from', $query_from ); $query_order = $wpdb->prepare( 'ORDER BY timestamp DESC LIMIT %d, %d;', ( $current_page - 1 ) * $per_page, $per_page ); $this->items = $wpdb->get_results( "SELECT * {$query_from} {$query_order}" ); // WPCS: cache ok, db call ok, unprepared SQL ok. $this->max_items = $wpdb->get_var( "SELECT COUNT( DISTINCT download_log_id ) {$query_from};" ); // WPCS: cache ok, db call ok, unprepared SQL ok. } }