. * * ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗ * ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝ * ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝ * ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗ * ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗ * ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ */ class Ai1wm_Backups { /** * Get all backup files * * @return array */ public function get_files() { $backups = array(); // Iterate over directory $iterator = new Ai1wm_Recursive_Directory_Iterator( AI1WM_BACKUPS_PATH ); // Recursively iterate over directory $iterator = new RecursiveIteratorIterator( $iterator, RecursiveIteratorIterator::CHILD_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD ); $iterator->setMaxDepth( 3 ); // Get backup files $iterator = new Ai1wm_Extension_Filter( $iterator, array( 'wpress', 'bin' ) ); foreach ( $iterator as $item ) { try { if ( ai1wm_is_filesize_supported( $item->getPathname() ) ) { $backups[] = array( 'path' => $iterator->getSubPath(), 'filename' => $iterator->getSubPathname(), 'mtime' => $iterator->getMTime(), 'size' => $iterator->getSize(), ); } else { $backups[] = array( 'path' => $iterator->getSubPath(), 'filename' => $iterator->getSubPathname(), 'mtime' => $iterator->getMTime(), 'size' => null, ); } } catch ( Exception $e ) { $backups[] = array( 'path' => $iterator->getSubPath(), 'filename' => $iterator->getSubPathname(), '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 ( validate_file( $file ) === 0 ) { return @unlink( ai1wm_backup_path( array( 'archive' => $file ) ) ); } } /** * 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; } }