status = $status; $this->reason_filter = $reason_filter; $this->per_page_option = $per_page_option; parent::__construct( array( 'singular' => 'medien-eintrag', 'plural' => 'medien-eintraege', 'ajax' => false, ) ); } public function get_columns() { $columns = array( 'cb' => '', 'preview' => '', 'path' => __( 'Path', '360-orbit-media-cleaner' ), 'reason' => __( 'Reason', '360-orbit-media-cleaner' ), 'file_size' => __( 'Size', '360-orbit-media-cleaner' ), 'moved_at' => __( 'Moved on', '360-orbit-media-cleaner' ), ); return $columns; } /** Filterbare Gruende auf dem Legacy-Medien-Tab (Original-Backups haben immer nur 'downscaled_original', kein Dropdown noetig). */ public static function filterable_reasons() { return array( 'unused_attachment' => __( 'not referenced anywhere', '360-orbit-media-cleaner' ), 'orphaned_size' => __( 'outdated image size', '360-orbit-media-cleaner' ), 'filesystem_orphan' => __( 'no media library entry', '360-orbit-media-cleaner' ), ); } protected function get_reason_label( $reason ) { $labels = self::filterable_reasons() + array( 'downscaled_original' => __( 'Original downscaled (backup)', '360-orbit-media-cleaner' ) ); return $labels[ $reason ] ?? $reason; } /** Ist dieser Tabellen-Aufruf der "Legacy-Medien"-Tab (nicht Original-Backups, nicht Papierkorb)? Dort macht ein Grund-Filter Sinn. */ private function is_legacy_tab() { return $this->status === 'legacy' && $this->reason_filter !== 'downscaled_original'; } /** Aktuell per ?reason= ausgewaehlter Grund auf dem Legacy-Medien-Tab, oder '' fuer "Alle Gruende". */ private function selected_reason() { if ( ! $this->is_legacy_tab() ) { return ''; } $requested = isset( $_GET['reason'] ) ? sanitize_key( wp_unslash( $_GET['reason'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended return isset( self::filterable_reasons()[ $requested ] ) ? $requested : ''; } /** Dropdown "Nach Grund filtern" fuer den Legacy-Medien-Tab -- steht wie bei den WordPress-Listen in der oberen Tabellen-Leiste (div.tablenav.top) neben den Bulk-Aktionen. Das Auswahlfeld hat bewusst kein name-Attribut und der Knopf ist type="button", damit der per JS/AJAX abgefangene Bulk-Actions-
davon unberuehrt bleibt. Navigiert per JS (admin.js) via GET, setzt dabei die Seiten-Paginierung zurueck. */ protected function extra_tablenav( $which ) { if ( 'top' !== $which || ! $this->is_legacy_tab() ) { return; } $current = $this->selected_reason(); ?>
status === 'legacy' ) { return array( 'restore' => __( 'Move back', '360-orbit-media-cleaner' ), 'trash' => __( 'Move to trash', '360-orbit-media-cleaner' ), ); } return array( 'delete' => __( 'Delete permanently', '360-orbit-media-cleaner' ), ); } public function column_cb( $item ) { return sprintf( '', $item->id ); } private function bucket_dir( $item ) { return $item->reason === 'downscaled_original' ? Wp360_Media_Cleaner_Mover::original_legacy_dir_path() : Wp360_Media_Cleaner_Mover::legacy_dir_path(); } public function column_preview( $item ) { $path = trailingslashit( $this->bucket_dir( $item ) ) . ltrim( $item->original_relative_path, '/' ); if ( preg_match( '/\.(jpe?g|png|gif|webp|avif)$/i', $path ) && is_file( $path ) ) { $upload_dir = wp_get_upload_dir(); $bucket_name = $item->reason === 'downscaled_original' ? 'uploads-original-legacy' : 'uploads-legacy'; $src = trailingslashit( dirname( $upload_dir['baseurl'] ) ) . $bucket_name . '/' . ltrim( $item->original_relative_path, '/' ); return ''; } return ''; } public function column_path( $item ) { $actions = array(); if ( $this->status === 'legacy' ) { $actions['restore'] = sprintf( '%s', $item->id, esc_html__( 'Move back', '360-orbit-media-cleaner' ) ); $actions['trash'] = sprintf( '%s', $item->id, esc_html__( 'Move to trash', '360-orbit-media-cleaner' ) ); } else { $actions['delete'] = sprintf( '%s', $item->id, esc_html__( 'Delete permanently', '360-orbit-media-cleaner' ) ); } return esc_html( $item->original_relative_path ) . $this->row_actions( $actions ); } public function column_reason( $item ) { return esc_html( $this->get_reason_label( $item->reason ) ); } public function column_file_size( $item ) { return esc_html( size_format( (int) $item->file_size ) ); } public function column_moved_at( $item ) { return esc_html( mysql2date( 'd.m.Y H:i', $item->moved_at ) ); } public function prepare_items() { global $wpdb; $per_page = $this->per_page_option ? (int) get_user_option( $this->per_page_option ) : 0; if ( $per_page < 1 ) { $per_page = 30; } $current_page = $this->get_pagenum(); $table = $wpdb->prefix . WP360_MC_TABLE; // Auf dem Legacy-Medien-Tab kann ?reason= den generischen exclude_originals- // Filter auf einen konkreten Grund einschraenken (extra_tablenav()). $selected_reason = $this->selected_reason(); $reason_filter = $selected_reason !== '' ? $selected_reason : $this->reason_filter; if ( $reason_filter === null ) { $where = $wpdb->prepare( 'status = %s', $this->status ); } elseif ( $reason_filter === 'exclude_originals' ) { $where = $wpdb->prepare( 'status = %s AND reason != %s', $this->status, Wp360_Media_Cleaner_Mover::ORIGINAL_BACKUP_REASON ); } else { $where = $wpdb->prepare( 'status = %s AND reason = %s', $this->status, $reason_filter ); } $total_items = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$table} WHERE {$where}" ); // phpcs:ignore $this->items = $wpdb->get_results( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- eigene Tracking-Tabelle, dafuer gibt es keine WP-API; die Liste muss aktuell sein, kein Cache. $wpdb->prepare( "SELECT * FROM {$table} WHERE {$where} ORDER BY moved_at DESC LIMIT %d OFFSET %d", // phpcs:ignore $per_page, ( $current_page - 1 ) * $per_page ) ); $this->_column_headers = array( $this->get_columns(), array(), array() ); $this->set_pagination_args( array( 'total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => (int) ceil( $total_items / $per_page ), ) ); } }