. * * ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗ * ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝ * ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝ * ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗ * ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗ * ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ */ 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 { $backups[] = array( 'filename' => $item->getFilename(), 'mtime' => $item->getMTime(), 'size' => $item->getSize(), ); } catch ( Exception $e ) { $backups[] = array( 'filename' => $item->getFilename(), 'mtime' => null, 'size' => ai1wm_filesize( $item->getPathname() ), ); } } // 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 ( empty( $file ) ) { throw new Ai1wm_Backups_Exception( __( 'File name is not specified.', AI1WM_PLUGIN_NAME ) ); } else if ( ! unlink( AI1WM_BACKUPS_PATH . DIRECTORY_SEPARATOR . $file ) ) { throw new Ai1wm_Backups_Exception( sprintf( __( 'Unable to delete "%s" file.', AI1WM_PLUGIN_NAME ), AI1WM_BACKUPS_PATH . DIRECTORY_SEPARATOR . $file ) ); } return true; } /** * 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; } }