. * * ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗ * ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝ * ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝ * ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗ * ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗ * ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ */ class Ai1wm_Backups { /** * Get all backup files * * @return array */ public function get_files() { $backups = array(); // Get backup files $iterator = new Ai1wm_Extension_Filter( new DirectoryIterator( AI1WM_BACKUPS_PATH ), array( 'wpress', 'bin' ) ); foreach ( $iterator as $item ) { try { if ( ai1wm_is_filesize_supported( $item->getPathname() ) ) { $backups[] = array( 'filename' => $item->getFilename(), 'mtime' => $item->getMTime(), 'size' => $item->getSize(), ); } else { $backups[] = array( 'filename' => $item->getFilename(), 'mtime' => $item->getMTime(), 'size' => null, ); } } catch ( Exception $e ) { $backups[] = array( 'filename' => $item->getFilename(), 'mtime' => null, 'size' => null, ); } } // Sort backups modified date usort( $backups, array( $this, 'compare' ) ); return $backups; } /** * Delete file * * @param string $file File name * @return boolean */ public function delete_file( $file ) { if ( ( $basename = basename( $file ) ) ) { return @unlink( AI1WM_BACKUPS_PATH . DIRECTORY_SEPARATOR . $basename ); } } /** * Compare backup files by modified time * * @param array $a File item A * @param array $b File item B * @return integer */ public function compare( $a, $b ) { if ( $a['mtime'] === $b['mtime'] ) { return 0; } return ( $a['mtime'] > $b['mtime'] ) ? - 1 : 1; } }