|  1:  | <?php | 
|  2:  | 	 | 
|  3:  |  | 
|  4:  |  | 
|  5:  |  | 
|  6:  |  | 
|  7:  |  | 
|  8:  |  | 
|  9:  |  | 
| 10:  |  | 
| 11:  |  | 
| 12:  |  | 
| 13:  |  | 
| 14:  | 	 | 
| 15:  |  | 
| 16:  |  | 
| 17:  |  | 
| 18:  | 	class Zip_Filter extends Archive_Base | 
| 19:  | 	{ | 
| 20:  | 		public static function extract_files($archive, $dest, array $file = null, ?array $opts = array()) | 
| 21:  | 		{ | 
| 22:  | 			$zip = new ZipArchive(); | 
| 23:  | 			if (!$zip->open($archive)) { | 
| 24:  | 				return error("unable to open archive `%(file)s': %(reason)s", [ | 
| 25:  | 					'file'   => $archive, | 
| 26:  | 					'reason' => $zip->getStatusString() | 
| 27:  | 				]); | 
| 28:  | 			} | 
| 29:  | 			$zip->extractTo($dest, $file); | 
| 30:  | 			$zip->close(); | 
| 31:  |  | 
| 32:  | 			return true; | 
| 33:  | 		} | 
| 34:  |  | 
| 35:  | 		public static function list_files($archive, ?array $opts = array()) | 
| 36:  | 		{ | 
| 37:  | 			$zip = new ZipArchive(); | 
| 38:  | 			if (!$zip->open($archive)) { | 
| 39:  | 				return error("unable to open archive `%(file)s': %(reason)s", [ | 
| 40:  | 					'file' => $archive, | 
| 41:  | 					'reason' => $zip->getStatusString() | 
| 42:  | 				]); | 
| 43:  | 			} | 
| 44:  | 			$files = []; | 
| 45:  | 			$n = $zip->count(); | 
| 46:  | 			for ($i = 0; $i < $n; $i++) { | 
| 47:  | 				$stat = $zip->statIndex($i); | 
| 48:  | 				$name = $stat['name']; | 
| 49:  | 				$files[] = [ | 
| 50:  | 					'file_name'   => $name, | 
| 51:  | 					'file_type'   => $name[-1] === '/' ? 'dir' : 'file', | 
| 52:  | 					'can_read'    => true, | 
| 53:  | 					'can_write'   => true, | 
| 54:  | 					'can_execute' => true, | 
| 55:  | 					'size'        => !$stat['size'] ? FILESYSTEM_BLKSZ*1024 : $stat['size'], | 
| 56:  | 					'packed_size' => $stat['comp_size'], | 
| 57:  | 					'crc'         => sprintf("%08X", $stat['crc'] ?? 0), | 
| 58:  | 					'link'        => 0, | 
| 59:  | 					'date'        => $stat['mtime'] | 
| 60:  | 				]; | 
| 61:  | 			} | 
| 62:  | 			return $files; | 
| 63:  |  | 
| 64:  | 		} | 
| 65:  | 	} | 
| 66:  |  |