$filters Keys: status, format, search. * @return iterable */ public function lines( array $filters ): iterable { yield $this->line( array( 'attachment_id', 'title', 'size', 'format', 'bytes_before', 'bytes_after', 'saved_percent', 'width', 'height', 'method', 'quality', 'status', 'error_code', 'updated_at_utc' ) ); $after = 0; do { $rows = $this->items->export_page( $filters, $after, self::PAGE_SIZE ); $size = count( $rows ); foreach ( $rows as $row ) { $after = (int) $row['id']; $before = (int) $row['bytes_before']; $bytes = (int) $row['bytes_after']; yield $this->line( array( (int) $row['attachment_id'], (string) ( $row['post_title'] ?? '' ), (string) $row['size_name'], (string) $row['format'], $before, $bytes, $before > 0 ? round( ( $before - $bytes ) / $before * 100, 1 ) : 0, (int) $row['w_after'], (int) $row['h_after'], (string) $row['method'], null === $row['quality'] ? '' : (int) $row['quality'], (string) $row['status'], (string) $row['error_code'], (string) $row['updated_at'], ) ); } } while ( self::PAGE_SIZE === $size ); } /** * Formats one CSV line. * * Text starting with a formula character gets an apostrophe, so a crafted image title * cannot run as a formula when the export is opened in a spreadsheet. * * @param array $cells Cells. * @return string */ public function line( array $cells ): string { $out = array(); foreach ( $cells as $cell ) { if ( is_string( $cell ) && preg_match( '/^[=+\-@\t\r]/', $cell ) ) { $cell = "'" . $cell; } $out[] = '"' . str_replace( '"', '""', (string) $cell ) . '"'; } return implode( ',', $out ) . "\r\n"; } }