collector->get_data(); echo '
'; if ( !empty( $data['files'] ) ) { $files_with_errors = 0; $path_components = $components = array(); $largest_file = array( 'path' => null, 'size' => 0 ); foreach ( $data['files'] as &$file ) { $file['_path_components'] = array(); foreach ( array_filter( explode( '/', str_replace( ABSPATH, '', dirname( $file['path'] ) ) ) ) as $path_component ) { $path_components[$path_component] = $file['_path_components'][$path_component] = 1; foreach ( explode( '-', $path_component ) as $smaller_path_component ) $path_components[$smaller_path_component] = $file['_path_components'][$smaller_path_component] = 1; } $components[$file['component']->name] = 1; } echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; foreach ( $data['files'] as $i => $file ) { if ( filesize( $file['path'] ) > $largest_file['size'] ) $largest_file = array( 'path' => $file['path'], 'size' => filesize( $file['path'] ), ); if ( !empty( $file['has_error'] ) ) $files_with_errors++; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
' . esc_html( $this->collector->name() ) . '
'; echo $this->build_sorter( __( '', 'query-monitor-extend' ) ); echo ''; echo $this->build_filter( 'path', array_map( 'esc_attr', array_keys( $path_components ) ), __( 'Path', 'query-monitor-extend' ) ); echo ''; echo $this->build_sorter( __( 'Filesize', 'query-monitor-extend' ) ); echo ''; echo $this->build_filter( 'component', array_map( 'esc_attr', array_keys( $components ) ), __( 'Component', 'query-monitor-extend' ) ); echo '
' . ( $i + 1 ) . '' . esc_html( str_replace( ABSPATH, '/', $file['path'] ) ) . '' . $this->human_file_size( filesize( $file['path'] ) ) . '' . esc_html( $file['component']->name ) . '
'; printf( esc_html__( 'Files in filter: %s', 'query-monitor-extend' ), '' . esc_html( number_format_i18n( count( $data['files']) ) ) . '' ); echo '
' . 'Total: ' . esc_html( number_format_i18n( count( $data['files'] ) ) ) . '' . ( !empty( $files_with_errors ) ? ', With error(s): ' . esc_html( number_format_i18n( $files_with_errors ) ) . '' : '' ) . 'Largest: ' . $this->human_file_size( $largest_file['size'] ) . 'Components: ' . count( $components ) . '
'; echo ''; } else { echo '
'; echo '

' . esc_html__( 'None', 'query-monitor' ) . '

'; echo '
'; } echo '
'; } public function admin_title( array $title ) { $data = $this->collector->get_data(); if ( !empty( $data['files'] ) ) { $_title = sprintf( esc_html_x( '%s F', 'Files count', 'query-monitor-extend' ), number_format_i18n( count( $data['files'] ) ) ); $_title = preg_replace( '#\s?([^0-9,\.]+)#', '$1', $_title ); $title[] = $_title; } return $title; } public function panel_menu( array $menu ) { $menu['files'] = $this->menu( array( 'title' => esc_html__( 'Files', 'query-monitor-extend' ), 'id' => 'query-monitor-extend-files', ) ); return $menu; } private function human_file_size( $bytes ) { $filesize_units = 'BKMGTP'; $factor = floor( ( strlen( $bytes ) - 1 ) / 3 ); return sprintf( "%.2f", $bytes / pow( 1024, $factor ) ) . @$filesize_units[$factor]; } } function register_qmx_output_html_files( array $output ) { if ( $collector = QMX_Collectors::get( 'files' ) ) { $output['files'] = new QMX_Output_Html_Files( $collector ); } return $output; } add_filter( 'qmx/outputter/html', 'register_qmx_output_html_files', 70 );